/*
 * Colosseum design system (UI-SPEC §1): tokens, reset, typography, components.
 * Screen stylesheets (css/home.css, css/battle.css) build on these tokens and classes; never redefine them.
 *
 * Tokens:      --bg-*, --panel*, --line*, --text, --muted, --faint, --gold*, --red-team, --blue-team,
 *              gilded layer (DECISIONS 29): --ink-*, --gild-*, --crimson*, --sapphire*, --parchment*, --font-serif,
 *              --grain, --ink-panel, --gild-rule, --gild-glow (ornament art: /assets/ui/ frame, medallion, gem-*, seal),
 *              --ok/--warn/--bad/--info, --buff/--debuff, --el-<element>, --radius*, --shadow*, --dur*, --ease,
 *              --font-display (pixel: big headings, banners, countdowns only) / --font-ui (condensed sans with tabular
 *              figures: every small label and number, DECISIONS 30) / --font-body / --font-mono, --z-* layers, --tile (ability tile size).
 * Components:  .btn .ico .chip .kbd .panel .tabs .toast .modal .tooltip .popover .ring .drawer .meter .pips .seg
 *              .gilded (obsidian panel in the gold 9-slice filigree frame) .medal (portrait in the gold medallion ring)
 *              .switch .field/.input/.select .ability-card .ability-tile .fighter-card .tdiag .portrait .spinner
 * Utilities:   .sr-only .muted .row .stack .grow .scroll .divider .pixel .display .num
 */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: dark;
  --bg-0: #080b12;
  --bg-1: #0c111b;
  --bg-2: #121827;
  --panel: rgba(14, 18, 28, 0.88);
  --panel-solid: #0e121c;
  --panel-2: #161d2d;
  --panel-3: #1c2538;
  --panel-hover: #222d45;
  --line: #3a4560;
  --line-soft: #262f45;
  --line-strong: #55638a;
  --text: #e9edf5;
  --muted: #9aa6bf;
  --faint: #6c7896;
  --gold: #e8c35a;
  --gold-2: #f6dc8f;
  --gold-3: #b8902e;
  --gold-ink: #1c1505;
  --gold-soft: rgba(232, 195, 90, 0.16);
  --gold-glow: 0 0 0 1px rgba(232, 195, 90, 0.55), 0 0 18px rgba(232, 195, 90, 0.28);
  --red-team: #ef5b5f;
  --red-team-soft: rgba(239, 91, 95, 0.16);
  --blue-team: #4b93ff;
  --blue-team-soft: rgba(75, 147, 255, 0.16);
  --ok: #46c27a;
  --warn: #f0a33a;
  --bad: #ef5656;
  --info: #5aa9e8;
  --buff: #4cc38a;
  --debuff: #ef6a6a;
  --neutral: #b98cff;
  /* element colours (from shared/pixelart/icons.js ELEMENT_UI) */
  --el-earth: #c08a52;
  --el-air: #86d0ff;
  --el-water: #4d7dff;
  --el-fire: #ff5a2a;
  --el-space: #9b6bff;
  --el-time: #e8c640;
  --el-light: #fff0a6;
  --el-dark: #9a5cff;
  --el-none: #a7b0c2;
  --el-variable: linear-gradient(90deg, #ff5a2a, #e8c640, #86d0ff, #4d7dff, #9b6bff);
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.35);
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.35);
  --inset: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 160ms;
  --dur-slow: 200ms;
  --font-display: 'Silkscreen', ui-monospace, 'Cascadia Mono', 'Consolas', monospace;
  --font-ui: 'Barlow Semi Condensed', 'Barlow', 'Segoe UI', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', 'SFMono-Regular', Consolas, monospace;
  --z-base: 1;
  --z-sticky: 10;
  --z-drawer: 40;
  --z-modal: 60;
  --z-popover: 70;
  --z-tooltip: 80;
  --z-toast: 90;
  --tile: 56px;
  --focus: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--gold);

  /* gilded JRPG layer (DECISIONS 29): obsidian ink, burnished gold, crimson Red, sapphire Blue */
  --ink-0: #08070b;
  --ink-1: #100e15;
  --ink-2: #18151e;
  --ink-3: #231f2b;
  --ink-line: #3b3124;
  --gild-hi: #fff2bf;
  --gild: #e6bf62;
  --gild-mid: #b5862f;
  --gild-lo: #5c3c14;
  --crimson: #d23f48;
  --crimson-hi: #ff8a8e;
  --crimson-deep: #3a0d14;
  --sapphire: #3b78e6;
  --sapphire-hi: #9cc0ff;
  --sapphire-deep: #0b1a3a;
  --parchment: #f1e8d4;
  --parchment-muted: #b4a98f;
  --font-serif: 'Cinzel', 'Trajan Pro', Georgia, 'Times New Roman', serif;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .92 0 0 0 0 .75 0 0 0 .055 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --ink-panel: var(--grain), linear-gradient(180deg, rgba(37, 31, 43, 0.97) 0%, rgba(20, 17, 25, 0.98) 38%, rgba(12, 10, 16, 0.98) 100%);
  --gild-rule: linear-gradient(90deg, transparent, var(--gild-lo) 6%, var(--gild-mid) 20%, var(--gild-hi) 50%, var(--gild-mid) 80%, var(--gild-lo) 94%, transparent);
  --gild-glow: 0 0 0 1px rgba(255, 226, 140, 0.75), 0 0 14px rgba(255, 200, 90, 0.45);
}
@media (max-width: 1279px) { :root { --tile: 48px; } }
@media (max-width: 600px) { :root { --tile: 56px; } }

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 50% -10%, #17203a 0%, var(--bg-1) 55%, var(--bg-0) 100%) fixed, var(--bg-1);
  color: var(--text);
  font: 14px/1.45 var(--font-body);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
img, svg, canvas, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--gold-2); text-underline-offset: 2px; }
p { margin: 0 0 0.6em; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.15; }
ul, ol { margin: 0; padding: 0; list-style: none; }
[hidden] { display: none !important; }
:focus-visible { outline: none; box-shadow: var(--focus); }
::selection { background: rgba(232, 195, 90, 0.35); }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ------------------------------------------------------------------ typography + utilities */
.display, h1.display, h2.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.h1 { font: 400 28px/1.1 var(--font-display); letter-spacing: 0.05em; text-transform: uppercase; }
.h2 { font: 400 18px/1.2 var(--font-display); letter-spacing: 0.05em; text-transform: uppercase; }
.h3 { font: 700 14px/1.3 var(--font-body); }
.eyebrow { font: 600 12px/1 var(--font-ui); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.gold { color: var(--gold); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.small { font-size: 12px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row--wrap { flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.scroll { overflow: auto; overscroll-behavior: contain; }
.divider { height: 1px; background: var(--line-soft); border: 0; margin: 8px 0; }
.vdivider { width: 1px; align-self: stretch; background: var(--line-soft); }
.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ app shell */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; animation: screen-in var(--dur-slow) var(--ease); }
@keyframes screen-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.boot {
  position: fixed; inset: 0; display: grid; place-items: center; gap: 16px; align-content: center;
  background: var(--bg-1); z-index: 100; transition: opacity var(--dur-slow) var(--ease);
}
.boot.is-done { opacity: 0; pointer-events: none; }
.logo {
  font: 400 34px/1 var(--font-display); letter-spacing: 0.08em; color: var(--gold);
  text-shadow: 0 2px 0 var(--gold-3), 0 0 24px rgba(232, 195, 90, 0.35);
}
.conn-banner {
  position: fixed; left: 50%; top: 10px; transform: translateX(-50%); z-index: var(--z-toast);
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: var(--radius-pill);
  background: rgba(40, 22, 12, 0.94); border: 1px solid #6b4a1e; color: #ffd9a1; font-size: 12px; box-shadow: var(--shadow-sm);
}
.screen-placeholder { margin: auto; max-width: 440px; padding: 24px; text-align: center; }

/* ------------------------------------------------------------------ icon */
.ico { width: 16px; height: 16px; flex: none; image-rendering: pixelated; image-rendering: crisp-edges; user-select: none; -webkit-user-drag: none; }
.ico--12 { width: 12px; height: 12px; image-rendering: auto; }
.ico--24 { width: 24px; height: 24px; }
.ico--32 { width: 32px; height: 32px; }
.ico--48 { width: 48px; height: 48px; }

/* ------------------------------------------------------------------ button */
.btn {
  --btn-bg: var(--panel-3); --btn-bd: var(--line); --btn-fg: var(--text); --btn-hover: var(--panel-hover);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--btn-bd);
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 600; font-size: 13px; line-height: 1; white-space: nowrap;
  box-shadow: var(--inset), 0 1px 0 rgba(0, 0, 0, 0.35);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), opacity var(--dur-fast);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--line-strong); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.45; }
.btn[aria-pressed='true'] { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold), var(--inset); color: var(--gold-2); }
.btn--primary {
  --btn-bg: linear-gradient(180deg, #f3d57e 0%, var(--gold) 55%, #d1a83f 100%); --btn-bd: #f7e2a2; --btn-fg: var(--gold-ink);
  --btn-hover: linear-gradient(180deg, #f8e19a 0%, #eccb6a 55%, #d9b24a 100%);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35); box-shadow: 0 2px 0 var(--gold-3), 0 6px 18px rgba(232, 195, 90, 0.22);
}
.btn--primary:hover:not(:disabled) { border-color: #fff0c4; }
.btn--primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--gold-3); }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-hover: rgba(255, 255, 255, 0.06); box-shadow: none; color: var(--muted); }
.btn--ghost:hover:not(:disabled) { color: var(--text); border-color: transparent; }
.btn--danger { --btn-bg: rgba(239, 86, 86, 0.14); --btn-bd: rgba(239, 86, 86, 0.55); --btn-fg: #ffb4b4; --btn-hover: rgba(239, 86, 86, 0.24); }
.btn--success { --btn-bg: rgba(70, 194, 122, 0.16); --btn-bd: rgba(70, 194, 122, 0.6); --btn-fg: #aef0c8; --btn-hover: rgba(70, 194, 122, 0.26); }
.btn--red { --btn-bg: var(--red-team-soft); --btn-bd: rgba(239, 91, 95, 0.6); --btn-fg: #ffc2c4; --btn-hover: rgba(239, 91, 95, 0.26); }
.btn--blue { --btn-bg: var(--blue-team-soft); --btn-bd: rgba(75, 147, 255, 0.6); --btn-fg: #c4dcff; --btn-hover: rgba(75, 147, 255, 0.26); }
.btn--sm { min-height: 28px; padding: 0 10px; font-size: 12px; gap: 6px; border-radius: var(--radius-sm); }
.btn--lg { min-height: 48px; padding: 0 22px; font: 400 15px/1 var(--font-display); letter-spacing: 0.06em; text-transform: uppercase; border-radius: 10px; }
.btn--block { display: flex; width: 100%; }
.btn--icon { padding: 0; width: 36px; min-width: 36px; }
.btn--icon.btn--sm { width: 28px; min-width: 28px; }
.btn--icon.btn--lg { width: 48px; min-width: 48px; }
.btn__badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font: 700 11px/18px var(--font-body); box-shadow: 0 0 0 2px var(--bg-1);
}
.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--btn-fg) transparent var(--btn-fg) transparent; animation: spin 0.8s linear infinite;
}
@media (pointer: coarse) { .btn { min-height: 44px; } .btn--sm { min-height: 36px; } .btn--icon { width: 44px; min-width: 44px; } }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--gold); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ chips + badges */
.chip {
  --chip-c: var(--muted);
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px 0 6px; border-radius: var(--radius-pill);
  border: 1px solid color-mix(in srgb, var(--chip-c) 55%, transparent);
  background: color-mix(in srgb, var(--chip-c) 14%, rgba(10, 13, 20, 0.6));
  color: color-mix(in srgb, var(--chip-c) 55%, white); font-size: 11.5px; font-weight: 600; white-space: nowrap; line-height: 1;
}
.chip .ico { width: 14px; height: 14px; image-rendering: auto; }
.chip--lg { height: 26px; font-size: 12.5px; padding: 0 10px 0 7px; }
.chip--lg .ico { width: 16px; height: 16px; image-rendering: pixelated; }
.chip--icon-only { padding: 0 4px; }
.chip__sub { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.chip--split { background: linear-gradient(90deg, color-mix(in srgb, var(--chip-a) 22%, transparent) 50%, color-mix(in srgb, var(--chip-b) 22%, transparent) 50%); border-color: var(--line-strong); color: var(--text); }
.chip--variable { border-color: transparent; background: linear-gradient(var(--bg-2), var(--bg-2)) padding-box, var(--el-variable) border-box; color: var(--text); }
.chip--buff { --chip-c: var(--buff); }
.chip--debuff { --chip-c: var(--debuff); }
.chip--neutral { --chip-c: var(--neutral); }
.chip--gold { --chip-c: var(--gold); }
.chip--info { --chip-c: var(--info); }
.chip--red { --chip-c: var(--red-team); }
.chip--blue { --chip-c: var(--blue-team); }
.chip--bad { --chip-c: var(--bad); }
.chip--cpu { --chip-c: #5ad1e8; }
.chip--rare {
  --chip-c: var(--gold); height: 18px; padding: 0 6px; font: 700 11px/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase;
  background: linear-gradient(180deg, #f3d57e, #c99a33); color: var(--gold-ink); border-color: #f7e2a2;
}
.chip--cost { --chip-c: #5ad1e8; font-variant-numeric: tabular-nums; }
.chip--cost.is-short { --chip-c: var(--bad); }
.kbd {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom-width: 2px; color: var(--muted);
  font: 600 10.5px/1 var(--font-mono);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot--ok { background: var(--ok); box-shadow: 0 0 8px rgba(70, 194, 122, 0.6); }
.dot--warn { background: var(--warn); }
.dot--bad { background: var(--bad); }

/* ------------------------------------------------------------------ panel */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm), var(--inset); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); min-width: 0;
}
.panel--solid { background: var(--panel-solid); backdrop-filter: none; }
.panel--raised { background: var(--panel-2); box-shadow: var(--shadow); }
.panel--flat { background: rgba(255, 255, 255, 0.02); border-color: var(--line-soft); box-shadow: none; backdrop-filter: none; }
.panel--gold { border-color: rgba(232, 195, 90, 0.6); box-shadow: var(--gold-glow); }
/* gilded frame: the Codex filigree 9-slice drawn just outside the box (its band sits 4 px inside the image) */
.gilded { position: relative; background: var(--ink-panel); }
.gilded::after {
  content: ''; position: absolute; inset: -4px; pointer-events: none; z-index: 2;
  border: 16px solid transparent; border-image: url(/assets/ui/frame.png) 16 / 16px stretch; image-rendering: pixelated;
}
.panel__head { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
.panel__title { font: 600 13px/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 8px; }
.panel__actions { display: flex; gap: 4px; align-items: center; }
.panel__body { padding: 12px; min-width: 0; }
.panel__body--flush { padding: 0; }
.panel__foot { padding: 10px 12px; border-top: 1px solid var(--line-soft); display: flex; gap: 8px; justify-content: flex-end; }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; flex-direction: column; min-height: 0; }
.tabs__list { display: flex; gap: 2px; padding: 4px; border-bottom: 1px solid var(--line-soft); overflow-x: auto; scrollbar-width: none; }
.tabs__list::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap;
  transition: color var(--dur-fast), background var(--dur-fast);
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab[aria-selected='true'] { color: var(--gold-2); background: var(--gold-soft); }
.tab[aria-selected='true']::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -5px; height: 2px; border-radius: 2px; background: var(--gold); }
.tab__badge { min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font: 700 10px/16px var(--font-body); }
.tabs__panel { flex: 1 1 auto; min-height: 0; overflow: auto; }

/* ------------------------------------------------------------------ segmented + switch + fields */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg__opt {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 30px; padding: 0 12px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; flex: 1 0 auto;
  transition: background var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.seg__opt:hover:not(:disabled) { color: var(--text); }
.seg__opt[aria-checked='true'] { background: var(--panel-3); color: var(--gold-2); box-shadow: inset 0 0 0 1px rgba(232, 195, 90, 0.55), var(--shadow-sm); }
.seg__opt:disabled { opacity: 0.4; }
.seg--block { display: flex; }
@media (pointer: coarse) { .seg__opt { min-height: 40px; } }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; min-height: 28px; }
.switch__track { position: relative; width: 36px; height: 20px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); transition: background var(--dur), border-color var(--dur); flex: none; }
.switch__track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform var(--dur) var(--ease), background var(--dur); }
.switch[aria-checked='true'] .switch__track { background: var(--gold-soft); border-color: var(--gold); }
.switch[aria-checked='true'] .switch__track::after { transform: translateX(16px); background: var(--gold); }
.switch { background: none; border: 0; padding: 0; color: var(--text); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.label { font-size: 11.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.02em; }
.input, .select {
  height: 36px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast); min-width: 0; width: 100%;
}
.input::placeholder { color: var(--faint); }
.input:hover, .select:hover { border-color: var(--line-strong); }
.input:focus, .select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.input--sm, .select--sm { height: 30px; font-size: 12.5px; }
.input-icon { position: relative; display: flex; align-items: center; }
.input-icon > .ico { position: absolute; left: 10px; opacity: 0.7; pointer-events: none; }
.input-icon > .input { padding-left: 32px; }
.select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
@media (pointer: coarse) { .input, .select { height: 44px; font-size: 16px; } }

/* ------------------------------------------------------------------ meters (HP, ATB, stats, charge pips) */
.meter {
  position: relative; height: 10px; border-radius: 1px; min-width: 40px; overflow: hidden;
  background: linear-gradient(180deg, #05040a, #1b1622); border: 1px solid var(--gild-mid);
  box-shadow: 0 0 0 1px #07060a, inset 0 1px 0 rgba(0, 0, 0, 0.6), 0 1px 0 1px rgba(255, 226, 150, 0.12);
}
.meter::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent calc(25% - 1px), rgba(0, 0, 0, 0.35) 0 25%, transparent 0 calc(50% - 1px), rgba(0, 0, 0, 0.35) 0 50%, transparent 0 calc(75% - 1px), rgba(0, 0, 0, 0.35) 0 75%, transparent 0); }
.meter__ghost, .meter__fill { position: absolute; inset: 0 auto 0 0; width: calc(var(--pct, 1) * 100%); }
.meter__ghost { width: calc(var(--ghost, 1) * 100%); background: rgba(255, 250, 240, 0.9); transition: width 600ms var(--ease) 250ms; }
.meter__fill {
  background: linear-gradient(180deg, #b9ffc9 0%, #3fcf78 38%, #167a45 100%); transition: width 260ms var(--ease), background var(--dur);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.3);
}
.meter.is-mid .meter__fill { background: linear-gradient(180deg, #fff0a8 0%, #f0b93a 38%, #9a6212 100%); }
.meter.is-low .meter__fill { background: linear-gradient(180deg, #ffb0a8 0%, #e8463f 38%, #7c141d 100%); }
.meter--atb { height: 4px; border-color: var(--gild-lo); background: rgba(92, 60, 20, 0.55); overflow: visible; }
.meter--atb::after { display: none; }
.meter--atb .meter__fill { background: linear-gradient(90deg, #2f6fd8, #a8e4ff); transition: width 1000ms linear; box-shadow: 0 0 6px rgba(120, 190, 255, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
.meter--atb.is-full .meter__fill { background: linear-gradient(90deg, var(--gild), var(--gild-hi)); box-shadow: 0 0 8px rgba(255, 214, 110, 0.9); }
.meter--atb.is-over .meter__fill { background: linear-gradient(90deg, var(--gild), #fffbe6); }
.meter--stat { height: 6px; }
.meter--stat .meter__fill { background: linear-gradient(90deg, var(--gold-3), var(--gold)); }
.meter__text { font: 600 11.5px/1 var(--font-ui); color: var(--parchment-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.meter__text b { color: #fff6e0; font-weight: 700; font-size: 13.5px; }
/* charge pips: gold-set jewels (client/assets/ui/gem-*.png); [data-team] ancestors pick ruby / sapphire */
.pips { display: inline-flex; gap: 2px; align-items: center; --gem-on: url(/assets/ui/gem-gold.png); }
[data-team='red'] .pips { --gem-on: url(/assets/ui/gem-red.png); }
[data-team='blue'] .pips { --gem-on: url(/assets/ui/gem-blue.png); }
.pip { width: 12px; height: 12px; background: url(/assets/ui/gem-empty.png) center / contain no-repeat; image-rendering: auto; }
.pip.is-on { background-image: var(--gem-on); filter: drop-shadow(0 0 3px rgba(255, 220, 140, 0.45)); }
.pip.is-cost { outline: 1px solid var(--gild); outline-offset: -1px; border-radius: 50%; }
.pips--sm .pip { width: 9px; height: 9px; }

/* ------------------------------------------------------------------ portrait */
.portrait {
  --el-c: var(--el-none);
  position: relative; display: inline-block; vertical-align: middle; width: 48px; height: 48px; flex: none; border-radius: var(--radius-sm); overflow: hidden;
  background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--el-c) 30%, #1a2233), #0b0f18 80%);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--el-c) 75%, transparent), inset 0 0 0 3px rgba(0, 0, 0, 0.5);
}
.portrait img { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; }
/* procedural (Modern) portraits are 96x96 painted pixel art: smooth (filtered) downscale when shown clearly smaller,
   crisp pixels from ~82 device px up (meters.js portrait() sets .is-crisp after measuring) */
.portrait img[src*="/assets/generated/"]:not(.is-crisp), .portrait img[src*="/assets/avatars/"]:not(.is-crisp) { image-rendering: auto; }
.portrait__fallback { position: absolute; inset: 0; display: grid; place-items: center; font: 400 18px/1 var(--font-display); color: var(--el-c); }
.portrait--sm { width: 32px; height: 32px; }
.portrait--lg { width: 64px; height: 64px; }
.portrait--xl { width: 96px; height: 96px; border-radius: var(--radius); }
.portrait.is-dead img { filter: grayscale(1) brightness(0.55); }
/* .medal: a round portrait set in the gold medallion ring (ring hole = 72.5 % of the ring) */
.medal { --medal-c: var(--gild-mid); position: relative; display: inline-grid; place-items: center; flex: none; border-radius: 50%; }
.medal > .portrait { border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6); background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--medal-c) 70%, #fff 0%), #07060a 85%); }
.medal::after { content: ''; position: absolute; inset: -19% -19% -21% -19%; pointer-events: none; background: url(/assets/ui/medallion.png) center / 100% 100% no-repeat; }
.medal--red { --medal-c: var(--crimson); }
.medal--blue { --medal-c: var(--sapphire); }

/* ------------------------------------------------------------------ layers: toast, modal, tooltip, popover, drawer */
.layer { position: fixed; inset: 0; pointer-events: none; }
#toast-layer { z-index: var(--z-toast); display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 8px; padding: 64px 16px 16px; }
@media (min-width: 601px) { #toast-layer { align-items: flex-end; justify-content: flex-end; padding: 16px; } }
.toast {
  --toast-c: var(--info);
  pointer-events: auto; display: flex; align-items: center; gap: 10px; width: min(380px, 100%); padding: 10px 10px 10px 12px;
  background: rgba(16, 21, 33, 0.97); border: 1px solid var(--line); border-left: 3px solid var(--toast-c); border-radius: var(--radius);
  box-shadow: var(--shadow); animation: toast-in var(--dur-slow) var(--ease);
}
.toast.is-leaving { animation: toast-out var(--dur) var(--ease) forwards; }
.toast--success { --toast-c: var(--ok); }
.toast--warn { --toast-c: var(--warn); }
.toast--error { --toast-c: var(--bad); }
.toast__msg { flex: 1 1 auto; min-width: 0; font-size: 13px; }
.toast__msg b { display: block; margin-bottom: 1px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px) scale(0.98); } }

#modal-layer { z-index: var(--z-modal); }
.modal-backdrop {
  position: fixed; inset: 0; pointer-events: auto; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 6, 12, 0.66); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade-in var(--dur) var(--ease);
}
.modal-backdrop.is-leaving { animation: fade-out var(--dur-fast) var(--ease) forwards; }
.modal {
  position: relative; width: min(520px, 100%); max-height: min(86vh, 760px); display: flex; flex-direction: column;
  background: var(--ink-panel); border: 0; border-radius: 2px;
  box-shadow: var(--shadow-lg); animation: modal-in var(--dur-slow) var(--ease);
}
.modal::after { content: ''; position: absolute; inset: -4px; pointer-events: none; border: 16px solid transparent; border-image: url(/assets/ui/frame.png) 16 / 16px stretch; image-rendering: pixelated; }
.modal--sm { width: min(400px, 100%); }
.modal--lg { width: min(760px, 100%); }
.modal--gold { box-shadow: var(--shadow-lg), 0 0 24px rgba(255, 200, 90, 0.3); }
.modal__head { display: flex; align-items: center; gap: 10px; padding: 18px 18px 10px; position: relative; }
.modal__head::after { content: ''; position: absolute; left: 18px; right: 18px; bottom: 2px; height: 1px; background: var(--gild-rule); opacity: 0.7; }
.modal__title { flex: 1 1 auto; font: 700 17px/1.2 var(--font-serif); letter-spacing: 0.04em; color: var(--gild-hi); text-shadow: 0 1px 0 #000, 0 0 12px rgba(230, 191, 98, 0.35); }
.modal__body { padding: 10px 18px 16px; overflow: auto; min-height: 0; }
.modal__foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 18px; flex-wrap: wrap; }
.modal__foot .btn { min-width: 96px; }
@media (max-width: 600px) {
  .modal-backdrop { place-items: end stretch; padding: 0; }
  .modal { width: 100%; max-height: 92vh; border-radius: 0; animation-name: sheet-in; }
  .modal::after { inset: -4px -4px 0; border-bottom-width: 0; }
  .modal__foot .btn { flex: 1 1 0; }
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }

#tooltip-layer { z-index: var(--z-tooltip); }
.tooltip {
  position: fixed; left: 0; top: 0; max-width: min(340px, calc(100vw - 16px)); pointer-events: none;
  background: var(--grain), linear-gradient(180deg, rgba(30, 25, 36, 0.98), rgba(11, 9, 15, 0.98)); border: 1px solid var(--gild-lo); border-radius: 3px;
  box-shadow: var(--shadow), 0 0 0 1px #07060a, inset 0 1px 0 rgba(255, 226, 150, 0.14);
  color: var(--text); font: 500 13.5px/1.35 var(--font-ui); padding: 8px 10px; opacity: 0; transform: translateY(2px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.tooltip.is-open { opacity: 1; transform: none; }
.tooltip--rich { padding: 0; max-width: min(360px, calc(100vw - 16px)); }
.tooltip--text { max-width: 260px; }
.tooltip--sheet {
  left: 0 !important; right: 0; top: auto !important; bottom: 0; max-width: none; width: 100%; pointer-events: auto;
  border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(100%); max-height: 75vh; overflow: auto;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-fast);
}
.tooltip--sheet.is-open { transform: none; }
.tooltip--sheet::before { content: ''; position: absolute; top: 7px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line); }
.tooltip--sheet.tooltip--rich { padding: 14px 0 env(safe-area-inset-bottom); }
.sheet-scrim { position: fixed; inset: 0; background: rgba(4, 6, 12, 0.5); pointer-events: auto; animation: fade-in var(--dur) var(--ease); }

.popover {
  position: fixed; z-index: var(--z-popover); min-width: 200px; max-width: min(340px, calc(100vw - 16px)); pointer-events: auto;
  background: var(--grain), linear-gradient(180deg, rgba(33, 27, 39, 0.99), rgba(12, 10, 16, 0.99)); border: 1px solid var(--gild-mid); border-radius: 3px;
  box-shadow: var(--shadow-lg), 0 0 0 1px #07060a, inset 0 1px 0 rgba(255, 226, 150, 0.16);
  padding: 8px; animation: pop-in var(--dur) var(--ease);
}
@keyframes pop-in { from { opacity: 0; transform: translateY(4px) scale(0.98); } to { opacity: 1; transform: none; } }
.popover__title { display: flex; align-items: center; gap: 6px; padding: 4px 6px 8px; font: 600 12.5px/1 var(--font-ui); letter-spacing: 0.08em; text-transform: uppercase; color: var(--gild); }
.popover__choices { display: flex; flex-direction: column; gap: 4px; }
.choice {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 6px 10px; text-align: left; border-radius: var(--radius-sm);
  border: 1px solid var(--ink-line); background: var(--ink-2); color: var(--text); transition: background var(--dur-fast), border-color var(--dur-fast);
}
.choice:hover:not(:disabled), .choice:focus-visible { background: color-mix(in srgb, var(--gild) 10%, var(--ink-3)); border-color: var(--gild); }
.choice:disabled { opacity: 0.45; }
.choice__key { flex: none; min-width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; background: var(--gold-soft); color: var(--gold-2); font: 700 12px/1 var(--font-mono); }
.choice__label { flex: 1 1 auto; min-width: 0; }
.choice__hint { display: block; font-size: 11.5px; color: var(--muted); }
.stepper { display: flex; align-items: center; gap: 8px; padding: 4px; }
.stepper__value { flex: 1 1 auto; text-align: center; font: 400 22px/1 var(--font-display); color: var(--gold-2); font-variant-numeric: tabular-nums; min-width: 64px; }
.stepper__range { width: 100%; accent-color: var(--gold); margin: 6px 0 2px; }
.stepper__preview { min-height: 18px; padding: 4px 6px; font-size: 12px; color: var(--muted); }
.stepper__meta { display: flex; justify-content: space-between; padding: 0 6px; font: 600 10.5px/1 var(--font-mono); color: var(--faint); }
.popover__foot { display: flex; gap: 6px; justify-content: flex-end; padding-top: 8px; }

.drawer-backdrop { position: fixed; inset: 0; z-index: var(--z-drawer); background: rgba(4, 6, 12, 0.55); animation: fade-in var(--dur) var(--ease); }
.drawer {
  position: fixed; z-index: calc(var(--z-drawer) + 1); display: flex; flex-direction: column; background: var(--panel-solid);
  border: 1px solid var(--line); box-shadow: var(--shadow-lg); transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
  visibility: hidden;
}
.drawer.is-open { visibility: visible; transition: transform var(--dur-slow) var(--ease), visibility 0s; }
.drawer--right { top: 0; right: 0; bottom: 0; width: min(420px, 100vw); transform: translateX(100%); border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
.drawer--left { top: 0; left: 0; bottom: 0; width: min(420px, 100vw); transform: translateX(-100%); border-radius: 0 var(--radius-lg) var(--radius-lg) 0; }
.drawer--bottom { left: 0; right: 0; bottom: 0; max-height: 80vh; transform: translateY(100%); border-radius: 16px 16px 0 0; }
.drawer.is-open { transform: none; }
.drawer__head { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line-soft); min-height: 52px; }
.drawer__title { flex: 1 1 auto; font: 700 15px/1 var(--font-serif); letter-spacing: 0.04em; }
.drawer__body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 12px 16px; }
@media (max-width: 600px) { .drawer--right, .drawer--left { width: 100vw; border-radius: 0; } }

/* ------------------------------------------------------------------ countdown ring */
.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { transform: rotate(-90deg); overflow: visible; }
.ring__track { fill: none; stroke: rgba(255, 255, 255, 0.1); }
.ring__bar { fill: none; stroke: var(--ring-c, var(--gold)); stroke-linecap: round; transition: stroke 300ms, stroke-dashoffset 110ms linear; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--ring-c, var(--gold)) 50%, transparent)); }
.ring.is-low { --ring-c: var(--bad); }
.ring__label { position: absolute; inset: 0; display: grid; place-items: center; font: 700 calc(var(--ring-size, 48px) * 0.42)/1 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--text); }

/* ------------------------------------------------------------------ targeting diagram */
.tdiag { display: inline-flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius-sm); background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line-soft); }
.tdiag__col { display: flex; flex-direction: column; gap: 3px; align-items: center; }
.tdiag__col--enemy .tdiag__cell { border-radius: 2px; }
.tdiag__cap { font: 600 10px/1 var(--font-ui); letter-spacing: 0.06em; color: var(--faint); text-transform: uppercase; margin-bottom: 1px; }
.tdiag__cell { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.16); }
.tdiag__cell.is-caster { background: var(--gold); border-color: var(--gold-2); box-shadow: 0 0 6px rgba(232, 195, 90, 0.6); }
.tdiag__cell.is-target { background: var(--bad); border-color: #ffb4b4; box-shadow: 0 0 6px rgba(239, 86, 86, 0.6); }
.tdiag__cell.is-hit { background: color-mix(in srgb, var(--bad) 70%, transparent); border-color: var(--bad); }
.tdiag__cell.is-splash { background: color-mix(in srgb, var(--bad) 30%, transparent); border-color: color-mix(in srgb, var(--bad) 70%, transparent); }
.tdiag__col--ally .tdiag__cell.is-target { background: var(--ok); border-color: #b7f5cf; box-shadow: 0 0 6px rgba(70, 194, 122, 0.6); }
.tdiag__col--ally .tdiag__cell.is-hit { background: color-mix(in srgb, var(--ok) 70%, transparent); border-color: var(--ok); }
.tdiag__col--ally .tdiag__cell.is-splash { background: color-mix(in srgb, var(--ok) 30%, transparent); border-color: var(--ok); }
.tdiag__cell.is-dead { background: repeating-linear-gradient(45deg, rgba(255,255,255,0.25) 0 2px, transparent 2px 4px); border-color: var(--muted); }
.tdiag__vs { width: 1px; align-self: stretch; background: var(--line-soft); margin: 0 2px; }
.tdiag__code { font: 700 11px/1 var(--font-mono); color: var(--muted); margin-left: 4px; }

/* ------------------------------------------------------------------ ability card (UI-SPEC §3) */
.ability-card {
  --el-c: var(--el-none);
  position: relative; display: flex; flex-direction: column; gap: 8px; padding: 12px; min-width: 0;
  background: linear-gradient(180deg, color-mix(in srgb, var(--el-c) 7%, var(--panel-2)), var(--panel-solid));
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--inset);
}
.ability-card::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--el-c); opacity: 0.9; }
.tooltip .ability-card { border: 0; background: transparent; box-shadow: none; }
.ability-card.is-disabled { opacity: 0.92; }
.ability-card.is-disabled .ability-card__icon { filter: grayscale(0.7) brightness(0.8); }
.ability-card--compact { padding: 8px 10px; gap: 6px; }
.ability-card--interactive { cursor: pointer; transition: border-color var(--dur-fast), transform var(--dur-fast) var(--ease), box-shadow var(--dur-fast); }
.ability-card--interactive:hover { border-color: color-mix(in srgb, var(--el-c) 60%, var(--line-strong)); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.ability-card__head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ability-card__icon {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--radius-sm);
  background: radial-gradient(circle at 40% 30%, color-mix(in srgb, var(--el-c) 35%, #1d2638), #0b0f18);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--el-c) 55%, transparent);
}
.ability-card__icon .ico { width: 32px; height: 32px; }
.ability-card--compact .ability-card__icon { width: 28px; height: 28px; }
.ability-card--compact .ability-card__icon .ico { width: 16px; height: 16px; }
.ability-card__titles { flex: 1 1 auto; min-width: 0; }
.ability-card__name { font-weight: 700; font-size: 14px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ability-card__meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ability-card__key { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.ability-card__keycap {
  min-width: 26px; height: 22px; padding: 0 6px; display: grid; place-items: center; border-radius: 5px;
  background: var(--bg-2); border: 1px solid var(--line-strong); font: 700 11.5px/1 var(--font-mono); color: var(--gold-2);
}
.ability-card__costs { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.ability-card__row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ability-card__desc { color: #d5dbe8; font-size: 12.5px; line-height: 1.45; margin: 0; }
.ability-card__desc q { quotes: '\201C' '\201D'; }
.ability-card__classic { color: var(--faint); font-size: 11px; line-height: 1.4; margin: 0; }
.ability-card__classic q { quotes: '\201C' '\201D'; font-style: italic; }
.ability-card__notes { color: var(--muted); font-size: 11.5px; line-height: 1.4; margin: 0; }
.ability-card__effects { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ability-card__label { font: 600 11px/1 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--faint); margin-right: 2px; }
.ability-card__partner { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.ability-card__partner .ok { color: var(--ok); }
.ability-card__partner .bad { color: var(--bad); }
.partner-link { border: 0; background: none; padding: 0; color: var(--gold-2); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.partner-link:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.ability-card__preview {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm);
  background: rgba(90, 169, 232, 0.1); border: 1px solid rgba(90, 169, 232, 0.35); font-size: 12px;
}
.ability-card__preview b { font-variant-numeric: tabular-nums; }
.ability-card__reason {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius-sm);
  background: rgba(239, 86, 86, 0.1); border: 1px solid rgba(239, 86, 86, 0.4); color: #ffc0c0; font-size: 12px;
}

/* ability tile (command dock button, 56x56; 48 at 960-1279) */
.ability-tile {
  --el-c: var(--el-none);
  position: relative; min-width: var(--tile); max-width: calc(var(--tile) * 1.9); height: calc(var(--tile) + 8px); flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 6px 8px 4px; border-radius: 3px; border: 1px solid var(--gild-mid); overflow: hidden;
  background:
    radial-gradient(70% 55% at 50% 36%, color-mix(in srgb, var(--el-c) 28%, transparent), transparent 75%),
    linear-gradient(180deg, #2a2431 0%, #17141d 55%, #0e0c12 100%);
  color: var(--parchment);
  box-shadow: 0 0 0 1px #07060a, inset 0 1px 0 rgba(255, 236, 180, 0.22), inset 0 0 0 1px rgba(0, 0, 0, 0.55), 0 3px 0 rgba(0, 0, 0, 0.45);
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast), box-shadow var(--dur-fast), opacity var(--dur-fast);
}
.ability-tile::before {
  /* shine sweep on hover / focus */
  content: ''; position: absolute; inset: 0; pointer-events: none; transform: translateX(-120%);
  background: linear-gradient(105deg, transparent 30%, rgba(255, 240, 190, 0.22) 50%, transparent 70%);
}
.ability-tile:hover:not(.is-disabled)::before, .ability-tile:focus-visible::before { transform: translateX(120%); transition: transform 520ms var(--ease); }
.ability-tile:hover:not(.is-disabled) { transform: translateY(-2px); border-color: var(--gild-hi); box-shadow: 0 0 0 1px #07060a, inset 0 1px 0 rgba(255, 236, 180, 0.3), 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 12px color-mix(in srgb, var(--el-c) 35%, transparent); }
.ability-tile:focus-visible { box-shadow: var(--focus); }
.ability-tile:active:not(.is-disabled) { transform: translateY(0); }
.ability-tile .ico { width: 24px; height: 24px; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--el-c) 55%, transparent)) drop-shadow(0 1px 0 #000); }
.ability-tile__name { max-width: 100%; text-align: center; font: 600 12px/1.1 var(--font-ui); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; color: var(--parchment); text-shadow: 0 1px 0 #000; }
.ability-tile__hotkey { position: absolute; top: 3px; left: 4px; font: 700 10px/1 var(--font-ui); color: var(--gild-mid); }
.ability-tile__key { position: absolute; top: 2px; left: 50%; transform: translateX(-50%); padding: 0 3px; border-radius: 2px; background: #07060a; border: 1px solid var(--gild-lo); font: 700 10px/1.25 var(--font-ui); color: var(--gild); max-width: 44px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ability-tile__cost { position: absolute; top: 3px; right: 4px; font: 700 10.5px/1 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--gild-hi); }
.ability-tile__cost.is-short { color: var(--bad); }
.ability-tile.is-disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.7); border-color: var(--gild-lo); }
.ability-tile.is-disabled .ability-tile__lock { position: absolute; top: 14px; right: 4px; width: 12px; height: 12px; }
.ability-tile.is-armed { border-color: var(--gild-hi); box-shadow: var(--gild-glow); animation: armed 160ms var(--ease); }
.ability-tile.is-flash { animation: armed 150ms var(--ease); }
@keyframes armed { 50% { transform: scale(1.06); } }
@media (max-width: 1279px) { .ability-tile .ico { width: 20px; height: 20px; } .ability-tile__name { font-size: 11.5px; } }
@media (max-width: 600px) { .ability-tile .ico { width: 24px; height: 24px; } }

/* ------------------------------------------------------------------ fighter card (gilded, DECISIONS 30) */
/* Ink panel with a team wash from the portrait side, medallion portrait, Cinzel name, UI-sans numbers; statuses grouped
   into Buffs / Debuffs / Other with framed badges (rim by polarity), turns-left pills and a one-line effect. */
.fighter-card {
  --el-c: var(--el-none); --team-c: var(--gild-mid);
  position: relative; display: flex; flex-direction: column; gap: 9px; padding: 12px 13px 13px; width: 316px; max-width: 100%;
  font-family: var(--font-ui); color: var(--parchment);
  background: linear-gradient(100deg, color-mix(in srgb, var(--team-c) 20%, transparent), transparent 55%), var(--ink-panel);
  border: 1px solid var(--gild-mid); border-radius: 3px;
  box-shadow: 0 0 0 1px #07060a, inset 0 1px 0 rgba(255, 236, 180, 0.16), inset 0 0 0 1px rgba(255, 226, 150, 0.06);
}
.fighter-card--red { --team-c: var(--crimson); }
.fighter-card--blue { --team-c: var(--sapphire); }
.fighter-card__head { display: flex; gap: 14px; align-items: center; min-width: 0; padding: 2px 0 0 4px; }
.fighter-card__medal .portrait { width: 46px; height: 46px; }
.fighter-card__medal.is-dead { filter: grayscale(1); opacity: 0.7; }
.fighter-card__who { flex: 1 1 auto; min-width: 0; }
.fighter-card__name { font: 700 16px/1.15 var(--font-serif); letter-spacing: 0.02em; color: var(--gild-hi); text-shadow: 0 1px 0 #000; display: flex; align-items: center; gap: 6px; min-width: 0; }
.fighter-card__name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fighter-card__sub { color: var(--parchment-muted); font-size: 13px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 3px; }
.fighter-card__team { width: 9px; height: 9px; transform: rotate(45deg); border-radius: 1px; background: var(--team-c); box-shadow: 0 0 5px var(--team-c); flex: none; }
.fighter-card__bars {
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 6px 9px; padding: 8px 9px;
  background: rgba(0, 0, 0, 0.32); border-top: 1px solid rgba(181, 134, 47, 0.45); border-bottom: 1px solid rgba(181, 134, 47, 0.2);
  font-size: 12.5px; font-weight: 600; color: var(--parchment-muted);
}
.fighter-card__bars .num { font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; color: var(--parchment-muted); }
.fighter-card__bars .num b { color: #fff6e0; font-weight: 700; }
.fighter-card__stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.stat-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px 4px; border-radius: 2px; background: linear-gradient(180deg, #1d1823, #0d0b11); border: 1px solid var(--ink-line); }
.stat-cell__k { font: 600 10.5px/1 var(--font-ui); letter-spacing: 0.06em; color: var(--parchment-muted); }
.stat-cell__v { font: 700 14px/1.25 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--parchment); }
.stat-cell.is-up { border-color: color-mix(in srgb, var(--buff) 45%, var(--ink-line)); }
.stat-cell.is-down { border-color: color-mix(in srgb, var(--debuff) 45%, var(--ink-line)); }
.stat-cell.is-up .stat-cell__v { color: #9df5be; }
.stat-cell.is-down .stat-cell__v { color: #ffaaa3; }
.fighter-card__statuses { display: flex; flex-direction: column; gap: 8px; }
.fighter-card__group { --pol-c: var(--gild-mid); display: flex; flex-direction: column; gap: 6px; }
.fighter-card__group--buff { --pol-c: #62d88f; }
.fighter-card__group--debuff { --pol-c: #ef5a52; }
.fighter-card__group--neutral { --pol-c: #a7a2ae; }
.fighter-card__grouphead { display: flex; align-items: center; gap: 7px; font: 700 12px/1 var(--font-serif); letter-spacing: 0.06em; color: var(--pol-c); }
.fighter-card__grouphead::after { content: ''; flex: 1 1 auto; height: 1px; background: linear-gradient(90deg, color-mix(in srgb, var(--pol-c) 60%, transparent), transparent); }
.fighter-card__count { order: 2; min-width: 17px; height: 16px; padding: 0 4px; display: grid; place-items: center; border-radius: 8px; font: 700 11px/1 var(--font-ui); color: #0b090e; background: var(--pol-c); }
.fighter-card__grouphead::after { order: 3; }
.status-row { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; line-height: 1.3; }
.status-row__badge {
  position: relative; flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 3px;
  background: linear-gradient(180deg, #221c29, #09070d); border: 1.5px solid var(--pol-c); box-shadow: 0 0 0 1px #07060a;
}
.status-row__badge .ico { width: 18px; height: 18px; image-rendering: pixelated; }
.status-row--buff .status-row__badge::before, .status-row--debuff .status-row__badge::before {
  position: absolute; left: -3px; top: -5px; font: 700 9px/1 var(--font-ui); color: var(--pol-c); text-shadow: 0 0 2px #000, 0 1px 0 #000;
}
.status-row--buff .status-row__badge::before { content: '▲'; }
.status-row--debuff .status-row__badge::before { content: '▼'; }
.status-row__body { flex: 1 1 auto; min-width: 0; }
.status-row__head { display: flex; align-items: baseline; gap: 6px; }
.status-row__name { font-weight: 700; font-size: 14px; color: color-mix(in srgb, var(--pol-c) 45%, #fff6e0); }
.status-row__stacks { font-weight: 700; color: var(--gild); font-variant-numeric: tabular-nums; }
.status-row__turns { margin-left: auto; flex: none; padding: 1px 6px; border-radius: 2px; font: 600 12px/1.3 var(--font-ui); font-variant-numeric: tabular-nums; color: var(--parchment); background: rgba(0, 0, 0, 0.45); border: 1px solid var(--ink-line); }
.status-row__desc { color: var(--parchment-muted); font-size: 12.5px; }
.status-row__src { color: color-mix(in srgb, var(--parchment-muted) 75%, transparent); font-size: 12px; font-style: italic; }
.fighter-card__flags { display: flex; flex-wrap: wrap; gap: 4px; }
.fighter-card__preview { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 2px; background: rgba(239, 86, 86, 0.12); border: 1px solid rgba(239, 86, 86, 0.45); font-size: 13.5px; }
.tooltip--rich:not(.tooltip--sheet):has(> .fighter-card) { background: none; border: 0; box-shadow: var(--shadow); }
.tooltip .fighter-card { width: 320px; }
.tooltip--sheet .fighter-card { width: 100%; }

/* ------------------------------------------------------------------ settings form */
.settings-form { display: flex; flex-direction: column; gap: 2px; min-width: 260px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 40px; padding: 4px 6px; border-radius: var(--radius-sm); }
.settings-row + .settings-row { border-top: 1px solid var(--line-soft); }
.settings-row__label { font-size: 13px; color: var(--text); }
.settings-row .stepper__range { width: 120px; margin: 0; }
.settings-form__help { align-self: flex-start; margin-top: 6px; }
.settings-row__app { display: inline-flex; align-items: center; gap: 8px; }
.settings-row__hint { max-width: 170px; text-align: right; }

/* ------------------------------------------------------------------ phones: landscape gate (index.html #rotate-gate)
 * Portrait phones (coarse pointer, no hover, ≤ 600 px wide) get a full-screen "Rotate your phone" overlay above every
 * screen. Tablets in portrait (≥ 744 px) and narrow desktop windows (fine pointer) are not blocked. */
.rotate-gate { display: none; }
@media (pointer: coarse) and (hover: none) and (orientation: portrait) and (max-width: 600px) {
  .rotate-gate {
    position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; padding: calc(24px + env(safe-area-inset-top)) 28px calc(24px + env(safe-area-inset-bottom)); text-align: center;
    background: radial-gradient(420px 320px at 50% 40%, #1a2440 0%, var(--bg-1) 60%, var(--bg-0) 100%);
  }
  body { overflow: hidden; }
}
.rotate-gate__phone {
  position: relative; width: 52px; height: 88px; margin-bottom: 18px; border-radius: 10px; border: 3px solid var(--gold);
  box-shadow: var(--gold-glow); animation: rotate-phone 2.6s var(--ease) infinite;
}
.rotate-gate__phone::after { content: ''; position: absolute; left: 50%; bottom: 5px; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: var(--gold-3); }
.rotate-gate__screen { position: absolute; inset: 6px 5px 17px; border-radius: 3px; background: linear-gradient(180deg, #2a3a63, #121827); }
.rotate-gate__logo { font-size: 18px; }
.rotate-gate__title { margin: 0; font: 400 20px/1.2 var(--font-display); letter-spacing: 0.04em; color: var(--gold-2); }
.rotate-gate__text { margin: 0; max-width: 300px; color: var(--muted); font-size: 14px; line-height: 1.45; }
@keyframes rotate-phone { 0%, 18% { transform: rotate(0deg); } 45%, 78% { transform: rotate(-90deg); } 100% { transform: rotate(0deg); } }
.art-toggle .label { margin: 0; }

/* ------------------------------------------------------------------ reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
:root[data-reduced-motion='true'] *, :root[data-reduced-motion='true'] *::before, :root[data-reduced-motion='true'] *::after {
  animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important;
}
