:root {
  --bg: #f5f2ec;
  --surface: #fffdf9;
  --surface-2: #eee9df;
  --text: #1d2130;
  --muted: #676b78;
  --border: #dbd4c6;
  --accent: #2f4ad0;
  --accent-text: #ffffff;
  --danger: #c92a2a;
  --cell: #e9e4d8;
  --cell-text: #9a9587;
  --on: #2f4ad0;
  --on-text: #ffffff;
  --magic: #ae3ec9;
  --need: #f59f00;
  --card: #ffffff;
  --card-text: #1d2130;
  --prime: #ffd43b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 18px rgba(0, 0, 0, 0.07);
  --p0: #2f4ad0; --p1: #e8590c; --p2: #2b8a3e; --p3: #ae3ec9; --p4: #0c8599; --p5: #c2255c;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #14161b;
  --surface: #1d2027;
  --surface-2: #292d36;
  --text: #ebe8e2;
  --muted: #9ea2ad;
  --border: #363b46;
  --accent: #6d86ff;
  --accent-text: #0d1020;
  --danger: #ff6b6b;
  --cell: #242831;
  --cell-text: #5f6470;
  --on: #5c7cfa;
  --on-text: #0d1020;
  --magic: #cc5de8;
  --need: #fab005;
  --card: #2a2e38;
  --card-text: #f1efe9;
  --prime: #ffd43b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 6px 18px rgba(0, 0, 0, 0.35);
  --p0: #5c7cfa; --p1: #ff8a3d; --p2: #40c057; --p3: #cc5de8; --p4: #22b8cf; --p5: #f06595;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); min-height: 1.4em; margin: 0.4rem 0 0; text-align: center; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5rem; }
h1 { font-size: clamp(1.6rem, 4.5vw, 2.5rem); letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

button, input, select { font: inherit; color: inherit; }
button {
  border-radius: 10px; border: 1px solid transparent; padding: 0.6rem 1rem; cursor: pointer;
  font-weight: 600; transition: transform 0.06s, background 0.15s, box-shadow 0.15s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); width: 100%; }
button.secondary { background: var(--surface-2); border-color: var(--border); }
button.ghost { background: transparent; border-color: var(--border); }
button.small { padding: 0.35rem 0.75rem; font-size: 0.875rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.55rem 0.75rem; min-width: 0;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.6rem 16px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 800; display: flex; align-items: center; gap: 0.55rem; font-size: 1.1rem; white-space: nowrap; }
.logo { position: relative; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); flex: none; }
.logo i { position: absolute; width: 9px; height: 9px; border-radius: 50%; }
.logo i:first-child { background: var(--prime); left: 6px; top: 6px; }
.logo i:last-child { background: #fff; right: 6px; bottom: 6px; }
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }
.theme-btn { width: 40px; padding: 0.45rem 0; font-size: 1.05rem; line-height: 1; }
.support-link {
  display: inline-flex; align-items: center; border-radius: 10px; padding: 0.6rem 1rem; font-weight: 600;
  background: var(--prime); color: #2b2100; text-decoration: none;
}
.support-link:hover { filter: brightness(0.95); }
.support-note { margin-top: 1.5rem; text-align: center; }
.support-note a { color: var(--accent); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 2rem; }

.hero { max-width: 660px; margin-bottom: 1.5rem; }
.hero p { color: var(--muted); font-size: 1.05rem; margin: 0; }
.field { display: flex; flex-direction: column; gap: 0.3rem; max-width: 320px; margin-bottom: 1.25rem; }
.field span { font-weight: 600; font-size: 0.9rem; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 1.15rem;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 0.75rem; min-width: 0;
}
.card p { margin: 0; }
.row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; }
#codeInput { text-transform: uppercase; letter-spacing: 0.15em; }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.bot-picker { display: flex; flex-direction: column; gap: 0.5rem; }
.bot-row { display: flex; gap: 0.5rem; align-items: center; }
.bot-row select { flex: 1; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--pc, var(--muted)); }
.c0 { --pc: var(--p0); } .c1 { --pc: var(--p1); } .c2 { --pc: var(--p2); }
.c3 { --pc: var(--p3); } .c4 { --pc: var(--p4); } .c5 { --pc: var(--p5); }

.leader-list { margin: 0; padding-left: 1.3rem; display: flex; flex-direction: column; gap: 0.2rem; }
.leader-list li span { color: var(--muted); font-size: 0.85rem; }

.lobby-card { max-width: 520px; margin: 0 auto; }
.room-code-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }
.room-code { font-size: 2.2rem; font-weight: 800; letter-spacing: 0.25em; font-family: ui-monospace, monospace; }
.seat-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.seat-list li { display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.75rem; border-radius: 10px; background: var(--surface-2); }
.seat-list .name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.75rem; padding: 0.1rem 0.45rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.host-controls { display: flex; flex-direction: column; gap: 0.75rem; }
.host-controls select { flex: 1; }

/* ---- Game ---- */
#game { padding-bottom: 210px; }
.opponents { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.25rem; margin-bottom: 1rem; scrollbar-width: thin; }
.seat {
  flex: 1 0 140px; max-width: 220px; display: flex; flex-direction: column; gap: 0.15rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.5rem 0.7rem;
  box-shadow: inset 4px 0 0 var(--pc);
}
.seat.turn { border-color: var(--pc); box-shadow: inset 4px 0 0 var(--pc), 0 0 0 2px var(--pc); }
.seat .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .meta { font-size: 0.8rem; color: var(--muted); display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.mini-cards { display: flex; gap: 2px; min-height: 18px; align-items: center; }
.mini-cards i { width: 11px; height: 16px; border-radius: 3px; background: var(--pc); opacity: 0.85; }
.badge { font-size: 0.7rem; font-weight: 700; padding: 0 0.4rem; border-radius: 999px; background: var(--danger); color: #fff; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1.25rem; align-items: start; }
@media (max-width: 860px) { .game-layout { grid-template-columns: minmax(0, 1fr); } }
.table-col { display: flex; flex-direction: column; gap: 0.75rem; min-width: 0; }
.table-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.status {
  font-weight: 600; padding: 0.4rem 0.9rem; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
}
.status.your-turn { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.tray { display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.tray-stack { width: 18px; height: 24px; border-radius: 4px; background: var(--accent); box-shadow: 3px -3px 0 var(--surface-2), 3px -3px 0 1px var(--border); }

.last-play { min-height: 1.5em; font-size: 0.95rem; }
.last-play b { font-weight: 800; }

.board {
  display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 8px;
}
.num {
  position: relative; aspect-ratio: 1; border-radius: 8px; display: grid; place-items: center;
  background: var(--cell); color: var(--cell-text); font-weight: 700; font-size: clamp(0.72rem, 2.4vw, 1rem);
  font-variant-numeric: tabular-nums;
}
.num.prime { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--prime) 60%, transparent); }
.num.need { box-shadow: inset 0 0 0 2px var(--need); color: var(--text); }
.num.on { background: var(--on); color: var(--on-text); box-shadow: none; }
.num.on.need { box-shadow: inset 0 0 0 3px var(--need); }
.num[data-count]::before {
  content: attr(data-count); position: absolute; left: 3px; top: 1px; font-size: 0.55em; font-weight: 800; opacity: 0.9;
}
.num.magic { background: var(--magic); color: #fff; }
.num.magic::after { content: '★'; position: absolute; top: 1px; right: 3px; font-size: 0.55em; }
.num.fresh { animation: pop 0.5s ease; }
@keyframes pop { 0% { transform: scale(1.35); } 100% { transform: scale(1); } }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0; }
.legend > span { display: inline-flex; align-items: center; gap: 0.35rem; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.lg-on { background: var(--on); } .lg-magic { background: var(--magic); } .lg-need { box-shadow: inset 0 0 0 2px var(--need); }

.side-col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.move-log { margin: 0; padding-left: 1.4rem; max-height: 260px; overflow-y: auto; font-size: 0.875rem; }
.chat-log { max-height: 180px; overflow-y: auto; font-size: 0.875rem; display: flex; flex-direction: column; gap: 0.2rem; }
.chat-log .sys { color: var(--muted); font-style: italic; }

/* Hand dock pinned to the bottom so it's always in reach on phones. */
.hand-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border); padding: 0.6rem 16px calc(0.4rem + env(safe-area-inset-bottom));
}
.hand-head { max-width: 1100px; margin: 0 auto 0.4rem; display: flex; align-items: center; gap: 0.75rem; }
.hand-label { font-weight: 700; }
.hand-head #passBtn { margin-left: auto; }
.hand { max-width: 1100px; margin: 0 auto; display: flex; gap: 0.5rem; overflow-x: auto; padding: 6px 2px 4px; scrollbar-width: thin; }
.pcard {
  position: relative; flex: none; width: 74px; height: 104px; border-radius: 12px; padding: 6px;
  background: var(--card); color: var(--card-text); border: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  box-shadow: var(--shadow);
}
.pcard .v { font-size: 1.75rem; font-weight: 800; line-height: 1; }
.pcard .kind { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 700; }
.pcard .factors { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.pcard .factors span {
  min-width: 20px; height: 20px; border-radius: 50%; font-size: 0.65rem; font-weight: 700; display: grid; place-items: center;
  border: 1.5px solid var(--muted); color: var(--muted); padding: 0 3px;
}
.pcard .factors span.have { border-color: var(--on); background: var(--on); color: var(--on-text); }
.pcard.prime { background: linear-gradient(160deg, var(--prime), color-mix(in srgb, var(--prime) 70%, #fff)); color: #2b2100; border-color: transparent; }
.pcard.prime .kind { color: #6b5600; }
.pcard.magic { background: linear-gradient(160deg, var(--magic), #7048e8); color: #fff; border-color: transparent; }
.pcard.skip { background: linear-gradient(160deg, #fa5252, #e8590c); color: #fff; border-color: transparent; }
.pcard.magic .kind, .pcard.skip .kind { color: rgba(255, 255, 255, 0.85); }
.pcard.one { background: linear-gradient(160deg, #ff922b, #f76707); color: #fff; border-color: transparent; }
.pcard.one .kind { color: rgba(255, 255, 255, 0.85); }
.pcard.playable { box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.pcard.playable:hover { transform: translateY(-4px); }
.pcard:disabled { opacity: 1; cursor: default; }
.pcard.blocked { opacity: 0.5; }
.pcard.new::before { content: 'new'; position: absolute; top: -7px; left: 50%; transform: translateX(-50%); font-size: 0.6rem; font-weight: 800; background: var(--text); color: var(--bg); border-radius: 999px; padding: 0 6px; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box {
  background: var(--surface); border-radius: 18px; padding: 1.4rem; max-width: 460px; width: 100%;
  box-shadow: var(--shadow); border: 1px solid var(--border); max-height: 90vh; overflow-y: auto;
}
.modal-box.rules { max-width: 620px; }
.modal-box.rules li { margin-bottom: 0.45rem; }
.end-actions { margin-top: 1rem; }
.end-actions button { flex: 1; }
.prime-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.prime-grid button { padding: 0.6rem 0; background: var(--surface-2); border-color: var(--border); }
.prime-grid button.useful { background: var(--prime); color: #2b2100; border-color: transparent; }
.prime-grid button.on { opacity: 0.6; }
.target-list { display: flex; flex-direction: column; gap: 0.5rem; }
.target-list button { display: flex; align-items: center; gap: 0.6rem; background: var(--surface-2); border-color: var(--border); text-align: left; }
.target-list button .n { flex: 1; }
.end-list { margin: 0; padding-left: 1.4rem; display: flex; flex-direction: column; gap: 0.35rem; }
.end-list li { padding: 0.25rem 0; }
.end-list .pts { float: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.end-list .left { display: block; font-size: 0.8rem; color: var(--muted); }

@media (max-width: 560px) {
  .topbar { padding: 0.5rem 12px; }
  .topbar-actions button, .support-link { padding: 0.35rem 0.65rem; font-size: 0.85rem; }
  main { padding: 1rem 12px 1.5rem; }
  .hand-dock { padding-left: 12px; padding-right: 12px; }
  .pcard { width: 62px; height: 90px; }
  .pcard .v { font-size: 1.45rem; }
  .board { gap: 3px; padding: 6px; }
  .num { border-radius: 6px; }
  .seat { flex-basis: 120px; }
  .status { font-size: 0.9rem; }
  #game { padding-bottom: 190px; }
}
@media (prefers-reduced-motion: reduce) { .num.fresh { animation: none; } .pcard.playable:hover { transform: none; } }
@media (max-width: 400px) {
  .brand { font-size: 0.95rem; gap: 0.4rem; }
  .logo { width: 24px; height: 24px; }
  .topbar-actions { gap: 0.3rem; }
  .topbar-actions button, .support-link { padding: 0.3rem 0.5rem; font-size: 0.8rem; }
  .theme-btn { width: 32px; }
}
@media (max-width: 359px) { .brand-name { display: none; } }

.credit { margin-top: 0.4rem; text-align: center; font-size: 0.85rem; }
.credit a { color: var(--accent); font-weight: 600; }

/* ======================================================================
   Cardboard look: kraft-paper table, card-stock panels, punched tokens.
   ====================================================================== */
:root {
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .32  0 0 0 0 .22  0 0 0 0 .12  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --fibre: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.02 .6' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 .4  0 0 0 0 .3  0 0 0 0 .18  0 0 0 .18 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23f)'/%3E%3C/svg%3E");
  --bg: #c9a77c;            /* kraft board */
  --bg-deep: #b38f63;
  --surface: #fbf6ea;       /* card stock */
  --surface-2: #efe5d0;
  --text: #2b2118;
  --muted: #6e5d4a;
  --border: #d8c8a8;
  --edge: #9c7b52;          /* cut cardboard edge */
  --accent: #2c4bc7;
  --cell: #e8dcc2;
  --cell-text: #a08b6c;
  --card: #fdf8ec;
  --card-text: #2b2118;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 2px 0 var(--edge), 0 6px 14px rgba(60, 38, 14, 0.22);
  --font-display: 'Fredoka', 'Baloo 2', ui-rounded, system-ui, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #2c241c;            /* dark chipboard */
  --bg-deep: #231c15;
  --surface: #3a3027;
  --surface-2: #463a2f;
  --text: #f1e7d6;
  --muted: #bba88f;
  --border: #574838;
  --edge: #17120d;
  --accent: #7d96ff;
  --cell: #4a3d31;
  --cell-text: #8f7b65;
  --card: #43382d;
  --card-text: #f4ead9;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 2px 0 var(--edge), 0 8px 18px rgba(0, 0, 0, 0.45);
}

body {
  background-color: var(--bg);
  background-image: var(--grain), var(--fibre), radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.18), transparent 60%);
  background-attachment: fixed;
}
h1, h2, h3, .brand, .room-code, .pcard .v, .num, .status, button.primary { font-family: var(--font-display); }
h1 { font-weight: 700; }

.topbar {
  background: var(--surface) var(--fibre);
  border-bottom: 0;
  box-shadow: 0 2px 0 var(--edge), 0 6px 12px rgba(60, 38, 14, 0.18);
}

/* Panels look like printed card stock with a die-cut edge. */
.card, .seat, .modal-box, .status, .lobby-card {
  background-color: var(--surface);
  background-image: var(--fibre);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card, .modal-box { border-radius: 14px; }

button.primary {
  background: var(--accent);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 60%, #000), 0 6px 10px rgba(0, 0, 0, 0.15);
  font-weight: 600; letter-spacing: 0.01em;
}
button.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 color-mix(in srgb, var(--accent) 60%, #000); }
button.secondary, button.ghost { background-color: var(--surface); box-shadow: 0 2px 0 var(--border); }

/* The number board is a printed game board with a thick cardboard edge. */
.board {
  background: var(--surface-2) var(--fibre);
  border: 0;
  border-radius: 18px;
  padding: 10px;
  gap: 6px;
  box-shadow: 0 0 0 2px var(--border) inset, 0 4px 0 var(--edge), 0 5px 0 color-mix(in srgb, var(--edge) 70%, #000), 0 14px 24px rgba(60, 38, 14, 0.28);
}
/* Each number is a punched-out round token. */
.num {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.35), transparent 60%), var(--cell);
  box-shadow: inset 0 2px 3px rgba(60, 38, 14, 0.25);
  font-weight: 600;
}
.num.prime { box-shadow: inset 0 2px 3px rgba(60, 38, 14, 0.25), inset 0 0 0 2px color-mix(in srgb, var(--prime) 70%, transparent); }
.num.on {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.35), transparent 55%), var(--pc, var(--accent));
  color: #fff;
  box-shadow: 0 2px 0 color-mix(in srgb, var(--pc, var(--accent)) 55%, #000), 0 3px 5px rgba(0, 0, 0, 0.25);
  transform: translateY(-2px);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
.num.magic { background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.35), transparent 55%), var(--pc, var(--magic)); outline: 2px dashed rgba(255, 255, 255, 0.85); outline-offset: -5px; }
.num.need { box-shadow: inset 0 0 0 3px var(--need), inset 0 2px 3px rgba(60, 38, 14, 0.25); color: var(--text); }
.num.on.need { box-shadow: 0 0 0 3px var(--need), 0 2px 0 color-mix(in srgb, var(--pc, var(--accent)) 55%, #000); }
.num[data-count]::before {
  content: attr(data-count); position: absolute; right: -4px; top: -6px; left: auto;
  font-size: 0.6em; font-weight: 800; background: var(--text); color: var(--bg);
  border-radius: 999px; padding: 0 4px; line-height: 1.5; opacity: 1;
}
.num.magic::after { top: auto; bottom: 0; right: 50%; transform: translateX(50%); }
.legend .lg { border-radius: 50%; }
.lg-on { background: var(--accent); }
.lg-magic { background: transparent; outline: 2px dashed var(--muted); outline-offset: -2px; }

/* Hand cards: thick card stock with a printed frame. */
.hand-dock {
  background: color-mix(in srgb, var(--bg-deep) 92%, transparent) var(--grain);
  border-top: 0;
  box-shadow: 0 -2px 0 var(--edge), 0 -8px 18px rgba(60, 38, 14, 0.25);
}
.hand-dock .hand-label, .hand-dock #handTotal { color: #fff8ec; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35); }
.pcard {
  border-radius: 12px;
  background-color: var(--card);
  background-image: var(--fibre);
  border: 0;
  box-shadow: inset 0 0 0 3px var(--card), inset 0 0 0 4px var(--border), 0 3px 0 var(--edge), 0 6px 10px rgba(0, 0, 0, 0.25);
  font-family: var(--font-display);
}
.pcard.prime { background: var(--fibre), linear-gradient(160deg, #ffe066, #fcc419); box-shadow: inset 0 0 0 3px #ffe066, inset 0 0 0 4px rgba(120, 90, 0, 0.35), 0 3px 0 #a07a00, 0 6px 10px rgba(0, 0, 0, 0.25); }
.pcard.magic { background: var(--fibre), linear-gradient(160deg, #b65fdc, #6741d9); box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35), 0 3px 0 #3b2580, 0 6px 10px rgba(0, 0, 0, 0.25); }
.pcard.skip { background: var(--fibre), linear-gradient(160deg, #ff6b6b, #e8590c); box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.35), 0 3px 0 #8f2d07, 0 6px 10px rgba(0, 0, 0, 0.25); }
.pcard.one { background: var(--fibre), linear-gradient(160deg, #ffa94d, #f76707); }
.pcard.playable { box-shadow: 0 0 0 3px var(--accent), 0 3px 0 var(--edge), 0 8px 14px rgba(0, 0, 0, 0.3); transform: translateY(-3px); }
.pcard.playable:hover { transform: translateY(-7px) rotate(-1deg); }
.pcard .factors span { background: var(--surface); }

/* Seats show the player's colour as a coloured card edge. */
.seat { border-top: 5px solid var(--pc); box-shadow: var(--shadow); }
.seat.turn { box-shadow: 0 0 0 3px var(--pc), var(--shadow); transform: translateY(-2px); }
.seat.winner { box-shadow: 0 0 0 3px var(--prime), 0 0 22px color-mix(in srgb, var(--prime) 70%, transparent), var(--shadow); }
.seat.winner .who::before { content: '👑 '; }
.tray-stack { background: var(--accent) var(--fibre); box-shadow: 3px -3px 0 var(--surface), 3px -3px 0 1px var(--edge), 6px -6px 0 var(--surface), 6px -6px 0 1px var(--edge); }

/* Winner highlight in the results list. */
.end-list li.winner { background: color-mix(in srgb, var(--prime) 35%, transparent); border-radius: 10px; padding: 0.35rem 0.5rem; font-weight: 700; }
.end-list li.winner::marker { content: '👑 '; }
#endTitle { font-size: 1.6rem; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 20; }

/* ---- Table numbers as small cards (overrides the round tokens) ---- */
.board { gap: 5px; }
.num {
  border-radius: 7px;
  aspect-ratio: 4 / 5;
  background-color: var(--card);
  background-image: var(--fibre);
  color: var(--cell-text);
  box-shadow: inset 0 0 0 2px var(--card), inset 0 0 0 3px var(--border), 0 1px 0 var(--edge);
  opacity: 0.8;
}
.num.prime { box-shadow: inset 0 0 0 2px var(--card), inset 0 0 0 3px color-mix(in srgb, var(--prime) 80%, var(--border)), 0 1px 0 var(--edge); }
.num.on {
  opacity: 1;
  background-color: var(--pc, var(--accent));
  background-image: var(--fibre), linear-gradient(160deg, rgba(255, 255, 255, 0.22), transparent 55%);
  color: #fff;
  box-shadow: inset 0 0 0 2px var(--pc, var(--accent)), inset 0 0 0 3px rgba(255, 255, 255, 0.45), 0 2px 0 color-mix(in srgb, var(--pc, var(--accent)) 50%, #000), 0 4px 6px rgba(0, 0, 0, 0.22);
  transform: translateY(-2px) rotate(var(--tilt, 0deg));
}
.num.magic { outline: none; }
.num.magic::after { content: '★'; position: absolute; top: 2px; right: 4px; bottom: auto; left: auto; transform: none; font-size: 0.6em; color: #fff; }
.num.need { opacity: 1; color: var(--text); box-shadow: inset 0 0 0 3px var(--need), 0 1px 0 var(--edge); }
.num.on.need { box-shadow: 0 0 0 3px var(--need), 0 2px 0 color-mix(in srgb, var(--pc, var(--accent)) 50%, #000); }
.num[data-count]::before { right: -5px; top: -7px; }
.num.fresh { animation: drop 0.45s ease; }
@keyframes drop { 0% { transform: translateY(-18px) scale(1.25) rotate(-6deg); opacity: 0.4; } 100% { transform: translateY(-2px); opacity: 1; } }

/* Key, pinned in the hand dock so it's always on screen. */
.hand-dock .legend {
  max-width: 1100px; margin: 0 auto 0.45rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1rem;
  font-size: 0.78rem; color: #fff8ec; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
.hand-dock .legend > span { display: inline-flex; align-items: center; gap: 0.35rem; white-space: nowrap; }
.legend .lg { display: inline-grid; place-items: center; width: 12px; height: 15px; border-radius: 3px; font-size: 9px; color: #fff; text-shadow: none; }
.lg-on { background: linear-gradient(90deg, var(--p0) 33%, var(--p1) 33% 66%, var(--p2) 66%); outline: none; }
.lg-magic { background: var(--p3); outline: none; }
.lg-need { background: var(--card); box-shadow: inset 0 0 0 2px var(--need); }
#game { padding-bottom: 235px; }
@media (max-width: 560px) {
  .hand-dock .legend { font-size: 0.72rem; gap: 0.15rem 0.7rem; }
  #game { padding-bottom: 215px; }
  .board { gap: 3px; padding: 6px; }
  .num { border-radius: 5px; font-size: 0.78rem; }
}

/* ======================================================================
   Storybook look: watercolour sky, painted hills, warm paper.
   Diwali touches: a string of diyas, marigold accents, rangoli, a festive
   night sky in dark mode, marigold-petal confetti.
   ====================================================================== */
:root {
  --sky-top: #a9d8ee;
  --sky-mid: #d9eef2;
  --sky-low: #fbf0d6;
  --hill-1: #9cc68a;
  --hill-2: #7aae6c;
  --hill-3: #5d9358;
  --marigold: #f4a227;
  --saffron: #e8743b;
  --bg: #fbf0d6;
  --bg-deep: #5d7f4f;
  --surface: #fffaf0;
  --surface-2: #f6ecd6;
  --text: #33291f;
  --muted: #776753;
  --border: #e6d6b6;
  --edge: #d6bf94;
  --accent: #3b6fb6;
  --card: #fffaf0;
  --cell-text: #b29d7d;
  --need: var(--saffron);
  --p0: #3b6fb6; --p1: #d9612c; --p2: #3f8a4a; --p3: #9a4fb5; --p4: #1f8a8a; --p5: #c2416b;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 3px 10px rgba(92, 70, 38, 0.16), 0 12px 24px rgba(92, 70, 38, 0.10);
  --clouds: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1600' height='520' viewBox='0 0 1600 520'%3E%3Cdefs%3E%3Cfilter id='b' x='-20%25' y='-50%25' width='140%25' height='200%25'%3E%3CfeGaussianBlur stdDeviation='6'/%3E%3C/filter%3E%3C/defs%3E%3Cg fill='%23fff' opacity='.85' filter='url(%23b)'%3E%3Cellipse cx='220' cy='120' rx='130' ry='38'/%3E%3Cellipse cx='300' cy='96' rx='90' ry='44'/%3E%3Cellipse cx='170' cy='104' rx='70' ry='34'/%3E%3Cellipse cx='1160' cy='80' rx='150' ry='36'/%3E%3Cellipse cx='1250' cy='58' rx='96' ry='42'/%3E%3Cellipse cx='1090' cy='66' rx='70' ry='30'/%3E%3Cellipse cx='720' cy='190' rx='110' ry='26'/%3E%3Cellipse cx='780' cy='172' rx='70' ry='30'/%3E%3C/g%3E%3C/svg%3E");
  --hills: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1600' height='300' viewBox='0 0 1600 300' preserveAspectRatio='none'%3E%3Cpath d='M0 170 C 220 90 420 120 620 150 S 1040 80 1260 120 S 1520 150 1600 130 V300 H0Z' fill='%239cc68a'/%3E%3Cpath d='M0 220 C 260 160 520 200 760 210 S 1180 150 1600 200 V300 H0Z' fill='%237aae6c'/%3E%3Cpath d='M0 262 C 300 230 640 250 980 256 S 1400 236 1600 250 V300 H0Z' fill='%235d9358'/%3E%3C/svg%3E");
  --rangoli: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='-100 -100 200 200'%3E%3Cg fill='none' stroke='%23e8743b' stroke-width='1.6' opacity='.5'%3E%3Ccircle r='14'/%3E%3Ccircle r='30' stroke-dasharray='3 5'/%3E%3Cg id='p'%3E%3Cpath d='M0-34 C 12-50 12-66 0-80 C-12-66-12-50 0-34Z'/%3E%3C/g%3E%3Cuse href='%23p' transform='rotate(45)'/%3E%3Cuse href='%23p' transform='rotate(90)'/%3E%3Cuse href='%23p' transform='rotate(135)'/%3E%3Cuse href='%23p' transform='rotate(180)'/%3E%3Cuse href='%23p' transform='rotate(225)'/%3E%3Cuse href='%23p' transform='rotate(270)'/%3E%3Cuse href='%23p' transform='rotate(315)'/%3E%3Ccircle r='92' stroke-dasharray='1 7' stroke-width='3'/%3E%3C/g%3E%3C/svg%3E");
  --diyas: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='34' viewBox='0 0 120 34'%3E%3Cdefs%3E%3CradialGradient id='g'%3E%3Cstop offset='0' stop-color='%23ffe08a' stop-opacity='.9'/%3E%3Cstop offset='1' stop-color='%23ffb347' stop-opacity='0'/%3E%3C/radialGradient%3E%3C/defs%3E%3Cpath d='M0 2 Q60 14 120 2' fill='none' stroke='%23a07a4a' stroke-width='1'/%3E%3Ccircle cx='60' cy='15' r='12' fill='url(%23g)'/%3E%3Cpath d='M60 6 C 63 10 63 13 60 15 C 57 13 57 10 60 6Z' fill='%23ffb020'/%3E%3Cpath d='M51 16 Q60 26 69 16 Z' fill='%23c4622d'/%3E%3Cpath d='M51 16 H69' stroke='%23e8a04a' stroke-width='1.4'/%3E%3C/svg%3E");
  --sky: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 38%, var(--sky-low) 72%);
}
:root[data-theme="dark"] {
  --sky-top: #141a3a;
  --sky-mid: #2a2756;
  --sky-low: #4a2f4f;
  --bg: #1c1a33;
  --bg-deep: #1d2b25;
  --surface: #2b2740;
  --surface-2: #35304d;
  --text: #f6ecd8;
  --muted: #c5b8a0;
  --border: #4a4366;
  --edge: #15122a;
  --accent: #8fb0ff;
  --card: #fff4e0;
  --card-text: #33291f;
  --cell-text: #9a8f7c;
  --p0: #6f9bff; --p1: #ff8a4c; --p2: #5cc46b; --p3: #c27be0; --p4: #3ccfcf; --p5: #f26b98;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 4px 14px rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 176, 32, 0.06);
  --clouds: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='420'%3E%3Cg fill='%23fff8dc'%3E%3Ccircle cx='60' cy='40' r='1.2'/%3E%3Ccircle cx='180' cy='110' r='.9'/%3E%3Ccircle cx='300' cy='30' r='1.4'/%3E%3Ccircle cx='420' cy='160' r='1'/%3E%3Ccircle cx='520' cy='70' r='1.6'/%3E%3Ccircle cx='640' cy='130' r='.8'/%3E%3Ccircle cx='760' cy='50' r='1.2'/%3E%3Ccircle cx='860' cy='190' r='1'/%3E%3Ccircle cx='120' cy='230' r='.8'/%3E%3Ccircle cx='350' cy='260' r='1.1'/%3E%3Ccircle cx='600' cy='240' r='.9'/%3E%3C/g%3E%3Cg fill='%23ffd27a' opacity='.9'%3E%3Ccircle cx='700' cy='90' r='34' opacity='.12'/%3E%3Ccircle cx='700' cy='90' r='20'/%3E%3C/g%3E%3C/svg%3E");
  --hills: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1600' height='300' viewBox='0 0 1600 300' preserveAspectRatio='none'%3E%3Cpath d='M0 170 C 220 90 420 120 620 150 S 1040 80 1260 120 S 1520 150 1600 130 V300 H0Z' fill='%232c3d3a'/%3E%3Cpath d='M0 220 C 260 160 520 200 760 210 S 1180 150 1600 200 V300 H0Z' fill='%23233230'/%3E%3Cpath d='M0 262 C 300 230 640 250 980 256 S 1400 236 1600 250 V300 H0Z' fill='%231a2624'/%3E%3C/svg%3E");
}

body {
  background-color: var(--bg);
  background-image: var(--hills), var(--clouds), var(--sky);
  background-repeat: no-repeat, repeat-x, no-repeat;
  background-size: 100% 260px, 1600px auto, 100% 100%;
  background-position: bottom center, top 60px center, top center;
  background-attachment: fixed;
}
/* Paper grain on top of everything painted. */
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: var(--grain); opacity: 0.35; mix-blend-mode: multiply;
}
:root[data-theme="dark"] body::before { opacity: 0.25; mix-blend-mode: overlay; }
main, .topbar, .hand-dock { position: relative; z-index: 1; }
.topbar { position: sticky; z-index: 5; }
.hand-dock { position: fixed; z-index: 4; }

h1 { color: var(--text); text-shadow: 0 2px 0 rgba(255, 255, 255, 0.5); }
:root[data-theme="dark"] h1 { text-shadow: 0 0 18px rgba(255, 190, 90, 0.35); }

/* String of diyas hanging under the top bar. */
.topbar { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(6px); box-shadow: 0 4px 14px rgba(92, 70, 38, 0.12); }
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; top: 100%; height: 34px; pointer-events: none;
  background: var(--diyas) repeat-x; background-size: 120px 34px; opacity: 0.95;
  animation: flicker 3.2s ease-in-out infinite;
}
@keyframes flicker { 0%, 100% { opacity: 0.95; } 45% { opacity: 0.8; } 60% { opacity: 1; } }
main { padding-top: 2.6rem; }

/* Soft painted panels instead of hard die-cut edges. */
.card, .seat, .modal-box, .status, .lobby-card {
  background-color: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  box-shadow: var(--shadow);
  border-radius: 18px;
}
.status.your-turn { background: linear-gradient(135deg, var(--marigold), var(--saffron)); color: #fff; box-shadow: 0 0 0 3px rgba(255, 210, 120, 0.4), var(--shadow); }
.seat { border-top: 0; box-shadow: inset 0 4px 0 var(--pc), var(--shadow); }
.seat.turn { box-shadow: inset 0 4px 0 var(--pc), 0 0 0 3px color-mix(in srgb, var(--pc) 70%, transparent), 0 0 18px color-mix(in srgb, var(--marigold) 45%, transparent); }

.support-link { background: linear-gradient(135deg, #ffd166, var(--marigold)); color: #3a2400; }
button.primary { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 85%, #fff), var(--accent)); }

/* The table: painted board with a faint rangoli in the middle. */
.board {
  background-color: color-mix(in srgb, var(--surface-2) 92%, transparent);
  background-image: var(--rangoli), var(--fibre);
  background-repeat: no-repeat, repeat;
  background-position: center, 0 0;
  background-size: min(70%, 360px) auto, auto;
  border-radius: 22px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--marigold) 35%, var(--border)) inset, 0 8px 22px rgba(92, 70, 38, 0.2);
}
:root[data-theme="dark"] .board { box-shadow: 0 0 0 2px rgba(255, 176, 32, 0.25) inset, 0 0 40px rgba(255, 176, 32, 0.08), 0 10px 26px rgba(0, 0, 0, 0.4); }
.num { background-color: color-mix(in srgb, var(--card) 85%, transparent); opacity: 0.9; }
:root[data-theme="dark"] .num:not(.on) { background-color: rgba(255, 244, 224, 0.1); color: #a89c86; box-shadow: inset 0 0 0 1px rgba(255, 244, 224, 0.18); }
:root[data-theme="dark"] .num.need { color: #ffd9a8; box-shadow: inset 0 0 0 2px var(--need); }
.num.on { box-shadow: inset 0 0 0 2px var(--pc), inset 0 0 0 3px rgba(255, 255, 255, 0.5), 0 3px 6px rgba(0, 0, 0, 0.22); }
:root[data-theme="dark"] .num.on { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.35), 0 0 12px color-mix(in srgb, var(--pc) 55%, transparent); }

/* Hand dock: a green meadow strip. */
.hand-dock {
  background: linear-gradient(180deg, color-mix(in srgb, var(--hill-2) 88%, transparent), color-mix(in srgb, var(--hill-3) 96%, transparent));
  box-shadow: 0 -6px 18px rgba(40, 60, 30, 0.25);
  border-top: 2px solid color-mix(in srgb, var(--marigold) 60%, transparent);
}
:root[data-theme="dark"] .hand-dock { background: linear-gradient(180deg, rgba(36, 34, 66, 0.94), rgba(22, 20, 44, 0.98)); border-top-color: rgba(255, 176, 32, 0.45); }
.pcard { box-shadow: inset 0 0 0 3px var(--card), inset 0 0 0 4px var(--border), 0 4px 10px rgba(0, 0, 0, 0.22); }
.pcard.prime { background: var(--fibre), linear-gradient(160deg, #ffe08a, var(--marigold)); }
.pcard.playable { box-shadow: 0 0 0 3px #ffe08a, 0 0 16px rgba(255, 200, 80, 0.55), 0 6px 12px rgba(0, 0, 0, 0.25); }
.pcard .factors span.have { background: var(--accent); border-color: var(--accent); }

.tray-stack { background: linear-gradient(135deg, var(--marigold), var(--saffron)); }
.end-list li.winner { background: linear-gradient(90deg, rgba(255, 209, 102, 0.55), rgba(244, 162, 39, 0.25)); }

/* ---- Tighter phone layout: fit the whole table above the hand ---- */
@media (max-width: 560px) {
  main { padding-top: 2.2rem; }
  .opponents { gap: 0.35rem; margin-bottom: 0.5rem; }
  .seat { flex: 1 0 96px; padding: 0.35rem 0.5rem; border-radius: 12px; gap: 0; }
  .seat .who { font-size: 0.85rem; }
  .seat .meta { font-size: 0.7rem; gap: 0.25rem; }
  .seat .meta span:nth-child(2) { display: none; } /* bot level: shown in the lobby and rules */
  .seat .mini-cards { display: none; }
  .table-col { gap: 0.4rem; }
  .table-head { gap: 0.4rem; }
  .status { font-size: 0.8rem; padding: 0.3rem 0.7rem; }
  .tray { font-size: 0.8rem; }
  .last-play { font-size: 0.82rem; min-height: 1.2em; }
  .board { gap: 3px; padding: 5px; border-radius: 14px; }
  .num { aspect-ratio: 5 / 6; font-size: 0.74rem; border-radius: 4px; }
  .num[data-count]::before { font-size: 0.55rem; right: -3px; top: -5px; }
  .hand-dock { padding-top: 0.4rem; }
  .hand-dock .legend { flex-wrap: wrap; font-size: 0.68rem; gap: 0.1rem 0.7rem; margin-bottom: 0.3rem; }
  .hand-head { margin-bottom: 0.2rem; }
  .hand { gap: 0.4rem; padding-top: 8px; }
  .pcard { width: 54px; height: 78px; padding: 4px; }
  .pcard .v { font-size: 1.25rem; }
  .pcard .factors span { min-width: 16px; height: 16px; font-size: 0.55rem; }
  .pcard .kind { font-size: 0.55rem; }
  #game { padding-bottom: 190px; }
  .side-col .card { padding: 0.8rem; }
}
@media (prefers-reduced-motion: reduce) { .topbar::after { animation: none; } }

/* Flying card used by the spring animation. */
.fly-card {
  position: fixed; left: 0; top: 0; z-index: 30; pointer-events: none; will-change: transform;
  display: grid; place-items: center; border-radius: 7px; font-family: var(--font-display); font-weight: 700;
  color: #fff; background: var(--pc, var(--accent)) var(--fibre);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.5), 0 10px 22px rgba(0, 0, 0, 0.3);
  font-size: clamp(0.8rem, 2.4vw, 1.1rem);
}
.fly-card.skip { background: linear-gradient(160deg, #ff6b6b, #e8590c); border-radius: 12px; }
.fly-card.magic { background: linear-gradient(160deg, #b65fdc, #6741d9); }
.num.landing-pending { visibility: hidden; }
.num.fresh { animation: none; }
.num.landed, .seat.landed { animation: land 0.42s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes land { 0% { transform: translateY(-2px) scale(1.12); } 100% { transform: translateY(-2px) scale(1) rotate(var(--tilt, 0deg)); } }
.seat.landed { animation: shake 0.45s ease; }
@keyframes shake { 0%, 100% { transform: none; } 25% { transform: translateX(-5px) rotate(-1deg); } 75% { transform: translateX(5px) rotate(1deg); } }
:root[data-theme="dark"] .pcard .factors span:not(.have) { background: #fff4e0; color: #776753; border-color: #b8a688; }

/* ---- Home: how to play (crawlable), kicker, noscript ---------------------- */
.kicker { margin: 0 0 0.3rem; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); }
.howto { margin-top: 1.5rem; }
.howto h2 { margin-top: 0; }
.howto ol { margin: 0.6rem 0; padding-left: 1.3rem; display: grid; gap: 0.35rem; }
.howto p { margin: 0.4rem 0; }
.noscript { position: fixed; inset: auto 1rem 1rem; padding: 0.8rem 1rem; border-radius: 12px; background: var(--text); color: var(--bg); text-align: center; z-index: 50; }
.brand-name sup { font-size: 0.55em; margin-left: 1px; font-weight: 600; }
