/* ---- themes ------------------------------------------------------------ */

:root {
  --cw: 80px; /* a card's width; each place that shows cards sets its own */
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --card: #fffdf8;
  --card-edge: rgba(0, 0, 0, 0.16);
  /* The four card colours. Yellow carries dark ink; the rest carry white. */
  --red: #d8372f;
  --blue: #2266d0;
  --green: #1d9a52;
  --yellow: #f2b705;
  --slate: #2d3242;
  /* A colour per seat, by where it sits: you, left, across, right. The same four as Hearts. */
  --p0: #4f9ff0;
  --p1: #ee7961;
  --p2: #a98cf5;
  --p3: #38c6b4;
  --bad: #ee7961;
}

[data-theme="felt"] {
  --bg: #0b241c;
  --felt-1: #2e8262;
  --felt-2: #164c38;
  --ink: #f3f6f1;
  --muted: rgba(243, 246, 241, 0.66);
  --panel: rgba(6, 26, 19, 0.7);
  --panel-edge: rgba(255, 255, 255, 0.11);
  --sheet: #103528;
  --accent: #f4c95d;
  --accent-ink: #2b2104;
  --back-1: #2c4fa8;
  --back-2: #1c3577;
}

[data-theme="midnight"] {
  --bg: #090b14;
  --felt-1: #2a3357;
  --felt-2: #12162a;
  --ink: #eef0f8;
  --muted: rgba(238, 240, 248, 0.62);
  --panel: rgba(9, 11, 22, 0.7);
  --panel-edge: rgba(255, 255, 255, 0.1);
  --sheet: #1a2038;
  --accent: #ffb454;
  --accent-ink: #2a1800;
  --back-1: #b9473d;
  --back-2: #8a2e27;
}

[data-theme="linen"] {
  --bg: #e9e2d3;
  --felt-1: #fcf9f2;
  --felt-2: #ebe4d4;
  --ink: #26241e;
  --muted: rgba(38, 36, 30, 0.6);
  --panel: rgba(255, 255, 255, 0.88);
  --panel-edge: rgba(0, 0, 0, 0.09);
  --sheet: #fffdf8;
  --accent: #1f7a63;
  --accent-ink: #ffffff;
  --back-1: #2a4470;
  --back-2: #1b2e50;
  --p0: #2f7fd1;
  --p1: #d9573d;
  --p2: #7b5fd6;
  --p3: #17968a;
  --bad: #d9573d;
  --card: #ffffff;
}

/* ---- base -------------------------------------------------------------- */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 500 15px/1.3 var(--font);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.p0 { --tc: var(--p0); }
.p1 { --tc: var(--p1); }
.p2 { --tc: var(--p2); }
.p3 { --tc: var(--p3); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px; border-radius: 999px; font-weight: 700; white-space: nowrap;
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  border: 1px solid var(--panel-edge);
  transition: transform 0.12s, filter 0.12s, background 0.12s;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 16%, transparent); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.small { padding: 7px 14px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.link { white-space: nowrap; color: var(--muted); font-size: 13px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }

/* ---- cards ------------------------------------------------------------- */

/* A white card with a coloured face inside its rim: the number in the corner,
   where it shows in a fanned hand, and big in the middle. */
.card {
  --k: var(--slate);
  position: relative; flex: 0 0 var(--cw); width: var(--cw); height: calc(var(--cw) * 1.42);
  border-radius: calc(var(--cw) * 0.11);
  background: var(--card);
  box-shadow: 0 0 0 1px var(--card-edge), 0 2px 5px rgba(0, 0, 0, 0.22);
  color: #fff;
  font-family: var(--font);
}
.card::before {
  content: ""; position: absolute; inset: calc(var(--cw) * 0.055); border-radius: calc(var(--cw) * 0.07);
  background: var(--k);
}
.card.k-R { --k: var(--red); }
.card.k-B { --k: var(--blue); }
.card.k-G { --k: var(--green); }
.card.k-Y { --k: var(--yellow); color: #3a2a00; }
.card.wild::before { background: conic-gradient(from 45deg, var(--blue) 0 25%, var(--green) 0 50%, var(--yellow) 0 75%, var(--red) 0); }
.card .idx {
  position: absolute; left: 8%; top: 6%; z-index: 1;
  display: flex; flex-direction: column; align-items: center; line-height: 1;
}
/* The corner number is as big as the part of the card that shows allows. Where cards
   overlap, the code that fans them sets --show to the width left uncovered. */
.card .idx b {
  --room: calc(var(--show, var(--cw)) - var(--cw) * 0.1);
  font-size: min(calc(var(--cw) * 0.38), calc(var(--room) * 0.95)); font-weight: 800; letter-spacing: -0.04em;
}
.card.wild .idx b { font-size: min(calc(var(--cw) * 0.36), calc(var(--room) * 0.78)); }
.card.two .idx b { font-size: min(calc(var(--cw) * 0.36), calc(var(--room) * 0.66)); letter-spacing: -0.09em; margin-left: -0.04em; }
/* A card seen whole (on the piles) keeps a modest corner, so the middle number leads. */
.pile .card .idx b { font-size: calc(var(--cw) * 0.3); }
.pile .card.two .idx b { font-size: calc(var(--cw) * 0.25); }
.card .idx i { display: block; width: calc(var(--cw) * 0.13); margin-top: calc(var(--cw) * 0.04); }
.card.skip .idx i { width: calc(var(--cw) * 0.22); margin-top: 0; }
/* The colour shapes are a menu setting, off unless someone turns them on. */
[data-shapes="off"] .card .idx .shape { display: none; }
.card .face { position: absolute; inset: 0; z-index: 1; display: grid; place-items: center; padding-top: calc(var(--cw) * 0.08); }
.card .face b { font-size: calc(var(--cw) * 0.6); font-weight: 900; letter-spacing: -0.04em; line-height: 1; text-shadow: 0 calc(var(--cw) * 0.025) 0 rgba(0, 0, 0, 0.16); }
.card.two .face b { font-size: calc(var(--cw) * 0.48); letter-spacing: -0.07em; }
.card.wild .face b {
  display: grid; place-items: center; width: 56%; aspect-ratio: 1; border-radius: 50%;
  background: #1c1f26; font-size: calc(var(--cw) * 0.34); text-shadow: none;
  box-shadow: 0 0 0 calc(var(--cw) * 0.03) #fff;
}
.card.wild .idx b, .card.skip .idx { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5); }
.card.skip .face svg { width: 56%; }
/* Where cards overlap, only the corner shows, so the big middle number is kept for
   the card on top; peeking out from under the next card it would read as a second number. */
:is(.hand .cards, .group) .card:not(:last-child):not(.dragging) .face { visibility: hidden; }
.card svg { display: block; width: 100%; height: auto; }

.back {
  border-radius: 6px;
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0 2px, transparent 2px 6px),
    linear-gradient(160deg, var(--back-1), var(--back-2));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7), 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ---- room -------------------------------------------------------------- */

.room { height: 100dvh; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }

.bar {
  position: relative; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
}
.bar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
  border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-edge);
  font-weight: 700; white-space: nowrap;
}
.chip small { color: var(--muted); font-weight: 600; font-size: 12px; }
.chip.icon { width: 40px; padding: 0; justify-content: center; font-size: 18px; }
.chip:hover { border-color: color-mix(in srgb, var(--ink) 30%, transparent); }

/* Lives in the top bar's markup; on a wide screen it hangs just below it, over the table's corner.
   A row per player: name, score, and the phase they're on. (The same board as Hearts.) */
.board {
  position: absolute; top: calc(100% + 12px); right: 22px; z-index: 4;
  display: grid; grid-template-columns: auto auto auto; align-items: stretch;
  border-radius: 14px; overflow: hidden; text-align: center;
  background: var(--panel); border: 1px solid var(--panel-edge);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-variant-numeric: tabular-nums;
}
.board .pl { display: contents; }
.board .pl > * {
  display: grid; place-items: center; padding: 3px 11px; min-height: 32px;
  background: color-mix(in srgb, var(--tc) 30%, transparent); border-top: 1px solid var(--panel-edge);
}
.board .head > * { min-height: 0; padding: 5px 11px 4px; background: none; border-top: 0; font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.board .pl > .tn { display: block; text-align: left; font-size: 13px; font-weight: 700; max-width: 14ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 26px; }
.board b { font-size: 18px; font-weight: 800; }
.board .ph { font-size: 14px; font-weight: 700; }
.board:hover { border-color: color-mix(in srgb, var(--ink) 30%, transparent); }

/* The table is a grid: a seat with its phase on each side, the piles in the middle. */
.felt {
  --mw: clamp(26px, min(4vw, 6.6vh), 56px); /* a card in a laid-down phase */
  --pw: clamp(48px, min(7vw, 11vh), 92px); /* a card on the piles */
  position: relative; margin: 0 10px; min-height: 0; border-radius: 28px;
  container-type: size;
  display: grid; gap: 8px 12px; padding: 12px 14px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top top top" "left mid right" "bottom bottom bottom";
  background: radial-gradient(ellipse 80% 70% at 50% 42%, var(--felt-1), var(--felt-2));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.07),
    inset 0 0 90px rgba(0, 0, 0, 0.22),
    0 14px 40px rgba(0, 0, 0, 0.28);
}

/* Felt fibres: a seamless grey tile laid over whichever theme colour is underneath. */
.felt::before, .home::before {
  content: ""; position: absolute; inset: 0; z-index: 0; border-radius: inherit; pointer-events: none;
  background: url(/felt.webp) 0 0 / 640px 320px;
  mix-blend-mode: overlay; opacity: 0.125;
}

/* ---- seats ------------------------------------------------------------- */

.zone { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
.zone.pos-top { grid-area: top; }
.zone.pos-bottom { grid-area: bottom; flex-direction: column-reverse; }
.zone.pos-left { grid-area: left; align-items: flex-start; align-self: center; }
.zone.pos-right { grid-area: right; align-items: flex-end; align-self: center; }

.seat {
  position: relative; display: flex; align-items: center; gap: 9px; max-width: 100%;
  padding: 6px 14px 6px 6px; border-radius: 999px;
  --seat-bg: color-mix(in srgb, var(--tc) 26%, var(--panel));
  background: var(--seat-bg);
  border: 1px solid color-mix(in srgb, var(--tc) 50%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  transition: box-shadow 0.25s, background 0.25s, transform 0.25s;
}
.seat.turn { box-shadow: 0 0 0 2px var(--accent), 0 0 24px color-mix(in srgb, var(--accent) 50%, transparent); }
.seat.won { box-shadow: 0 0 0 3px var(--accent); }
.seat.away .avatar, .seat.away .who { opacity: 0.5; }
.seat.empty { padding: 6px; gap: 6px; border-style: dashed; }
.seat.empty .link { padding: 0 10px 0 4px; }

.avatar {
  position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; font-size: 16px;
  color: #fff; background: var(--tc);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.avatar > svg:not(.ring) { width: 23px; height: 23px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2)); }
.ring { position: absolute; inset: -5px; width: calc(100% + 10px); height: calc(100% + 10px); transform: rotate(-90deg); pointer-events: none; }
.ring circle {
  fill: none; stroke: var(--accent); stroke-width: 3.5; stroke-linecap: round;
  stroke-dasharray: 100; stroke-dashoffset: var(--from);
  animation: drain linear forwards;
}
@keyframes drain { to { stroke-dashoffset: 100; } }

.who { min-width: 0; }
.who .name { display: flex; align-items: center; gap: 7px; font-weight: 700; white-space: nowrap; }
.who .name span { overflow: hidden; text-overflow: ellipsis; max-width: 13ch; }
.who .stat { font-size: 12.5px; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat.turn .stat, .stat .host { color: var(--accent); }
/* The dealer button: a white disc on the corner of the picture, ringed in the seat's colour. */
.dealer {
  position: absolute; right: -5px; bottom: -4px; z-index: 1; display: grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%;
  font-size: 9.5px; font-weight: 800; font-style: normal; line-height: 1; text-shadow: none;
  background: #f7f4ec; color: #1c1c1c;
  box-shadow: 0 0 0 2px var(--seat-bg), inset 0 0 0 1.5px #d9d3c3;
}
/* How many cards someone holds, on their picture. Only on a phone; elsewhere it's in words. */
.avatar .count { display: none; }
.seat .x { width: 24px; height: 24px; border-radius: 50%; color: var(--muted); font-size: 16px; line-height: 1; margin-right: -6px; }
.seat .x:hover { background: color-mix(in srgb, var(--ink) 14%, transparent); color: var(--ink); }

/* When the table is waiting on you, your own seat becomes the banner. */
.seat.me.turn {
  --seat-bg: var(--accent);
  background: var(--accent); border-color: transparent; color: var(--accent-ink);
  padding: 8px 22px 8px 8px;
  animation: beckon 1.6s ease-in-out infinite;
}
.seat.me.turn .name { font-size: 18px; font-weight: 800; }
.seat.me.turn .stat { color: inherit; opacity: 0.8; }
.seat.me.turn .avatar { background: var(--accent-ink); color: var(--accent); text-shadow: none; }
.seat.me.turn .ring circle { stroke: var(--accent-ink); }
@keyframes beckon {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent), 0 8px 24px rgba(0, 0, 0, 0.3); }
  50% { box-shadow: 0 0 0 12px color-mix(in srgb, var(--accent) 0%, transparent), 0 8px 24px rgba(0, 0, 0, 0.3); }
}

/* ---- phases on the table ---------------------------------------------- */

.melds { display: flex; gap: 10px; justify-content: center; max-width: 100%; min-width: 0; }
.zone.pos-left .melds, .zone.pos-right .melds { flex-direction: column; align-items: flex-start; width: 100%; gap: 6px; }
.zone.pos-right .melds { align-items: flex-end; }
.group {
  --cw: var(--mw);
  display: flex; flex: none; padding: 4px; border-radius: calc(var(--mw) * 0.2);
  background: color-mix(in srgb, #000 12%, transparent);
  transition: box-shadow 0.15s, background 0.15s;
}
.group .card { box-shadow: 0 0 0 1px var(--card-edge), 1px 1px 3px rgba(0, 0, 0, 0.25); }
/* Before a phase is down, dashed spaces say what it needs. */
.group.ghost {
  display: grid; place-items: center; min-width: calc(var(--mw) * 2.4); height: calc(var(--mw) * 1.42 + 8px); padding: 0 10px;
  border: 1.5px dashed color-mix(in srgb, var(--ink) 32%, transparent); background: none;
  font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap;
}
.my-turn[data-step="play"] .group.can { cursor: pointer; background: color-mix(in srgb, var(--accent) 22%, transparent); box-shadow: 0 0 0 2px var(--accent); }
.group.drop { background: color-mix(in srgb, var(--accent) 45%, transparent) !important; }

/* ---- the piles --------------------------------------------------------- */

.mid { grid-area: mid; position: relative; z-index: 1; display: grid; place-items: center; min-height: 0; }
.piles { display: flex; gap: clamp(14px, 3vw, 28px); align-items: flex-start; }
.pile { --cw: min(var(--pw), var(--pfit, 999px)); /* --pfit: the most the middle row has room for */ display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: default; }
.pile small { font-size: 12px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.pile .stack {
  position: relative; display: block; width: var(--cw); height: calc(var(--cw) * 1.42); border-radius: calc(var(--cw) * 0.11);
  outline: 1.5px dashed color-mix(in srgb, var(--ink) 25%, transparent); outline-offset: -1px;
  transition: box-shadow 0.2s, transform 0.15s;
}
.pile .stack:not(:empty) { outline: 0; }
.pile .stack > * { position: absolute; inset: 0; width: 100%; height: 100%; }
.pile.draw .back { border-radius: inherit; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7), 2px 2px 0 -1px var(--back-2), 4px 4px 0 -2px var(--back-2), 0 6px 14px rgba(0, 0, 0, 0.3); }
.pile.discard .card { box-shadow: 0 0 0 1px var(--card-edge), 0 6px 14px rgba(0, 0, 0, 0.3); transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.3s; }
.pile.discard .card.enter { opacity: 0; }
.pile.discard .card.enter.from-bottom { transform: translateY(30cqh) scale(0.9); }
.pile.discard .card.enter.from-top { transform: translateY(-30cqh) scale(0.9); }
.pile.discard .card.enter.from-left { transform: translateX(-30cqw) scale(0.9); }
.pile.discard .card.enter.from-right { transform: translateX(30cqw) scale(0.9); }
/* Your turn to draw: both piles (or just the one you may take from) call for a tap. */
.pile.live { cursor: pointer; }
.pile.live .stack { box-shadow: 0 0 0 3px var(--accent), 0 0 26px color-mix(in srgb, var(--accent) 55%, transparent); animation: nudge 1.6s ease-in-out infinite; }
.pile.live:hover .stack { transform: translateY(-3px); }
.pile.live small { color: var(--accent); }
@keyframes nudge { 50% { box-shadow: 0 0 0 3px var(--accent), 0 0 6px color-mix(in srgb, var(--accent) 20%, transparent); } }
.dragging-card .pile.target .stack { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent); }
.pile.target.drop .stack { box-shadow: 0 0 0 3px var(--accent), 0 0 26px color-mix(in srgb, var(--accent) 55%, transparent); transform: scale(1.05); }
.pile.target { cursor: pointer; }

/* ---- centre of the table ---------------------------------------------- */

.center {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(92%, 460px); text-align: center; z-index: 3; pointer-events: none;
}
.center:empty { display: none; }
.center > * { pointer-events: auto; }
/* In the lobby the settings take the middle of the grid, between the seats. */
[data-phase="lobby"] .center { position: relative; left: auto; top: auto; transform: none; grid-area: mid; align-self: center; justify-self: center; width: min(100%, 440px); }
.panel {
  max-height: calc(100cqh - 16px); overflow-y: auto;
  padding: 20px; border-radius: 22px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}
.panel h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.panel h2 code { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0.08em; }
.panel p { color: var(--muted); margin-top: 6px; }
.panel p .link { margin-left: 4px; }
.panel .row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.status {
  display: inline-block; max-width: 100%; padding: 9px 18px; border-radius: 22px; font-weight: 700; font-size: 15px; overflow-wrap: anywhere;
  background: var(--panel); border: 1px solid var(--panel-edge);
}

.seg { display: inline-flex; padding: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 9%, transparent); }
.seg button { padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--ink); color: var(--bg); }
.opts { display: grid; gap: 6px; margin-top: 14px; justify-content: center; }
.opt { display: grid; grid-template-columns: 84px auto; align-items: center; justify-items: start; gap: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---- your hand --------------------------------------------------------- */

.hand {
  --cw: clamp(58px, min(9vw, 15vh), 120px);
  position: relative; display: flex; flex-direction: column;
  padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}
/* Nothing is dealt yet in the lobby, so the table gets the room. */
[data-phase="lobby"] .hand { padding-bottom: 14px; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 52px; padding: 8px 12px 6px; }
.actions:empty { min-height: 0; padding: 0; }
.actions .btn { padding: 9px 18px; font-size: 14.5px; }
.actions .btn.ghost { background: none; border-color: color-mix(in srgb, var(--ink) 18%, transparent); color: var(--muted); }
.actions .btn.ghost:hover { color: var(--ink); }
.actions .sort { min-width: 64px; gap: 4px; }
.sort .dot { width: 9px; height: 9px; border-radius: 50%; }
.sort .dot.k-R { background: var(--red); }
.sort .dot.k-B { background: var(--blue); }
.sort .dot.k-G { background: var(--green); }
.sort .dot.k-Y { background: var(--yellow); }
.hand .cards { position: relative; margin: 10px 14px 0; height: calc(var(--cw) * 1.42 + 8px); display: flex; justify-content: center; }
[data-phase="lobby"] .hand .cards, .hand .cards:empty { display: none; }
.hand .card {
  --lift: 0px;
  transform: translateY(calc(var(--dy, 0px) + var(--lift))) rotate(var(--rot, 0deg));
  transition: transform 0.18s, translate 0.2s, margin-left 0.18s, filter 0.2s, opacity 0.14s, box-shadow 0.2s;
  touch-action: none; /* so a finger can drag a card rather than pan the page */
  cursor: pointer;
}
.hand .card.fresh { transition: none; }
.hand .card.drawn { animation: drop-in 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
@keyframes drop-in { from { translate: 0 calc(var(--cw) * -0.9); opacity: 0; } }
@media (hover: hover) { .hand .card:hover { --lift: calc(var(--cw) * -0.08); } }
/* Picked cards stand up with a gold edge. */
.hand .card.picked { --lift: calc(var(--cw) * -0.24) !important; box-shadow: 0 0 0 3px var(--accent), 0 8px 18px rgba(0, 0, 0, 0.35); }
/* On your turn, once your phase is down, a gold dot marks each card that can go on the table. */
.hand.live .card.fits::after {
  content: ""; position: absolute; z-index: 2; right: calc(var(--cw) * 0.1); top: calc(var(--cw) * -0.12);
  width: calc(var(--cw) * 0.13); height: calc(var(--cw) * 0.13); border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg);
}
.hand.waiting .card { filter: brightness(0.84); }
.hand .card.dragging {
  z-index: 50; cursor: grabbing; --lift: 0px !important;
  transition: box-shadow 0.12s;
  box-shadow: 0 0 0 2px var(--accent), 0 18px 34px rgba(0, 0, 0, 0.45);
}
.hand .card.sent { --lift: calc(var(--cw) * -0.5); opacity: 0; }
.home .join input.nope { animation: nope 0.3s; }
@keyframes nope { 25% { translate: -5px 0; } 75% { translate: 5px 0; } }

/* Shown in place of a hand when you are not seated. */
.watching { position: relative; display: grid; place-items: center; margin: 0; padding: 30px 24px; text-align: center; font-weight: 600; color: var(--muted); }

/* ---- sheets, menu, toast ---------------------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, 0.45); animation: fade 0.2s;
}
.sheet {
  width: min(100%, 460px); max-height: 100%; overflow: hidden auto; padding: 24px; border-radius: 24px; text-align: center;
  background: var(--sheet); border: 1px solid var(--panel-edge); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.wide { width: min(100%, 600px); }
.sheet h2 { font-size: 24px; font-weight: 800; overflow-wrap: anywhere; }
.sheet p { color: var(--muted); margin-top: 6px; }
.sheet .row { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.sheet input {
  width: 100%; margin-top: 16px; padding: 13px 16px; border-radius: 14px; text-align: center; font-weight: 700; font-size: 17px;
  background: color-mix(in srgb, var(--ink) 8%, transparent); border: 1px solid var(--panel-edge); outline: none;
  -webkit-user-select: text; user-select: text;
}
.sheet input:focus { border-color: var(--accent); }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(0.98); } }

.countdown { margin-top: 18px; font-size: 13px; font-weight: 600; color: var(--muted); }
.countdown i { display: block; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--accent); transform-origin: 0 50%; animation: shrink linear forwards; }
@keyframes shrink { to { transform: scaleX(0); } }

.tally { width: 100%; margin-top: 16px; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.tally th:first-child { width: 25%; }
.tally th, .tally td { padding: 7px 6px; text-align: right; }
.tally th:first-child, .tally td:first-child { text-align: left; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tally thead th { font-size: 13px; font-weight: 700; color: var(--tc); border-bottom: 1px solid var(--panel-edge); }
.tally thead th span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally td small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.tally .sum td { border-top: 1px solid var(--panel-edge); font-weight: 700; }
.tally .total td { font-size: 20px; font-weight: 800; }
.tally .total td:first-child { font-size: 15px; }
/* Whether a phase was made: a green tick, or a cross in the warning colour. */
.made { font-style: normal; font-weight: 800; }
.made.yes { color: #4ccf7d; }
.made.no { color: var(--bad); }
[data-theme="linen"] .made.yes { color: #1d8a4a; }

/* The full score sheet: current standings, then a row per hand with a column per player. */
.standings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.standing {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; padding: 8px 14px 8px 12px; border-radius: 14px;
  background: color-mix(in srgb, var(--tc) 22%, transparent); text-align: left; min-width: 0;
}
.standing span { font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.standing span small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.standing b { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--tc); }
.scroll { max-height: min(46vh, 420px); overflow: auto; margin-top: 10px; }
.tally.log { margin-top: 0; }
.tally.log thead th { position: sticky; top: 0; z-index: 1; background: var(--sheet); font-size: 12px; }
.tally.log tbody td { padding: 8px 6px; border-top: 1px solid var(--panel-edge); vertical-align: top; }
.tally.log tbody tr:first-child td { border-top: 0; }
.tally.log td b { display: block; font-size: 16px; font-weight: 800; color: var(--ink); }
.tally.log td small { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tally.log td:first-child b { font-size: 13px; font-weight: 700; }

/* The ten phases, with yours picked out. */
.phases { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; text-align: left; }
.phases li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; font-weight: 600; font-size: 14px; }
.phases li b { flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: color-mix(in srgb, var(--ink) 12%, transparent); font-size: 13px; font-weight: 800; }
.phases li.on { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.phases li.on b { background: var(--accent); color: var(--accent-ink); }
.rules { margin-top: 14px; text-align: left; }
.rules p { margin-top: 8px; font-size: 14px; line-height: 1.45; }
.rules b { color: var(--ink); }

.menu {
  position: fixed; right: 12px; top: calc(max(10px, env(safe-area-inset-top)) + 46px); z-index: 15; width: 250px; padding: 8px;
  max-height: calc(100dvh - 70px); overflow-y: auto;
  border-radius: 18px; background: var(--sheet); border: 1px solid var(--panel-edge); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  animation: rise 0.16s;
}
.menu .item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 11px; font-weight: 600; }
.menu button.item:hover { background: color-mix(in srgb, var(--ink) 9%, transparent); }
.menu .item.static { justify-content: space-between; padding: 6px 8px 6px 12px; }
.menu .seg button { padding: 5px 8px; font-size: 12px; }
.menu .check { width: 16px; font-style: normal; font-weight: 800; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--panel-edge); margin: 6px 4px; }
.menu .swatches { display: flex; gap: 8px; padding: 8px 12px 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; box-shadow: 0 0 0 1px var(--panel-edge); }
.swatch.on { border-color: var(--accent); }
.swatch[data-set-theme="felt"] { background: radial-gradient(#2e8262, #164c38); }
.swatch[data-set-theme="midnight"] { background: radial-gradient(#2a3357, #12162a); }
.swatch[data-set-theme="linen"] { background: radial-gradient(#fcf9f2, #e0d7c3); }

.toast {
  position: fixed; left: 50%; top: 40%; transform: translateX(-50%); z-index: 30;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; text-align: center;
  background: var(--ink); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: rise 0.2s;
}

/* ---- home -------------------------------------------------------------- */

.home { position: relative; isolation: isolate; height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(ellipse at 50% 30%, var(--felt-1), var(--felt-2) 70%); }
.home .sheet { position: relative; z-index: 1; animation: none; }
.home .logo { width: 96px; margin: 0 auto; }
.home .logo svg { display: block; width: 100%; height: auto; }
.home h2 { margin-top: 10px; }
.home h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; margin-top: 2px; }
.home .tag { margin-top: 2px; }
.home .btn.primary { width: 100%; margin-top: 12px; padding: 14px; font-size: 17px; }
.home .join { display: flex; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--panel-edge); }
.home .join input { margin: 0; text-transform: uppercase; letter-spacing: 0.12em; }
.home .join .btn { flex: none; }
.home .rules-link { margin-top: 16px; }

/* A tablet held upright: plenty of height, so the cards can grow. */
@media (min-width: 641px) and (orientation: portrait) {
  .hand { --cw: clamp(62px, 12vw, 120px); }
  .felt { --mw: clamp(30px, 4.4vw, 46px); --pw: clamp(60px, 10vw, 100px); }
}

/* Narrower than a laptop: scoreboard names get shorter so the board stays in its corner. */
@media (max-width: 900px) {
  .board .pl > .tn { max-width: 9ch; }
}

/* ---- small screens ----------------------------------------------------- */

@media (max-width: 640px) {
  .chip.table small { display: none; }
  .bar { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .chip.table { flex-direction: column; align-items: flex-start; justify-content: center; gap: 0; height: 46px; border-radius: 14px; line-height: 1.1; }
  .chip.table .word { font-size: 10.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
  .felt { margin: 0 6px; border-radius: 22px; padding: 8px; gap: 6px; --mw: clamp(22px, 7.4vw, 34px); --pw: clamp(46px, 14vw, 64px); }

  /* The scoreboard sits in the top bar: a coloured column per player, name over score. */
  .bar .spacer { display: none; }
  .board { position: static; display: flex; flex: 1 1 0; min-width: 0; max-width: 300px; margin-left: auto; height: 46px; }
  .board .pl {
    display: grid; align-content: center; justify-items: center; gap: 2px; flex: 1 1 0; min-width: 0; padding: 0 5px;
    background: color-mix(in srgb, var(--tc) 30%, transparent); border-left: 1px solid var(--panel-edge);
  }
  .board .pl.head + .pl { border-left: 0; }
  .board .pl > * { display: block; min-height: 0; padding: 0; background: none; border: 0; }
  .board .pl.head, .board .pl > .ph { display: none; }
  .board .pl > .tn { max-width: 100%; font-size: 10.5px; line-height: 1.1; text-align: center; color: var(--muted); }
  .board b { font-size: 18px; line-height: 1; }

  /* Bigger cards in the hand, smaller name plates. */
  .hand { --cw: clamp(58px, 21vw, 92px); }
  .hand .cards { margin: 6px 8px 0; }
  .actions { min-height: 48px; padding: 6px 8px 2px; gap: 6px; }
  .actions .btn { padding: 8px 13px; font-size: 13.5px; }
  .actions .sort { min-width: 0; padding: 8px 11px; }
  .panel { padding: 16px; }
  .panel .row { margin-top: 12px; }

  .seat { gap: 7px; padding: 4px 11px 4px 4px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .avatar > svg:not(.ring) { width: 19px; height: 19px; }
  .who .name { font-size: 14px; }
  .who .stat { font-size: 11.5px; }
  .seat.me.turn { padding: 6px 18px 6px 6px; }
  .seat.me.turn .name { font-size: 16px; }
  .zone.pos-top .who .name span { max-width: 10ch; }
  /* How many cards someone holds moves onto their picture, so the line under the name stays short.
     Your own count is your hand, right there below. */
  .stat .cards { display: none; }
  .avatar .count {
    display: grid; place-items: center; position: absolute; left: -7px; top: -6px; z-index: 1;
    min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
    font-size: 10px; font-weight: 800; font-style: normal; line-height: 1; text-shadow: none;
    background: var(--ink); color: var(--bg); box-shadow: 0 0 0 2px var(--seat-bg);
  }
  .seat.me .avatar .count { display: none; }

  /* With someone at each side, those two seats stand upright and slim: picture over name over phase. */
  .zone.pos-left, .zone.pos-right { width: min(104px, 27vw); align-self: center; }
  .zone.pos-left .seat, .zone.pos-right .seat { flex-direction: column; gap: 2px; padding: 5px 6px 6px; border-radius: 16px; text-align: center; width: 100%; }
  .zone.pos-left .who, .zone.pos-right .who { width: 100%; }
  .zone.pos-left .name, .zone.pos-right .name { justify-content: center; }
  .zone.pos-left .name span, .zone.pos-right .name span { max-width: 100%; min-width: 0; }
  .zone.pos-left .btn.small, .zone.pos-right .btn.small { padding: 5px 8px; font-size: 11.5px; }

  /* Other players' empty phase boxes go: their seat already says which phase they're on. */
  .group.ghost { font-size: 11px; padding: 0 7px; min-width: 0; }
  .zone:not(.pos-bottom) .group.ghost { display: none; }
  .zone.pos-bottom .group.ghost { height: calc(var(--mw) * 1.42); font-size: 10.5px; }
  /* The piles lose their captions; the draw pile's count sits on its back. */
  .pile small { display: none; }
  .pile.draw { position: relative; }
  .pile.draw small {
    display: block; position: absolute; left: 50%; bottom: 7px; transform: translateX(-50%);
    padding: 1px 7px; border-radius: 999px; background: rgba(0, 0, 0, 0.5); color: #fff; font-size: 10.5px;
  }

  /* In the lobby the settings fill the middle, so the side seats drop below them. */
  [data-phase="lobby"] .felt { grid-template-columns: 1fr 1fr; grid-template-areas: "top top" "mid mid" "left right" "bottom bottom"; }
  [data-phase="lobby"] .zone.pos-left, [data-phase="lobby"] .zone.pos-right { width: auto; }
  [data-phase="lobby"] .zone.pos-left .seat, [data-phase="lobby"] .zone.pos-right .seat { flex-direction: row; text-align: left; width: auto; border-radius: 999px; padding: 4px 11px 4px 4px; }
  [data-phase="lobby"] .zone.pos-left .seat.empty, [data-phase="lobby"] .zone.pos-right .seat.empty { padding: 4px; }
  [data-phase="lobby"] .zone.pos-left .name, [data-phase="lobby"] .zone.pos-right .name { justify-content: flex-start; }

  .sheet { padding: 20px 16px; }
  .phases { grid-template-columns: 1fr; gap: 2px; }
  .tally th, .tally td { padding: 7px 4px; }
  .tally th:first-child { width: 27%; }
  .tally .total td { font-size: 18px; }
  .standing { padding: 7px 10px; }
  .standing b { font-size: 19px; }
}

/* Short phones: tighten up so the whole table fits. */
@media (max-width: 640px) and (max-height: 700px) {
  .panel { padding: 12px 14px; border-radius: 18px; }
  .panel h2 { font-size: 19px; }
  .panel > p:first-of-type { display: none; }
  .panel .row { margin-top: 10px; }
  .opts { margin-top: 10px; gap: 4px; }
  .hand { --cw: clamp(52px, 15vw, 74px); }
}

/* ---- short windows ----------------------------------------------------- */

/* A laptop window that isn't tall: Phase stacks more down the table than the trick
   games, so this starts higher than their 620px. Smaller cards, a compact scoreboard,
   other players' empty phase boxes gone, and the side seats low, clear of the scoreboard. */
@media (max-height: 760px) and (min-width: 641px) {
  .hand { --cw: clamp(52px, min(9vw, 13vh), 104px); }
  .felt { --mw: clamp(22px, min(3.4vw, 5vh), 40px); --pw: clamp(44px, min(6vw, 9vh), 76px); }
  .board .pl > * { min-height: 25px; padding: 1px 10px; }
  .board .head > * { min-height: 0; padding: 4px 10px 3px; }
  .board b { font-size: 16px; }
  .board .pl > .tn { line-height: 22px; }
  .zone:not(.pos-bottom) .group.ghost { display: none; }
  .zone.pos-left, .zone.pos-right { align-self: end; }
}

/* Shorter still: the scoreboard joins the top bar as a strip, name and score side by side,
   so it never sits over a seat. */
@media (max-height: 620px) and (min-width: 641px) {
  .board { position: static; display: flex; height: 34px; }
  .board .pl {
    display: flex; align-items: center; gap: 6px; padding: 0 10px;
    background: color-mix(in srgb, var(--tc) 30%, transparent); border-left: 1px solid var(--panel-edge);
  }
  .board .pl.head + .pl { border-left: 0; }
  .board .pl > * { display: block; min-height: 0; padding: 0; background: none; border: 0; }
  .board .pl.head, .board .pl > .ph { display: none; }
  .board .pl > .tn { max-width: 7ch; font-size: 12px; line-height: 1.2; }
  .board b { font-size: 15px; }
}

/* A phone on its side: very little height, so everything flattens out. */
@media (max-height: 480px) and (min-width: 641px) {
  .bar { padding-top: 6px; padding-bottom: 6px; }
  .chip { height: 34px; }
  .chip.icon { width: 34px; }
  .hand { --cw: clamp(48px, 7vw, 70px); padding-bottom: calc(env(safe-area-inset-bottom) + 6px); }
  .actions { min-height: 40px; padding: 4px 12px 0; }
  .actions .btn { padding: 6px 14px; font-size: 13px; }
  .hand .cards { margin-top: 4px; }
  .felt { margin: 0 8px; border-radius: 20px; padding: 6px 10px; gap: 4px 10px; --mw: clamp(20px, 3vw, 30px); --pw: clamp(40px, 8vh, 56px); }
  .zone { flex-direction: row; gap: 8px; }
  .zone.pos-top, .zone.pos-bottom { flex-direction: row; justify-content: center; }
  .zone.pos-left, .zone.pos-right { flex-direction: column; }
  .seat { padding: 3px 10px 3px 3px; gap: 6px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
  .who .name { font-size: 13px; }
  .who .stat { font-size: 11px; }
  .panel { padding: 10px 14px; border-radius: 16px; max-height: calc(100cqh - 8px); }
  .panel h2 { font-size: 17px; }
  .panel > p:first-of-type { display: none; }
  .panel .row { margin-top: 8px; }
  .opts { margin-top: 8px; gap: 3px; }
}
