/* StraightUpTuppi — mökki theme: a weathered plank wall under a warm lamp, a green baize card
   table with a walnut rim, a board ledge for your hand, paper-note banners, tartan card backs.
   No web fonts. The surfaces are photographic CC0 tiles in /textures (Poly Haven, ambientCG —
   credits in README) layered under gradients; see --tex-* below. Mobile-first. */

:root {
  /* Baize is the table top, wood the log wall and rim, gold the lantern's amber. */
  --felt-1: #2f6b45;
  --felt-2: #1f4a30;
  --felt-3: #16351f;
  /* Photographic textures (CC0, see README "Tekstuurit"): a weathered dark plank wall, a
     walnut board for rim and ledge, a fine cloth weave (greyscale, coloured by the gradient
     under it) and a flecked paper. Served from /textures, cached by the browser. */
  --tex-wall: url('/textures/wall.jpg');
  --tex-wood: url('/textures/wood.jpg');
  --tex-cloth: url('/textures/cloth.jpg');
  --tex-paper: url('/textures/paper.jpg');
  --cream: #f3e7c8;
  --paper: #efe2c0;
  --ink: #3d2812;
  --red: #a03030;
  --black: #2b2521;
  --gold: #ffb95e;
  --team-a: #7fa8c9;
  --team-b: #c98a6b;
  --card-w: clamp(46px, 11vw, 78px);
  --card-h: calc(var(--card-w) * 1.4);
  /* Cards on the felt can be bigger than the hand's: the felt has room, the hand doesn't. */
  --trick-w: var(--card-w);
  --trick-h: calc(var(--trick-w) * 1.4);
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
/* Components below set display:flex/grid, which would otherwise beat the UA's
   [hidden] { display:none } and leave "hidden" overlays blocking the whole screen. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Plank wall with a warm lamp pool from above and darker corners. */
  background:
    radial-gradient(ellipse 85% 55% at 50% 10%, rgba(255, 196, 110, 0.24), transparent 70%),
    radial-gradient(ellipse 120% 100% at 50% 60%, transparent 55%, rgba(10, 5, 2, 0.55)),
    linear-gradient(rgba(140, 80, 30, 0.22), rgba(140, 80, 30, 0.22)),
    var(--tex-wall) center top / 900px auto repeat,
    #2a1d12;
  background-attachment: fixed;
  color: var(--cream);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

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

/* #main is the flex child of #app; it must stretch and pass its height down, otherwise the
   table's 1fr felt row collapses to zero and every seat/trick card piles onto the scorebar. */
#main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(#1d1106d9, #150c06e6), var(--tex-wood) center / 600px auto;
  border-bottom: 1px solid #c9a86a33;
  box-shadow: 0 2px 10px #0008;
  padding-top: max(8px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-suits { color: var(--gold); font-size: 1.1em; letter-spacing: 2px; }
.brand-name { font-size: 1.05em; letter-spacing: 0.5px; }
.brand-name b { color: var(--gold); }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  background: #2e1f10;
  color: var(--cream);
  border: 1px solid #a58a5e55;
  border-radius: 8px;
  font-size: 1.05em;
  padding: 6px 9px;
  cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }

.conn-status { width: 10px; height: 10px; border-radius: 50%; background: #d55; margin-right: 2px; }
.conn-status.ok { background: #6c6; box-shadow: 0 0 6px #6c6; }
.conn-status.warn { background: #dd5; }

/* ---------------------------------------------------------------- update banner */

.update-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 7px 12px;
  background: linear-gradient(#3a2f0f, #2a2209);
  border-bottom: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.92em;
  animation: bannerSlide 0.3s ease-out;
}
.update-banner .big-btn { padding: 6px 14px; font-size: 0.95em; }
@keyframes bannerSlide { from { transform: translateY(-100%); opacity: 0; } }

/* Sits inside the paper-coloured .overlay-card: ink on paper, not the cream used on the wood. */
.whats-new { text-align: left; margin: 8px 0 14px; padding-left: 20px; line-height: 1.45; color: var(--ink); }
.whats-new li + li { margin-top: 6px; }
.version-line { text-align: center; font-size: 0.75em; color: #b9a67d; margin: 0; }

/* ---------------------------------------------------------------- lobby */

.lobby {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 90px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.lobby h1 { margin: 0; font-size: 1.3em; }
.lobby .sub { color: #d8c49a; margin: 4px 0 12px; }

.card-panel {
  background: linear-gradient(#2a1a0bd9, #1d1106e6);
  border: 1px solid #c9a86a40;
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 6px 18px #0007, inset 0 1px 0 #ffffff14;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.name-row { display: flex; gap: 8px; }
.name-row input {
  flex: 1;
  font-size: 1em;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #a58a5e55;
  background: #00000038;
  color: var(--cream);
}

.name-row input { min-width: 0; width: 0; }
.name-row .big-btn { flex: none; white-space: nowrap; }

.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #3d2b1666;
  border: 1px solid #a58a5e2e;
}
.room-row .room-name { flex: 1; min-width: 0; }
.room-row .room-seats { color: #d8c49a; font-size: 0.85em; }
.room-row .badge {
  font-size: 0.72em;
  padding: 2px 7px;
  border-radius: 99px;
  background: #c9b489;
  color: #3d2812;
  font-weight: 700;
}
.room-row .badge.open { background: #3f7d46; color: #eafbe8; }

button.big-btn, a.big-btn {
  display: inline-block;
  background: linear-gradient(#ecd7a6, #d3b276);
  color: #4a3116;
  border: 1px solid #8a6a3a;
  border-bottom-width: 3px;
  font-weight: 700;
  font-size: 1em;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
button.big-btn:active, a.big-btn:active { transform: scale(0.97); }
button.big-btn.ghost {
  background: #2e1f10;
  color: #e8d5ac;
  border: 1px solid #a58a5e66;
  border-bottom-width: 3px;
  border-bottom-color: #1d1207;
  font-weight: 500;
}
button.big-btn:disabled { opacity: 0.45; cursor: default; }

/* ---------------------------------------------------------------- table */

.table-wrap {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.scorebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 10px;
  font-size: 0.95em;
  background: #0004;
}
.scorebar .team {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 99px;
  border: 1px solid #a58a5e3d;
}
.scorebar .team.a { color: var(--team-a); }
.scorebar .team.b { color: var(--team-b); }
.scorebar .team.nousu { border-color: var(--gold); box-shadow: 0 0 8px #d9b45a55; }
.scorebar .team .pts { font-weight: 800; color: var(--cream); font-size: 1.1em; }
.scorebar .mid {
  color: #d8c49a;
  font-size: 0.8em;
  text-align: center;
  line-height: 1.25;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

/* The table: green baize with a lamp pool and a vignette, inside a wooden rim (grain via
   border-image). A rounded rectangle rather than an ellipse — on a phone the ellipse became a
   tall egg and wasted the corners; a rectangle gives the trick and the seats room. */
.felt {
  position: relative;
  margin: 6px 10px 0;
  border-radius: 32px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(255, 230, 170, 0.14), transparent 70%),
    var(--tex-cloth) center / 240px auto repeat,
    radial-gradient(ellipse 90% 90% at 50% 50%, var(--felt-1), var(--felt-2) 70%, var(--felt-3)),
    linear-gradient(#3a2614aa, #1d12088c),
    var(--tex-wood) center / 700px auto repeat;
  /* The weave is greyscale: multiplying it over the gradient colours it felt-green and keeps
     the lamp pool and vignette. The rim is a background layer clipped to the border box, so
     the corners stay round (border-image would square them off). */
  background-blend-mode: normal, multiply, normal, normal, normal;
  border: 12px solid transparent;
  background-clip: padding-box, padding-box, padding-box, border-box, border-box;
  box-shadow:
    inset 0 0 60px rgba(0, 20, 8, 0.55),
    inset 0 2px 3px rgba(255, 240, 200, 0.12),
    0 10px 30px #000b;
  /* Deliberately NOT overflow:hidden — seat plates and their buttons live at the felt's
     edge and may stick out past the elliptical border; clipping made them unreachable. */
  overflow: visible;
}

.seat {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 90px;
  /* Above the trick layer so seat buttons stay clickable. */
  z-index: 3;
}
.seat-plate {
  display: flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(#3a2817, #2b1c0e);
  border: 1px solid #c9a86a4d;
  border-radius: 99px;
  padding: 4px 10px;
  font-size: 0.88em;
  color: #ecd9ae;
  white-space: nowrap;
  transition: box-shadow 0.25s, border-color 0.25s;
}
.seat.turn .seat-plate {
  border-color: var(--gold);
  box-shadow: 0 0 12px #d9b45a88;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 50% { box-shadow: 0 0 20px #d9b45acc; } }
.seat.speaking .seat-plate { border-color: #7ce07c; box-shadow: 0 0 14px #7ce07caa; }
.seat.empty .seat-plate { opacity: 0.6; border-style: dashed; }
.seat-cardcount { font-size: 0.75em; color: #d8c49a; }
.seat-role { font-size: 0.72em; color: var(--gold); }
.seat-team-dot { width: 8px; height: 8px; border-radius: 50%; }
.seat-team-dot.a { background: var(--team-a); }
.seat-team-dot.b { background: var(--team-b); }
.seat-disconnect { color: #e88; font-size: 0.72em; }

/* Relative seat positions: 0 = me (bottom), 1 = my left, 2 = partner (top), 3 = my right —
   play runs clockwise, so the next player always sits on my left. */
.seat-0 { bottom: 6%; left: 50%; transform: translateX(-50%); }
.seat-1 { top: 30%; left: 4%; transform: translateY(-50%); }
.seat-2 { top: 6%; left: 50%; transform: translateX(-50%); }
.seat-3 { top: 30%; right: 4%; transform: translateY(-50%); }

.trick {
  position: absolute;
  left: 50%; top: 50%;
  width: 0; height: 0;
  z-index: 1;
}
.trick-card {
  position: absolute;
  width: var(--trick-w);
  height: var(--trick-h);
  margin-left: calc(var(--trick-w) / -2);
  margin-top: calc(var(--trick-h) / -2);
  transition: transform 0.4s cubic-bezier(0.5, 0, 0.75, 0), opacity 0.4s ease-in;
}
.trick-card .card-face, .trick-card svg { display: block; width: 100%; height: 100%; }
.trick-card.p0 { transform: translate(0, calc(var(--trick-h) * 0.55)); }
.trick-card.p1 { transform: translate(calc(var(--trick-w) * -1.1), 0); }
.trick-card.p2 { transform: translate(0, calc(var(--trick-h) * -0.55)); }
.trick-card.p3 { transform: translate(calc(var(--trick-w) * 1.1), 0); }
.trick-card.winning { filter: drop-shadow(0 0 6px #d9b45a99); }
/* Completed trick: the taking card glows and rises; the rest dim slightly. */
.trick-card.taker {
  z-index: 2;
  filter: drop-shadow(0 0 10px #f0c95acc) drop-shadow(0 0 3px #f0c95a);
  outline: 3px solid var(--gold);
  outline-offset: 1px;
  border-radius: calc(var(--trick-w) * 0.09);
}
.trick:has(.taker) .trick-card:not(.taker) { filter: brightness(0.82); }
/* Sweep: every card slides off toward the seat that took the trick. */
.trick-card.sweep { opacity: 0; }
.trick-card.sweep.to-p0 { transform: translate(0, calc(var(--trick-h) * 2.4)) scale(0.6); }
.trick-card.sweep.to-p1 { transform: translate(calc(var(--trick-w) * -3), 0) scale(0.6); }
.trick-card.sweep.to-p2 { transform: translate(0, calc(var(--trick-h) * -2.4)) scale(0.6); }
.trick-card.sweep.to-p3 { transform: translate(calc(var(--trick-w) * 3), 0) scale(0.6); }
.trick-caption {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--trick-h) * 1.08 + 6px);
  transform: translateX(-50%);
  z-index: 3;
  pointer-events: none;
  white-space: nowrap;
  background: #2b1c0ee6;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.85em;
  padding: 3px 10px;
  border-radius: 99px;
  animation: bannerIn 0.25s ease-out;
}
.trick-caption.fade { opacity: 0; transition: opacity 0.3s; }

/* The seat that took the trick flashes. */
.seat.took .seat-plate {
  border-color: var(--gold);
  background: #4a3116ee;
  box-shadow: 0 0 16px #f0c95acc;
  animation: took 0.5s ease-out 2;
}
@keyframes took { 50% { transform: scale(1.12); } }

/* ---------------------------------------------------------------- last trick */

button.big-btn.ghost.last-trick-btn.active { border-color: var(--gold); color: var(--gold); }
.last-trick-panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  z-index: 7;
  background: #241708f5;
  border: 1px solid var(--gold);
  border-radius: 12px;
  padding: 10px 12px 8px;
  box-shadow: 0 8px 30px #000c;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 16px);
  cursor: pointer;
  animation: panelIn 0.2s ease-out;
}
@keyframes panelIn { from { opacity: 0; transform: translate(-50%, -46%); } }
.last-trick-title { color: var(--gold); font-weight: 700; font-size: 0.9em; text-align: center; }
.last-trick-row { display: flex; gap: 8px; }
.last-trick-play { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.last-trick-play .card { --card-w: clamp(40px, min(15vw, 14dvh), 70px); flex: none; }
.last-trick-play.taker .card { outline: 3px solid var(--gold); outline-offset: 1px; }
.last-trick-who {
  font-size: 0.75em;
  color: #d8c49a;
  max-width: clamp(40px, min(15vw, 14dvh), 70px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.last-trick-play.taker .last-trick-who { color: var(--gold); font-weight: 700; }
.last-trick-hint { font-size: 0.7em; color: #b9a67d; }

.deal-banner {
  position: absolute;
  left: 50%; top: 9%;
  transform: translate(-50%, -50%) rotate(-1deg);
  background: var(--tex-paper) center / 320px auto, var(--paper); background-blend-mode: multiply;
  border: 1px solid #b89a67;
  color: #6b3d1e;
  box-shadow: 2px 3px 8px #0007;
  font-weight: 800;
  font-size: 1.05em;
  padding: 7px 16px;
  border-radius: 10px;
  z-index: 5;
  pointer-events: none;
  animation: bannerIn 0.3s ease-out;
  white-space: nowrap;
}
.deal-banner.nolo { border-color: #9db4c9; color: #46596b; }
@keyframes bannerIn { from { transform: translate(-50%, -60%) rotate(-1deg) scale(0.85); opacity: 0; } }

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

/* A plank ledge in front of you: your cards rest on wood, not on the wall. */
.hand-zone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(#7a553080, #3d2814b3), var(--tex-wood) center / 700px auto;
  border-top: 2px solid #c9a86a55;
  box-shadow: 0 -6px 16px #0008, inset 0 1px 0 #ffffff1a;
}
.hand-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  width: 100%;
  min-height: calc(var(--card-h) * 0.9);
  padding: 0 2vw;
}
.hand .card {
  position: relative;
  flex: none;
  /* Overlap adapts to the card count (--n, set by app.js): each card shows a step of at most
     62% of its width, less when that's what it takes to fit the hand on screen. */
  margin: 0 calc((min(var(--card-w) * 0.62, (100% - var(--card-w)) / max(var(--n, 13) - 1, 1)) - var(--card-w)) / 2);
  transition: transform 0.18s ease, filter 0.18s ease;
  transform-origin: bottom center;
  cursor: pointer;
  z-index: 1;
}
.hand .card.playable:hover, .hand .card.playable:active { transform: translateY(-14px); z-index: 5; }
.hand .card.unplayable { opacity: 0.55; transform: translateY(6px); cursor: default; }
.hand .card.selected { transform: translateY(-20px); z-index: 6; }
.hand .card:not(.playable) .card-face { pointer-events: none; }

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.09);
  background: var(--cream);
  box-shadow: 0 2px 6px #0007, inset 0 0 0 1px #00000022;
  overflow: hidden;
}
.card svg { display: block; width: 100%; height: 100%; }

/* ---------------------------------------------------------------- voice */

.voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 4px;
  font-size: 0.85em;
  color: #d8c49a;
}
.voice-bar .mute-hint { font-size: 0.9em; }
#btn-voice.muted { background: #6e2a2a; border-color: #e09a7a; color: #ffd9c9; }
#btn-voice.off { opacity: 0.75; }

/* Per-seat mute + volume (shown under a plate while in voice). Compact on purpose: two of
   these sit at the felt's left and right edges, where horizontal room is scarce. */
.seat-voice {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}
.seat-voice .seat-mute {
  padding: 2px 6px;
  font-size: 0.78em;
  line-height: 1.2;
  border-radius: 8px;
}
.seat-mute.muted { background: #6e2a2a; border-color: #e09a7a; }
.seat-voice input[type='range'] {
  width: 54px;
  height: 16px;
  margin: 0;
  accent-color: var(--gold);
}

/* ---------------------------------------------------------------- chat */

.chat-drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: min(320px, 88vw);
  background: #241708f2;
  border-left: 1px solid #a58a5e3d;
  display: flex;
  flex-direction: column;
  z-index: 30;
  padding-top: env(safe-area-inset-top);
}
.chat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #a58a5e33;
  font-weight: 700;
}
.chat-lines {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9em;
  -webkit-user-select: text;
  user-select: text;
}
.chat-line .who { color: var(--gold); margin-right: 6px; font-weight: 700; }
.chat-line.system { color: #b9a67d; font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid #a58a5e33; }
.chat-form input {
  flex: 1;
  border-radius: 8px;
  border: 1px solid #a58a5e55;
  background: #00000038;
  color: var(--cream);
  padding: 8px 10px;
  font-size: 1em;
}
.chat-form button {
  background: linear-gradient(#ecd7a6, #d3b276);
  border: 1px solid #8a6a3a;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 1em;
  cursor: pointer;
}
#btn-chat { position: relative; }
/* Pinned to the chat button's corner (it used to be position:fixed and covered the score). */
.chat-unread {
  position: absolute;
  top: -5px; right: -7px;
  line-height: 1.2;
  pointer-events: none;
  background: #c0392b;
  color: white;
  font-size: 0.75em;
  font-weight: 700;
  min-width: 22px;
  text-align: center;
  border-radius: 99px;
  padding: 3px 6px;
  z-index: 25;
}

/* ---------------------------------------------------------------- overlays */

.overlay {
  position: fixed;
  inset: 0;
  background: #1a0f06cc;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
/* The `hidden` attribute alone loses to .overlay's display:flex — make hiding win again. */
.overlay[hidden] {
  display: none;
}
.overlay-card {
  background: var(--tex-paper) center / 320px auto, var(--paper); background-blend-mode: multiply;
  border: 1px solid #b89a67;
  border-radius: 6px;
  color: var(--ink);
  transform: rotate(-0.6deg);
  padding: 22px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px #000c;
  /* End-of-game stats and the history list can outgrow the viewport. */
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.overlay-card h1, .overlay-card h2 { margin: 0 0 8px; color: #7a4520; }
.overlay-card p { margin: 6px 0 14px; color: #4a3116; }
.overlay-card .fineprint { font-size: 0.8em; color: #8a6f4d; }
.deal-result { font-size: 1.05em; line-height: 1.5; }
.deal-result .pts { color: #8c5a1d; font-weight: 800; }

/* Game stats (game-over modal + history detail): ink on the paper card. */
.stats-block { text-align: left; margin: 10px 0 4px; }
.stats-block h3 { margin: 14px 0 6px; font-size: 0.95em; color: #7a4520; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 8px 0 12px; }
.stats-grid .stat {
  background: #8a6f4d1f;
  border: 1px solid #b89a6755;
  border-radius: 6px;
  padding: 6px 2px;
  text-align: center;
}
.stats-grid .stat-num { display: block; font-size: 1.3em; font-weight: 800; color: #7a4520; }
.stats-grid .stat-label {
  display: block;
  font-size: 0.62em;
  color: #8a6f4d;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.stat-table, .deal-table { width: 100%; border-collapse: collapse; font-size: 0.85em; }
.stat-table th, .deal-table th {
  text-align: left;
  color: #8a6f4d;
  font-weight: 600;
  padding: 4px 8px 4px 0;
}
.stat-table td, .deal-table td { text-align: right; color: var(--ink); padding: 4px 0 4px 8px; }
.deal-table tr + tr th, .deal-table tr + tr td { border-top: 1px solid #b89a6733; }
.deal-table .pts { color: #8c5a1d; font-weight: 800; }

/* History viewer: one expandable row per saved game. */
.history-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; text-align: left; }
.history-item {
  border: 1px solid #b89a6755;
  border-radius: 8px;
  overflow: hidden;
  background: #8a6f4d14;
}
.history-head { padding: 8px 10px; cursor: pointer; }
.history-item.open .history-head { background: #8a6f4d26; }
.history-when { font-size: 0.8em; color: #8a6f4d; }
.history-names { font-size: 0.86em; color: var(--ink); margin: 2px 0; }
.history-score { font-size: 0.92em; font-weight: 700; color: #7a4520; }
.history-detail { padding: 2px 10px 10px; border-top: 1px solid #b89a6733; }
.history-detail .stats-block { margin-top: 4px; }

/* ---------------------------------------------------------------- misc */

.hint { color: #d8c49a; font-size: 0.9em; text-align: center; }
.error-toast {
  position: fixed;
  left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  background: #7c2d2d;
  color: #ffecec;
  padding: 8px 14px;
  border-radius: 8px;
  z-index: 40;
  animation: bannerIn 0.25s ease-out;
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 620px) {
  :root {
    --card-w: clamp(44px, 14.5vw, 60px);
    --trick-w: clamp(56px, 19vw, 80px);
  }
  .seat { min-width: 64px; }
  .seat-plate { font-size: 0.75em; padding: 3px 8px; }
  .seat-voice input[type='range'] { width: 42px; }
  .scorebar { font-size: 0.85em; gap: 6px; }
  /* Keep "edellinen tikki" + voice on one row so they don't eat the felt's height. */
  .hand-zone > .hand-actions { gap: 6px; }
  .hand-zone > .hand-actions .big-btn { font-size: 0.85em; padding: 7px 10px; }
  .felt { margin: 4px 6px 0; border-radius: 26px; border-width: 9px; }
}

@media (min-width: 900px) {
  :root { --card-w: 76px; --trick-w: 84px; }
  .felt { border-radius: 60px; margin: 8px 16px 0; }
}

/* Short landscape screens (phones on their side): width-based card sizing would leave the
   felt ~120px tall and pile seats onto the trick. Size cards by height, slim the chrome,
   put the hand beside its buttons and inline each seat's card count. */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --card-w: clamp(34px, 11.5dvh, 60px); --trick-w: var(--card-w); }
  .topbar { padding-top: max(3px, env(safe-area-inset-top)); padding-bottom: 3px; }
  .icon-btn { padding: 3px 8px; }
  .scorebar { padding: 2px 10px; font-size: 0.82em; }
  .scorebar .team { padding: 1px 8px; }
  .felt { margin: 2px 10px 0; border-width: 7px; border-radius: 22px; }
  .hand-zone {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 14px;
    padding: 4px 10px max(4px, env(safe-area-inset-bottom));
  }
  .hand { flex: 1 1 0; min-width: 0; width: auto; padding: 0; min-height: var(--card-h); }
  .hand-zone > .hand-actions { flex: none; }
  .hand-zone > .hand-actions { max-width: 45%; }
  .seat { flex-direction: row; gap: 6px; }
  .seat-0 { bottom: 4%; }
  .seat-2 { top: 4%; }
  .seat-1, .seat-3 { top: 50%; }
  .trick-card.p0 { transform: translate(0, calc(var(--trick-h) * 0.38)); }
  .trick-card.p2 { transform: translate(0, calc(var(--trick-h) * -0.38)); }
  .trick-card.p1 { transform: translate(calc(var(--trick-w) * -1.15), 0); }
  .trick-card.p3 { transform: translate(calc(var(--trick-w) * 1.15), 0); }
  /* No room above/below the trick here: the caption sits in the felt's bottom-left corner. */
  .trick-caption { left: 10px; top: auto; bottom: 10px; transform: none; }
  .deal-banner { top: 50%; }
}
