@font-face { font-family: 'Space Grotesk'; src: url(fonts/space-grotesk-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Space Grotesk'; src: url(fonts/space-grotesk-500.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Space Grotesk'; src: url(fonts/space-grotesk-700.woff2) format('woff2'); font-weight: 700; font-display: swap; }

:root {
  --bg: #262421;
  --panel: #21201d;
  --ink: #e4e1dd;
  --dim: #98948e;
  --tile: #4b4741;
  --edge: #3a3733;
  --go: #81b64c;
  --warn: #d9a13b;
  --paper: #efebe4;
  --red: #c2412f;
  --black: #1f1d1b;
  --cw: clamp(52px, 16vw, 84px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: 'Space Grotesk', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

#app { height: 100dvh; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; }

/* Bars reach the window edges. */
.bar {
  background: var(--panel);
  box-shadow: 0 0 0 100vmax var(--panel);
  clip-path: inset(0 -100vmax);
  padding-inline: 16px;
}
.top { display: flex; align-items: center; gap: 12px; padding-block: 10px; border-bottom: 1px solid var(--edge); font-size: 15px; }
.top .where { flex: 1; color: var(--dim); }
.top .where b { color: var(--ink); font-weight: 700; }
.link { background: none; border: 0; padding: 6px 4px; color: var(--dim); font-size: 15px; }
.link:hover { color: var(--ink); }

/* ---- home ---- */
.home { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding: 24px 16px 0; overflow-y: auto; }
.home h1 { font-size: clamp(56px, 17vw, 112px); line-height: 0.86; letter-spacing: -0.03em; margin: 0 0 18px; font-weight: 700; }
.home .suits { font-size: 28px; letter-spacing: 6px; margin-bottom: 10px; }
.rules { margin: 0 0 20px; padding: 0; list-style: none; font-size: 17px; line-height: 1.4; }
.rules li { padding: 9px 0; border-top: 1px solid var(--edge); display: flex; gap: 12px; }
.rules li span { color: var(--dim); font-weight: 700; min-width: 1.2em; }
.home-foot { padding-block: 14px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--edge); display: flex; flex-direction: column; gap: 12px; }
.pick { display: flex; align-items: center; gap: 12px; }
.pick .lbl { color: var(--dim); font-size: 15px; }
.seg { display: flex; flex: 1; background: var(--bg); border-radius: 6px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 0; border-radius: 5px; color: var(--dim); font-weight: 500; font-size: 16px; }
.seg button.on { background: var(--tile); color: var(--ink); font-weight: 700; }

.go {
  display: block; width: 100%; border: 0; border-radius: 6px;
  background: var(--go); color: #172010; font-weight: 700; font-size: 19px; padding: 15px 12px;
}
.go:disabled { background: var(--tile); color: var(--dim); cursor: default; }
.go.quiet { background: var(--tile); color: var(--ink); }

/* ---- table ---- */
.table {
  flex: 1; min-height: 0; position: relative;
  display: grid; grid-template-columns: 1fr auto 1fr; grid-template-rows: auto 1fr;
  padding: 10px 16px 6px; gap: 6px;
}
.seat { font-size: 14px; line-height: 1.3; color: var(--dim); min-width: 0; }
.seat .nm { color: var(--ink); font-weight: 700; font-size: 16px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.seat .nm i { font-style: normal; font-weight: 400; color: var(--dim); font-size: 13px; }
.seat b { color: var(--ink); }
.seat .st { display: flex; flex-wrap: wrap; gap: 0 10px; }
.s1 .st, .s3 .st { flex-direction: column; }
.s2 .st { justify-content: center; }
.seat.turn .nm::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); align-self: center; }
.s2 { grid-column: 2; grid-row: 1; text-align: center; }
.s2 .nm { justify-content: center; }
.s1 { grid-column: 1; grid-row: 2; align-self: center; }
.s3 { grid-column: 3; grid-row: 2; align-self: center; text-align: right; }
.s3 .nm { justify-content: flex-end; }
.piles { display: flex; gap: 2px; margin-top: 4px; flex-wrap: wrap; }
.s3 .piles { justify-content: flex-end; }
.s2 .piles { justify-content: center; }
.pile { width: 9px; height: 13px; border-radius: 2px; background: var(--tile); border: 1px solid var(--edge); }

.mid {
  grid-column: 2; grid-row: 2; align-self: center;
  display: grid; gap: 6px;
  grid-template-columns: var(--cw) var(--cw) var(--cw);
  grid-template-rows: calc(var(--cw) * 1.4) calc(var(--cw) * 1.4) calc(var(--cw) * 1.4);
  grid-template-areas: ". t ." "l c r" ". b .";
}
.mid .p0 { grid-area: b; } .mid .p1 { grid-area: l; } .mid .p2 { grid-area: t; } .mid .p3 { grid-area: r; }
.mid .centre { grid-area: c; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; color: var(--dim); }

.prompt-big { grid-column: 1 / -1; grid-row: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
.prompt-big .glyph { font-size: calc(var(--cw) * 2); line-height: 1; }
.prompt-big .say { font-size: 18px; color: var(--ink); }
.prompt-big .say.dim { color: var(--dim); font-size: 15px; }

/* ---- cards ---- */
.card {
  position: relative; aspect-ratio: 5 / 7; width: 100%;
  background: var(--paper); color: var(--black);
  border: 0; border-radius: 6px; padding: 0;
  display: block; overflow: hidden;
}
.card.red { color: var(--red); }
.card .r { position: absolute; left: 6%; top: 3%; font-weight: 700; font-size: calc(var(--cw) * 0.3); line-height: 1; text-align: center; }
.card .r small { display: block; font-size: 0.8em; }
.card .s { position: absolute; right: 8%; bottom: 4%; font-size: calc(var(--cw) * 0.5); line-height: 1; }
.mid .card { width: var(--cw); height: calc(var(--cw) * 1.4); }
.mid .card.win { box-shadow: 0 0 0 3px var(--ink); }
.mid .card.drop { animation: drop 180ms ease-out; }
@keyframes drop { from { transform: scale(1.15); opacity: 0; } to { transform: none; opacity: 1; } }

.you { padding-block: 10px; border-top: 1px solid var(--edge); display: flex; flex-direction: column; gap: 10px; }
.you .line { display: flex; align-items: center; gap: 14px; font-size: 15px; color: var(--dim); flex-wrap: wrap; }
.you .line b { color: var(--ink); }
.you .suit { font-size: 30px; line-height: 1; }
.you .say { flex: 1; min-width: 10em; color: var(--ink); font-size: 16px; text-align: right; }
.you .say.warn { color: var(--warn); }
.you.turn { box-shadow: 0 0 0 100vmax var(--panel), inset 0 3px 0 var(--go); }

.hand {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  padding-block: 4px calc(12px + env(safe-area-inset-bottom));
}
.hand .card { --cw: 14vw; }
@media (min-width: 640px) {
  .hand { grid-template-columns: repeat(13, 1fr); }
  .hand .card { --cw: 52px; }
}
.hand .card.mine::after { content: ''; position: absolute; left: 8%; right: 8%; bottom: 0; height: 4px; background: currentColor; border-radius: 2px 2px 0 0; }
.hand .card.legal { box-shadow: 0 0 0 3px var(--go); }
.hand .card.off { opacity: 0.38; }
.hand .card.sel { transform: translateY(-8px); box-shadow: 0 0 0 3px var(--go); }
.hand .card.new .r::after { content: ''; display: block; width: 7px; height: 7px; margin: 4px auto 0; border-radius: 50%; background: var(--dim); }
.hand .card { transition: transform 120ms; }

.bids { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.bids button { border: 0; border-radius: 6px; background: var(--tile); padding: 11px 0; font-weight: 700; font-size: 18px; }
.bids button.on { background: var(--go); color: #172010; }
@media (min-width: 640px) { .bids { grid-template-columns: repeat(14, 1fr); } }

/* ---- score ---- */
.sheet { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 0; }
.sheet h2 { font-size: clamp(30px, 8vw, 44px); margin: 4px 0 14px; line-height: 1.05; }
.row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 4px 14px; align-items: center; padding: 12px 0; border-top: 1px solid var(--edge); }
.row .who { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.row .who .suit { font-size: 28px; line-height: 1; width: 1em; text-align: center; }
.row .red { color: var(--red); }
.row .num { text-align: right; color: var(--dim); font-size: 14px; }
.row .num b { display: block; color: var(--ink); font-size: 20px; }
.row .num.pts b.hit { color: var(--go); }
.row .got { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px; }
.row .got .card { --cw: 30px; width: 30px; }
.row.lead .who::after { content: 'lowest'; font-size: 12px; font-weight: 500; color: var(--bg); background: var(--ink); padding: 2px 6px; border-radius: 4px; }
.sheet-foot { padding-block: 12px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--edge); display: flex; gap: 10px; }
.sheet-foot .go { flex: 1; }

.overlay { position: absolute; inset: 0; background: var(--bg); z-index: 5; overflow-y: auto; padding: 16px; }
.overlay h2 { margin: 0 0 12px; }
