/*
 * Bidel styles. Colours are varagh's Namad tokens: night petrol felt, ivory as the only pressable colour.
 * Phone portrait first; .is-desktop (fine pointer, wide screen) and landscape phones adjust the table.
 * Seats on the table are physical (left/right never mirror in RTL): play goes counter-clockwise.
 */
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/vazirmatn-arabic.woff2) format('woff2');
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC;
}
@font-face {
  font-family: 'Vazirmatn';
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/vazirmatn-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2190-2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --void: #070d12;
  --felt: #0d2a33;
  --felt-lit: #134350;
  --felt-deep: #081c24;
  --s1: #12202a;
  --s2: #1b2d39;
  --s3: #26404f;
  --line: rgba(242, 238, 223, 0.14);
  --line-2: rgba(242, 238, 223, 0.24);
  --t1: #f2eedf;
  --t2: #b7c6cb;
  --t3: #93a5ac;
  --paper: #f2eedf;
  --on-paper: #0b1a20;
  --us: #8ec5ff;
  --urgent: #ff6a4d;
  --ok: #6fd3a0;
  --gold: #e3b04b;
  --heart: #ff6b81;

  --card-face: #f6f0de;
  --card-dim: #c4c5bf;
  --ink: #1b2128;
  --red: #b3122b;
  --ink-dim: #4a5058;
  --red-dim: #7d2a3a;

  --font: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --r1: 10px;
  --r2: 14px;
  --r3: 20px;
  --tap: 44px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--felt-lit) 0%, var(--felt) 45%, var(--felt-deep) 100%) fixed, var(--felt-deep);
  color: var(--t1);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
a { color: var(--us); }
[hidden] { display: none !important; }
.muted { color: var(--t2); }
.small { font-size: 0.85rem; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.row { display: flex; align-items: center; gap: 8px; }
.row.center { justify-content: center; }
.row.gap { gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.noscript { padding: 24px; text-align: center; }
:focus-visible { outline: 3px solid var(--us); outline-offset: 2px; }

/* ---------- Buttons and inputs ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 8px 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--r2);
  background: var(--s2);
  color: var(--t1);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s var(--ease), background 0.15s;
  user-select: none;
}
.btn:hover { background: var(--s3); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary { background: var(--paper); color: var(--on-paper); border-color: var(--paper); box-shadow: 0 2px 0 #9c9885, 0 8px 14px -8px rgba(0, 0, 0, 0.6); }
.btn-primary:hover { background: #fffaf0; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--t2); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.06); color: var(--t1); }
.btn-danger { background: transparent; border-color: rgba(255, 106, 77, 0.5); color: #ffb3a3; }
.btn-lg { min-height: 56px; font-size: 1.1rem; padding: 10px 26px; }
.btn-sm { min-height: 34px; padding: 4px 12px; font-size: 0.9rem; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--s1);
  color: var(--t2);
  cursor: pointer;
}
.icon-btn:hover { color: var(--t1); background: var(--s2); }
input:not([type]), input[type='text'] {
  min-height: var(--tap);
  padding: 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r2);
  background: var(--void);
  color: var(--t1);
  flex: 1;
  min-width: 0;
}
.code-input { text-align: center; font-size: 1.3rem; font-weight: 800; letter-spacing: 0.3em; text-transform: uppercase; }

.pip { display: block; width: 1em; height: 1em; }
.inline-pip { display: inline-block; width: 0.95em; height: 0.95em; vertical-align: -0.12em; }
.s-H, .s-D { color: var(--heart); }

/* ---------- BoardBazi bar ---------- */
.bb-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: var(--safe-t) 12px 0;
  padding-inline: max(12px, env(safe-area-inset-left, 0px));
  background: rgba(14, 18, 29, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font-size: 14px;
}
.bb-bar a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 8px; min-height: 44px; min-width: 0; }
.bb-mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; flex: none; }
.bb-word { font-weight: 700; }
.bb-chip { overflow: hidden; }
.bb-avatar { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #334155; font-size: 12px; font-weight: 700; flex: none; }
.bb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.bb-level { color: #94a3b8; font-size: 12px; white-space: nowrap; }
.bb-xp { width: 48px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.15); overflow: hidden; flex: none; }
.bb-xp i { display: block; height: 100%; background: linear-gradient(90deg, #6366f1, #06b6d4); }
@media (max-width: 380px) { .bb-word { display: none; } }

/* ---------- Screens ---------- */
.screen { min-height: calc(100dvh - 44px); padding: 16px 16px calc(24px + var(--safe-b)); }
.boot { display: grid; place-content: center; justify-items: center; gap: 12px; min-height: 100dvh; color: var(--t2); }
.boot-mark { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--paper); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.intro, .home, .lobby { max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.intro { text-align: center; align-items: center; padding-top: 8px; }
.logo { margin: 0; font-size: 3.2rem; font-weight: 900; line-height: 1.1; letter-spacing: -0.01em; }
.logo-sm { font-size: 2.2rem; }
.tagline { margin: -8px 0 0; color: var(--t2); }
.lead { margin: 0; font-size: 1.05rem; max-width: 34ch; }
.features { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; width: 100%; max-width: 320px; }
.features li { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--r2); background: rgba(8, 28, 36, 0.6); border: 1px solid var(--line); text-align: start; }
.features .pip { width: 20px; height: 20px; color: var(--t2); flex: none; }
.features li:nth-child(2) .pip { color: var(--heart); }
.dev-form { width: 100%; padding: 12px; border: 1px dashed var(--line-2); border-radius: var(--r2); }
.dev-form p { margin: 0 0 8px; }

.hero-cards { position: relative; width: 220px; height: 150px; margin: 8px auto 4px; }
.hero-cards .card { --cw: 78px; position: absolute; left: 50%; bottom: 0; transform-origin: 50% 120%; }
.hero-c0 { transform: translateX(-50%) rotate(-24deg); }
.hero-c1 { transform: translateX(-50%) rotate(-8deg); }
.hero-c2 { transform: translateX(-50%) rotate(8deg); }
.hero-c3 { transform: translateX(-50%) rotate(24deg); }

.home-head { text-align: center; }
.hello { margin: 4px 0 0; font-size: 1.1rem; font-weight: 600; }
.home-head .muted { margin: 2px 0 0; }
.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--paper);
  border-radius: var(--r3);
  background: linear-gradient(135deg, var(--paper), #e7dcc0);
  color: var(--on-paper);
  text-align: start;
  cursor: pointer;
  box-shadow: 0 2px 0 #9c9885, 0 14px 24px -14px rgba(0, 0, 0, 0.7);
  transition: transform 0.12s var(--ease);
}
.tile:active { transform: translateY(1px); }
.tile-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--on-paper); color: var(--heart); flex: none; }
.tile-icon .pip { width: 28px; height: 28px; }
.tile-text { display: flex; flex-direction: column; }
.tile-text b { font-size: 1.25rem; }
.tile-text small { opacity: 0.75; }

.panel { padding: 16px; border-radius: var(--r3); background: rgba(8, 28, 36, 0.72); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.panel-title { margin: 0; font-size: 1.1rem; display: flex; flex-direction: column; }
.panel-title small { font-size: 0.82rem; font-weight: 400; color: var(--t2); }
.picker { border: 0; padding: 0; margin: 0; min-width: 0; }
.picker legend { padding: 0; margin-bottom: 6px; font-size: 0.9rem; color: var(--t2); }
.segs { display: flex; gap: 8px; }
.seg { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tap); padding: 8px; border-radius: var(--r1); border: 1px solid var(--line-2); background: var(--s1); cursor: pointer; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg.on { background: var(--paper); color: var(--on-paper); border-color: var(--paper); }
.seg:focus-within { outline: 3px solid var(--us); outline-offset: 2px; }
.seg-title { font-weight: 700; }
.seg-help { font-size: 0.75rem; opacity: 0.75; }
.picker:disabled .seg { cursor: default; }
.picker:disabled .seg:not(.on) { opacity: 0.6; }

/* ---------- Lobby ---------- */
.lobby-head { text-align: center; }
.lobby-head p { margin: 0; }
.room-code { font-size: 3rem; font-weight: 900; letter-spacing: 0.25em; padding-inline-start: 0.25em; line-height: 1.2; font-family: ui-monospace, 'SF Mono', Menlo, monospace; }
.lseats { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lseat { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: var(--r2); background: var(--s1); border: 1px solid var(--line); min-height: 60px; }
.lseat.me { border-color: var(--us); }
.lseat.empty { border-style: dashed; background: transparent; color: var(--t2); }
.lseat-n { width: 22px; text-align: center; color: var(--t3); font-weight: 700; flex: none; }
.lseat-body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.lseat-body b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lseat-body small { font-size: 0.8rem; }
.lseat-ctl { display: flex; gap: 6px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 0.72rem; padding: 1px 8px; border-radius: 99px; background: var(--s3); color: var(--t1); white-space: nowrap; }
.tag-you { background: var(--us); color: var(--on-paper); }
.tag-bot { background: #3b3357; }
.tag-warn { background: rgba(255, 106, 77, 0.25); color: #ffc2b5; }
.tag-ok { background: rgba(111, 211, 160, 0.2); color: var(--ok); }
.waiting { text-align: center; color: var(--t2); margin: 0; }

.avatar {
  --ring-c: var(--line-2);
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(145deg, #2f5566, #1b3644);
  color: var(--t1);
  font-weight: 800;
  flex: none;
  box-shadow: 0 0 0 2px var(--felt-deep), 0 0 0 3.5px var(--ring-c);
}
.avatar.bot { background: linear-gradient(145deg, #4a3f73, #2a2447); }
.avatar.sm { width: 28px; height: 28px; font-size: 0.8rem; display: inline-grid; vertical-align: middle; margin-inline-end: 8px; }
/* the turn timer: a ring that empties as time runs out (--p goes 1 -> 0) */
.avatar.ring { --ring-c: var(--paper); }
.avatar.ring[data-ends]::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: conic-gradient(var(--paper) calc(var(--p, 1) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}
.avatar.ring.urgent::after { background: conic-gradient(var(--urgent) calc(var(--p, 1) * 360deg), transparent 0); }
.crown { position: absolute; top: -9px; inset-inline-end: -6px; width: 16px; height: 12px; background: var(--gold); clip-path: polygon(0 100%, 0 20%, 25% 55%, 50% 0, 75% 55%, 100% 20%, 100% 100%); }

/* ---------- Cards ---------- */
.card {
  position: relative;
  display: block;
  flex: none;
  width: var(--cw, 68px);
  height: calc(var(--cw, 68px) * 1.42);
  padding: 0;
  border: 0;
  font-size: var(--cw, 68px);
  line-height: 1;
  text-align: left;
  direction: ltr;
  border-radius: 0.1em;
  background: var(--card-face);
  color: var(--sc, var(--ink));
  box-shadow: 0 0 0 0.012em rgba(0, 0, 0, 0.4), 0 0.02em 0 rgba(0, 0, 0, 0.25), 0 0.07em 0.12em -0.03em rgba(0, 0, 0, 0.55);
  user-select: none;
  -webkit-user-select: none;
}
.card[data-suit='H'], .card[data-suit='D'] { --sc: var(--red); }
.card .face { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; }
.card .face::after { content: ''; position: absolute; inset: 0.035em; border-radius: 0.07em; box-shadow: inset 0 0 0 0.012em rgba(27, 33, 40, 0.12); }
.card .pp { position: absolute; width: 0.18em; height: 0.18em; transform: translate(-50%, -50%); }
.card .pp[data-flip] { transform: translate(-50%, -50%) rotate(180deg); }
.card .pp .pip, .card .ace .pip { width: 100%; height: 100%; }
.card .ace { position: absolute; left: 66%; top: 56%; width: 0.5em; height: 0.5em; transform: translate(-50%, -50%); }
.card .courtbox { position: absolute; left: 67%; top: 50%; width: 0.54em; height: 0.89em; transform: translate(-50%, -50%); }
.card .court { position: absolute; inset: 0; width: 100%; height: 100%; }
.card .court .cg { fill: currentColor; }
.card .court .ch { fill: var(--card-face); stroke: currentColor; stroke-width: 1.4; }
.card .court .cd { fill: none; stroke: var(--card-face); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.card .idx { position: absolute; z-index: 2; left: 0.04em; top: 0.04em; width: 0.32em; display: flex; flex-direction: column; align-items: center; gap: 0.012em; padding: 0.025em 0 0.03em; background: var(--card-face); border-radius: 0.06em; }
.card .rank { font-family: var(--font); font-weight: 800; font-size: 0.3em; line-height: 0.98; font-variant-numeric: lining-nums tabular-nums; }
.card .rank.r10 { display: inline-block; transform: scaleX(0.8); letter-spacing: -0.05em; }
.card .idx-pip { width: 0.225em; height: 0.225em; }
.card.back { background: repeating-linear-gradient(45deg, #1f4a59 0 0.04em, #173b48 0.04em 0.08em); box-shadow: inset 0 0 0 0.05em var(--card-face), 0 0.04em 0.1em rgba(0, 0, 0, 0.5); }
.card.mini { --cw: 40px; }
.card.micro { --cw: 26px; }
.card.micro .face { display: none; }
.card.micro .idx { width: 0.9em; left: 0.05em; background: transparent; }
.card.micro .rank { font-size: 0.48em; }
.card.micro .idx-pip { width: 0.38em; height: 0.38em; }

/* states: dim is a re-tinted face, never opacity, so the index stays readable */
.card[data-tint='dim'] { background: var(--card-dim); --sc: var(--ink-dim); }
.card[data-tint='dim'][data-suit='H'], .card[data-tint='dim'][data-suit='D'] { --sc: var(--red-dim); }
.card[data-tint='dim'] .idx { background: var(--card-dim); }
.card[data-tint='dim'] .court .ch { fill: var(--card-dim); }
.card[data-tint='dim'] .court .cd { stroke: var(--card-dim); }
.card[data-tint='legal'] { box-shadow: 0 0 0 0.012em rgba(0, 0, 0, 0.4), 0 0 0 0.02em var(--felt-deep), 0 0 0 0.045em var(--us), 0 0.08em 0.14em -0.03em rgba(0, 0, 0, 0.6); }
.card[data-lifted] { box-shadow: 0 0 0 0.012em rgba(0, 0, 0, 0.4), 0 0 0 0.02em var(--felt-deep), 0 0 0 0.05em var(--paper), 0 0.12em 0.2em -0.02em rgba(0, 0, 0, 0.65); }
.card[data-winner] { box-shadow: 0 0 0 0.03em var(--gold), 0 0.1em 0.2em -0.02em rgba(0, 0, 0, 0.6); }

/* ---------- Table ---------- */
body[data-screen='table'] { overflow: hidden; }
.table-screen {
  position: fixed;
  inset: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: 1fr;
  grid-template-areas: 'hud' 'arena' 'me';
  background:
    radial-gradient(70% 55% at 50% 45%, rgba(47, 196, 178, 0.1), transparent 70%),
    radial-gradient(130% 90% at 50% 50%, var(--felt-lit) 0%, var(--felt) 50%, var(--felt-deep) 100%);
}
.hud { grid-area: hud; display: flex; align-items: center; gap: 8px; padding: calc(6px + var(--safe-t)) 8px 6px; z-index: 30; }
.hud-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: rgba(8, 28, 36, 0.8); color: var(--t1); cursor: pointer; flex: none; }
.burger, .burger::before, .burger::after { display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; position: relative; }
.burger::before, .burger::after { content: ''; position: absolute; left: 0; }
.burger::before { top: -6px; }
.burger::after { top: 6px; }
.hud-score-ico { font-weight: 900; font-size: 1.1rem; }
.hud-mid { flex: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; min-width: 0; }
.hud-chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; background: rgba(8, 28, 36, 0.75); border: 1px solid var(--line); font-size: 0.78rem; white-space: nowrap; }
.hud-chip .pip { width: 12px; height: 12px; color: var(--t3); }
.hud-chip.hearts.broken { border-color: rgba(255, 107, 129, 0.5); }
.hud-chip.hearts.broken .pip { color: var(--heart); }
.dir { font-weight: 900; direction: ltr; }

.arena { grid-area: arena; position: relative; min-height: 0; }
.seat {
  position: absolute;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border-radius: 16px;
  background: rgba(8, 28, 36, 0.78);
  border: 1px solid var(--line);
  max-width: 46%;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.seat.is-turn { border-color: var(--paper); box-shadow: 0 0 0 1px var(--paper), 0 8px 18px -10px #000; }
.seat.is-out { opacity: 0.6; }
.seat-top { top: 6px; left: 50%; transform: translateX(-50%); }
.seat-left, .seat-right { top: 46%; transform: translateY(-50%); flex-direction: column; padding: 8px 6px; gap: 4px; width: min(27vw, 140px); max-width: none; text-align: center; }
.seat-left { left: 4px; }
.seat-right { right: 4px; }
.seat-left .seat-info, .seat-right .seat-info { align-items: center; width: 100%; }
.seat-left .seat-name, .seat-right .seat-name { max-width: 100%; }
.seat-left .seat-line, .seat-right .seat-line, .seat-left .seat-badges, .seat-right .seat-badges { justify-content: center; }
.seat-left .mini-hand, .seat-right .mini-hand { position: absolute; top: 8px; width: 20px; height: 28px; font-size: 0.68rem; }
.seat-left .mini-hand { right: 6px; }
.seat-right .mini-hand { left: 6px; }
.seat-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.seat-name { font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; }
.seat-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.score { font-weight: 900; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.hand-pts { font-size: 0.78rem; font-weight: 700; color: var(--heart); }
.taken { display: inline-flex; gap: 4px; }
.tk { display: inline-flex; align-items: center; gap: 2px; padding: 0 6px; border-radius: 99px; font-size: 0.72rem; font-weight: 700; background: rgba(255, 255, 255, 0.08); direction: ltr; }
.tk .pip { width: 10px; height: 10px; }
.tk-h { color: var(--heart); }
.tk-q { color: var(--t1); background: rgba(227, 176, 75, 0.25); }
.seat-badges { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 2px; }
.seat-badges:empty { display: none; }
.badge { font-size: 0.66rem; padding: 0 6px; border-radius: 99px; background: var(--s3); white-space: nowrap; }
.badge-warn { background: rgba(255, 106, 77, 0.3); color: #ffd0c6; }
.badge-ok { background: rgba(111, 211, 160, 0.22); color: var(--ok); }
.badge-us { background: rgba(142, 197, 255, 0.22); color: var(--us); }
.badge-dim { background: rgba(255, 255, 255, 0.08); color: var(--t2); }
.mini-hand {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 36px;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, #1f4a59 0 3px, #173b48 3px 6px);
  box-shadow: inset 0 0 0 2px var(--card-face), 3px -2px 0 -1px #173b48, 3px -2px 0 1px var(--card-face);
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--t1);
  text-shadow: 0 1px 2px #000;
  flex: none;
}
.seat-top .mini-hand { order: -1; }

/* the trick: four slots around the centre of the arena */
.trick { position: absolute; inset: 0; pointer-events: none; z-index: 5; --tw: clamp(54px, min(17vw, 13vh), 92px); }
.trick-cards { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.tc { --cw: var(--tw); position: absolute; left: calc(var(--tw) / -2); top: calc(var(--tw) * -0.71); transition: transform 0.25s var(--ease); }
.tc-bottom { transform: translate(0, 58%) rotate(-2deg); }
.tc-top { transform: translate(0, -58%) rotate(3deg); }
.tc-left { transform: translate(-62%, 0) rotate(-7deg); }
.tc-right { transform: translate(62%, 0) rotate(6deg); }
.fly-bottom { animation: fly-bottom 0.32s var(--ease) both; }
.fly-top { animation: fly-top 0.32s var(--ease) both; }
.fly-left { animation: fly-left 0.32s var(--ease) both; }
.fly-right { animation: fly-right 0.32s var(--ease) both; }
@keyframes fly-bottom { from { transform: translate(0, 260%) scale(1.15); opacity: 0.4; } }
@keyframes fly-top { from { transform: translate(0, -260%) scale(0.7); opacity: 0; } }
@keyframes fly-left { from { transform: translate(-300%, 0) scale(0.7); opacity: 0; } }
@keyframes fly-right { from { transform: translate(300%, 0) scale(0.7); opacity: 0; } }
.trick-cards[class*='sweep-'] { animation: sweep 0.38s ease-in 0.85s forwards; }
.sweep-bottom { --sx: 0px; --sy: calc(var(--tw) * 3); }
.sweep-top { --sx: 0px; --sy: calc(var(--tw) * -3); }
.sweep-left { --sx: calc(var(--tw) * -3); --sy: 0px; }
.sweep-right { --sx: calc(var(--tw) * 3); --sy: 0px; }
@keyframes sweep { to { transform: translate(var(--sx), var(--sy)) scale(0.4); opacity: 0; } }

.center-panel { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); z-index: 15; width: min(92%, 380px); }
.center-panel:empty { display: none; }
.pass-panel, .recap {
  padding: 14px 16px;
  border-radius: var(--r3);
  background: rgba(7, 13, 18, 0.88);
  border: 1px solid var(--line-2);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  box-shadow: 0 12px 30px -16px #000;
}
.pass-panel p, .recap p { margin: 0; }
.pp-title { font-weight: 800; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.pp-title .dir { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--paper); color: var(--on-paper); }
.recap { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(80%, 300px); z-index: 6; animation: fade-in 0.3s both; }
.recap-cards { display: flex; gap: 6px; justify-content: center; direction: ltr; }
@keyframes fade-in { from { opacity: 0; transform: translate(-50%, -44%); } }
.timer-bar { display: block; width: 100%; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.timer-bar i { display: block; height: 100%; width: calc(var(--p, 1) * 100%); background: var(--paper); transition: width 0.2s linear; }
.timer-bar.urgent i { background: var(--urgent); }

.me-zone { grid-area: me; position: relative; z-index: 20; padding: 0 0 calc(6px + var(--safe-b)); }
.me-line { display: flex; align-items: center; gap: 10px; padding: 4px 12px 8px; min-height: 56px; }
.me-info { flex: 1; display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.me-status { display: flex; flex-direction: column; font-size: 0.88rem; }
.turn-yours { color: var(--paper); }
.me-line.my-turn .turn-yours { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.hint { font-size: 0.78rem; color: var(--t2); }
.act-btn { flex: none; max-width: 52%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.away-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 12px 6px; padding: 8px 12px; border-radius: var(--r2); background: rgba(255, 106, 77, 0.2); border: 1px solid rgba(255, 106, 77, 0.5); font-size: 0.9rem; }
#awayBanner:empty { display: none; }

.hand { position: relative; margin: 0 8px; touch-action: none; }
.hand .hc { position: absolute; bottom: 0; cursor: default; transition: transform 0.16s var(--ease), left 0.25s var(--ease); }
.hand .hc[data-tint='legal'] { cursor: pointer; }
.hand .hc[data-lifted] { transform: translateY(-22%); }
.hand .hc.hover:not([aria-disabled='true']) { transform: translateY(-14%); }
.hand .hc.hover[data-lifted] { transform: translateY(-26%); }
.hand .hc.is-new::before { content: ''; position: absolute; top: -0.06em; left: 50%; width: 0.12em; height: 0.12em; margin-left: -0.06em; border-radius: 50%; background: var(--us); box-shadow: 0 0 0 0.02em var(--felt-deep); z-index: 3; }
.hand .hc.shake { animation: shake 0.3s; }
@keyframes shake { 25% { margin-left: -4px; } 75% { margin-left: 4px; } }
@media (hover: hover) and (pointer: fine) {
  .hand .hc[data-tint='legal']:hover, .hand .hc:not([data-tint]):hover { transform: translateY(-12%); }
  .hand .hc[data-lifted]:hover { transform: translateY(-22%); }
}

.side-score { display: none; }

/* desktop: a roomier table with the scoreboard always open on the side */
body.is-desktop .table-screen { grid-template-columns: 1fr 300px; grid-template-areas: 'hud hud' 'arena side' 'me side'; }
body.is-desktop .side-score { display: block; grid-area: side; margin: 0 12px 12px 0; padding: 14px; border-radius: var(--r3); background: rgba(7, 13, 18, 0.6); border: 1px solid var(--line); overflow: auto; }
html[dir='rtl'] body.is-desktop .side-score { margin: 0 0 12px 12px; }
body.is-desktop .seat { padding: 10px 14px 10px 10px; }
body.is-desktop .avatar:not(.sm) { width: 48px; height: 48px; font-size: 1.1rem; }
body.is-desktop .seat-name { font-size: 0.95rem; max-width: 180px; }
body.is-desktop .trick { --tw: clamp(80px, 12vh, 110px); }
body.is-desktop .hud-chip { font-size: 0.85rem; padding: 4px 12px; }
body.is-desktop .me-zone { padding-bottom: 14px; }
body.is-desktop .me-line, body.is-desktop .away-banner { max-width: 720px; margin-inline: auto; width: 100%; }
body.is-desktop .hand { max-width: 1100px; margin-inline: auto; }

/* landscape phones: seats hug the sides, smaller trick */
@media (max-height: 520px) and (orientation: landscape) {
  .hud { padding-top: 4px; padding-bottom: 2px; }
  .hud-target { display: none; }
  .seat-left, .seat-right { top: 45%; }
  .seat-top { top: 2px; padding: 3px 8px 3px 4px; }
  .seat-top .avatar { width: 30px; height: 30px; }
  .trick { --tw: clamp(46px, 15vh, 70px); }
  .trick-cards, .recap { top: 52%; }
  .center-panel { bottom: 4px; }
  .pass-panel .small { display: none; }
  .me-line { min-height: 44px; padding-bottom: 2px; }
  .me-line .avatar { width: 32px; height: 32px; }
  .seat .seat-badges { display: none; }
}
@media (max-width: 360px) {
  .hud-chip { padding: 1px 7px; font-size: 0.72rem; }
  .seat-name { max-width: 24vw; }
}

/* ---------- Sheets ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 80; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(3, 8, 11, 0.6); animation: fade 0.2s both; }
.sheet-layer[data-kind='summary'] .sheet-backdrop { background: rgba(3, 8, 11, 0.35); }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  border-radius: 22px 22px 0 0;
  background: var(--s1);
  border: 1px solid var(--line-2);
  border-bottom: 0;
  box-shadow: 0 -14px 30px -20px #000;
  animation: rise 0.28s var(--ease) both;
  padding-bottom: var(--safe-b);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  .sheet-layer { align-items: center; }
  .sheet { border-radius: 22px; border-bottom: 1px solid var(--line-2); max-height: 86vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 1.2rem; }
.sheet-body { padding: 4px 16px 18px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: var(--tap); padding: 6px 14px; border-radius: var(--r2); background: var(--s2); border: 1px solid var(--line-2); cursor: pointer; font-weight: 600; }
.toggle input { position: absolute; opacity: 0; }
.toggle i { width: 44px; height: 26px; border-radius: 13px; background: var(--s3); position: relative; flex: none; transition: background 0.2s; }
.toggle i::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--t2); transition: inset-inline-start 0.2s, background 0.2s; }
.toggle input:checked + i { background: var(--us); }
.toggle input:checked + i::after { inset-inline-start: 21px; background: #fff; }
.toggle:focus-within { outline: 3px solid var(--us); outline-offset: 2px; }
.rules-sec h3 { margin: 0 0 4px; font-size: 1rem; }
.rules-sec ul { margin: 0; padding-inline-start: 20px; display: grid; gap: 4px; color: var(--t2); }

.score-wrap { overflow-x: auto; }
.score-table, .sum-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.score-table { table-layout: fixed; }
.score-table th:first-child, .score-table td:first-child { width: 3.2em; }
.score-table th, .score-table td { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.score-table th { font-weight: 600; color: var(--t2); max-width: 80px; }
.th-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 80px; margin: 0 auto; }
.score-table td.moon { color: var(--gold); font-weight: 700; white-space: nowrap; }
.score-table tr.extra td { background: rgba(227, 176, 75, 0.06); }
.score-table tfoot td { font-weight: 900; border-bottom: 0; font-size: 1rem; }
.score-table tfoot td.low { color: var(--ok); }
.side-score .score-table th, .side-score .score-table td { font-size: 0.82rem; }

.sum-table th { font-size: 0.8rem; color: var(--t2); font-weight: 600; padding: 4px; text-align: center; }
.sum-table td { padding: 8px 4px; border-top: 1px solid var(--line); text-align: center; }
.sum-table td:first-child { text-align: start; }
.sum-table tr.me td { background: rgba(142, 197, 255, 0.07); }
.moon-banner, .playoff-banner { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--r2); background: rgba(227, 176, 75, 0.14); border: 1px solid rgba(227, 176, 75, 0.45); }
.moon-banner p, .playoff-banner p { margin: 2px 0 0; font-size: 0.85rem; color: var(--t2); }
.playoff-banner { display: block; background: rgba(142, 197, 255, 0.1); border-color: rgba(142, 197, 255, 0.4); }
.moon-ico { font-size: 2rem; color: var(--gold); }
.next-in { margin: 0; text-align: center; color: var(--t2); font-size: 0.9rem; }
.deals summary { cursor: pointer; color: var(--us); padding: 6px 0; }
.deal-row { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-top: 1px solid var(--line); }
.deal-row b { font-size: 0.85rem; }
.deal-cards { display: flex; flex-wrap: wrap; gap: 3px; direction: ltr; }

.result-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px; }
.result-hero b { font-size: 1.4rem; }
.result-hero p { margin: 0; }
.trophy { font-size: 2.6rem; line-height: 1; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank-row { display: flex; align-items: center; gap: 4px; padding: 8px 12px; border-radius: var(--r2); background: var(--s2); }
.rank-row.won { background: rgba(227, 176, 75, 0.16); border: 1px solid rgba(227, 176, 75, 0.45); }
.place { width: 44px; font-weight: 800; color: var(--t2); flex: none; }
.rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-pts { font-weight: 800; font-variant-numeric: tabular-nums; }
.progress-box { padding: 10px; border-radius: var(--r2); background: rgba(99, 102, 241, 0.12); border: 1px solid rgba(99, 102, 241, 0.4); text-align: center; }
.progress-box p { margin: 0 0 6px; }
.prog { padding: 2px 10px; border-radius: 99px; background: rgba(255, 255, 255, 0.1); font-weight: 700; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Toasts and connection ---------- */
.toasts { position: fixed; left: 50%; top: calc(56px + var(--safe-t)); transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { padding: 10px 14px; border-radius: var(--r2); background: rgba(7, 13, 18, 0.95); border: 1px solid var(--line-2); font-size: 0.9rem; text-align: center; animation: rise 0.25s var(--ease) both; transition: opacity 0.4s, transform 0.4s; }
.toast.error { border-color: rgba(255, 106, 77, 0.6); }
.toast.warn { border-color: rgba(227, 176, 75, 0.5); }
.toast.ok { border-color: rgba(111, 211, 160, 0.5); }
.toast.out { opacity: 0; transform: translateY(-8px); }
.conn-banner { position: fixed; bottom: calc(12px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 95; padding: 8px 16px; border-radius: 99px; background: var(--urgent); color: #fff; font-size: 0.85rem; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
}
