/* Shelem - phone first. Namad look from Varagh: night petrol felt, ivory as the only pressable colour.
   Layouts: body[data-layout=mobile] (a compact table; landscape phones squeeze it further) and
   body[data-layout=desktop] (a felt with the scoreboard and the log beside it). */

@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/vazirmatn-arabic.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/vazirmatn-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: dark;
  --void: #070d12;
  --felt: #0d2a33;
  --felt-lit: #134350;
  --felt-deep: #081c24;
  --felt-edge: #050f14;
  --s1: #12202a;
  --s2: #1b2d39;
  --s3: #26404f;
  --line: rgba(242, 238, 223, 0.14);
  --line-2: rgba(242, 238, 223, 0.24);
  --line-3: rgba(242, 238, 223, 0.42);
  --t1: #f2eedf;
  --t2: #b7c6cb;
  --t3: #93a5ac;
  --paper: #f2eedf;
  --on-paper: #0b1a20;
  --us: #8ec5ff;
  --them: #ffb27a;
  --urgent: #ff6a4d;
  --ok: #6fd3a0;
  --gold: #e3b04b;
  --turq: #2fc4b2;
  --r1: 10px;
  --r2: 14px;
  --r3: 20px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --sh-btn: 0 2px 0 #9c9885, 0 8px 14px -8px rgba(0, 0, 0, 0.6);
  --sh-card: 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);

  /* card faces (Legibility Core) */
  --face: #f6f0de;
  --face-dim: #bfc1bb;
  --ink: #1b2128;
  --red: #b3122b;
  --red-dim: #8a1730;
  --blue: #173f9a;
  --green: #0f5e33;
  --green-dim: #0b4f2a;
  --c-s: var(--ink);
  --c-c: var(--ink);
  --c-h: var(--red);
  --c-d: var(--red);
  --c-h-dim: var(--red-dim);
  --c-d-dim: var(--red-dim);
  --c-c-dim: var(--ink);
}
body[data-colors='four'] {
  --c-c: var(--green);
  --c-d: var(--blue);
  --c-c-dim: var(--green-dim);
  --c-d-dim: var(--blue);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; overscroll-behavior: none; }

body {
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', Roboto, Tahoma, sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, var(--felt-lit) 0%, var(--felt) 45%, var(--felt-deep) 80%, var(--void) 100%) fixed;
  background-color: var(--felt-deep);
  color: var(--t1);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}
body.busy .hand, body.busy .panel-sheet { pointer-events: none; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.3; }

.muted { color: var(--t2); }
.small { font-size: 0.86rem; }
.tiny { font-size: 0.76rem; margin: 0; }
.center { text-align: center; }
.block { display: block; }
.good { color: var(--ok); }
.bad { color: var(--urgent); }
:focus-visible { outline: 3px solid var(--us); outline-offset: 2px; }

/* ============================================================ */
/* BOARDBAZI BAR (the hub's own colours, the same in every game) */
/* ============================================================ */
.bb-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding-top: var(--safe-top);
  padding-inline: max(12px, env(safe-area-inset-left, 0px)) max(12px, env(safe-area-inset-right, 0px));
  background: rgba(14, 18, 29, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font-size: 14px;
}
.bb-brand, .bb-chip { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; min-width: 0; height: 44px; }
.bb-mark {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; color: #fff;
  background: linear-gradient(135deg, #6366f1, #06b6d4); flex: none;
}
.bb-avatar {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: #334155; font-size: 12px; font-weight: 700;
}
.bb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.bb-level { font-size: 12px; color: #94a3b8; 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-fill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #6366f1, #06b6d4); }
@media (max-width: 360px) { .bb-word { display: none; } }

.connection-banner {
  position: fixed;
  inset-inline: 0;
  top: var(--safe-top);
  z-index: 60;
  padding: 6px 12px;
  text-align: center;
  font-size: 0.86rem;
  background: var(--urgent);
  color: #1a0904;
  font-weight: 700;
}

/* ============================================================ */
/* COMMON PIECES                                                 */
/* ============================================================ */
.view { display: none; }
.view.active { display: block; }

.page {
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 16px calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: var(--s1);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px -18px #000;
}

.label { font-weight: 800; color: var(--t1); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row-center { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 8px 18px;
  border-radius: var(--r1);
  border: 1px solid transparent;
  font-weight: 700;
  text-decoration: none;
  transition: transform 120ms var(--ease), background 120ms;
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-lg { min-height: 56px; font-size: 1.08rem; }
.btn-sm { min-height: 38px; padding: 4px 12px; font-size: 0.9rem; }
.btn-primary { background: var(--paper); color: var(--on-paper); box-shadow: var(--sh-btn); }
.btn-secondary { background: var(--s2); border-color: var(--line-2); color: var(--t1); }
.btn-secondary.active { background: var(--paper); color: var(--on-paper); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--t1); }
.btn-danger { background: transparent; border-color: rgba(255, 106, 77, 0.6); color: var(--urgent); }
.btn-call { background: linear-gradient(135deg, var(--gold), #f6d48a); color: #2b1a00; box-shadow: 0 2px 0 #9a7426; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--r1);
  border: 1px solid var(--line);
  background: var(--s2);
  font-size: 1.1rem;
  flex: none;
}
.icon-btn.small { width: 34px; height: 34px; font-size: 0.9rem; }
.icon-btn.active { background: var(--paper); color: var(--on-paper); }

.input {
  min-height: 48px;
  padding: 8px 12px;
  border-radius: var(--r1);
  border: 1px solid var(--line-2);
  background: var(--felt-deep);
  color: var(--t1);
  min-width: 0;
}
.code-input { text-transform: uppercase; letter-spacing: 0.3em; text-align: center; font-weight: 800; flex: 1; }
.join-row { display: flex; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { padding: 3px 10px; border-radius: 99px; background: var(--s2); border: 1px solid var(--line); font-size: 0.85rem; }

.tag {
  display: inline-block;
  padding: 0 8px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 700;
  background: var(--s3);
  color: var(--t1);
  white-space: nowrap;
}
.tag-host { background: var(--gold); color: #2b1a00; }
.tag-you { background: var(--us); color: #04213d; }
.tag-off { background: rgba(255, 106, 77, 0.25); color: #ffc2b5; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r1); overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; min-height: 38px; font-weight: 700; color: var(--t2); }
.seg button.active { background: var(--paper); color: var(--on-paper); }
.seg button:disabled { cursor: default; }

.option-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.option-row.disabled { opacity: 0.55; }
.toggle.active { background: var(--paper); color: var(--on-paper); }

.divider { display: flex; align-items: center; gap: 10px; color: var(--t3); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.avatar {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--s3);
  font-weight: 800;
  flex: none;
}
.avatar-bot { background: var(--s2); }
.avatar-empty { background: transparent; border: 1px dashed var(--line-3); color: var(--t3); }

/* ============================================================ */
/* LANDING                                                       */
/* ============================================================ */
.landing-head { text-align: center; padding: 18px 0 4px; }
.title { margin: 6px 0 0; font-size: 3rem; font-weight: 900; letter-spacing: 0.02em; }
.tagline { margin: 0; color: var(--t2); }
.intro { margin: 0; }
.credits { margin: 0; }
.logo-fan { position: relative; width: 120px; height: 92px; margin: 0 auto; }
.fan-card {
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 54px;
  height: 78px;
  border-radius: 7px;
  background: var(--face);
  box-shadow: 0 6px 14px -6px #000;
  transform-origin: 50% 110%;
}
.fan-card::after {
  content: '';
  position: absolute;
  inset: 14px 12px;
  border-radius: 4px;
  background: var(--red);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.fan-card.c1 { transform: translateX(-50%) rotate(-18deg); }
.fan-card.c1::after { background: var(--ink); clip-path: polygon(50% 0, 90% 55%, 60% 70%, 60% 100%, 40% 100%, 40% 70%, 10% 55%); }
.fan-card.c2 { transform: translateX(-50%) rotate(0deg); z-index: 1; }
.fan-card.c3 { transform: translateX(-50%) rotate(18deg); z-index: 2; background: linear-gradient(160deg, #1c4252, #12303c); border: 2px solid var(--face); }
.fan-card.c3::after { background: transparent; border: 1.5px dashed rgba(242, 238, 223, 0.55); clip-path: none; inset: 8px; }

.account-row { display: flex; align-items: center; gap: 10px; }
.account-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.account-name { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================================================ */
/* LOBBY                                                         */
/* ============================================================ */
.live-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--t2); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(111, 211, 160, 0.6); animation: pulse 1.6s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(111, 211, 160, 0); } 100% { box-shadow: 0 0 0 0 rgba(111, 211, 160, 0); } }

.code-card { align-items: center; text-align: center; }
.room-code { font-size: 2.6rem; font-weight: 900; letter-spacing: 0.3em; padding-inline-start: 0.3em; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { border-radius: var(--r1); border: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.team[data-team='0'] { border-color: rgba(142, 197, 255, 0.35); }
.team[data-team='1'] { border-color: rgba(255, 178, 122, 0.35); }
.team-name { font-weight: 800; font-size: 0.9rem; }
.team[data-team='0'] .team-name { color: var(--us); }
.team[data-team='1'] .team-name { color: var(--them); }
.seats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.seat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: var(--r1);
  background: var(--s2);
  min-width: 0;
  flex-wrap: wrap;
}
.seat .avatar { width: 32px; height: 32px; font-size: 0.9rem; }
.seat-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.seat .tags { display: flex; gap: 3px; flex-wrap: wrap; }
.seat.moving { outline: 2px solid var(--paper); }
.seat[data-target] { outline: 2px dashed var(--us); cursor: pointer; }
.seat-empty { background: transparent; border: 1px dashed var(--line-2); }
.notice { margin: 0; text-align: center; color: var(--t2); }
.result-panel p { margin: 0; }
@media (max-width: 380px) {
  .teams { grid-template-columns: 1fr; }
}

/* ============================================================ */
/* CARDS (em-based: font-size = card width)                      */
/* ============================================================ */
.card {
  --sc: var(--c-s);
  position: relative;
  display: block;
  flex: none;
  width: var(--cw, 68px);
  height: calc(var(--cw, 68px) * 1.42);
  padding: 0;
  border: 0;
  font: inherit;
  font-size: var(--cw, 68px);
  line-height: 1;
  text-align: left;
  border-radius: 0.12em;
  background: var(--face);
  color: var(--sc);
  box-shadow: var(--sh-card);
  cursor: default;
  direction: ltr;
}
.card[data-suit='S'] { --sc: var(--c-s); }
.card[data-suit='H'] { --sc: var(--c-h); }
.card[data-suit='D'] { --sc: var(--c-d); }
.card[data-suit='C'] { --sc: var(--c-c); }
.card .pip { display: block; width: 1em; height: 1em; }
.card .face { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; }
.card .face::after { content: ''; position: absolute; inset: 0.035em; border-radius: 0.09em; box-shadow: inset 0 0 0 0.012em rgba(27, 33, 40, 0.1); }
.card .mid { position: absolute; inset: 0; line-height: 0; }
.card .pp { position: absolute; width: 0.18em; height: 0.18em; transform: translate(-50%, -50%); }
.card .pp.flip { transform: translate(-50%, -50%) rotate(180deg); }
.card .pp .pip, .card .ace .pip, .card .ace .star { 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 .g { fill: currentColor; }
.card .court .hd { fill: var(--face); stroke: currentColor; stroke-width: 1.4; }
.card .court .dt { fill: none; stroke: var(--face); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.card[data-joker] .ace { width: 0.46em; height: 0.46em; }
.card .idx {
  position: absolute;
  z-index: 4;
  left: 0.05em;
  top: 0.04em;
  width: 0.32em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.012em;
  padding: 0.025em 0 0.03em;
  line-height: 1;
  background: var(--face);
  border-radius: 0.07em;
}
.card .rank { font-weight: 800; font-size: 0.3em; line-height: 0.98; color: var(--sc); font-variant-numeric: lining-nums tabular-nums; font-family: system-ui, 'Segoe UI', Roboto, sans-serif; }
.card .rank.r10 { display: inline-block; transform: scaleX(0.8); letter-spacing: -0.05em; margin-inline: -0.02em; }
.card .rank.rjk { display: inline-block; transform: scaleX(0.74); letter-spacing: -0.05em; margin-inline: -0.04em; }
.card .idx-pip, .card .idx .star { width: 0.225em; height: 0.225em; color: var(--sc); }

/* state: re-tinted, never faded with opacity */
.card[data-tint='dim'] { background: var(--face-dim); }
.card[data-tint='dim'][data-suit='H'] { --sc: var(--c-h-dim); }
.card[data-tint='dim'][data-suit='D'] { --sc: var(--c-d-dim); }
.card[data-tint='dim'][data-suit='C'] { --sc: var(--c-c-dim); }
.card[data-tint='dim'] .idx { background: var(--face-dim); }
.card[data-tint='dim'] .court .hd { fill: var(--face-dim); }
.card[data-tint='dim'] .court .dt { stroke: var(--face-dim); }
.card[data-tint='legal'] { cursor: pointer; }
.card[data-winner='true'] { box-shadow: 0 0 0 0.03em var(--paper), 0 0 0.25em 0.02em rgba(227, 176, 75, 0.65), 0 0.1em 0.2em -0.02em rgba(0, 0, 0, 0.6); }
.card.from-widow::before {
  content: '';
  position: absolute;
  z-index: 5;
  left: 0.1em;
  right: 0.1em;
  bottom: 0.04em;
  height: 0.05em;
  border-radius: 0.03em;
  background: var(--felt);
  opacity: 0.85;
}
.card.mini { --cw: 34px; }

.cardback {
  position: absolute;
  width: var(--bw, 26px);
  height: calc(var(--bw, 26px) * 1.4);
  border-radius: calc(var(--bw, 26px) * 0.12);
  background: linear-gradient(160deg, #1c4252, #12303c);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.4);
}
.cardback svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.backs { position: relative; display: block; flex: none; }
.backs[data-axis='h'] { --bw: 22px; height: 31px; width: calc(22px + var(--k, 5) * 8px); }
.backs[data-axis='h'] .cardback { top: 0; left: calc(var(--j) * 8px); }
.backs[data-axis='v'] { --bw: 22px; width: 24px; height: calc(31px + var(--k, 4) * 6px); }
.backs[data-axis='v'] .cardback { left: 1px; top: calc(var(--j) * 6px); }

.suit-ico { display: inline-flex; width: 1em; height: 1em; vertical-align: -0.12em; }
.suit-ico .pip { width: 100%; height: 100%; }
.suit-ico[data-suit='S'], .suit-ico[data-suit='C'] { color: var(--t1); }
.suit-ico[data-suit='H'], .suit-ico[data-suit='D'] { color: #ff6f7f; }
body[data-colors='four'] .suit-ico[data-suit='C'] { color: #5fd38f; }
body[data-colors='four'] .suit-ico[data-suit='D'] { color: #7aa2ff; }

/* ============================================================ */
/* TABLE                                                         */
/* ============================================================ */
#gameView.active { display: grid; height: 100dvh; grid-template-columns: minmax(0, 1fr); }
.side { display: none; }

.table {
  position: relative;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  grid-template-columns: minmax(0, 1fr);
  padding: var(--safe-top) 6px var(--safe-bottom);
  overflow: hidden;
  min-width: 0;
}

.hud { display: flex; align-items: center; gap: 6px; padding: 6px 2px 4px; min-width: 0; }
.hud-scores { display: flex; gap: 6px; flex: 1; min-width: 0; }
.score-box {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 6px;
  align-items: baseline;
  padding: 3px 8px 5px;
  border-radius: var(--r1);
  background: var(--s1);
  border: 1px solid var(--line);
}
.score-box[data-team='us'] { border-color: rgba(142, 197, 255, 0.45); }
.score-box[data-team='them'] { border-color: rgba(255, 178, 122, 0.45); }
.score-name { font-size: 0.78rem; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-box[data-team='us'] .score-name { color: var(--us); }
.score-box[data-team='them'] .score-name { color: var(--them); }
.score-num { font-size: 1.15rem; font-weight: 900; text-align: end; font-variant-numeric: tabular-nums; }
.score-bar { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.score-bar i { display: block; height: 100%; background: var(--us); }
.score-box[data-team='them'] .score-bar i { background: var(--them); }
.score-box.big { padding: 10px 14px; }
.score-box.big .score-num { font-size: 1.8rem; }
.hud-side { display: flex; flex-direction: column; align-items: center; gap: 0; flex: none; }
.hud-meta { display: flex; gap: 6px; font-size: 0.72rem; white-space: nowrap; color: var(--t2); }
.trump-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  border-radius: 99px;
  background: var(--face);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.78rem;
}
.trump-chip .pip { width: 18px; height: 18px; }
.trump-chip[data-suit='H'], .trump-chip[data-suit='D'] { color: var(--red); }
body[data-colors='four'] .trump-chip[data-suit='C'] { color: var(--green); }
body[data-colors='four'] .trump-chip[data-suit='D'] { color: var(--blue); }
.trump-chip.none { background: var(--s2); color: var(--t2); }
.trump-chip span { color: var(--on-paper); font-size: 0.7rem; }
.trump-chip.none span { color: var(--t2); }

.contract-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0 2px 4px;
  padding: 4px 10px;
  border-radius: var(--r1);
  background: var(--s1);
  border: 1px solid var(--line);
  font-size: 0.86rem;
  min-height: 34px;
}
.contract-bar[data-team='us'] { border-color: rgba(142, 197, 255, 0.5); }
.contract-bar[data-team='them'] { border-color: rgba(255, 178, 122, 0.5); }
.contract-bar .big { font-size: 1.05rem; }
.contract-head { white-space: nowrap; }
.contract-line { flex: 1; color: var(--t2); min-width: 0; }
.trick-count { font-weight: 900; font-variant-numeric: tabular-nums; direction: ltr; white-space: nowrap; }
.trick-count small { color: var(--t3); margin: 0 2px; }

/* the felt: partner on top, opponents left and right (physical sides: play goes to the right) */
.felt {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-radius: 28px;
  background: radial-gradient(100% 80% at 50% 45%, rgba(19, 67, 80, 0.9), rgba(8, 28, 36, 0.4));
  box-shadow: inset 0 0 0 1px var(--line), inset 0 0 40px rgba(0, 0, 0, 0.35);
  padding: 4px;
}
.felt::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 23px;
  border: 1px dashed rgba(242, 238, 223, 0.12);
  pointer-events: none;
}
.mid-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; min-height: 0; }
.seat-slot { display: flex; justify-content: center; align-items: center; min-width: 0; }
.at-left, .at-right { width: 74px; }

.seat-box { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; max-width: 100%; }
.pos-top { flex-direction: row; gap: 8px; }
.pos-bottom { flex-direction: row; }
.seat-id { display: flex; align-items: center; gap: 5px; min-width: 0; padding: 2px 8px 2px 2px; border-radius: 99px; background: rgba(7, 13, 18, 0.55); border: 1px solid var(--line); max-width: 100%; }
.pos-left .seat-id, .pos-right .seat-id { flex-direction: column; padding: 4px; border-radius: 14px; text-align: center; gap: 1px; }
.seat-box[data-team='us'] .seat-id { border-color: rgba(142, 197, 255, 0.4); }
.seat-box[data-team='them'] .seat-id { border-color: rgba(255, 178, 122, 0.4); }
.seat-box.active .seat-id { border-color: var(--paper); box-shadow: 0 0 0 2px rgba(242, 238, 223, 0.25); }
.seat-avatar { position: relative; display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--s3); font-weight: 800; font-size: 0.85rem; flex: none; }
.seat-box[data-team='us'] .seat-avatar { background: #24486a; }
.seat-box[data-team='them'] .seat-avatar { background: #5d3a22; }
.ring { position: absolute; inset: -4px; width: 40px; height: 40px; transform: rotate(-90deg); pointer-events: none; display: none; }
.ring circle { fill: none; stroke: var(--paper); stroke-width: 2.5; stroke-dasharray: 100; stroke-dashoffset: 0; stroke-linecap: round; }
.ring.low circle { stroke: var(--urgent); }
.seat-box.active .ring { display: block; }
.seat-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.seat-name { font-size: 0.8rem; }
.seat-box .seat-name { max-width: 9em; display: block; }
.pos-left .seat-name, .pos-right .seat-name { max-width: 64px; font-size: 0.72rem; }
.seat-name small { color: var(--t3); font-weight: 400; }
.seat-status { font-size: 0.66rem; color: var(--t3); }
.seat-status.off { color: #ffc2b5; }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; font-size: 0.66rem; font-weight: 800; background: var(--s3); flex: none; }
.badge.crown { background: var(--gold); color: #2b1a00; font-size: 0.8rem; }
.badge.ok { background: var(--ok); color: #05301b; }
.seat-cards { display: flex; align-items: center; gap: 4px; }
.pos-left .seat-cards, .pos-right .seat-cards { flex-direction: column; }
.seat-cards .count { font-size: 0.7rem; color: var(--t2); font-weight: 700; }
.bubble {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 900;
  background: var(--paper);
  color: var(--on-paper);
  animation: pop 220ms var(--ease);
}
.bubble.pass { background: var(--s3); color: var(--t2); }
.bubble.call { background: var(--gold); color: #2b1a00; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* the trick: a cross of four slots in the middle of the felt */
.trick {
  --tw: clamp(46px, 15vw, 76px);
  position: relative;
  min-height: calc(var(--tw) * 2.6);
  height: 100%;
  max-height: calc(var(--tw) * 3.6);
  align-self: center;
}
.trick .card { --cw: var(--tw); }
.trick-slot { position: absolute; left: 50%; top: 50%; transition: transform 300ms var(--ease), opacity 300ms; }
.slot-bottom { transform: translate(-50%, calc(-50% + var(--tw) * 0.72)); z-index: 4; }
.slot-top { transform: translate(-50%, calc(-50% - var(--tw) * 0.72)); z-index: 1; }
.slot-left { transform: translate(calc(-50% - var(--tw) * 0.68), -50%) rotate(-6deg); z-index: 2; }
.slot-right { transform: translate(calc(-50% + var(--tw) * 0.68), -50%) rotate(6deg); z-index: 3; }
.trick-slot.enter.slot-bottom { animation: from-bottom 260ms var(--ease); }
.trick-slot.enter.slot-top { animation: from-top 260ms var(--ease); }
.trick-slot.enter.slot-left { animation: from-left 260ms var(--ease); }
.trick-slot.enter.slot-right { animation: from-right 260ms var(--ease); }
@keyframes from-bottom { from { transform: translate(-50%, 150%); opacity: 0.2; } }
@keyframes from-top { from { transform: translate(-50%, -260%); opacity: 0.2; } }
@keyframes from-left { from { transform: translate(-260%, -50%); opacity: 0.2; } }
@keyframes from-right { from { transform: translate(160%, -50%); opacity: 0.2; } }
.trick-slot.collect { opacity: 0; }
.trick-slot.collect.to-bottom { transform: translate(-50%, 180%) scale(0.6); }
.trick-slot.collect.to-top { transform: translate(-50%, -280%) scale(0.6); }
.trick-slot.collect.to-left { transform: translate(-280%, -50%) scale(0.6); }
.trick-slot.collect.to-right { transform: translate(180%, -50%) scale(0.6); }
.trick-hint { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--t2); font-size: 0.85rem; padding: 0 8px; }
.widow-pile { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.widow-pile .count { font-size: 0.72rem; color: var(--t2); }
.mini-trick { height: 220px; --tw: 64px; }
.last-trick-btn {
  position: absolute;
  bottom: 6px;
  inset-inline-end: 8px;
  z-index: 6;
  border: 1px solid var(--line);
  background: rgba(7, 13, 18, 0.6);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 0.72rem;
  color: var(--t2);
}

/* the action sheet above the hand */
.panel-sheet {
  margin: 4px 2px 0;
  padding: 10px 12px;
  border-radius: var(--r2);
  background: var(--s1);
  border: 1px solid var(--line-2);
  box-shadow: 0 -14px 30px -20px #000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: rise 220ms var(--ease);
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.panel-sheet p { margin: 0; }
.panel-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.panel-head b { font-size: 1rem; }
.panel-timer { margin-inline-start: auto; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--t2); }
.panel-timer.low { color: var(--urgent); }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.panel-actions .btn { flex: 1 1 auto; min-height: 46px; }
.chip-grid { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.chip-grid .chip-btn { flex: 0 0 auto; min-width: 54px; scroll-snap-align: start; }
.chip-btn {
  min-height: 40px;
  border-radius: var(--r1);
  border: 1px solid var(--line-2);
  background: var(--s2);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.chip-btn.active { background: var(--paper); color: var(--on-paper); border-color: var(--paper); }
.suit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.suit-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 6px 2px;
  border-radius: var(--r1);
  border: 1px solid var(--line-2);
  background: var(--face);
  color: var(--ink);
  font-weight: 800;
}
.suit-btn .pip { width: 28px; height: 28px; }
.suit-btn[data-suit='H'], .suit-btn[data-suit='D'] { color: var(--red); }
body[data-colors='four'] .suit-btn[data-suit='C'] { color: var(--green); }
body[data-colors='four'] .suit-btn[data-suit='D'] { color: var(--blue); }
.suit-btn span, .suit-btn small { color: var(--on-paper); }
.suit-btn small { font-weight: 400; font-size: 0.72rem; }
.suit-btn.active { outline: 3px solid var(--us); outline-offset: 1px; }
.look { display: flex; flex-direction: column; gap: 4px; }
.mini-row { display: flex; flex-wrap: wrap; gap: 3px; direction: ltr; }

.status {
  min-height: 26px;
  padding: 2px 8px;
  text-align: center;
  font-size: 0.86rem;
  color: var(--t2);
}
.status .your-turn { color: var(--paper); }
.who { color: var(--t1); }

/* the hand: one overlapping row, the overlap computed so every index stays visible */
.hand {
  --cw: 64px;
  --step: 30px;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 18px 4px 8px;
  min-height: calc(var(--cw) * 1.42 + 26px);
  min-width: 0;
  overflow-x: clip;
  touch-action: manipulation;
}
.hand .card { margin-inline-end: calc(var(--step) - var(--cw)); transition: transform 140ms var(--ease); }
.hand .card:last-child { margin-inline-end: 0; }
.hand .card[data-lifted='true'] { transform: translateY(-16px); box-shadow: 0 0 0 0.03em var(--paper), 0 0.12em 0.2em -0.02em rgba(0, 0, 0, 0.65); }
.hand[data-mode='play'] .card[data-tint='legal'] { transform: translateY(-4px); }
.hand[data-mode='play'] .card[data-tint='legal'][data-lifted='true'] { transform: translateY(-18px); }
@media (hover: hover) {
  .hand .card[data-tint='legal']:hover { transform: translateY(-10px); }
}

/* ============================================================ */
/* MODALS                                                        */
/* ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(3, 8, 11, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms;
}
.modal.open { opacity: 1; pointer-events: auto; }
.sheet {
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  border-radius: var(--r3) var(--r3) 0 0;
  background: var(--s1);
  border: 1px solid var(--line-2);
  border-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(24px);
  transition: transform 220ms var(--ease);
}
.modal.open .sheet { transform: none; }
.sheet.tall { max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-actions { display: flex; flex-direction: column; align-items: stretch; gap: 6px; text-align: center; }
.settings { display: flex; flex-direction: column; gap: 14px; }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .sheet { border-radius: var(--r3); border-bottom: 1px solid var(--line-2); }
}

.rules h3 { margin: 12px 0 4px; font-size: 1rem; }
.rules p, .rules ul { margin: 0; color: var(--t2); }
.rules ul { padding-inline-start: 18px; }

.sum-hero { text-align: center; padding: 8px; border-radius: var(--r2); background: var(--s2); }
.sum-hero h2 { margin: 2px 0; font-size: 1.35rem; }
.sum-hero p { margin: 2px 0; }
.sum-hero.won { box-shadow: inset 0 0 0 1px rgba(111, 211, 160, 0.4); }
.sum-hero.lost { box-shadow: inset 0 0 0 1px rgba(255, 106, 77, 0.35); }
.sum-badge { font-size: 0.75rem; color: var(--t3); }
.sum-table, .score-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.sum-table th, .sum-table td, .score-table th, .score-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.sum-table tbody th { text-align: start; font-weight: 400; color: var(--t2); }
.sum-table thead th[data-team='us'], .score-table thead th[data-team='us'] { color: var(--us); }
.sum-table thead th[data-team='them'], .score-table thead th[data-team='them'] { color: var(--them); }
.sum-table .delta td { font-size: 1.1rem; }
.sum-table .total td { font-size: 1.15rem; }
.score-table td small { display: block; color: var(--t3); font-size: 0.72rem; }
.score-table td.hk { text-align: start; font-size: 0.85rem; }
.score-table tbody tr { cursor: default; }
.score-table tfoot th { font-size: 1.05rem; }
.note { margin: 0; font-size: 0.85rem; color: var(--t2); }
.deals summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.deal-row { display: flex; flex-direction: column; gap: 3px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.deal-name { font-size: 0.82rem; }
.final-scores { display: flex; gap: 10px; }
.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.result-list li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--r1); background: var(--s2); flex-wrap: wrap; }
.result-list li.win { box-shadow: inset 0 0 0 1px rgba(227, 176, 75, 0.6); }
.place { width: 22px; text-align: center; }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 0.86rem; color: var(--t2); }
.log li { padding: 3px 0; border-bottom: 1px solid var(--line); }

.toasts { position: fixed; z-index: 70; top: calc(var(--safe-top) + 56px); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 12px; }
.toast {
  max-width: 460px;
  padding: 8px 14px;
  border-radius: var(--r1);
  background: rgba(18, 32, 42, 0.96);
  border: 1px solid var(--line-2);
  box-shadow: 0 10px 24px -12px #000;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 200ms, transform 200ms var(--ease);
}
.toast.show { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255, 106, 77, 0.7); }

/* ============================================================ */
/* PHONES IN LANDSCAPE: everything shrinks to fit the short side */
/* ============================================================ */
@media (max-height: 500px) {
  body[data-layout='mobile'] .hud { padding: 2px; }
  body[data-layout='mobile'] .score-box { padding: 1px 8px 3px; }
  body[data-layout='mobile'] .score-num { font-size: 1rem; }
  body[data-layout='mobile'] .contract-bar { min-height: 28px; padding: 2px 8px; font-size: 0.8rem; margin-bottom: 2px; }
  body[data-layout='mobile'] .trick { --tw: clamp(38px, 9vh, 52px); }
  body[data-layout='mobile'] .seat-avatar { width: 26px; height: 26px; }
  body[data-layout='mobile'] .ring { width: 34px; height: 34px; }
  body[data-layout='mobile'] .backs[data-axis='h'] { display: none; }
  body[data-layout='mobile'] .hand { padding: 12px 4px 2px; min-height: calc(var(--cw) * 1.42 + 14px); }
  body[data-layout='mobile'] .panel-sheet { position: absolute; z-index: 20; bottom: calc(var(--hand-h, 110px) + 4px); inset-inline: 8px; max-width: 520px; margin-inline: auto; }
  body[data-layout='mobile'] .status { min-height: 20px; font-size: 0.78rem; }
}

/* ============================================================ */
/* DESKTOP: a roomy felt, the scoreboard and log beside it       */
/* ============================================================ */
body[data-layout='desktop'] #gameView.active { grid-template-columns: minmax(0, 1fr) 320px; max-width: 1400px; margin: 0 auto; }
body[data-layout='desktop'] .side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 14px 14px 0;
  height: 100dvh;
  overflow-y: auto;
}
html[dir='rtl'] body[data-layout='desktop'] .side { padding: 14px 0 14px 14px; }
body[data-layout='desktop'] .side-box { background: var(--s1); border: 1px solid var(--line); border-radius: var(--r2); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
body[data-layout='desktop'] .hud-score-btn { display: none; }
body[data-layout='desktop'] .table { padding: 12px 18px; }
body[data-layout='desktop'] .hud { padding: 0 0 8px; }
body[data-layout='desktop'] .score-box { padding: 6px 14px 8px; }
body[data-layout='desktop'] .score-num { font-size: 1.5rem; }
body[data-layout='desktop'] .score-name { font-size: 0.9rem; }
body[data-layout='desktop'] .contract-bar { font-size: 0.95rem; padding: 6px 14px; }
body[data-layout='desktop'] .felt { border-radius: 120px / 90px; padding: 14px 24px; }
body[data-layout='desktop'] .felt::before { border-radius: 112px / 84px; inset: 10px; }
body[data-layout='desktop'] .trick { --tw: clamp(72px, 8vw, 104px); }
body[data-layout='desktop'] .at-left, body[data-layout='desktop'] .at-right { width: 120px; }
body[data-layout='desktop'] .seat-avatar { width: 40px; height: 40px; font-size: 1rem; }
body[data-layout='desktop'] .ring { width: 48px; height: 48px; }
body[data-layout='desktop'] .seat-name { font-size: 0.92rem; }
body[data-layout='desktop'] .pos-left .seat-name, body[data-layout='desktop'] .pos-right .seat-name { max-width: 110px; font-size: 0.85rem; }
body[data-layout='desktop'] .backs[data-axis='h'] { --bw: 30px; height: 42px; width: calc(30px + var(--k, 5) * 11px); }
body[data-layout='desktop'] .backs[data-axis='h'] .cardback { left: calc(var(--j) * 11px); }
body[data-layout='desktop'] .backs[data-axis='v'] { --bw: 30px; width: 32px; height: calc(42px + var(--k, 4) * 9px); }
body[data-layout='desktop'] .backs[data-axis='v'] .cardback { top: calc(var(--j) * 9px); }
body[data-layout='desktop'] .panel-sheet {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(var(--hand-h, 160px) + 8px);
  width: min(640px, calc(100% - 300px));
  margin: 0;
  transform: translateX(-50%);
  animation: none;
  box-shadow: 0 18px 40px -16px #000;
}
body[data-layout='desktop'] .chip-grid { flex-wrap: wrap; overflow: visible; }
body[data-layout='desktop'] .status { font-size: 0.95rem; }
body[data-layout='desktop'] .hand { padding-top: 26px; }
body[data-layout='desktop'] .card.mini { --cw: 40px; }
body[data-layout='desktop'] .page { max-width: 640px; padding-top: 28px; }

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