/* Design tokens: the one set of values every Overdrive Chronicle screen is built from.
   Docs: docs/DESIGN-SYSTEM-17.md · living guide: public/ui-preview.html
   Load this BEFORE home.css / library.css / any screen stylesheet. Unlayered on purpose (same as home.css).

   Two scopes:
   1) :root              names nothing else in the project defines: safe everywhere.
   2) .oc-ui / .home / .library   three names that older layers already use for other things:
        --ink   (game.css :root = #0d1520, used by board.css)
        --line  (game.css :root = #b7a36a45, board.css .game-shell = a length)
        --tap   (board.css .game-shell = a fluid length)
      Defining those on :root would silently restyle the duel board, so they live on the new-UI screen roots only.
      A new screen puts class "oc-ui" on its root element and then reads --ink / --line / --tap like Home does. */

:root{
  /* ---------- spacing: inside a group tighter than around it (see docs) ---------- */
  --s1:4px;   /* icon <-> its own label, number <-> "+" */
  --s2:8px;   /* items inside one group */
  --s3:12px;  /* padding inside pills and small panels */
  --s4:16px;  /* between related groups; screen edge on phones */
  --s5:24px;  /* between unrelated zones; panel padding and screen edge on desktop */
  --s6:32px;  /* between big groups; around the primary action */
  --s7:48px;  /* breathing room on large screens */

  /* ---------- colour roles: surfaces (navy) ---------- */
  --bg:#08111a;                 /* the page behind everything; also the bottom of a sheet gradient */
  --surface-glass:#0a121bd9;    /* floating pills and bars over the scene (translucent) */
  --surface-solid:#0b141e;      /* opaque version of glass: rings, cut-outs */
  --surface-sheet:#0d1824;      /* top of a sheet / detail panel gradient (sheet = this -> --bg) */
  --surface-card:#ffffff08;     /* a card-like block sitting on a sheet */
  --surface-hover:#ffffff0d;    /* hover wash on a ghost control */
  --scrim:#03070cb3;            /* dark layer behind a sheet */

  /* ---------- colour roles: lines ---------- */
  --line-gold:#e2c58947;        /* default hairline (Home) */
  --line-soft:#e2c58933;        /* quieter hairline (Library, dividers) */
  --line-hi:#e9cf98;            /* hovered / emphasised border, avatar ring */

  /* ---------- colour roles: text ---------- */
  --text:#f4ecda;               /* normal text */
  --text-dim:#b9b2a1;           /* secondary text */
  --text-faint:#8f8a7d;         /* hints, kickers, disabled (12px+ only) */
  --text-title:#fff4dc;         /* headings (Taviraj) */
  --text-body:#e7dfcc;          /* long reading text on a sheet */
  --on-gold:#2c1a05;            /* text and icons ON a gold fill */
  --on-gold-dim:#4a2e08;        /* small caption ON a gold fill */

  /* ---------- gold ramp: the brand accent. Reserve for the main action, selection, progress ---------- */
  --gold-1:#ffe7a8;             /* highlight: focus ring, selected text, top of a gold gradient */
  --gold-2:#e2b053;             /* mid: borders of active things, filled badges */
  --gold-3:#9c6420;             /* shade: bottom of a gold gradient */
  --gold-hover-1:#fff1c8;       /* hovered primary button gradient (top -> bottom) */
  --gold-hover-2:#ecbe62;
  --gold-hover-3:#ab7128;
  --gold-fill:linear-gradient(180deg,var(--gold-1),var(--gold-2) 52%,var(--gold-3));              /* primary button */
  --gold-fill-hover:linear-gradient(180deg,var(--gold-hover-1),var(--gold-hover-2) 52%,var(--gold-hover-3));

  /* ---------- status colours: base = fills/borders, -text = readable on navy ---------- */
  --danger:#d8423a;     --danger-text:#f1a59c;
  --success:#5fae7a;    --success-text:#a6dcb8;
  --info:#5ab8ff;       --info-text:#a9deef;

  /* ---------- rarity (gacha, card frames): base = frame/fill, glow = box-shadow/particles, text = on navy ---------- */
  --rarity-n:#8d9aab;    --rarity-n-glow:#8d9aab66;    --rarity-n-text:#b4bfcc;     /* N   steel grey */
  --rarity-r:#4a8fe0;    --rarity-r-glow:#4a8fe08c;    --rarity-r-text:#8fbaf2;     /* R   blue */
  --rarity-sr:#9b6be0;   --rarity-sr-glow:#9b6be099;   --rarity-sr-text:#c9aef5;    /* SR  violet */
  --rarity-ssr:#e2b053;  --rarity-ssr-glow:#ffd27acc;  --rarity-ssr-text:#ffe7a8;   /* SSR gold */

  /* ---------- factions (the five elements): values copied from the game ----------
     --el-*     = the faction colour in duel-app.js (E[k].color): deck crests, tags, borders, library
     --el-*-fx  = the brighter tint in duel-app.js (fxTint): particles, glows, flashes only */
  --el-water:#80a9c9;  --el-water-fx:#5ab8ff;   /* มังกรสีคราม */
  --el-earth:#86a381;  --el-earth-fx:#86e06c;   /* ผืนป่า */
  --el-dark:#ab94be;   --el-dark-fx:#b98bff;    /* ผู้ลงทัณฑ์ */
  --el-light:#d6b97c;  --el-light-fx:#ffd86a;   /* วัลคีรี */
  --el-fire:#c56650;   --el-fire-fx:#ff8052;    /* ราชันยักษา */

  /* ---------- currency ---------- */
  --currency-coin:#f6c95a;   /* gold coin icon and amount */
  --currency-gem:#7fe0ee;    /* gem icon and amount (card.css has its own per-frame --gem: do not reuse that name) */

  /* ---------- type ---------- */
  --font-ui:'Kanit','Leelawadee UI',Tahoma,sans-serif;   /* body, labels, numbers */
  --font-display:'Taviraj',Georgia,serif;                /* titles, Battle, deck names */
  /* size + matching line-height (Thai: body >= 1.55, labels >= 1.25, never below 1.1, min 12px).
     -sm and smaller are for ONE line; if they wrap, switch to --lh-body. */
  --fs-xs:12px;  --lh-xs:1.3;    /* badge, kicker, tile label on phones */
  --fs-sm:13px;  --lh-sm:1.3;    /* caption, hint, button sub-label */
  --fs-md:14px;  --lh-md:1.55;   /* secondary text, chips */
  --fs-base:15px;--lh-base:1.55; /* body */
  --fs-lg:17px;  --lh-lg:1.3;    /* menu row, strong line */
  --fs-xl:20px;  --lh-xl:1.3;    /* panel title, deck name */
  --fs-2xl:24px; --lh-2xl:1.3;   /* sheet title */
  --fs-3xl:30px; --lh-3xl:1.25;  /* primary action word, page title */
  --fs-4xl:38px; --lh-4xl:1.1;   /* hero / reveal word: the lowest line-height allowed */
  --lh-body:1.55; --lh-loose:1.65; --lh-label:1.3; --lh-button:1.25; --lh-display:1.1;
  /* ready-made shorthands: font:var(--type-body) */
  --type-body:500 var(--fs-base)/var(--lh-body) var(--font-ui);
  --type-label:600 var(--fs-sm)/var(--lh-label) var(--font-ui);
  --type-button:600 var(--fs-md)/var(--lh-button) var(--font-ui);
  --type-title:700 var(--fs-2xl)/var(--lh-2xl) var(--font-display);
  --type-display:800 var(--fs-3xl)/var(--lh-3xl) var(--font-display);
  --tracking-label:.06em;       /* small caps-like labels */
  --tracking-kicker:.14em;      /* uppercase kickers */

  /* ---------- radii: use the step, not a new number ---------- */
  --r-4:4px;   /* progress bars, tiny marks */
  --r-6:6px;   /* badges, tags */
  --r-8:8px;   /* small stat boxes, cards in a grid */
  --r-10:10px; /* buttons, chips, mode tiles */
  --r-12:12px; /* rows, tiles, small panels */
  --r-14:14px; /* panels, banners */
  --r-18:18px; /* the dock, big containers */
  --r-pill:999px; /* pills, round buttons (circle = 50%) */

  /* ---------- game shapes ---------- */
  --cut-s:11px; --cut-m:14px; --cut-l:18px; --cut-xl:24px;   /* corner cut of a button bar (set --cut to one of these) */
  --clip-hex:polygon(50% 0,96% 25%,96% 75%,50% 100%,4% 75%,4% 25%);    /* crest / emblem hexagon */
  --clip-badge:polygon(7px 0,calc(100% - 7px) 0,100% 50%,calc(100% - 7px) 100%,7px 100%,0 50%);  /* small count badge */
  /* the button bar uses a variable cut, and a variable cannot be baked into a token: use the class .u-cut-bar below */

  /* ---------- elevation ---------- */
  --elev-1:0 4px 12px #0006;          /* pills, chips floating over the scene */
  --elev-2:0 10px 26px #0008;         /* banners, docks, floating panels */
  --elev-3:0 18px 40px #000d;         /* popovers, dropdown panels */
  --elev-sheet:-20px 0 50px #000a;    /* side sheet edge */
  --elev-drop:drop-shadow(0 10px 22px #000b);   /* filter for clip-path buttons (box-shadow would be clipped) */
  --glow-gold:0 0 10px #e2b053aa;     /* "this is on / chosen" */
  --glow-gold-strong:0 0 8px var(--gold-1);

  /* ---------- motion ---------- */
  --dur-fast:150ms;    /* hover, press, colour changes */
  --dur-base:220ms;    /* sheets, panels, small enters */
  --dur-slow:400ms;    /* large enters, counters */
  --dur-scene:800ms;   /* cinematic beats (gacha reveal); the only place long motion is allowed */
  --ease-standard:cubic-bezier(.4,0,.2,1);    /* things that move and stay on screen */
  --ease-enter:cubic-bezier(.2,.8,.3,1);      /* things arriving (the sheet slide-in) */
  --ease-exit:cubic-bezier(.4,0,1,1);         /* things leaving */
  --ease-overshoot:cubic-bezier(.34,1.56,.64,1);   /* a reward landing, a badge popping */

  /* ---------- layers (z-index): real values already in the project, never reorder ----------
     Home and Library each form their own stacking context (isolation:isolate), so the small numbers are local. */
  --z-home-art:-1;     /* Home: painted scene */
  --z-home-leader:1;   /* Home: Leader standee */
  --z-home-ui:2;       /* Home: side column, dock, Battle */
  --z-home-top:3;      /* Home: top bar */
  --z-home-scrim:5;    /* Home: dark layer behind a sheet */
  --z-home-sheet:6;    /* Home: side sheets */
  --z-library:35;      /* Library screen (full screen); inside it: count badge 6, filter panel 8, scrim 9, detail 10 */
  --z-gacha:37;        /* Gacha screen: above Library, below dialogs (new) */
  --z-fx:38;           /* full-screen fx canvas (new): above gacha, below dialogs so a confirm box stays readable */
  --z-gacha-stage:39;  /* gacha pack + revealed cards: ABOVE the fx canvas, so light plays behind the cards and never washes out their art */
  --z-modal:40;        /* .modal-root: settings, rules, result, confirm dialogs */
  --z-toast:60;        /* .toast, the dragged-card ghost on the board */
  --z-rotate:2147483000;   /* "rotate your phone" gate (board.css .rotate-notice uses 2147483647) */

  /* ---------- focus ---------- */
  --focus-color:var(--gold-1);
  --focus-ring:2px solid var(--focus-color);  /* outline:var(--focus-ring) */
  --focus-offset:3px;                         /* outline-offset; 2px on dense controls */
}

/* New-UI screen scope (also .home and .library, which predate the class). Zero specificity so a screen can override. */
:where(.oc-ui,.home,.library){
  --ink:var(--surface-glass);
  --ink-solid:var(--surface-solid);
  --line:var(--line-gold);
  --tap:48px;                   /* minimum touch target; dense screens may set 44px */
}

/* Base for a new screen: font, Thai line breaking, button reset, focus ring. */
.oc-ui{
  color:var(--text);font:var(--type-body);
  /* Thai has no spaces between words: break only between phrases, so a word is never split (การัน|ตี) */
  word-break:keep-all;overflow-wrap:anywhere;
}
.oc-ui :where(button){font:inherit;color:inherit;cursor:pointer;-webkit-tap-highlight-color:transparent}
.oc-ui :where(button,a,input,[tabindex]):focus-visible{outline:var(--focus-ring);outline-offset:var(--focus-offset)}
.oc-ui :where(h1,h2,h3,p){margin:0}

/* Cut-corner button bar: <button class="u-cut-bar" style="--cut:var(--cut-l)">; fill it with background, add depth with filter, not box-shadow. */
.u-cut-bar{
  --cut:var(--cut-l);
  clip-path:polygon(var(--cut) 0,calc(100% - var(--cut)) 0,100% 50%,calc(100% - var(--cut)) 100%,var(--cut) 100%,0 50%);
}

/* Reduced motion: every duration token collapses, so anything built on tokens obeys it for free. */
@media (prefers-reduced-motion:reduce){
  :root{--dur-fast:.01ms;--dur-base:.01ms;--dur-slow:.01ms;--dur-scene:.01ms}
}
