/* Lightkeepers UI — Moonlit Porcelain (v0.2).
   Midnight-indigo glass, glazed ivory, fine gold hairlines; team Jade (seat 0,
   circle) vs Amber (seat 1, diamond). Board colours live in public/js/theme.js. */
:root {
  --ink: #1b2140;
  --bg: #070b1f;
  --panel: rgba(17, 23, 54, 0.84);
  --panel-edge: rgba(201, 164, 92, 0.5);
  --hair: rgba(201, 164, 92, 0.55);
  --ivory: #f8f5ee;
  --ivory-2: #e4ddcd;
  --cream: #f3efe6;
  --muted: #aab3d6;
  --gold: #e6c27a;
  --gold-hot: #fff4d6;
  --gold-deep: #a87a26;
  --danger: #ff6b7d;
  --seat0: #2aa98f;
  --seat0-dark: #17695b;
  --seat0-light: #a3f0dc;
  --seat1: #ee8446;
  --seat1-dark: #a84f22;
  --seat1-light: #ffcaa4;
  --team: var(--seat0);
  --team-dark: var(--seat0-dark);
  --team-light: var(--seat0-light);
  --opp: var(--seat1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
body[data-seat="1"] {
  --team: var(--seat1);
  --team-dark: var(--seat1-dark);
  --team-light: var(--seat1-light);
  --opp: var(--seat0);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 80% at 50% 20%, #1a2452 0%, #0c1230 55%, var(--bg) 100%);
  color: var(--cream);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }
.sprite-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button, input { font: inherit; color: inherit; }
kbd {
  display: inline-block; min-width: 1.5em; padding: 0 .35em; border-radius: 5px;
  border: 1px solid var(--hair); background: rgba(255,255,255,.06); font-size: .85em; text-align: center;
}

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; }
#app[data-screen="home"] #screen-home,
#app[data-screen="lobby"] #screen-lobby { display: flex; }
#app[data-screen="game"] #screen-game { display: flex; }

/* ---------- home / lobby ---------- */
.backdrop { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .55; filter: brightness(.7) saturate(1.05); }
.home-inner {
  position: relative; z-index: 1; margin: auto; width: min(440px, 100%);
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px; max-height: 100%; overflow-y: auto;
}
/* ---------- home: fixed app shell (header · panel · bottom tabs) ---------- */
/* The page never scrolls; only the active panel does, when it must. */
.shell {
  position: relative; z-index: 1; width: min(480px, 100%); height: 100%; margin: 0 auto;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
}
.shell-head {
  display: flex; align-items: center; min-height: 64px; min-width: 0;
  /* right: room for the fixed ? ♪ ≈ buttons */
  padding: calc(10px + var(--safe-top)) 164px 6px 12px;
}
.hdr-trophies {
  display: flex; align-items: center; gap: 8px; min-height: 44px; min-width: 0; max-width: 100%;
  padding: 3px 14px 3px 6px; border-radius: 999px; cursor: pointer; color: var(--ivory);
  background: rgba(14, 20, 50, .88); border: 1px solid var(--panel-edge); box-shadow: 0 3px 0 #0b0f26;
}
.hdr-trophy-icon { width: 32px; height: 32px; flex: none; filter: drop-shadow(0 0 8px rgba(255, 210, 120, .5)); }
.hdr-trophy-text { display: flex; flex-direction: column; min-width: 0; text-align: left; line-height: 1.1; }
.hdr-trophy-text b { font-family: var(--serif); font-size: 19px; color: var(--gold-hot); font-variant-numeric: tabular-nums; }
.hdr-trophy-text span {
  font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--gold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.shell-main { position: relative; min-height: 0; }
.tab-panel {
  position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 16px 14px; display: flex; flex-direction: column; gap: 12px;
}
.tab-panel:focus { outline: none; }
/* Centre the Battle content when it fits; auto margins collapse (no clipping) when it doesn't. */
.battle > :first-child { margin-top: auto; }
.battle > :last-child { margin-bottom: auto; }
.panel-title { margin: 6px 0 0; font-family: var(--serif); font-weight: 600; font-size: 24px; color: var(--ivory); }

.tabbar {
  position: relative; z-index: 2; padding: 6px 10px calc(6px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(8, 12, 34, .98), rgba(12, 17, 44, .92)); border-top: 1px solid var(--hair);
}
.tabbar [role="tablist"] { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tab {
  min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  font-weight: 700; font-size: 12px; letter-spacing: 1px; text-transform: uppercase;
}
.tab svg { width: 26px; height: 26px; opacity: .75; }
.tab[aria-selected="true"] { color: var(--gold-hot); background: rgba(201,164,92,.14); border-color: var(--panel-edge); }
.tab[aria-selected="true"] svg { opacity: 1; }

.brand { text-align: center; display: flex; flex-direction: column; align-items: center; }
.brand-icon { width: 56px; height: 56px; filter: drop-shadow(0 0 18px rgba(255, 220, 150, .6)); }
body.has-art .brand-icon { display: none; }
.hero {
  display: block; height: clamp(84px, 20vh, 170px); width: auto; max-width: 100%; aspect-ratio: 640 / 300;
  margin: 0 auto -4px; filter: drop-shadow(0 12px 18px rgba(0,0,0,.5));
}
h1 {
  margin: 2px 0 4px; font-family: var(--serif); font-weight: 600; text-transform: uppercase;
  /* sized so the full word always fits a 320 px wide column (it used to clip at 360 px) */
  font-size: clamp(24px, 7.6vw, 38px); letter-spacing: .12em; padding-left: .12em; line-height: 1.05;
  white-space: nowrap; max-width: 100%;
  color: var(--ivory);
  text-shadow: 0 0 22px rgba(255, 230, 180, .35), 0 2px 0 rgba(10, 14, 40, .9);
}
.tagline {
  margin: 0 auto; max-width: 34ch; color: #e6e9f7; line-height: 1.4; font-size: 14px;
  text-shadow: 0 1px 2px #000, 0 0 12px rgba(0,0,0,.8);
}
.play-panel { padding: 14px; gap: 10px; }
.friend-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.friend-row .btn { padding: 10px 8px; }
.play-panel .error:empty { min-height: 0; margin-top: -10px; } /* kept in the tree for role=alert */
.panel {
  background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 22px;
  padding: 18px; box-shadow: 0 18px 40px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.07);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; flex-direction: column; gap: 12px;
}
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: 14px; cursor: pointer;
  border: 1px solid var(--hair); background: linear-gradient(180deg, #26305e, #1a2248); color: var(--ivory);
  font-weight: 700; font-size: 16px; letter-spacing: .02em;
  box-shadow: 0 3px 0 #0b0f26, inset 0 1px 0 rgba(255,255,255,.1); transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #0b0f26; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, #fffdf8, #e7dfcd); color: #1b2140; border-color: var(--gold);
  box-shadow: 0 3px 0 #8f7440, 0 0 24px rgba(255, 220, 160, .22), inset 0 1px 0 #fff;
}
.btn.big { min-height: 56px; font-size: 18px; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.2); box-shadow: none; color: var(--muted); }
:focus-visible { outline: 3px solid var(--gold-hot); outline-offset: 2px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--hair); opacity: .5; }
.join-row { display: flex; gap: 10px; }
.field-label { font-weight: 700; font-size: 14px; color: var(--gold-hot); }
.join-row input, .share input {
  flex: 1; min-width: 0; min-height: 48px; border-radius: 14px; border: 1px solid var(--hair);
  background: #0a1030; padding: 0 14px; font-size: 22px; letter-spacing: 6px; text-transform: uppercase; font-weight: 700;
  box-shadow: inset 0 2px 0 rgba(0,0,0,.4);
}
.share input { font-size: 13px; letter-spacing: 0; text-transform: none; font-weight: 500; color: var(--muted); }
.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.hint b { color: var(--ivory); }
.error { margin: 0; min-height: 1em; color: var(--danger); font-weight: 700; font-size: 14px; }
.status { margin: 0; text-align: center; font-weight: 700; color: var(--gold-hot); }
.howto ol { padding-left: 20px; margin: 0 0 10px; line-height: 1.45; font-size: 14px; color: #dfe3f3; }
.howto li { margin-bottom: 6px; }
.gallery-link {
  display: block; text-align: center; color: var(--gold-hot); font-weight: 600; font-size: 14px;
  padding: 12px; border-radius: 14px; background: rgba(10, 15, 40, .75); border: 1px solid rgba(201,164,92,.3);
  text-decoration: none;
}
.gallery-link:hover { background: rgba(26, 34, 72, .9); }
.sheet-body .gallery-link { margin-top: 12px; }

/* dialogs (Join, Help) */
.sheet {
  padding: 0; border: 0; background: transparent; color: var(--cream);
  width: min(440px, calc(100% - 24px)); max-height: calc(100% - 24px);
}
.sheet::backdrop { background: rgba(4, 7, 22, .76); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.sheet-card {
  display: flex; flex-direction: column; gap: 10px; max-height: calc(100dvh - 24px); overflow: hidden;
  background: linear-gradient(180deg, #1c2554, #121939); border: 1px solid var(--panel-edge); border-radius: 22px;
  padding: 14px 16px 16px; box-shadow: 0 24px 50px rgba(0,0,0,.6); animation: rise .25s ease-out;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sheet-head h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 22px; color: var(--ivory); }
.sheet-close { flex: none; font-size: 16px; }
.sheet-body { overflow-y: auto; min-height: 0; overscroll-behavior: contain; }

/* Cards tab */
.card-info { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card-info li {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 16px;
  background: linear-gradient(180deg, rgba(28, 37, 84, .92), rgba(14, 20, 50, .92)); border: 1px solid rgba(201,164,92,.35);
}
.ci-art { width: 56px; height: 56px; display: grid; place-items: center; }
.ci-art svg, .ci-art .portrait { width: 52px; height: 52px; }
.ci-art .portrait { display: none; }
.card-info li.has-art .portrait { display: block; }
.card-info li.has-art svg { display: none; }
.card-info h3 { margin: 0 0 2px; font-size: 16px; display: flex; align-items: baseline; gap: 8px; color: var(--ivory); }
.ci-cost { font-size: 12px; font-weight: 700; color: #1b2140; background: var(--gold); border-radius: 999px; padding: 1px 8px; }
.card-info p { margin: 0; font-size: 13px; line-height: 1.4; color: #dfe3f3; }
.rule-list { margin: 0; display: grid; gap: 4px; font-size: 13px; padding: 10px 12px; border-radius: 14px; background: rgba(10, 15, 40, .8); border: 1px solid rgba(201,164,92,.25); }
.rule-list div { display: grid; grid-template-columns: 7.5em 1fr; gap: 8px; }
.rule-list dt { color: var(--gold); font-weight: 700; }
.rule-list dd { margin: 0; color: #dfe3f3; }

/* personal progression: trophies, Trophy Road, record */
.journey {
  background: linear-gradient(180deg, rgba(28, 37, 84, .9), rgba(14, 20, 50, .9)); border: 1px solid var(--panel-edge);
  border-radius: 20px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 12px 30px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,255,255,.07);
}
.journey-head { display: flex; align-items: center; gap: 10px; }
.trophy-icon { width: 40px; height: 40px; flex: none; filter: drop-shadow(0 0 12px rgba(255, 210, 120, .55)); }
.journey-total { display: flex; flex-direction: column; min-width: 0; }
.journey-total b { font-family: var(--serif); font-size: 30px; line-height: 1; color: var(--gold-hot); font-variant-numeric: tabular-nums; }
.journey-total span { font-size: 12px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: var(--gold); }
.record { margin: 0 0 0 auto; display: grid; gap: 2px; text-align: right; font-size: 13px; }
.record div { display: flex; gap: 8px; justify-content: flex-end; }
.record dt { color: var(--muted); font-weight: 600; }
.record dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ivory); }
.road-bar { position: relative; height: 10px; border-radius: 999px; background: #0a1030; border: 1px solid rgba(201,164,92,.4); overflow: hidden; }
.road-bar i {
  position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--p, 0));
  background: linear-gradient(90deg, #a87a26, #f3c566 70%, #fff4d6); transition: transform .6s ease-out;
}
.road-next { margin: 0; font-size: 12px; font-weight: 700; color: #dfe3f3; }
.road-next:empty { display: none; }
.journey[data-state="unavailable"] .trophy-icon, .journey[data-state="unavailable"] .road-bar { opacity: .4; }
.journey-block { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 18px; background: rgba(10, 15, 40, .82); border: 1px solid rgba(201,164,92,.25); }
.journey-block h3 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--gold); }
.road-list, .recent-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.road-list li { display: flex; justify-content: space-between; padding: 5px 10px; border-radius: 10px; background: rgba(255,255,255,.03); color: var(--muted); }
.road-list li.reached { color: var(--ivory); background: rgba(201,164,92,.12); }
.road-list li.current { outline: 1px solid var(--gold); color: var(--gold-hot); font-weight: 700; }
.road-list .rl-at { font-variant-numeric: tabular-nums; }
.recent-list li {
  display: grid; grid-template-columns: 3.2em 1fr auto auto; gap: 2px 8px; align-items: baseline;
  padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,.04); border-left: 3px solid var(--muted);
}
.recent-list li.win { border-left-color: var(--seat0-light); }
.recent-list li.loss { border-left-color: var(--danger); }
.recent-list .rc-out { font-weight: 700; }
.recent-list .rc-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #dfe3f3; }
.recent-list .rc-score, .recent-list .rc-delta { font-variant-numeric: tabular-nums; font-weight: 700; }
.recent-list .rc-when { grid-column: 2 / -1; font-size: 11px; color: var(--muted); }
.disclosure { text-align: center; color: #dfe3f3; }

/* Journey: keep your progress (private code copy / restore) */
.keep { display: block; }
.keep-body { display: flex; flex-direction: column; gap: 8px; }
.keep summary {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; margin: -6px -8px;
  padding: 0 8px; border-radius: 12px; cursor: pointer; list-style: none;
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; color: var(--gold);
}
.keep summary::-webkit-details-marker { display: none; }
.keep summary::after { content: "▾"; font-size: 16px; letter-spacing: 0; transition: transform .15s; }
.keep[open] summary { margin-bottom: 6px; }
.keep[open] summary::after { transform: rotate(180deg); }
.keep-warn b { color: var(--gold-hot); }
.keep-status:empty { display: none; }
.keep-status[data-kind="ok"] { color: #9ff0d0; font-weight: 700; }
.keep-status[data-kind="bad"] { color: var(--danger); font-weight: 700; }
.keep-reveal { display: flex; flex-direction: column; gap: 6px; }
.code-field {
  width: 100%; min-width: 0; min-height: 44px; border-radius: 12px; border: 1px solid var(--hair); background: #0a1030;
  padding: 0 10px; font: 600 12px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0; /* 36 chars fit at 360 px */
  box-shadow: inset 0 2px 0 rgba(0,0,0,.4); user-select: all; -webkit-user-select: all;
}
.restore-form { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; padding-top: 10px; border-top: 1px solid rgba(201,164,92,.2); }
.restore-row { display: flex; flex-wrap: wrap; gap: 8px; }
.restore-row .code-field { flex: 1 1 12em; width: auto; }
.restore-row .btn { flex: 1 0 auto; min-height: 44px; }
.restore-compare { margin: 0; display: grid; gap: 6px; font-size: 14px; }
.restore-compare div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 12px; background: rgba(255,255,255,.04); }
.restore-compare dt { color: var(--muted); font-weight: 600; }
.restore-compare dd { margin: 0; font-weight: 700; color: var(--ivory); text-align: right; font-variant-numeric: tabular-nums; }
.restore-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#restore-dialog .sheet-card { overflow-y: auto; overscroll-behavior: contain; }
#restore-dialog .error:empty { display: none; }

/* result: trophy change */
.result-progress {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 12px; border-radius: 16px;
  background: rgba(201,164,92,.1); border: 1px solid rgba(201,164,92,.35); position: relative;
}
.rp-line { display: flex; align-items: center; gap: 8px; }
.rp-icon { width: 34px; height: 34px; }
.rp-line b { font-family: var(--serif); font-size: 30px; line-height: 1; color: var(--gold-hot); font-variant-numeric: tabular-nums; }
.result-progress[data-dir="down"] b { color: #cfd6f5; }
.rp-line span { font-weight: 700; color: var(--ivory); font-variant-numeric: tabular-nums; }
.rp-note { margin: 0; font-size: 13px; color: #dfe3f3; line-height: 1.4; }
.result-progress[data-status]:not([data-status="saved"]) .rp-icon { opacity: .4; }
.result-progress.celebrate { animation: glow 1.4s ease-out; }
.result-progress.celebrate .rp-icon { animation: trophy-pop .7s cubic-bezier(.2, 1.6, .4, 1); }
.result-progress.celebrate b { animation: pop .6s ease-out .15s both; }
.result-progress.celebrate::after {
  content: ""; position: absolute; inset: -2px; border-radius: 16px; pointer-events: none;
  box-shadow: 0 0 0 2px var(--gold-hot), 0 0 40px rgba(255, 220, 150, .7); opacity: 0; animation: ring 1.4s ease-out;
}

/* difficulty segmented control */
.difficulty { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 4px; border-radius: 14px; background: rgba(5, 8, 26, .6); border: 1px solid rgba(201,164,92,.25); }
.difficulty button {
  min-height: 44px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--muted);
  font-weight: 700; font-size: 14px; cursor: pointer;
}
.difficulty button[aria-checked="true"] { background: linear-gradient(180deg, #fffdf8, #e7dfcd); color: #1b2140; border-color: var(--gold); }

/* practice search */
.search {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 7, 22, .78); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.search-card {
  width: min(360px, 100%); text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center;
  background: linear-gradient(180deg, #1c2554, #121939); border: 1px solid var(--panel-edge); border-radius: 22px; padding: 26px 20px 18px;
  box-shadow: 0 24px 50px rgba(0,0,0,.6); animation: rise .3s ease-out;
}
.search-card h2 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 24px; color: var(--ivory); }
.search-kicker, .result-kicker {
  margin: 0; text-transform: uppercase; letter-spacing: 3px; font-size: 12px; color: var(--gold); font-weight: 700;
}
.search-card .btn { width: 100%; margin-top: 6px; }
.search-orbit { position: relative; width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--hair); margin-bottom: 4px;
  background: radial-gradient(circle, rgba(110, 235, 205, .35), rgba(110, 235, 205, 0) 60%); }
.search-orbit span {
  position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff4d6, #f3c566 55%, #a87a26); box-shadow: 0 0 10px rgba(255, 210, 120, .8);
  animation: orbit 1.6s linear infinite;
}
.search-orbit span:nth-child(2) { animation-delay: -.53s; }
.search-orbit span:nth-child(3) { animation-delay: -1.07s; }

/* lobby */
.lobby h2 { margin: 0; text-align: center; font-size: 14px; text-transform: uppercase; letter-spacing: 3px; color: var(--gold); font-weight: 700; }
.code-tiles { display: flex; gap: 8px; justify-content: center; }
.code-tiles span {
  width: 52px; height: 64px; display: grid; place-items: center; border-radius: 12px;
  background: linear-gradient(180deg, #fffdf8, #e4ddcd); color: #1b2140; font-size: 32px; font-weight: 700; font-family: var(--serif);
  border: 1px solid var(--gold); box-shadow: 0 4px 0 #8f7440, 0 0 20px rgba(255, 220, 160, .2);
}
.share { display: flex; flex-direction: column; gap: 8px; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 12px;
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.12); font-weight: 700; font-size: 14px;
}
.seat .seat-state { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 600; }
.seat.you { border-color: var(--gold); }
.seat.on .seat-state { color: #9ff0d0; }

.emblem { display: inline-block; width: 14px; height: 14px; border: 1.5px solid var(--ivory); flex: none; }
.emblem.circle { border-radius: 50%; background: var(--seat0); }
.emblem.diamond { background: var(--seat1); transform: rotate(45deg) scale(.85); }

.settings-float { position: fixed; top: calc(10px + var(--safe-top)); right: 10px; z-index: 5; display: flex; gap: 8px; }
#app[data-screen="game"] .settings-float { display: none; }
#app[data-screen="lobby"] #btn-help { display: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--hair); cursor: pointer;
  background: rgba(20, 27, 62, .9); color: var(--ivory); font-size: 19px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 3px 0 #0b0f26;
}
.icon-btn.off { opacity: .45; text-decoration: line-through; }

/* ---------- game ---------- */
#screen-game {
  flex-direction: column; width: min(100%, 640px); left: 50%; transform: translateX(-50%);
  background: #070b1f; box-shadow: 0 0 80px rgba(0,0,0,.6);
}
.hud {
  position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(6px + var(--safe-top)) 10px 6px; gap: 8px; z-index: 2;
  background: linear-gradient(180deg, rgba(8, 12, 34, .96), rgba(12, 17, 44, .82));
  border-bottom: 1px solid var(--hair);
}
.score { display: flex; align-items: center; gap: 7px; min-width: 0; }
.score b { font-size: 30px; font-weight: 700; line-height: 1; font-family: var(--serif); text-shadow: 0 2px 0 rgba(0,0,0,.6); }
.score .who {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); font-weight: 700;
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.score.me { justify-content: flex-end; }
.score.me b { color: var(--team-light); }
.score.opp b { color: var(--opp); }
body[data-seat="0"] .score.me .emblem, body[data-seat="1"] .score.opp .emblem { border-radius: 50%; background: var(--seat0); transform: none; }
body[data-seat="1"] .score.me .emblem, body[data-seat="0"] .score.opp .emblem { background: var(--seat1); transform: rotate(45deg) scale(.85); border-radius: 0; }
.clock {
  font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 4px 11px; border-radius: 12px;
  background: linear-gradient(180deg, #fffdf8, #e4ddcd); color: #1b2140; border: 1px solid var(--gold);
  box-shadow: 0 3px 0 #8f7440;
}
.clock.low { color: #fff; background: linear-gradient(180deg, #d9546a, #9c2a41); border-color: #ffb3bf; animation: pulse 1s infinite; }
.hud-tools { position: absolute; right: 8px; top: calc(100% + 8px); display: flex; flex-direction: column; gap: 6px; }
.hud-tools .icon-btn { width: 38px; height: 38px; font-size: 16px; opacity: .88; }

.board-wrap { position: relative; flex: 1; min-height: 0; touch-action: none; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }

.banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3;
  padding: 8px 14px; border-radius: 12px; background: rgba(50, 14, 30, .94); border: 1px solid var(--danger);
  font-weight: 700; font-size: 14px; white-space: nowrap; box-shadow: 0 6px 18px rgba(0,0,0,.4);
}
.banner.info { background: rgba(14, 20, 50, .95); border-color: var(--gold); }
.countdown {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 3; pointer-events: none;
  font-size: 118px; font-weight: 600; font-family: var(--serif); color: var(--ivory);
  text-shadow: 0 0 40px rgba(255, 220, 160, .8), 0 4px 0 rgba(10, 14, 40, .9); background: rgba(5, 8, 24, .35);
}
.countdown.pop { animation: pop .5s ease-out; }
.toast {
  position: absolute; left: 50%; top: 58px; transform: translate(-50%, -12px); z-index: 3; opacity: 0;
  padding: 10px 14px; border-radius: 12px; background: rgba(14, 19, 48, .96); border: 1px solid var(--hair);
  font-weight: 700; font-size: 14px; max-width: 92%; text-align: center; pointer-events: none;
  transition: opacity .18s, transform .18s; box-shadow: 0 6px 18px rgba(0,0,0,.45);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--danger); }
.toast.warn { border-color: var(--gold); color: var(--gold-hot); }
.lane-hint {
  position: absolute; left: 50%; top: 44%; transform: translateX(-50%); z-index: 2; pointer-events: none;
  padding: 6px 12px; border-radius: 999px; background: rgba(10, 14, 40, .75); font-weight: 700; font-size: 13px;
  letter-spacing: 1px; text-transform: uppercase; color: var(--team-light); border: 1px solid var(--hair);
}

.hand {
  position: relative; z-index: 2; padding: 8px 10px calc(10px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(8, 12, 34, .98), rgba(12, 17, 44, .9));
  border-top: 1px solid var(--hair);
}
.focus-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.focus-label { display: flex; align-items: baseline; gap: 4px; min-width: 70px; }
.focus-label b { font-size: 24px; font-weight: 700; font-family: var(--serif); color: #dcd6ff; }
.focus-label span { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted); font-weight: 700; }
.focus-label .surge-badge {
  align-self: center; margin-left: 2px; padding: 2px 6px; border-radius: 999px; letter-spacing: 0;
  font-size: 12px; color: #1b2140; background: linear-gradient(180deg, #fff4d6, #f3c566); border: 1px solid var(--gold-hot);
  box-shadow: 0 0 12px rgba(255, 210, 120, .55);
}
.hand.surge .focus-bar i::after { background: linear-gradient(180deg, #fff4d6, #f3c566); }
.clock.surge:not(.low) { box-shadow: 0 3px 0 #8f7440, 0 0 0 2px var(--gold-hot), 0 0 18px rgba(255, 210, 120, .55); }
.phase-cue {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 3; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 16px; border-radius: 14px;
  background: rgba(14, 19, 48, .94); border: 1px solid var(--gold-hot); box-shadow: 0 0 24px rgba(255, 210, 120, .4);
  text-align: center; white-space: nowrap; animation: pop .45s ease-out;
}
.phase-cue b { font-family: var(--serif); font-size: 20px; color: var(--gold-hot); }
.phase-cue span { font-size: 12px; font-weight: 700; color: #dfe3f3; }
.queue-chip {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 3; max-width: calc(100% - 20px);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; border-radius: 999px;
  background: rgba(14, 19, 48, .95); border: 1px dashed var(--gold-hot); font-weight: 700; font-size: 13px;
  box-shadow: 0 6px 18px rgba(0,0,0,.45);
  pointer-events: none; /* taps on the text still reach the lanes; only Cancel is a target */
}
.queue-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.queue-chip button {
  pointer-events: auto; flex: none; min-height: 36px; padding: 0 12px; border-radius: 999px; cursor: pointer; font-weight: 700; font-size: 13px;
  border: 1px solid var(--hair); background: #26305e; color: var(--ivory);
}
.focus-bar { flex: 1; display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; height: 14px; }
.focus-bar i { position: relative; border-radius: 4px; background: #121a40; border: 1px solid rgba(201,164,92,.35); overflow: hidden; }
.focus-bar i::after {
  content: ""; position: absolute; inset: 0; transform-origin: left; transform: scaleX(var(--fill, 0));
  background: linear-gradient(180deg, #f4f1ff, #9b8ff0);
}
.carriers {
  min-width: 52px; text-align: center; font-weight: 700; font-size: 13px; padding: 4px 8px; border-radius: 10px;
  background: #121a40; border: 1px solid rgba(201,164,92,.35); color: var(--muted);
}
.carriers.full { color: var(--gold-hot); border-color: var(--gold); }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  min-height: 92px; padding: 6px 4px 7px; border-radius: 14px; cursor: pointer; touch-action: none; user-select: none;
  -webkit-user-select: none; -webkit-touch-callout: none;
  background: linear-gradient(180deg, #213063, #111838);
  background: linear-gradient(180deg, color-mix(in srgb, var(--team) 26%, #1c2554), #111838);
  border: 1px solid var(--hair); color: var(--ivory);
  box-shadow: 0 4px 0 #0b0f26, inset 0 1px 0 rgba(255,255,255,.12);
  transition: transform .1s, box-shadow .1s, filter .15s, opacity .15s;
}
.card[data-card="hook"] { background: linear-gradient(180deg, #5a2a3a, #221433); }
.card[data-card="cover"] { background: linear-gradient(180deg, #2c4a5e, #121c3a); }
.card svg { width: 50px; height: 50px; margin-top: 8px; filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
.card .portrait { display: none; width: 60px; height: 60px; margin-top: 2px; }
.card.has-art .portrait { display: block; }
.card.has-art > svg { display: none; }
.card .name { font-weight: 700; font-size: 12px; margin-top: 2px; text-transform: uppercase; letter-spacing: 1.2px; }
.card .cost {
  position: absolute; top: -8px; left: -6px; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #1b2140; font-family: var(--serif);
  background: radial-gradient(circle at 35% 30%, #fffdf8, #e2dacb); border: 1.5px solid var(--gold);
  box-shadow: 0 2px 0 #8f7440;
}
.card .key { position: absolute; top: 4px; right: 7px; font-size: 11px; color: var(--muted); font-weight: 700; opacity: .7; }
.card[aria-pressed="true"] {
  transform: translateY(-8px); border-color: var(--gold-hot);
  box-shadow: 0 9px 0 #0b0f26, 0 0 0 2px var(--team), 0 0 26px rgba(255, 220, 160, .45);
}
.card.poor { filter: grayscale(.75) brightness(.7); }
.card.pending { opacity: .7; }
.card.pending::after {
  content: ""; position: absolute; inset: 4px; border-radius: 10px; border: 2px dashed var(--gold-hot);
  animation: spin 1s linear infinite;
}
.card.shake { animation: shake .35s; }
.card.queued { border-color: var(--gold-hot); border-style: dashed; }
.card .queued-tag {
  display: none; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%); padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: #1b2140; background: var(--gold-hot);
}
.card.queued .queued-tag { display: block; }
.card.late::before {
  content: "⏱"; position: absolute; top: 3px; left: 24px; font-size: 12px; line-height: 1; opacity: .9;
}
.card.late .name { color: var(--muted); }
.card.alert { box-shadow: 0 4px 0 #0b0f26, 0 0 0 2px var(--danger), 0 0 22px rgba(255, 90, 110, .6); }
.card.dragging { opacity: .55; }
.drag-ghost {
  position: fixed; z-index: 50; width: 64px; height: 64px; margin: -32px 0 0 -32px; pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.6)); opacity: .95;
}

/* ---------- result ---------- */
.result {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(4, 7, 22, .74); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.result-card {
  width: min(420px, 100%); max-height: 100%; overflow-y: auto; text-align: center;
  background: linear-gradient(180deg, #1c2554, #0f1536); border: 1px solid var(--panel-edge); border-radius: 24px;
  padding: 20px 18px calc(18px + var(--safe-bottom)); box-shadow: 0 30px 60px rgba(0,0,0,.6);
  display: flex; flex-direction: column; gap: 12px; animation: rise .35s ease-out;
}
.result-card h2 {
  margin: 0; font-size: 44px; font-weight: 600; font-family: var(--serif); color: var(--ivory);
  text-shadow: 0 0 30px rgba(255, 220, 160, .55), 0 3px 0 rgba(0,0,0,.6);
}
.result-card.lose h2 { color: #cfd6f5; text-shadow: 0 3px 0 rgba(0,0,0,.6); }
.result-card.draw h2 { color: #e9f5f0; }
.result-score { display: flex; justify-content: center; align-items: center; gap: 16px; }
.rs { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }
.rs b { font-size: 44px; line-height: 1; font-family: var(--serif); color: var(--ivory); }
.rs.me b { color: var(--team-light); }
.rs.opp b { color: var(--opp); }
body[data-seat="0"] .rs.me .emblem, body[data-seat="1"] .rs.opp .emblem { border-radius: 50%; background: var(--seat0); }
body[data-seat="1"] .rs.me .emblem, body[data-seat="0"] .rs.opp .emblem { background: var(--seat1); transform: rotate(45deg) scale(.85); }
.rs-dash { font-size: 30px; color: var(--muted); }
.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats th { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 4px; }
.stats td { padding: 5px 6px; border-top: 1px solid rgba(201,164,92,.15); }
.stats td:first-child { text-align: left; color: #d7dcef; }
.stats td:not(:first-child) { font-weight: 700; font-variant-numeric: tabular-nums; width: 72px; }
.result-actions { display: grid; gap: 10px; }

@keyframes pulse { 50% { filter: brightness(1.35); } }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes glow { 0% { background: rgba(255, 220, 150, .45); } 100% { background: rgba(201,164,92,.1); } }
@keyframes trophy-pop { 0% { transform: scale(.3) rotate(-18deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes ring { 0% { opacity: 1; transform: scale(.96); } 100% { opacity: 0; transform: scale(1.08); } }
@keyframes orbit { from { transform: rotate(0deg) translateX(30px); } to { transform: rotate(360deg) translateX(30px); } }

/* Reduced motion: OS preference or in-game toggle */
body.reduced *, body.reduced *::before, body.reduced *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Short/landscape phones: tighten the hand so the board keeps room */
@media (max-height: 760px) {
  .tagline { display: none; }
}
@media (max-height: 640px) {
  .card { min-height: 70px; }
  .card svg { width: 36px; height: 36px; margin-top: 4px; }
  .card .portrait { width: 40px; height: 40px; }
  .hero { height: clamp(64px, 15vh, 100px); }
  .brand-icon { width: 44px; height: 44px; }
  .shell-head { min-height: 58px; padding-top: calc(7px + var(--safe-top)); }
  .tab { min-height: 50px; }
  .focus-row { margin-bottom: 6px; }
  .score b { font-size: 24px; }
  .clock { font-size: 20px; }
}
/* Very short viewports (landscape phones, 200% zoom): drop the art, keep every control; the panel scrolls. */
@media (max-height: 480px) {
  .hero, .brand-icon { display: none !important; }
  h1 { font-size: 22px; margin: 0; }
  .shell-head { min-height: 52px; padding-top: calc(4px + var(--safe-top)); padding-bottom: 2px; }
  .settings-float { top: calc(4px + var(--safe-top)); }
  .tab { min-height: 46px; flex-direction: row; gap: 6px; }
  .tab svg { width: 22px; height: 22px; }
}
@media (min-width: 700px) {
  .hud-tools { right: -56px; top: 8px; }
}
