/* Layout, components and the chess board. */

*, *::before, *::after { box-sizing: border-box; }

/*
 * min-height, not height. With `height: 100%` the body box is exactly one
 * viewport tall while the content overflows it, which is the classic reason a
 * page refuses to scroll on mobile browsers with a collapsing toolbar.
 */
html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg-base);
  color: var(--text);
  font: 400 var(--fs-md)/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* Ambient blueprint backdrop — fixed, never repaints. */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(1200px 700px at 78% -12%, var(--accent-soft), transparent 62%),
    radial-gradient(900px 600px at 4% 108%, var(--accent-2-soft), transparent 60%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 44px 44px;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.15;
  color: var(--text-hi);
  margin: 0;
  letter-spacing: -.011em;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }

.eyebrow {
  font-size: var(--fs-2xs); text-transform: uppercase;
  letter-spacing: var(--ls-caps-wide); color: var(--text-dim); font-weight: 600;
}
.num { font-variant-numeric: tabular-nums; }
.dim { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.center { text-align: center; }

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); color: var(--text-hi); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; border: 2px solid var(--bg-base); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation-duration: 1ms !important; transition-duration: 1ms !important;
}

/* ============================================================ buttons ==== */

.btn {
  appearance: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px 16px; min-height: 38px;
  font: 600 var(--fs-md) var(--font-ui);
  color: var(--text-hi);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--hairline);
  transition: background var(--dur-2), border-color var(--dur-2), transform var(--dur-1), box-shadow var(--dur-2);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  color: var(--accent-ink); border-color: transparent;
}
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); background: linear-gradient(180deg, var(--accent-hi), var(--accent)); }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn--danger { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, transparent); background: var(--danger-soft); }
.btn--danger:hover:not(:disabled) { background: color-mix(in oklab, var(--danger) 22%, transparent); }
.btn--sm { min-height: 30px; padding: 5px 11px; font-size: var(--fs-sm); }
.btn--lg { min-height: 46px; padding: 12px 24px; font-size: var(--fs-lg); }
.btn--block { width: 100%; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  padding: 10px 12px;
  font: 400 var(--fs-md) var(--font-ui);
  color: var(--text-hi);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color var(--dur-2), box-shadow var(--dur-2);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { min-height: 120px; resize: vertical; font-family: var(--font-mono); font-size: var(--fs-sm); }
label { display: block; font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: var(--sp-2); font-weight: 500; }

/* ============================================================== cards ==== */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2), var(--hairline);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
}
.card__body { padding: var(--sp-5); }
.card__body--tight { padding: var(--sp-4); }

.grid { display: grid; gap: var(--sp-4); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid--4 { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack--sm { gap: var(--sp-2); }
.spacer { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-full);
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .02em;
  background: var(--surface-3); color: var(--text-dim);
  border: 1px solid var(--border-subtle);
}
.chip--ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip--warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.chip--accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip--gold { background: var(--accent-3-soft); color: var(--accent-3); border-color: transparent; }

.rar { color: var(--rc); }
[data-rarity="common"] { --rc: var(--r-common); }
[data-rarity="uncommon"] { --rc: var(--r-uncommon); }
[data-rarity="rare"] { --rc: var(--r-rare); }
[data-rarity="epic"] { --rc: var(--r-epic); }
[data-rarity="legendary"] { --rc: var(--r-legendary); }
[data-rarity="mythic"] { --rc: var(--r-mythic); }

/* ============================================================= layout ==== */

.app {
  display: grid;
  min-height: 100dvh;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "top top" "side main";
}
.app__top {
  grid-area: top;
  position: sticky; top: 0; z-index: var(--z-sticky);
  display: flex; align-items: center; gap: var(--sp-4);
  padding: 0 var(--sp-5);
  background: var(--surface-glass);
  backdrop-filter: blur(14px) saturate(1.3);
  border-bottom: 1px solid var(--border);
}
.app__side {
  grid-area: side;
  border-right: 1px solid var(--border);
  background: color-mix(in oklab, var(--surface-1) 72%, transparent);
  backdrop-filter: blur(8px);
  padding: var(--sp-4) var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-1);
  position: sticky; top: var(--topbar-h);
  height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
}
.app__main {
  grid-area: main;
  padding: var(--sp-6);
  max-width: var(--content-max);
  width: 100%;
}

.brand { display: flex; align-items: center; gap: var(--sp-3); font-family: var(--font-display); }
.brand__mark {
  width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); font-weight: 800; font-size: 15px;
  box-shadow: 0 0 18px -4px var(--accent);
}
.brand__name { font-weight: 700; color: var(--text-hi); letter-spacing: -.01em; font-size: var(--fs-lg); }

.navgroup { margin-top: var(--sp-4); padding: 0 var(--sp-3) var(--sp-2); }
.navitem {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); border-radius: var(--r-md);
  color: var(--text-dim); font-weight: 500; font-size: var(--fs-md);
  cursor: pointer; position: relative;
  transition: background var(--dur-2), color var(--dur-2);
  border: none; background: none; width: 100%; text-align: left;
  font-family: inherit;
}
.navitem:hover { background: var(--surface-2); color: var(--text-hi); }
.navitem.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.navitem.is-active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px;
  background: var(--accent); border-radius: 2px; box-shadow: 0 0 8px var(--accent);
}
.navitem__icon { width: 20px; text-align: center; font-size: 15px; flex: none; }
.navitem__badge {
  margin-left: auto; font-size: var(--fs-2xs); font-weight: 700;
  background: var(--danger); color: #fff; border-radius: var(--r-full);
  min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px;
}

.wallet { display: flex; align-items: center; gap: var(--sp-4); }
.wallet__item { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: var(--fs-sm); }
.wallet__item b { color: var(--text-hi); font-variant-numeric: tabular-nums; }
.wallet__icon { font-size: 13px; }
.wallet__item--cr .wallet__icon { color: var(--accent-3); }
.wallet__item--tk .wallet__icon { color: var(--accent-2); }

.page__head { margin-bottom: var(--sp-6); }
.page__head p { color: var(--text-dim); margin-top: 6px; max-width: 70ch; }

/* ========================================================== stat bars ==== */

.stat { display: grid; grid-template-columns: 1fr auto; gap: 4px var(--sp-3); align-items: center; }
.stat__top { display: flex; align-items: baseline; gap: var(--sp-2); grid-column: 1 / -1; }
.stat__label { font-size: var(--fs-sm); color: var(--text-dim); }
.stat__icon { color: var(--tier); font-size: var(--fs-sm); }
.stat__value { margin-left: auto; font-weight: 700; color: var(--text-hi); font-variant-numeric: tabular-nums; }
.stat__eff { font-size: var(--fs-xs); color: var(--ok); font-weight: 600; }
.stat__eff--down { color: var(--danger); }
.stat__track {
  grid-column: 1 / -1;
  position: relative; height: 8px; border-radius: var(--r-full);
  background: var(--bg-sunken); box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5);
  overflow: hidden;
  background-image: repeating-linear-gradient(90deg, transparent 0 calc(10% - 1px), rgba(255,255,255,.06) calc(10% - 1px) 10%);
}
.stat__fill {
  position: absolute; inset: 0 auto 0 0; width: var(--v, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in oklab, var(--tier) 50%, #000), var(--tier));
  box-shadow: 0 0 10px -2px var(--tier);
  transition: width var(--dur-5) var(--ease-out);
}
.stat__pot {
  position: absolute; top: 0; bottom: 0; width: 2px; left: var(--p, 100%);
  background: var(--text-hi); opacity: .5;
}
.stat[data-tier="1"] { --tier: var(--tier-1); }
.stat[data-tier="2"] { --tier: var(--tier-2); }
.stat[data-tier="3"] { --tier: var(--tier-3); }
.stat[data-tier="4"] { --tier: var(--tier-4); }
.stat[data-tier="5"] { --tier: var(--tier-5); }
.stat[data-tier="6"] { --tier: var(--tier-6); }

.meter { height: 6px; border-radius: var(--r-full); background: var(--bg-sunken); overflow: hidden; }
.meter__fill { height: 100%; width: var(--v, 0%); border-radius: inherit; background: var(--c, var(--accent)); transition: width var(--dur-4) var(--ease-out); }

/* =========================================================== bot card ==== */

.botcard {
  position: relative; border-radius: var(--r-lg); padding: 1.5px;
  background: linear-gradient(150deg, color-mix(in oklab, var(--rc) 65%, transparent), color-mix(in oklab, var(--rc) 12%, transparent) 55%, color-mix(in oklab, var(--rc) 50%, transparent));
  box-shadow: var(--sh-2);
  cursor: pointer;
  transition: transform var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
  border: none; display: block; width: 100%; text-align: left; font: inherit; color: inherit;
}
.botcard:hover, .botcard:focus-visible {
  transform: translateY(-3px);
  box-shadow: var(--sh-3), 0 0 26px -8px var(--rc);
}
.botcard__in {
  border-radius: calc(var(--r-lg) - 1.5px);
  background: linear-gradient(180deg, var(--surface-2), var(--surface-1));
  padding: var(--sp-4);
  box-shadow: var(--hairline);
  position: relative; overflow: hidden;
}
.botcard__in::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 120px; height: 120px;
  background: radial-gradient(circle, color-mix(in oklab, var(--rc) 22%, transparent), transparent 70%);
  pointer-events: none;
}
.botcard__head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.botcard__name { font-family: var(--font-display); font-weight: 700; color: var(--text-hi); font-size: var(--fs-lg); }
.botcard__sub { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-dim); margin-bottom: var(--sp-3); }
.botcard__elo { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 700; color: var(--text-hi); line-height: 1; }
.botcard__stats { display: grid; gap: 6px; margin-top: var(--sp-3); }
.botcard__foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--border-subtle); font-size: var(--fs-xs); }

.sigil { width: 42px; height: 42px; flex: none; border-radius: var(--r-md); display: grid; place-items: center;
  background: var(--bg-sunken); border: 1px solid var(--border); color: var(--rc); }
.sigil svg { width: 26px; height: 26px; }

.formdots { display: inline-flex; gap: 3px; }
.formdots i { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); }
.formdots i.w { background: var(--ok); }
.formdots i.d { background: var(--warn); }
.formdots i.l { background: var(--danger); }

/* ============================================================== board ==== */

.boardwrap { display: flex; gap: var(--sp-3); align-items: stretch; }

.board {
  --n: 8;
  --sq: calc(100% / var(--n));
  position: relative; aspect-ratio: 1; width: 100%;
  border-radius: var(--r-md);
  background: var(--board-frame);
  box-shadow: var(--sh-3), 0 0 0 1px var(--border);
  overflow: hidden;
  user-select: none; touch-action: manipulation;
}
.board__squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); }
.board__squares div { background: var(--sq-light); }
.board__squares div.dk { background: var(--sq-dark); }
.board__marks, .board__pieces { position: absolute; inset: 0; }
.pc, .mark {
  position: absolute; top: 0; left: 0; width: var(--sq); height: var(--sq);
  translate: calc(var(--f) * 100%) calc(var(--r) * 100%);
}
.pc {
  z-index: 2; will-change: translate;
  transition: translate var(--dur-move) var(--ease-out);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
}
.pc svg { width: 100%; height: 100%; display: block; }
.pc[data-c="w"] { --pf: var(--piece-w-fill); --ps: var(--piece-w-stroke); }
.pc[data-c="b"] { --pf: var(--piece-b-fill); --ps: var(--piece-b-stroke); }
.pc path, .pc circle, .pc rect {
  fill: var(--pf); stroke: var(--ps); stroke-width: 1.4;
  stroke-linejoin: round; stroke-linecap: round;
  vector-effect: non-scaling-stroke; paint-order: stroke fill;
}
.pc.is-moving { z-index: 4; }
.pc.is-gone { animation: capture 200ms var(--ease-in) forwards; z-index: 1; }
@keyframes capture { to { opacity: 0; scale: .55; filter: brightness(2) blur(1px); } }
.pc.is-new { animation: spawn 300ms var(--ease-spring) both; }
@keyframes spawn { from { scale: .3; opacity: 0; } }

.mark--last { background: var(--sq-last); }
.mark--sel { background: var(--sq-sel); box-shadow: inset 0 0 0 2px var(--accent); }
.mark--legal::after { content: ""; position: absolute; inset: 38%; border-radius: 50%; background: var(--sq-legal); }
.mark--legal.cap::after { inset: 5%; background: none; border: 4px solid var(--sq-legal); border-radius: 50%; }
.mark--check { background: radial-gradient(circle, var(--sq-check) 10%, transparent 72%); animation: pulse 900ms ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }

.board__coords { position: absolute; inset: 0; pointer-events: none; }
.board__coords span { position: absolute; font: 700 var(--fs-2xs) var(--font-mono); opacity: .65; padding: 2px 3px; }

.evalbar {
  /* Wide enough for a four-character score such as "+12.4" without clipping. */
  position: relative; width: 28px; flex: none; border-radius: var(--r-sm);
  background: var(--piece-b-fill); overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border);
}
.evalbar__fill { position: absolute; inset: auto 0 0 0; height: var(--p, 50%); background: var(--piece-w-fill); transition: height var(--dur-4) var(--ease-out); }
.evalbar__mid { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--accent); opacity: .6; }
.evalbar__num { position: absolute; left: 0; right: 0; text-align: center;
  font: 700 10px/1.4 var(--font-mono); letter-spacing: -.03em; }
.evalbar[data-lead="w"] .evalbar__num { bottom: 3px; color: var(--piece-b-fill); }
.evalbar[data-lead="b"] .evalbar__num { top: 3px; color: var(--piece-w-fill); }

/* ============================================================= match ===== */

.matchgrid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--sp-5); align-items: start; }
/* Keep the board inside the viewport: scrolling during a live game is the one
   thing that ruins watching it. */
.matchboard { max-width: min(620px, 100%, calc(100dvh - 300px)); }

.playerbar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md); }
.playerbar.is-turn { border-color: var(--accent); box-shadow: var(--glow-accent); }
.playerbar__name { font-family: var(--font-display); font-weight: 700; color: var(--text-hi); }
.playerbar__elo { font-size: var(--fs-sm); color: var(--text-dim); font-variant-numeric: tabular-nums; }

.movelist { max-height: 260px; overflow-y: auto; font-family: var(--font-mono); font-size: var(--fs-sm); }
.moverow { display: grid; grid-template-columns: 34px 1fr 1fr; gap: var(--sp-2); padding: 3px var(--sp-2); border-radius: var(--r-xs); }
.moverow:nth-child(odd) { background: color-mix(in oklab, var(--surface-2) 60%, transparent); }
.moverow__n { color: var(--text-faint); }
.movesan { cursor: pointer; padding: 1px 4px; border-radius: var(--r-xs); display: inline-flex; align-items: center; gap: 2px; }
.movesan:hover { background: var(--surface-3); }
.movesan.is-current { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.movesan.is-blunder { color: var(--danger); }
.movesan.is-good { color: var(--ok); }
.fig { width: 1em; height: 1em; vertical-align: -.16em; }
.fig path, .fig circle, .fig rect { fill: currentColor; stroke: none; }

.comment { max-height: 200px; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: var(--sp-2); }
.comment__line { font-size: var(--fs-sm); color: var(--text); padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border-left: 2px solid var(--border-strong); border-radius: 0 var(--r-sm) var(--r-sm) 0; animation: slideIn var(--dur-3) var(--ease-out); }
.comment__line.hot { border-left-color: var(--accent-3); color: var(--text-hi); }
.comment__line.bad { border-left-color: var(--danger); }
@keyframes slideIn { from { opacity: 0; translate: -8px 0; } }

.orders { display: grid; gap: var(--sp-2); }
.order {
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--sp-3); align-items: center;
  padding: var(--sp-3); border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; text-align: left; font: inherit; color: inherit;
  transition: border-color var(--dur-2), background var(--dur-2);
}
.order:hover:not(:disabled) { border-color: var(--accent); background: var(--surface-3); }
.order:disabled { opacity: .4; cursor: not-allowed; }
.order__name { font-weight: 600; color: var(--text-hi); font-size: var(--fs-sm); }
.order__desc { font-size: var(--fs-xs); color: var(--text-dim); line-height: 1.4; }
.order__cost { font-size: var(--fs-2xs); font-weight: 700; color: var(--accent-2); background: var(--accent-2-soft); padding: 3px 7px; border-radius: var(--r-full); }
.order__icon { font-size: 18px; }

.critical-flash { animation: critFlash 1.2s var(--ease-out); }
@keyframes critFlash { 0%, 100% { box-shadow: var(--sh-2); } 40% { box-shadow: 0 0 0 2px var(--accent-3), 0 0 40px -6px var(--accent-3); } }

/* ============================================================= tables ==== */

.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface-1); }
table.dt { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.dt thead th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 1;
  text-align: left; white-space: nowrap; padding: var(--sp-3) var(--sp-4);
  font: 600 var(--fs-2xs) var(--font-ui); letter-spacing: var(--ls-caps);
  text-transform: uppercase; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.dt td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-subtle); }
.dt tbody tr:last-child td { border-bottom: none; }
.dt tbody tr:hover td { background: var(--surface-2); }
.dt tbody tr.is-you td { background: var(--accent-soft); }
.dt tbody tr.is-you td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.dt tbody tr.zone-up td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
.dt tbody tr.zone-down td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.dt .n { text-align: right; font-variant-numeric: tabular-nums; }

/* ============================================================== tabs ===== */

.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); margin-bottom: var(--sp-5); overflow-x: auto; }
.tabs button {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: var(--sp-3) var(--sp-4); font: 500 var(--fs-md) var(--font-ui);
  color: var(--text-dim); border-bottom: 2px solid transparent; margin-bottom: -1px;
  white-space: nowrap; transition: color var(--dur-2), border-color var(--dur-2);
}
.tabs button:hover { color: var(--text-hi); }
.tabs button.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* ============================================================== items ==== */

.item {
  display: grid; grid-template-columns: 1fr auto; gap: var(--sp-3);
  padding: var(--sp-4); border-radius: var(--r-md);
  background: var(--surface-1); border: 1px solid var(--border);
  transition: border-color var(--dur-2);
}
.item:hover { border-color: var(--border-strong); }
.item__name { font-weight: 600; color: var(--text-hi); }
.item__desc { font-size: var(--fs-xs); color: var(--text-dim); line-height: 1.45; margin-top: 3px; }
.item__price { font-weight: 700; color: var(--accent-3); font-variant-numeric: tabular-nums; white-space: nowrap; }
.item__side { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-2); }
.item.is-owned { border-color: color-mix(in oklab, var(--ok) 35%, transparent); }
.item.is-equipped { background: var(--accent-soft); border-color: var(--accent); }

.tiers { display: flex; gap: 3px; margin-top: 6px; }
.tiers i { width: 14px; height: 4px; border-radius: 2px; background: var(--border-strong); }
.tiers i.on { background: var(--accent-3); }

/* ============================================================= toasts ==== */

.toasts {
  position: fixed; top: calc(var(--topbar-h) + var(--sp-3)); right: var(--sp-4);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--sp-2);
  width: min(360px, calc(100vw - var(--sp-8))); pointer-events: none;
}
.toast {
  pointer-events: auto; position: relative; overflow: hidden;
  display: grid; grid-template-columns: 20px 1fr; gap: var(--sp-3); align-items: start;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-glass); backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--border); border-left: 3px solid var(--tone, var(--accent));
  border-radius: var(--r-md); box-shadow: var(--sh-3);
  animation: toastIn var(--dur-3) var(--ease-spring) both;
}
.toast.is-out { animation: toastOut 200ms var(--ease-in) forwards; }
@keyframes toastIn { from { translate: 16px 0; scale: .97; opacity: 0; } }
@keyframes toastOut { to { translate: 16px 0; scale: .97; opacity: 0; margin-bottom: -60px; } }
.toast--ok { --tone: var(--ok); }
.toast--warn { --tone: var(--warn); }
.toast--err { --tone: var(--danger); }
.toast--xp { --tone: var(--accent-2); }
.toast--gold { --tone: var(--accent-3); }
.toast__title { font-weight: 600; color: var(--text-hi); font-size: var(--fs-sm); }
.toast__body { font-size: var(--fs-xs); color: var(--text-dim); margin-top: 2px; }

/* ============================================================= modals ==== */

dialog.modal {
  border: 1px solid var(--border); border-radius: var(--r-xl);
  background: var(--surface-1); color: var(--text); padding: 0;
  width: min(560px, calc(100vw - var(--sp-8))); max-height: min(86dvh, 760px);
  box-shadow: var(--sh-4);
}
dialog.modal::backdrop { background: var(--scrim); backdrop-filter: blur(3px); }
.modal__head { padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border-subtle); }
.modal__body { padding: var(--sp-5) var(--sp-6); overflow-y: auto; max-height: 60dvh; }
.modal__foot { display: flex; gap: var(--sp-3); justify-content: flex-end; padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border-subtle); }

/* ========================================================= celebration === */

.celebrate {
  position: fixed; inset: 0; z-index: var(--z-celebration);
  display: grid; place-items: center; pointer-events: none;
  background: radial-gradient(circle, transparent 35%, var(--scrim));
  animation: fadeOut 2.4s forwards;
}
@keyframes fadeOut { 0%, 70% { opacity: 1; } 100% { opacity: 0; } }
.celebrate__ring { position: absolute; width: 220px; aspect-ratio: 1; border-radius: 50%; border: 3px solid var(--accent-3); animation: shock 700ms var(--ease-out) both; }
@keyframes shock { from { scale: 0; opacity: 1; } to { scale: 1.8; opacity: 0; } }
.celebrate__text { font: 700 var(--fs-4xl)/1 var(--font-display); color: var(--text-hi); text-shadow: 0 0 40px var(--accent-3); animation: titleIn 500ms var(--ease-spring) both; text-align: center; }
.celebrate__sub { font-size: var(--fs-lg); color: var(--accent-3); margin-top: var(--sp-3); text-align: center; }
@keyframes titleIn { from { scale: 1.4; opacity: 0; letter-spacing: .3em; } to { scale: 1; opacity: 1; letter-spacing: 0; } }
.spark { position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--accent-3); animation: burst 1s var(--ease-out) both; }
@keyframes burst { from { translate: 0 0; opacity: 1; } to { translate: var(--dx) var(--dy); opacity: 0; scale: .3; } }

/* =============================================================== auth ==== */

.authpage { min-height: 100dvh; display: grid; grid-template-columns: 1fr 460px; }
.authpage__left { padding: var(--sp-16) var(--sp-12); display: flex; flex-direction: column; justify-content: center; gap: var(--sp-8); }
.authpage__right { background: var(--surface-1); border-left: 1px solid var(--border); padding: var(--sp-12) var(--sp-8); display: flex; flex-direction: column; justify-content: center; }
.authhero { font: 700 clamp(2rem, 4.5vw, 3.4rem)/1.05 var(--font-display); color: var(--text-hi); letter-spacing: -.02em; }
.authhero em { font-style: normal; background: linear-gradient(100deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.feature { display: grid; grid-template-columns: 34px 1fr; gap: var(--sp-4); }
.feature__icon { width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 17px; }
.feature__title { font-weight: 600; color: var(--text-hi); }
.feature__desc { font-size: var(--fs-sm); color: var(--text-dim); margin-top: 3px; line-height: 1.5; }

.langpick { display: flex; gap: var(--sp-2); }
.langpick button { flex: 1; }
.langpick button.is-active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.formerr { color: var(--danger); font-size: var(--fs-sm); min-height: 20px; }

.acceptbox {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  font-size: var(--fs-sm); color: var(--text-dim); margin: 0; line-height: 1.5; cursor: pointer;
}
.acceptbox input { width: 18px; height: 18px; flex: none; margin-top: 1px; accent-color: var(--accent); }
.acceptbox a { text-decoration: underline; }

/* ============================================================ helpers ==== */

.empty {
  padding: var(--sp-12) var(--sp-6); text-align: center; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: var(--r-lg);
}
.empty__icon { font-size: 34px; opacity: .4; margin-bottom: var(--sp-3); }

.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 7px 0; border-bottom: 1px solid var(--border-subtle); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: none; }
.kv b { color: var(--text-hi); font-variant-numeric: tabular-nums; }

.bigstat { text-align: center; padding: var(--sp-3); }
.bigstat__v { font: 700 var(--fs-3xl)/1 var(--font-display); color: var(--text-hi); font-variant-numeric: tabular-nums; }
.bigstat__l { font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: var(--ls-caps); color: var(--text-dim); margin-top: 5px; }

.radar { width: 100%; height: auto; overflow: visible; }
.radar__ring { fill: none; stroke: var(--border); stroke-width: .8; }
.radar__spoke { stroke: var(--border-subtle); stroke-width: .8; }
.radar__area { fill: color-mix(in oklab, var(--accent) 20%, transparent); stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.radar__area--2 { fill: color-mix(in oklab, var(--accent-2) 12%, transparent); stroke: var(--accent-2); stroke-dasharray: 3 3; }
.radar__dot { fill: var(--accent); }
.radar__lbl { fill: var(--text-dim); font-size: 8px; font-family: var(--font-ui); text-anchor: middle; letter-spacing: .04em; }

.progressline { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-dim); }

.onboard { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; background: var(--scrim); backdrop-filter: blur(6px); }
.onboard__card { width: min(520px, calc(100vw - 32px)); text-align: center; padding: var(--sp-8); }
.onboard__dots { display: flex; gap: 6px; justify-content: center; margin: var(--sp-5) 0; }
.onboard__dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); transition: background var(--dur-2); }
.onboard__dots i.on { background: var(--accent); width: 20px; border-radius: 4px; }

.codepill {
  display: inline-block; margin-top: 6px; padding: 8px 16px;
  background: var(--bg-sunken); border: 1px solid var(--accent);
  border-radius: var(--r-md); color: var(--accent);
  font-size: var(--fs-xl); font-weight: 700; letter-spacing: .22em;
}

/* ======================================================= legal chrome ==== */

.sitefoot {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3) var(--sp-5);
  margin-top: var(--sp-12); padding: var(--sp-5) 0 var(--sp-4);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-faint); font-size: var(--fs-xs);
}
.sitefoot a { color: var(--text-dim); }
.sitefoot a:hover { color: var(--accent); }
.sitefoot__links { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin-left: auto; }

.storagenotice {
  position: fixed; left: var(--sp-4); bottom: var(--sp-4); z-index: var(--z-toast);
  width: min(430px, calc(100vw - var(--sp-8)));
  display: flex; flex-direction: column; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  background: var(--surface-glass); backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  font-size: var(--fs-sm); color: var(--text);
  animation: toastIn var(--dur-4) var(--ease-spring) both;
}
.storagenotice a { text-decoration: underline; }
.storagenotice .btn { align-self: flex-start; }

/* =========================================================== responsive == */

@media (max-width: 1100px) {
  .matchgrid { grid-template-columns: minmax(0, 1fr); }
  .authpage { grid-template-columns: 1fr; }
  .authpage__left { display: none; }
  .authpage__right { border-left: none; }
}



/* ========================================================== tutorial ===== */

.tut {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--sp-4);
  background: var(--scrim); backdrop-filter: blur(8px);
  animation: toastIn var(--dur-3) var(--ease-out);
}
.tut.is-out { animation: fadeAway 200ms forwards; }
@keyframes fadeAway { to { opacity: 0; } }
.tut__card {
  width: min(560px, 100%); padding: var(--sp-8) var(--sp-7) var(--sp-6);
  text-align: center; box-shadow: var(--sh-4);
}
.tut__icon {
  width: 64px; height: 64px; margin: 0 auto var(--sp-4);
  display: grid; place-items: center; border-radius: var(--r-lg);
  background: var(--accent-soft); color: var(--accent); font-size: 30px;
}
.tut__body {
  color: var(--text); line-height: 1.7; margin: var(--sp-4) 0 0;
  font-size: var(--fs-lg); text-align: left;
}

/* ===================================================== content + rail ==== */

/*
 * Main column plus a side rail. These were written as inline grid styles in
 * each view with no breakpoint, so on a phone the two columns squeezed into
 * the same space and their cards overlapped. One class, one breakpoint, and
 * the rail drops below the content where there is no room for it.
 */
.grid--rail {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 350px);
  align-items: start;
}
.grid--rail-wide { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }

@media (max-width: 960px) {
  .grid--rail, .grid--rail-wide { grid-template-columns: minmax(0, 1fr); }
}

/* On a phone the bottom bar is the navigation: the storage notice must sit
   above it, not on top of it. */
@media (max-width: 860px) {
  .storagenotice {
    left: var(--sp-3); right: var(--sp-3); width: auto;
    bottom: calc(72px + env(safe-area-inset-bottom));
  }
  .toasts { top: calc(var(--topbar-h) + var(--sp-2)); right: var(--sp-3); left: var(--sp-3); width: auto; }
}

/* ===================================================== mobile navigation == */

.navitem--more { display: none; }
.navscrim { display: none; }

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) 1fr auto;
    grid-template-areas: "top" "main" "side";
  }

  /* Four destinations plus More. Anything else lives in the sheet: a bar that
     scrolls sideways hides its own contents behind an affordance nobody sees. */
  .app__side {
    position: sticky; bottom: 0; top: auto; height: auto;
    flex-direction: row; justify-content: space-around;
    overflow: visible; padding: var(--sp-2) var(--sp-1);
    padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
    background: var(--surface-glass); backdrop-filter: blur(14px);
    z-index: var(--z-sticky);
  }
  .navgroup { display: none; }
  .app__side .navitem { display: none; }
  .app__side .navitem--primary,
  .app__side .navitem--more { display: flex; }
  .navitem {
    flex-direction: column; gap: 3px; font-size: var(--fs-2xs);
    padding: 6px 4px; min-width: 0; flex: 1; text-align: center;
    border-radius: var(--r-md);
  }
  .navitem__icon { font-size: 17px; }
  .navitem.is-active::before { display: none; }
  .navitem.is-active { background: var(--accent-soft); }

  /* The sheet: every destination, laid out so none of them is off-screen. */
  .app.nav-open .app__side {
    position: fixed; inset: auto 0 0 0;
    flex-direction: row; flex-wrap: wrap; justify-content: flex-start;
    gap: var(--sp-2); padding: var(--sp-4);
    padding-bottom: calc(var(--sp-4) + env(safe-area-inset-bottom));
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: var(--sh-4);
    max-height: 70dvh; overflow-y: auto;
    z-index: var(--z-modal);
    animation: sheetUp var(--dur-3) var(--ease-out);
  }
  @keyframes sheetUp { from { translate: 0 100%; } }
  .app.nav-open .app__side .navitem { display: flex; flex: 0 0 calc(33.333% - var(--sp-2)); }
  .app.nav-open .navgroup {
    display: block; flex: 0 0 100%; padding: var(--sp-2) var(--sp-1) 0;
  }
  .app.nav-open .navscrim {
    display: block; position: fixed; inset: 0;
    background: var(--scrim); backdrop-filter: blur(3px);
    z-index: calc(var(--z-modal) - 1);
  }

  .app__main { padding: var(--sp-4); padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .wallet { gap: var(--sp-3); }
  .brand__name { display: none; }

  /* Tabs wrap instead of scrolling, so no tab is ever hidden off the edge. */
  .tabs { flex-wrap: wrap; gap: 2px; overflow: visible; }
  .tabs button { padding: var(--sp-2) var(--sp-3); font-size: var(--fs-sm); }
}
