/* Copyright (c) Edward James Harrison (composer of the Neotokyo OST). All rights reserved. */
/*
 * iOnym: Cards — app shell, home/catalog, the game table and its cards.
 * Colours and type come only from tokens.css. No game logic lives here: every state the CSS styles is either
 * structural (from the view) or an interaction state (dragging, pending, hint shown after a paid hint).
 */

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
html, body { min-height: 100%; }
body {
  /* a column, so the footer sits at the foot of a short screen and after a long one */
  display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-standard);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── the night sky behind everything (celestial panel canvas + faint starfield) ── */
.sky {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(110% 80% at 80% -10%, rgba(127,214,255,0.07), transparent 60%),
    radial-gradient(90% 70% at 0% 110%, rgba(183,156,255,0.07), transparent 55%),
    linear-gradient(160deg, var(--table-1), var(--table-2) 55%, var(--table-3));
}
.sky::before {
  content: ''; position: absolute; inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, var(--star), transparent),
    radial-gradient(1px 1px at 70% 60%, var(--star), transparent),
    radial-gradient(1px 1px at 45% 85%, var(--star), transparent),
    radial-gradient(1px 1px at 88% 18%, var(--star), transparent),
    radial-gradient(1px 1px at 8% 72%, var(--star), transparent),
    radial-gradient(1px 1px at 58% 12%, var(--star), transparent);
  background-size: 420px 420px;
  opacity: 0.5;
}

/* ── header ── */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--header-h); padding: 0 var(--gutter);
  border-bottom: 1px solid var(--border);
}
.wordmark {
  font-family: var(--font-wordmark); font-weight: 400; font-size: 19px; letter-spacing: 0.06em;
  color: var(--gold); text-decoration: none; white-space: nowrap;
  text-shadow: 0 0 14px rgba(233,201,138,0.28);
}
.wordmark small {
  font-family: 'Cinzel', serif; font-size: 10px; letter-spacing: 0.28em; color: var(--text-muted);
  margin-left: 8px; text-transform: uppercase; vertical-align: 2px;
}
.header-right { display: flex; align-items: center; gap: 8px; }

/* ── buttons, pills, segmented control (NOW .cal-pill / .cal-seg / .btn-primary) ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 34px; padding: 6px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font-size: 12.5px; font-family: var(--font-body); line-height: 1;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent-border); background: var(--surface-hover); }
/* one visible focus ring for every keyboard-reachable thing (links, buttons, cards, pile heads, the stock, toasts) */
:where(a, button, [tabindex], [role="button"]):focus-visible,
.btn:focus-visible, .seg button:focus-visible, .card:focus-visible, .slot-head:focus-visible, .slot--stock:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* the screen region and state titles take focus only so the reader lands there; no ring for them */
#screen:focus, #screen:focus-visible, .state-title:focus, .state-title:focus-visible { outline: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--accent-bg); border-color: var(--accent-border); color: var(--accent); font-weight: 600; }
.btn--primary:hover:not(:disabled) { background: var(--accent-border); }
.btn--ghost { background: transparent; }
.btn--icon { width: 34px; padding: 0; }
.cost {
  font-variant-numeric: tabular-nums; font-size: 11px; letter-spacing: 0.02em;
  color: var(--text-muted); padding-left: 7px; border-left: 1px solid var(--border);
}
.cost--free { color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.seg button {
  background: transparent; border: none; padding: 7px 14px; font-size: 12px; cursor: pointer; color: var(--text);
  transition: background .12s, color .12s;
}
.seg button[aria-checked="true"] { background: var(--accent-bg); color: var(--accent); font-weight: 600; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap;
  color: var(--accent); background: var(--accent-bg); border: 1px solid var(--accent-border);
}
.badge--quiet { color: var(--text-muted); background: transparent; border-color: var(--border); }
.badge--warn { color: #e9c98a; border-color: rgba(233,201,138,0.35); background: rgba(233,201,138,0.08); }
[data-theme="light"] .badge--warn, [data-theme="warm"] .badge--warn { color: #8a5a18; border-color: rgba(138,90,24,0.35); background: rgba(138,90,24,0.07); }

.eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: var(--accent);
}

#screen { flex: 1 0 auto; }

/* ── footer (NOW's public pages: a hairline, dim small type, the links in celestial cyan) ── */
.app-footer {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 18px;
  padding: 18px var(--gutter) max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  font-size: 11.5px; line-height: 1.5; letter-spacing: 0.02em; text-align: center; color: var(--text-dim);
}
.app-footer-links { display: inline-flex; align-items: center; gap: 10px; }
.app-footer a { color: var(--cel-cyan, var(--accent)); text-decoration: none; border-radius: 3px; }
.app-footer a:hover { text-decoration: underline; text-underline-offset: 3px; }
.app-footer-dot { color: var(--text-dim); }

/* ── the notice: one quiet line under the header (busy dealer, rate-limit countdown) — never a toast stack ── */
.notice {
  position: fixed; left: 50%; top: calc(var(--header-h) + 10px); transform: translateX(-50%); z-index: 10000;
  display: flex; align-items: center; gap: 10px; max-width: calc(100% - 2 * var(--gutter));
  padding: 9px 16px; border-radius: 999px;
  background: var(--modal-bg); border: 1px solid var(--modal-line); color: var(--modal-text);
  box-shadow: 0 10px 28px rgba(0,0,0,0.35);
  font-size: 13px; line-height: 1.35;
  animation: toast-in .24s var(--ease-out);
}
.notice-glyph { color: var(--cel-gold, #e9c98a); font-size: 12px; flex: none; }
.notice-text { font-family: var(--font-quote); font-size: 16px; color: var(--modal-ink); }
.notice-count {
  flex: none; padding-left: 10px; border-left: 1px solid var(--modal-line);
  font-variant-numeric: tabular-nums; font-size: 11.5px; letter-spacing: 0.04em; color: var(--modal-dim);
}
.notice-count:empty { display: none; }
.notice[data-kind="busy"] .notice-glyph { animation: notice-breathe 1.6s ease-in-out infinite; }
@keyframes notice-breathe { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }

/* ── state panels: offline, a table that belongs to someone else, a game that has ended (the night panel) ── */
.state-card {
  position: relative; overflow: hidden; max-width: 520px; margin: 40px auto; padding: 30px 28px 26px;
  border-radius: 18px; text-align: center;
  background: var(--modal-bg); border: 1px solid var(--modal-line); color: var(--modal-text);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.state-card::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--cel-gold, #e9c98a); opacity: .75; }
.state-medal {
  width: 64px; height: 64px; margin-bottom: 4px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--cel-gold, #e9c98a); font-family: var(--font-glyph); font-size: 30px;
  background: color-mix(in srgb, #e9c98a 10%, var(--modal-bg)); border: 1px solid color-mix(in srgb, #e9c98a 35%, var(--modal-bg));
}
.state-medal svg { width: 46px; height: 46px; opacity: .85; }
.state-eyebrow { font-size: 10.5px; font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: var(--modal-accent-default); }
.state-title { font-family: var(--font-display); font-weight: 500; font-size: 21px; line-height: 1.3; letter-spacing: 0.02em; color: var(--modal-ink); max-width: 30ch; }
.state-text { font-family: var(--font-quote); font-size: 17px; line-height: 1.5; color: var(--modal-dim); max-width: 42ch; }
.state-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }
.state-card .btn { background: var(--modal-raised2); border-color: var(--modal-line); color: var(--modal-ink); }
.state-card .btn--primary { border-color: color-mix(in srgb, var(--modal-accent-default) 55%, var(--modal-line)); color: var(--modal-ink); }
.state-card .btn:hover:not(:disabled) { border-color: var(--modal-accent-default); background: var(--modal-raised); }
.state-card :focus-visible { outline-color: var(--modal-accent-default); }
.home-list > .state-card { margin-top: 20px; }

/* while moves are paused (a rate limit) the table still shows, and still opens a card's info */
.table-host.is-paused .card.is-grabbable { cursor: pointer; }
.table-host.is-paused .slot--stock { cursor: default; }

/* ── the terms page (terms.html): NOW's legal-page reading column ── */
.terms { padding: 34px var(--gutter) 64px; }
.terms-body { max-width: 68ch; margin: 0 auto; font-size: 15px; line-height: 1.7; }
.terms-body h1 {
  font-family: var(--font-display); font-weight: 500; font-size: clamp(26px, 5vw, 34px); letter-spacing: 0.04em;
  color: var(--gold); margin: 6px 0 2px;
}
.terms-meta { font-size: 12px; letter-spacing: 0.04em; color: var(--text-dim); margin-bottom: 22px; }
.terms-lede { font-family: var(--font-quote); font-size: 19px; line-height: 1.5; color: var(--text-muted); }
.terms-body h2 {
  display: flex; align-items: center; gap: 10px; margin: 30px 0 8px;
  font-family: var(--font-display); font-weight: 500; font-size: 16px; letter-spacing: 0.05em; color: var(--text);
}
.terms-body h2::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--cel-glow, var(--border)), transparent 80%); }
.terms-body p { color: var(--text); margin: 0 0 10px; }
.terms-body code { font-size: 0.92em; padding: 1px 6px; border-radius: 6px; background: var(--input-bg); border: 1px solid var(--border); }
.header-right a.btn { text-decoration: none; }

/* ═══════════════ HOME / CATALOG ═══════════════ */
.home { max-width: 1080px; margin: 0 auto; padding: 34px var(--gutter) 64px; }
.home-hero { text-align: center; padding: 10px 0 26px; }
.home-hero h1 {
  font-family: var(--font-display); font-weight: 500; font-size: clamp(26px, 5vw, 38px); letter-spacing: 0.04em;
  color: var(--gold); text-shadow: 0 0 18px rgba(233,201,138,0.25); margin: 8px 0 10px;
}
.home-hero .lede {
  font-family: var(--font-quote); font-size: clamp(17px, 2.4vw, 20px); line-height: 1.5; color: var(--text-muted);
  max-width: 46ch; margin: 0 auto 20px;
}
.home-mode { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.home-mode .hint { color: var(--text-dim); font-size: 12px; }
.home-state { text-align: center; color: var(--text-muted); padding: 40px 0; }

.family { margin-top: 38px; }
.family-head { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.family-head::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--cel-glow, var(--border)), transparent 80%); }
.family-name { font-family: var(--font-display); font-weight: 500; font-size: 20px; letter-spacing: 0.06em; color: var(--text); }
.family-blurb { font-family: var(--font-quote); font-size: 17px; color: var(--text-muted); margin: 4px 0 14px; max-width: 70ch; }
.variant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; }
.variant-tile {
  position: relative; display: flex; flex-direction: column; gap: 10px; overflow: hidden;
  padding: 20px 20px 18px; border-radius: 18px;
  background: linear-gradient(160deg, var(--card-face-1), var(--card-face-2));
  border: 1px solid var(--card-line);
  transition: border-color .15s, transform .15s var(--ease-out);
}
.variant-tile::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--accent); opacity: .85; }
.variant-tile:hover { border-color: var(--accent-border); transform: translateY(-1px); }
.variant-tile h3 { font-family: var(--font-display); font-weight: 500; font-size: 19px; letter-spacing: 0.03em; color: var(--card-ink); line-height: 1.2; }
.variant-tile p { font-family: var(--font-quote); font-size: 16.5px; line-height: 1.5; color: var(--card-dim); flex: 1; }
.variant-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.variant-meta .badge { white-space: normal; line-height: 1.35; }
.variant-actions { display: flex; justify-content: flex-end; }

/* ═══════════════ GAME ═══════════════ */
.game { padding: 0 0 96px; }
.game-bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--border);
}
.game-title { display: flex; flex-direction: column; min-width: 0; flex: 1 1 200px; }
.game-title .eyebrow { font-size: 10px; letter-spacing: 0.2em; }
.game-title h2 {   /* the variant's whole name, wrapping (two lines on a phone) rather than ever being cut off */
  font-family: var(--font-display); font-weight: 500; font-size: 18px; letter-spacing: 0.04em; color: var(--text);
  line-height: 1.2; overflow-wrap: break-word; text-wrap: balance;
  padding: 0.08em 0;   /* Cinzel's glyph box (1.35 em) at line-height 1.2 */
}
.game-notes { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 3px; }

.score {
  display: flex; align-items: stretch; gap: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); overflow: hidden;
}
.score-cell { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 5px 12px; min-width: 54px; }
.score-cell + .score-cell { border-left: 1px solid var(--border); }
.score-k { font-size: 9.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-dim); }
.score-v { font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 500; color: var(--text); line-height: 1.25; }
.score-cell--points .score-v { font-family: 'Cinzel', serif; font-size: 17px; color: var(--gold); }
.score-v.bump { animation: bump .5s var(--ease-spring); }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }

.game-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ── the table ── */
.table {
  --card-w: 80px;
  --card-h: calc(var(--card-w) * 1.42);
  --gap: 8px;
  --r: calc(var(--card-w) * 0.085);
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: center;
  gap: calc(var(--gap) * 3) calc(var(--gap) * 4);
  padding: 22px var(--gutter) 30px;
  max-width: 100%;
  user-select: none; -webkit-user-select: none;
}
.zone { display: flex; flex-direction: column; align-items: center; gap: 8px; max-width: 100%; min-width: 0; }
.zone--wide { flex-basis: 100%; }
.zone-label {
  align-self: stretch; display: flex; align-items: center; gap: 10px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--cel-cyan, var(--accent));
}
.zone-label::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, var(--cel-glow, var(--border)), transparent 80%); }

.zone-row { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--gap); max-width: 100%; }

/* grid (lattice): an optional label column + colLabels header row */
.zone-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 2px; }
.zone-grid { display: grid; gap: var(--gap); align-items: start; justify-items: center; }
.grid-label {
  font-size: clamp(8.5px, calc(var(--card-w) * 0.13), 11px); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-muted); text-align: center; line-height: 1.2; overflow-wrap: anywhere;
}
.grid-label--col { align-self: end; padding-bottom: 2px; width: var(--card-w); }
.grid-label--row { align-self: center; justify-self: end; text-align: right; max-width: 7.5em; padding-right: 2px; }
.grid-corner { width: 1px; }
.grid-void {
  width: var(--card-w); height: var(--card-h); border-radius: var(--r);
  background: repeating-linear-gradient(135deg, transparent 0 6px, var(--slot-fill) 6px 7px);
  border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center; color: var(--text-dim); font-size: 11px;
}

/* wheel: slots on a circle (JS sets --wx/--wy in px); below the breakpoint, a 6 × 2 grid */
.zone-wheel { position: relative; }
.zone-wheel.is-circle .slot { position: absolute; left: var(--wx); top: var(--wy); }
.zone-wheel.is-grid { display: grid; grid-template-columns: repeat(6, var(--card-w)); gap: var(--gap); }
.wheel-art {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  color: var(--back-edge); pointer-events: none;
}
.wheel-art svg { display: block; width: 100%; height: 100%; }

/* ── slots ── */
.slot { position: relative; width: var(--card-w); flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; }
.slot-cards { position: relative; width: var(--card-w); height: var(--card-h); }
.slot-cards::before {   /* the empty place: a hairline outline */
  content: ''; position: absolute; inset: 0; border-radius: var(--r);
  border: 1px dashed var(--slot-line); background: var(--slot-fill);
}
.slot-mark {   /* centre mark in an empty place (cards.js renderMark fits its size and lines) */
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 6px; color: var(--text-dim); font-size: clamp(8px, calc(var(--card-w) * 0.12), 11px);
  letter-spacing: 0.1em; text-transform: uppercase; line-height: 1.25; pointer-events: none;
}
.slot-mark--glyph { font-family: var(--font-glyph); font-size: calc(var(--card-w) * 0.34); letter-spacing: 0; text-transform: none; }
.slot-caption {   /* under a slot; cards.js captionLayout fits it (smaller, then two lines), never cut off */
  flex: none; margin-top: 4px; text-align: center; line-height: 1.2; padding: 0.04em 0;
  font-size: clamp(8px, calc(var(--card-w) * 0.11), 10.5px); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--text-dim);
}
.slot--stock { cursor: pointer; }
.slot--stock .slot-cards::before { border-style: solid; }
.stock-count {
  position: absolute; right: -4px; bottom: -6px; z-index: 60; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-variant-numeric: tabular-nums; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); pointer-events: none;
}
.slot.is-over .slot-cards::before { border-color: var(--accent-border); border-style: solid; }

/* the head of a foundation / axis pile: an embossed plate above its place */
.slot-head {
  --tone: var(--ink-neutral);
  position: relative; width: calc(var(--card-w) + 6px); margin-bottom: 6px; padding: 5px 4px 6px;
  border-radius: calc(var(--r) * 1.2); cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: linear-gradient(180deg, color-mix(in oklab, var(--tone) 16%, var(--card-face-1)), color-mix(in oklab, var(--tone) 6%, var(--card-face-2)));
  border: 1px solid color-mix(in oklab, var(--tone) 38%, var(--card-line));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10), inset 0 -2px 0 rgba(0,0,0,0.28), 0 1px 0 rgba(0,0,0,0.3);
}
.slot-head-glyph {
  font-family: var(--font-glyph); line-height: 1; font-size: calc(var(--card-w) * 0.3);
  color: color-mix(in oklab, var(--tone) var(--tone-text-mix), var(--card-ink));
  text-shadow: 0 1px 0 rgba(0,0,0,0.45), 0 -1px 0 rgba(255,255,255,0.06);
}
.slot-head-name {   /* cards.js headLayout fits it (size, lines); the plate grows to hold it */
  display: block; font-family: 'Cinzel', serif; font-weight: 600; font-size: clamp(7.5px, calc(var(--card-w) * 0.115), 11px);
  letter-spacing: 0.06em; line-height: 1.15; color: var(--card-ink); max-width: 100%;
  padding: 0.11em 0;    /* holds Cinzel's 1.35 em glyph box at line-height 1.15 */
}
/* a fitted label's lines (client/fit.js): each line is set whole, so what was measured is what shows */
.fit-line { display: block; white-space: nowrap; }

/* ═══════════════ CARDS ═══════════════ */
.card {
  --tone: var(--ink-neutral);
  --tone-ink: color-mix(in oklab, var(--tone) var(--tone-text-mix), var(--card-ink));
  position: absolute; left: 0; top: 0;
  width: var(--card-w); height: var(--card-h); border-radius: var(--r);
  container-type: size;
  background: linear-gradient(165deg, var(--card-face-1), var(--card-face-2));
  border: 1px solid color-mix(in oklab, var(--tone) 26%, var(--card-line));
  box-shadow: var(--card-shadow);
  color: var(--card-ink);
  overflow: hidden;
  touch-action: manipulation;
  transition: box-shadow .15s, border-color .15s;
}
.card.is-grabbable { cursor: grab; touch-action: none; }
.card.is-tappable { cursor: pointer; }
.card::before {   /* the accent line in the card's own tone (NOW modal-standard anatomy) */
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: max(2px, 3cqw); background: var(--tone); z-index: 1;
}
.card-band {   /* top, height, padding and gap come from cards.js faceLayout (the band grows to hold the name) */
  position: absolute; left: 0; right: 0; top: max(2px, 3cqw); height: 19cqh;
  display: flex; align-items: center; gap: 4cqw; padding: 0 7cqw;
  border-bottom: 1px solid color-mix(in oklab, var(--tone) 18%, transparent);
}
.card-band-glyph { font-family: var(--font-glyph); color: var(--tone-ink); font-size: 15cqw; line-height: 1; flex: none; text-align: center; }
.card-band-name {   /* the whole name, in the lines fit.js chose; never ellipsized */
  display: block; flex: none; font-family: 'Cinzel', serif; font-weight: 600; font-size: 12cqw; letter-spacing: 0.03em;
  line-height: 1.1; color: var(--card-ink);
  padding: 0.135em 0;   /* Cinzel's glyph box is 1.35 em tall: at line-height 1.1 it overhangs each line by 0.125 em */
}
.card.is-narrow .card-band { justify-content: center; }
.card.is-narrow .card-band-name { text-align: center; }
.card-medal {   /* size and centre (below the band) come from faceLayout */
  position: absolute; left: 50%; top: 56%; transform: translate(-50%, -50%);
  width: 58cqw; height: 58cqw; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in oklab, var(--tone) 13%, var(--card-face-2));
  border: 1px solid color-mix(in oklab, var(--tone) 42%, var(--card-face-2));
  box-shadow: 0 0 0 3cqw color-mix(in oklab, var(--tone) 5%, transparent);
}
.card-glyph {
  font-family: var(--font-glyph); line-height: 1; font-size: 32cqw; color: var(--tone-ink);
  text-shadow: 0 0 6cqw color-mix(in oklab, var(--tone) 30%, transparent);
}
.card-glyph.is-text { font-family: 'Cinzel', serif; font-weight: 500; letter-spacing: 0.02em; text-shadow: none; }
.card-band-glyph.is-text { font-family: 'Cinzel', serif; font-weight: 700; letter-spacing: 0.02em; }
.card-title {   /* a card with no glyph (deities, days): its name is the face; faceLayout fits it below the band */
  position: absolute; left: 7cqw; right: 7cqw; top: 30cqh; height: 50cqh;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-family: 'Cinzel', serif; font-weight: 600; line-height: 1.12; letter-spacing: 0.03em;
  color: var(--tone-ink);
}
.card-title-text { display: block; padding: 0.125em 0; }   /* Cinzel's 1.35 em glyph box at line-height 1.12 */
.card.glyph-none .card-band-name { color: var(--card-dim); font-weight: 500; }
.card.glyph-none .card-band-name.is-sole { color: var(--card-ink); }   /* no room for the title: the band is the name */
.card-sub {   /* one fitted line, or not shown at all (faceLayout): never cut off */
  position: absolute; left: 4cqw; right: 4cqw; bottom: 5.5cqh; text-align: center; line-height: 1.2;
  font-size: clamp(6px, 9.5cqw, 10px); letter-spacing: 0.14em; text-transform: uppercase; color: var(--card-dim);
  white-space: nowrap; padding: 0.04em 0;
}
/* a picture face (tarot): the whole image, contained (never cropped), as a framed plate on the face below the band */
.card-art {
  position: absolute; border-radius: calc(var(--r) * 0.55); pointer-events: none;
  background: color-mix(in oklab, var(--tone) 10%, var(--card-face-2));
  border: 1px solid color-mix(in oklab, var(--tone) 40%, var(--card-line));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.card-art-img {   /* the pictures run 182–194 × 330: contained in the 190 × 330 box, never stretched or cropped */
  display: block; object-fit: contain; border-radius: calc(var(--r) * 0.35); pointer-events: none;
  -webkit-user-drag: none; user-select: none; -webkit-user-select: none;
  background: var(--card-face-2);
}

/* the back: deep field, gold hairline frame, the astrolabe motif */
.card.is-down {
  border-color: var(--back-edge);
  background:
    repeating-linear-gradient(45deg, transparent 0 5px, rgba(233,201,138,0.035) 5px 6px),
    repeating-linear-gradient(-45deg, transparent 0 5px, rgba(233,201,138,0.035) 5px 6px),
    radial-gradient(70% 55% at 50% 50%, var(--back-1), var(--back-2));
}
.card.is-down::before {
  height: auto; inset: 5cqw; background: none; border-radius: calc(var(--r) * 0.6);
  border: 1px solid var(--back-edge);
}
.card-back-art { position: absolute; left: 50%; top: 50%; width: 78cqw; height: 78cqw; transform: translate(-50%, -50%); color: var(--back-ink); }

/* stack depth: a thin edge per few cards under the top one */
.slot-cards[data-depth="1"] > .card:first-child { box-shadow: 1px 1px 0 var(--card-line), var(--card-shadow); }
.slot-cards[data-depth="2"] > .card:first-child { box-shadow: 1px 1px 0 var(--card-line), 2px 2px 0 rgba(0,0,0,0.35), 3px 3px 0 var(--card-line), var(--card-shadow); }
.slot-cards[data-depth="3"] > .card:first-child { box-shadow: 1px 1px 0 var(--card-line), 2px 2px 0 rgba(0,0,0,0.35), 3px 3px 0 var(--card-line), 4px 4px 0 rgba(0,0,0,0.35), 5px 5px 0 var(--card-line), var(--card-shadow); }

/* interaction states */
.card.is-lifted { visibility: hidden; }
.drag-layer { position: fixed; left: 0; top: 0; z-index: 900; pointer-events: none; will-change: transform; }
.drag-layer .card { box-shadow: 0 14px 30px rgba(0,0,0,0.5), 0 2px 0 rgba(0,0,0,0.3); }
.drag-layer.is-dragging .card { cursor: grabbing; }
.drag-layer.is-pending { opacity: 0.55; animation: pending 1s ease-in-out infinite alternate; }
@keyframes pending { from { opacity: 0.4; } to { opacity: 0.7; } }
.card.is-shaking { animation: shake .42s var(--ease-out); }
@keyframes shake {
  0%, 100% { translate: 0 0; } 20% { translate: -5px 0; } 40% { translate: 4px 0; } 60% { translate: -3px 0; } 80% { translate: 2px 0; }
}
.hint-src { outline: 2px solid var(--gold); outline-offset: 2px; animation: hint-pulse 0.9s ease-in-out 3; }
.slot.hint-dst .slot-cards::before { border: 2px solid var(--gold); }
.slot.hint-dst { animation: hint-pulse 0.9s ease-in-out 3; }
@keyframes hint-pulse { 0%, 100% { filter: none; } 50% { filter: drop-shadow(0 0 10px rgba(233,201,138,0.75)); } }

/* floating points delta ("−5") */
.delta-float {
  position: fixed; z-index: 1000; pointer-events: none; transform: translate(-50%, -50%);
  font-family: 'Cinzel', serif; font-weight: 600; font-size: 18px; color: #ef6c5b;
  text-shadow: 0 1px 0 rgba(0,0,0,0.6);
  animation: delta-rise 1.3s var(--ease-out) forwards;
}
.delta-float.is-plus { color: #7ed3a8; }
@keyframes delta-rise { 0% { opacity: 0; translate: 0 6px; } 15% { opacity: 1; } 100% { opacity: 0; translate: 0 -34px; } }

/* ── the caption ("why it fits") and toasts ── */
.toasts {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 1200; display: flex; flex-direction: column-reverse; align-items: center; gap: 8px;
  width: min(560px, calc(100% - 2 * var(--gutter))); pointer-events: none;
}
.toast {
  position: relative; overflow: hidden; pointer-events: auto; width: 100%;
  padding: 12px 40px 12px 18px; border-radius: 14px;
  background: var(--modal-bg); color: var(--modal-text); border: 1px solid var(--modal-line);
  font-size: 13px; line-height: 1.5;
  animation: toast-in .28s var(--ease-out);
}
.toast::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--toast-accent, var(--modal-accent-default)); }
.toast.is-leaving { animation: toast-out .22s ease-in forwards; }
.toast-eyebrow { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--toast-accent, var(--modal-accent-default)); margin-bottom: 2px; }
.toast-text { font-family: var(--font-quote); font-size: 17px; line-height: 1.45; color: var(--modal-ink); }
.toast--plain .toast-text { font-family: var(--font-body); font-size: 13px; color: var(--modal-text); }
.toast-close {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  background: var(--modal-raised2); border: 1px solid var(--modal-line); color: var(--modal-dim); font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ── responsive ── */
@media (max-width: 720px) {
  .game-bar { gap: 8px 10px; }
  .score-cell { padding: 4px 8px; min-width: 44px; }
  .btn { min-height: 32px; padding: 5px 11px; font-size: 12px; }
  .btn .btn-label-long { display: none; }
}
@media (max-width: 480px) {
  :root { --gutter: 12px; }
  .table { --gap: 4px; padding-top: 16px; }
  .wordmark { font-size: 16px; }
  .wordmark small { display: none; }
  .game-title h2 { font-size: 16px; }
  .score-v { font-size: 14px; }
  .score-cell--points .score-v { font-size: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  .delta-float { animation: none; opacity: 1; }
}

/* ═══════════════ CODEX button + REWARD MOMENT ═══════════════ */
.codex-btn { border-color: rgba(233,201,138,0.35); }
.codex-btn-glyph { color: var(--gold); font-size: 13px; line-height: 1; }
.codex-count {
  min-width: 22px; padding: 2px 7px; border-radius: 999px; text-align: center;
  font-family: 'Cinzel', serif; font-weight: 600; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--gold); background: rgba(233,201,138,0.1); border: 1px solid rgba(233,201,138,0.3);
}
.codex-btn.is-ticking .codex-count { animation: codex-tick .5s var(--ease-spring); }
.codex-btn.is-ticking { animation: codex-glow .7s ease-out; }
@keyframes codex-tick { 0% { transform: scale(1); } 40% { transform: scale(1.32); } 100% { transform: scale(1); } }
@keyframes codex-glow { 0% { box-shadow: 0 0 0 0 rgba(233,201,138,0.55); } 100% { box-shadow: 0 0 0 10px rgba(233,201,138,0); } }

/* the moment: a night-panel card of collectible tokens beside the destination (always the night panel, like the modal) */
.reward-moment {
  --reward-accent: var(--cel-gold, #e9c98a);
  position: fixed; z-index: 1100; overflow: visible;
  padding: 12px 12px 10px; border-radius: 16px;
  background: var(--modal-bg); border: 1px solid var(--modal-line); color: var(--modal-text);
  box-shadow: 0 18px 40px rgba(0,0,0,0.45);
  animation: reward-panel-in .3s var(--ease-out);
  cursor: pointer;
}
.reward-moment::before {
  content: ''; position: absolute; left: 14px; right: 14px; top: 0; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--reward-accent), #e9c98a, transparent);
}
.reward-moment.is-leaving { background: transparent; border-color: transparent; box-shadow: none; transition: background .35s, border-color .35s, box-shadow .35s; }
.reward-moment.is-leaving .reward-eyebrow { opacity: 0; transition: opacity .25s; }
.reward-eyebrow {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin: 0 4px 8px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.2em; text-transform: uppercase; color: #e9c98a;
}
.reward-hops { color: var(--modal-faint); letter-spacing: 0.12em; }
.reward-chain { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.reward-token {
  position: relative; overflow: hidden; padding: 9px 12px 8px; border-radius: 12px;
  background: linear-gradient(160deg, var(--modal-raised2), var(--modal-raised));
  border: 1px solid color-mix(in srgb, #e9c98a 34%, var(--modal-line));
  opacity: 0; transform: translateY(8px) scale(.94);
}
.reward-token.is-in { animation: reward-collect .62s var(--ease-spring) forwards; }
.reward-token.is-in::after {   /* the "collected" sheen: one sweep of light across the token */
  content: ''; position: absolute; top: 0; bottom: 0; left: -60%; width: 50%; pointer-events: none;
  background: linear-gradient(100deg, transparent, rgba(255,240,205,0.28), transparent);
  animation: reward-sheen .9s .12s ease-out forwards;
}
.reward-token.is-known { border-color: var(--modal-line); }
/* the path: a hairline joining each token to the next (card → … → head) */
.reward-chain.is-path .reward-token:not(:last-child)::before {
  content: ''; position: absolute; left: 22px; bottom: -11px; width: 1px; height: 11px;
  background: linear-gradient(#e9c98a, transparent);
}
.reward-chain.is-path .reward-token { overflow: visible; }
.reward-chain.is-path .reward-token.is-in::after { display: none; }
.reward-chain.is-path .reward-token.is-in { box-shadow: inset 0 0 0 1px rgba(233,201,138,0.0); animation: reward-collect .62s var(--ease-spring) forwards, reward-ring .9s .1s ease-out; }
.reward-link { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; color: var(--modal-ink); }
.reward-ent { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.reward-glyph { font-family: var(--font-glyph); font-size: 17px; line-height: 1; color: #e9c98a; }
.reward-ent.is-from .reward-glyph { color: var(--reward-accent); }
.reward-name { font-family: 'Cinzel', serif; font-weight: 600; letter-spacing: 0.03em; font-size: 13px; }
.reward-arrow { color: var(--modal-faint); }
.reward-caption { margin-top: 3px; font-family: var(--font-quote); font-size: 15px; line-height: 1.35; color: var(--modal-text); }
.reward-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 5px; }
.reward-badge {
  font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px;
  color: var(--modal-dim); border: 1px solid var(--modal-line);
}
.reward-known { font-size: 11px; color: var(--modal-faint); font-style: italic; }
.reward-moment.is-still .reward-token { opacity: 1; transform: none; animation: none; }
.reward-moment.is-still .reward-token::after { display: none; }
@keyframes reward-panel-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes reward-collect {
  0% { opacity: 0; transform: translateY(8px) scale(.94); }
  60% { opacity: 1; transform: translateY(0) scale(1.03); }
  100% { opacity: 1; transform: none; }
}
@keyframes reward-sheen { to { left: 120%; } }
@keyframes reward-ring { 0% { box-shadow: 0 0 0 0 rgba(233,201,138,0.45); } 100% { box-shadow: 0 0 0 8px rgba(233,201,138,0); } }
@media (prefers-reduced-motion: reduce) {
  .reward-token { opacity: 1; transform: none; }
}
