/* ============================================================
   Solkemon Design System v1
   Tokens + utility classes. Prefix `ds-` to avoid collisions
   with the legacy inline-style world.

   How to use:
     <button class="ds-btn ds-btn--primary">Save</button>
     <div class="ds-card">...</div>
     <div class="ds-stack ds-stack--md">...</div>
     <h2 class="ds-h2">Title</h2>

   Migrate one component at a time. Don't touch legacy classes —
   add ds-* alongside, drop inline styles when comfortable.
   ============================================================ */

:root {
    /* ── Colors: brand ─────────────────────────────────────── */
    --ds-color-brand-50:  #eef2ff;
    --ds-color-brand-100: #e0e7ff;
    --ds-color-brand-300: #818cf8;
    --ds-color-brand-500: #4f46e5;   /* primary */
    --ds-color-brand-600: #4338ca;
    --ds-color-brand-700: #3730a3;
    --ds-color-brand-900: #1e1b4b;   /* deep brand bg */

    /* ── Colors: accent (Solana-ish) ───────────────────────── */
    --ds-color-accent-400: #34d399;
    --ds-color-accent-500: #10b981;  /* success / accept */
    --ds-color-accent-600: #059669;

    /* ── Colors: warning / danger ──────────────────────────── */
    --ds-color-warn-500:   #f59e0b;
    --ds-color-danger-500: #ef4444;
    --ds-color-danger-600: #dc2626;

    /* ── Colors: surfaces (light theme — modals are light) ─ */
    --ds-color-surface-0:  #ffffff;
    --ds-color-surface-1:  #f9fafb;
    --ds-color-surface-2:  #f3f4f6;
    --ds-color-surface-3:  #e5e7eb;

    /* ── Colors: dark surfaces (game UI) ───────────────────── */
    --ds-color-dark-0:     #0c0a23;
    --ds-color-dark-1:     #16142e;
    --ds-color-dark-2:     #1e1b4b;
    --ds-color-dark-3:     #312e81;

    /* ── Text contrast ─────────────────────────────────────── */
    --ds-text-primary:     #111827;
    --ds-text-secondary:   #4b5563;
    --ds-text-muted:       #9ca3af;
    --ds-text-inverse:     #f9fafb;

    /* ── Borders ───────────────────────────────────────────── */
    --ds-border-subtle:    #e5e7eb;
    --ds-border-default:   #d1d5db;
    --ds-border-strong:    #9ca3af;

    /* ── Spacing scale (4-pt grid) ─────────────────────────── */
    --ds-space-xs:  4px;
    --ds-space-sm:  8px;
    --ds-space-md:  12px;
    --ds-space-lg:  16px;
    --ds-space-xl:  24px;
    --ds-space-2xl: 32px;
    --ds-space-3xl: 48px;

    /* ── Radius ────────────────────────────────────────────── */
    --ds-radius-sm:   6px;
    --ds-radius-md:   10px;
    --ds-radius-lg:   14px;
    --ds-radius-xl:   20px;
    --ds-radius-full: 9999px;

    /* ── Shadows ───────────────────────────────────────────── */
    --ds-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --ds-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.12);
    --ds-shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.20);
    --ds-shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.28);

    /* ── Typography sizes ──────────────────────────────────── */
    --ds-text-xs:   11px;
    --ds-text-sm:   13px;
    --ds-text-md:   15px;
    --ds-text-lg:   18px;
    --ds-text-xl:   22px;
    --ds-text-2xl:  28px;
    --ds-text-3xl:  36px;

    /* ── Line heights ──────────────────────────────────────── */
    --ds-leading-tight: 1.2;
    --ds-leading-snug:  1.4;
    --ds-leading-normal: 1.55;

    /* ── Transitions ───────────────────────────────────────── */
    --ds-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --ds-dur-fast: 120ms;
    --ds-dur-base: 200ms;
    --ds-dur-slow: 320ms;
}

/* ============================================================
   Buttons
   ============================================================ */
.ds-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-sm);
    padding: 10px 18px;
    min-height: 40px;
    font-family: inherit;
    font-size: var(--ds-text-md);
    font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    border-radius: var(--ds-radius-md);
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color var(--ds-dur-fast) var(--ds-ease-out),
                border-color var(--ds-dur-fast) var(--ds-ease-out),
                transform var(--ds-dur-fast) var(--ds-ease-out),
                box-shadow var(--ds-dur-fast) var(--ds-ease-out);
    white-space: nowrap;
}
.ds-btn:active:not(:disabled) { transform: translateY(1px); }
.ds-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.ds-btn--primary {
    background: var(--ds-color-brand-500);
    color: var(--ds-text-inverse);
    box-shadow: var(--ds-shadow-sm);
}
.ds-btn--primary:hover:not(:disabled) {
    background: var(--ds-color-brand-600);
    box-shadow: var(--ds-shadow-md);
}

.ds-btn--accent {
    background: var(--ds-color-accent-500);
    color: var(--ds-text-inverse);
    box-shadow: var(--ds-shadow-sm);
}
.ds-btn--accent:hover:not(:disabled) {
    background: var(--ds-color-accent-600);
    box-shadow: var(--ds-shadow-md);
}

.ds-btn--ghost {
    background: transparent;
    color: var(--ds-text-primary);
    border-color: var(--ds-border-default);
}
.ds-btn--ghost:hover:not(:disabled) {
    background: var(--ds-color-surface-2);
    border-color: var(--ds-border-strong);
}

.ds-btn--ghost-light {
    background: rgba(255, 255, 255, 0.12);
    color: var(--ds-text-inverse);
    border-color: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.ds-btn--ghost-light:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.22);
}

.ds-btn--danger {
    background: var(--ds-color-danger-500);
    color: var(--ds-text-inverse);
}
.ds-btn--danger:hover:not(:disabled) {
    background: var(--ds-color-danger-600);
}

.ds-btn--sm {
    padding: 6px 12px;
    min-height: 32px;
    font-size: var(--ds-text-sm);
    border-radius: var(--ds-radius-sm);
}
.ds-btn--lg {
    padding: 14px 24px;
    min-height: 48px;
    font-size: var(--ds-text-lg);
    border-radius: var(--ds-radius-lg);
}
.ds-btn--block { width: 100%; }
.ds-btn--icon {
    padding: 0;
    width: 36px;
    min-width: 36px;
    min-height: 36px;
    aspect-ratio: 1;
    border-radius: var(--ds-radius-full);
}

/* ============================================================
   Cards & surfaces
   ============================================================ */
.ds-card {
    background: var(--ds-color-surface-0);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-lg);
    padding: var(--ds-space-lg);
    box-shadow: var(--ds-shadow-sm);
}
.ds-card--elevated  { box-shadow: var(--ds-shadow-md); }
.ds-card--floating  { box-shadow: var(--ds-shadow-lg); border: none; }
.ds-card--muted     { background: var(--ds-color-surface-1); }
.ds-card--padded    { padding: var(--ds-space-xl); }
.ds-card--compact   { padding: var(--ds-space-md); }

.ds-card--glass {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: var(--ds-text-inverse);
}

/* ============================================================
   Modal scaffolding (use with the data-backdrop-close pattern)
   ============================================================ */
.ds-modal-backdrop {
    position: fixed;
    inset: 0;
    /* Almost invisible sheet — use filter "none" (not blur(0)) to avoid GPU dimming */
    background: rgba(0, 0, 0, 0.02);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--ds-space-lg);
    animation: ds-fade-in var(--ds-dur-base) var(--ds-ease-out);
}
.ds-modal-card {
    position: relative;
    background: var(--ds-color-surface-0);
    border-radius: var(--ds-radius-xl);
    box-shadow: none;
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: ds-pop-in var(--ds-dur-base) var(--ds-ease-out);
}
.ds-modal-header {
    padding: var(--ds-space-lg) var(--ds-space-xl);
    border-bottom: 1px solid var(--ds-border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-md);
    background: linear-gradient(135deg, var(--ds-color-brand-700), var(--ds-color-brand-500));
    color: var(--ds-text-inverse);
}
.ds-modal-title {
    font-size: var(--ds-text-xl);
    font-weight: 700;
    line-height: var(--ds-leading-tight);
    margin: 0;
}
.ds-modal-body {
    padding: var(--ds-space-xl);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
}
.ds-modal-footer {
    padding: var(--ds-space-md) var(--ds-space-xl);
    border-top: 1px solid var(--ds-border-subtle);
    display: flex;
    gap: var(--ds-space-sm);
    justify-content: flex-end;
    background: var(--ds-color-surface-1);
}

/* ============================================================
   Layout helpers
   ============================================================ */
.ds-stack         { display: flex; flex-direction: column; gap: var(--ds-space-md); }
.ds-stack--xs     { gap: var(--ds-space-xs); }
.ds-stack--sm     { gap: var(--ds-space-sm); }
.ds-stack--lg     { gap: var(--ds-space-lg); }
.ds-stack--xl     { gap: var(--ds-space-xl); }

.ds-row           { display: flex; flex-direction: row; gap: var(--ds-space-md); align-items: center; }
.ds-row--wrap     { flex-wrap: wrap; }
.ds-row--between  { justify-content: space-between; }
.ds-row--end      { justify-content: flex-end; }
.ds-row--center   { justify-content: center; }
.ds-row--top      { align-items: flex-start; }

.ds-grid           { display: grid; gap: var(--ds-space-md); }
.ds-grid--2        { grid-template-columns: repeat(2, 1fr); }
.ds-grid--3        { grid-template-columns: repeat(3, 1fr); }
.ds-grid--4        { grid-template-columns: repeat(4, 1fr); }
.ds-grid--auto-sm  { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.ds-grid--auto-md  { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.ds-grid--auto-lg  { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

@media (max-width: 640px) {
    .ds-grid--2,
    .ds-grid--3,
    .ds-grid--4 { grid-template-columns: 1fr; }
}

.ds-divider {
    height: 1px;
    background: var(--ds-border-subtle);
    border: 0;
    margin: var(--ds-space-md) 0;
}

/* ============================================================
   Typography
   ============================================================ */
.ds-h1 { font-size: var(--ds-text-3xl); font-weight: 800; line-height: var(--ds-leading-tight); margin: 0; color: var(--ds-text-primary); }
.ds-h2 { font-size: var(--ds-text-2xl); font-weight: 700; line-height: var(--ds-leading-tight); margin: 0; color: var(--ds-text-primary); }
.ds-h3 { font-size: var(--ds-text-xl); font-weight: 700; line-height: var(--ds-leading-snug); margin: 0; color: var(--ds-text-primary); }
.ds-h4 { font-size: var(--ds-text-lg); font-weight: 600; line-height: var(--ds-leading-snug); margin: 0; color: var(--ds-text-primary); }
.ds-body         { font-size: var(--ds-text-md); line-height: var(--ds-leading-normal); color: var(--ds-text-primary); margin: 0; }
.ds-body--small  { font-size: var(--ds-text-sm); line-height: var(--ds-leading-normal); color: var(--ds-text-secondary); margin: 0; }
.ds-caption      { font-size: var(--ds-text-xs); line-height: var(--ds-leading-snug); color: var(--ds-text-muted); margin: 0; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.ds-text-muted   { color: var(--ds-text-muted); }
.ds-text-success { color: var(--ds-color-accent-600); }
.ds-text-warn    { color: var(--ds-color-warn-500); }
.ds-text-danger  { color: var(--ds-color-danger-500); }
.ds-text-center  { text-align: center; }
.ds-truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================
   Stat tile (used in profile, leaderboard, battle pass)
   ============================================================ */
.ds-stat {
    background: var(--ds-color-surface-1);
    border: 1px solid var(--ds-border-subtle);
    border-radius: var(--ds-radius-md);
    padding: var(--ds-space-md);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-height: 88px;
    justify-content: center;
}
.ds-stat__icon  { font-size: 22px; line-height: 1; margin-bottom: 4px; opacity: 0.9; }
.ds-stat__value { font-size: var(--ds-text-xl); font-weight: 800; color: var(--ds-text-primary); line-height: 1.1; }
.ds-stat__label { font-size: var(--ds-text-xs); color: var(--ds-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.ds-stat--dark {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}
.ds-stat--dark .ds-stat__value { color: var(--ds-text-inverse); }
.ds-stat--dark .ds-stat__label { color: rgba(255, 255, 255, 0.7); }

/* ============================================================
   Badges & chips
   ============================================================ */
.ds-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    font-size: var(--ds-text-xs);
    font-weight: 700;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface-2);
    color: var(--ds-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1;
}
.ds-badge--brand   { background: var(--ds-color-brand-100); color: var(--ds-color-brand-700); }
.ds-badge--success { background: #d1fae5; color: #065f46; }
.ds-badge--warn    { background: #fef3c7; color: #92400e; }
.ds-badge--danger  { background: #fee2e2; color: var(--ds-color-danger-600); }

/* ============================================================
   Animations
   ============================================================ */
@keyframes ds-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes ds-pop-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================
   Mobile tweaks
   ============================================================ */
@media (max-width: 640px) {
    .ds-modal-backdrop { padding: 0; }
    .ds-modal-card {
        max-width: 100%;
        max-height: 100dvh;
        border-radius: 0;
        height: 100dvh;
    }
    .ds-modal-header { padding: var(--ds-space-md) var(--ds-space-lg); }
    .ds-modal-body   { padding: var(--ds-space-lg); }
    .ds-modal-title  { font-size: var(--ds-text-lg); }

    .ds-h1 { font-size: var(--ds-text-2xl); }
    .ds-h2 { font-size: var(--ds-text-xl); }
    .ds-h3 { font-size: var(--ds-text-lg); }
}
