/* ─── HK Mahjong — table design system ───────────────────────────────────────
   Jade felt, dark lacquer rim, ivory tiles, a single gold accent. Depth is
   restrained (one bevel + one soft shadow). All motion uses transform/opacity
   and is disabled or shortened by the animation setting / prefers-reduced-motion. */
:root {
  --felt: #1d5a45;
  --felt-hi: #2a7558;
  --felt-lo: #123d2f;
  --lacquer: #1a120d;
  --lacquer-2: #2a1d14;
  --panel: rgba(16, 20, 18, .86);
  --panel-solid: #161b19;
  --panel-line: rgba(216, 178, 90, .28);
  --ink: #f3ecdc;
  --ink-dim: rgba(243, 236, 220, .66);
  --ink-faint: rgba(243, 236, 220, .4);
  --gold: #d8b25a;
  --gold-hi: #f1d38a;
  --red: #c9493d;
  --green: #4fb286;
  --blue: #6a9fd8;
  --pos: #7fd6a4;
  --neg: #f08a7e;
  --ivory: #f8f2e3;
  --ivory-edge: #e2d6b8;
  --back: #2c7a58;
  --back-2: #1f5c42;
  --focus: #ffd56b;
  --radius: 14px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', 'Noto Serif TC', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --font-display: 'Cormorant Garamond', 'Noto Serif TC', Georgia, serif;
  --font-cjk: 'Noto Serif TC', 'PingFang TC', 'Microsoft JhengHei', serif;
  /* Tile widths (height follows the face aspect). Clamped so tiles never shrink
     below a usable/legible size; the hand wraps to two rows instead. */
  --t-hand: clamp(36px, min(calc((100vw - 40px) / 14.8), 7.4vh), 60px);
  --t-meld: clamp(24px, min(2.7vw, 4.6vh), 38px);
  --t-river: clamp(21px, min(2.6vw, 4.1vh), 38px);
  --t-opp: clamp(16px, min(1.9vw, 3vh), 26px);
  --dur: 1;           /* multiplied into animation durations (0 when off) */
  color-scheme: dark;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; height: 100dvh; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font); color: var(--ink); -webkit-tap-highlight-color: transparent;
  background:
    radial-gradient(120% 90% at 50% 0%, #22392f 0%, #121a16 55%, #0b0f0d 100%);
  font-size: 15px; line-height: 1.4;
}
button { font: inherit; color: inherit; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd { font: 600 .68em/1 var(--font); padding: 2px 4px; border-radius: 4px; border: 1px solid currentColor; opacity: .7; margin-left: 6px; }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid rgba(216, 178, 90, .55);
  background: linear-gradient(180deg, #e2bf6c, #b98f38);
  color: #1d150b; font-weight: 700; letter-spacing: .2px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .35) inset, 0 4px 14px rgba(0, 0, 0, .35);
  transition: transform .14s ease, filter .14s ease, box-shadow .14s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px) scale(.98); }
.btn.sec { background: rgba(255, 255, 255, .06); color: var(--ink); border-color: rgba(243, 236, 220, .2); box-shadow: none; }
.btn.sec:hover { background: rgba(255, 255, 255, .11); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); box-shadow: none; min-height: 36px; padding: 6px 10px; }
.btn.ghost:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }
.btn.danger { background: rgba(201, 73, 61, .16); border-color: rgba(201, 73, 61, .55); color: #ffb3aa; box-shadow: none; }
.btn.wide { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; filter: grayscale(.4); }
.icon-btn {
  min-width: 40px; min-height: 40px; padding: 6px 10px; border-radius: 10px; cursor: pointer;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(243, 236, 220, .14); color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: .85rem; font-weight: 600;
}
.icon-btn:hover { background: rgba(255, 255, 255, .1); }
.icon-btn .lbl { white-space: nowrap; }
.seg { display: flex; background: rgba(0, 0, 0, .3); border: 1px solid rgba(243, 236, 220, .14); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; min-height: 34px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-dim); font-weight: 600; font-size: .85rem; cursor: pointer; padding: 4px 8px; }
.seg button[aria-pressed="true"] { background: rgba(216, 178, 90, .9); color: #1d150b; }

/* ─── Screens & cards ─────────────────────────────────────────────────────── */
.screen { display: none; position: fixed; inset: 0; z-index: 20; overflow-y: auto; }
.screen.active { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px 16px; }
#gameScreen.active { padding: 0; justify-content: stretch; align-items: stretch; overflow: hidden; }
.card {
  position: relative; width: min(460px, 100%); padding: 26px 24px; border-radius: 20px;
  background: linear-gradient(180deg, rgba(30, 38, 34, .95), rgba(18, 23, 21, .97));
  border: 1px solid var(--panel-line);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .55), 0 1px 0 rgba(255, 255, 255, .06) inset;
  display: flex; flex-direction: column; gap: 12px;
}
.card.wide { width: min(640px, 100%); }
.brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 4px; }
.brand .mark { width: 74px; aspect-ratio: 157 / 200; }
.brand h1 { font-family: var(--font-display); font-weight: 700; font-size: 2.3rem; letter-spacing: .5px; line-height: 1.05; text-align: center; }
.brand .sub { color: var(--ink-dim); font-size: .86rem; text-align: center; }
.card h2 { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; }
.card h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-faint); font-weight: 700; margin-top: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.divider { height: 1px; background: rgba(243, 236, 220, .1); margin: 2px 0; }
.muted { color: var(--ink-dim); font-size: .85rem; }
.faint { color: var(--ink-faint); font-size: .78rem; }
.err { color: #ff9a8e; font-size: .85rem; min-height: 1.1em; text-align: center; }
input[type=text], input:not([type]), select {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px; font: inherit; color: var(--ink);
  background: rgba(0, 0, 0, .28); border: 1px solid rgba(243, 236, 220, .18);
}
input:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
select option { background: #1b211e; }
.field { display: grid; grid-template-columns: 1fr minmax(140px, 46%); gap: 10px; align-items: center; font-size: .9rem; }
.field label { color: var(--ink); }
.field .hint { grid-column: 1 / -1; margin-top: -6px; }
input[type=range] { width: 100%; accent-color: var(--gold); min-height: 30px; }
input[type=checkbox] { accent-color: var(--gold); width: 20px; height: 20px; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: var(--ink-dim); }
.pill.gold { background: rgba(216, 178, 90, .18); color: var(--gold-hi); }
.player-list { display: flex; flex-direction: column; gap: 6px; }
.player-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.player-row.empty { opacity: .55; }
.player-row .grow { flex: 1; }
.room-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.home-stats { text-align: center; color: var(--ink-faint); font-size: .78rem; }
.resume-card { border: 1px solid rgba(216, 178, 90, .45); background: rgba(216, 178, 90, .08); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }

/* Seat-wind discs (text + colour, never colour alone) */
.wind { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 30px; height: 30px; border-radius: 50%;
  font-family: var(--font-cjk); font-weight: 700; font-size: 1rem; color: #fff; border: 1px solid rgba(255, 255, 255, .35);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4) }
.wind.east { background: #9d3a30; } .wind.south { background: #2f7d5b; } .wind.west { background: #8a6a2a; } .wind.north { background: #3d5f8f; }
.wind.sm { width: 22px; height: 22px; font-size: .8rem; }

/* ─── Tiles ───────────────────────────────────────────────────────────────── */
/* The art (public-domain SVGs) carries its own 3D body, so we crop to the face
   and draw a lighter body here: one bevel, one edge, one soft shadow. */
.tile {
  --tw: var(--t-hand);
  position: relative; flex: none; width: var(--tw); height: calc(var(--tw) * 1.274 + var(--tw) * .1);
  padding: 0; border: 0; background: none; cursor: default; display: inline-block;
  transform-origin: 50% 100%;
}
.tile .body {
  position: absolute; inset: 0 0 calc(var(--tw) * .1) 0; border-radius: calc(var(--tw) * .12);
  background: linear-gradient(180deg, #fffaf0, var(--ivory) 40%, #efe6cf);
  box-shadow:
    0 0 0 1px rgba(60, 45, 20, .35),
    0 calc(var(--tw) * .06) 0 var(--ivory-edge),
    0 calc(var(--tw) * .1) 0 var(--back),
    0 calc(var(--tw) * .1) 0 1px rgba(0, 0, 0, .3),
    0 calc(var(--tw) * .16) calc(var(--tw) * .22) rgba(0, 0, 0, .35);
  overflow: hidden;
}
.tile .face { position: absolute; inset: 6% 7% 5% 7%; overflow: hidden; border-radius: calc(var(--tw) * .06); }
.tile .face img { position: absolute; width: 133.76%; height: 127.5%; left: -14.65%; top: -18%; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.tile .body::after { content: ''; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, .5), rgba(255, 255, 255, 0) 28%); mix-blend-mode: soft-light; }
.tile.back .body { background: linear-gradient(160deg, var(--felt-hi), var(--back) 45%, var(--back-2)); }
.tile.back .body::before { content: ''; position: absolute; inset: 14%; border-radius: 4px; border: 1px solid rgba(255, 255, 255, .14); }
.tile.dim .body { filter: brightness(.82) saturate(.8); }
.tile.mini { --tw: var(--t-river); }
.tile.meld { --tw: var(--t-meld); }
.tile.opp { --tw: var(--t-opp); }
.tile.flower { --tw: calc(var(--t-meld) * .82); }
/* Hand tiles are interactive */
.hand .tile { cursor: pointer; transition: translate .16s cubic-bezier(.2, .8, .3, 1.2); }
.hand .tile:hover { translate: 0 -4px; }
.hand .tile.selected { translate: 0 calc(var(--tw) * -.32); }
.hand .tile.selected .body { box-shadow: 0 0 0 2px var(--gold), 0 0 0 5px rgba(216, 178, 90, .3), 0 calc(var(--tw) * .1) 0 var(--back), 0 10px 18px rgba(0, 0, 0, .45); }
.hand .tile.selected::after { content: 'Discard?'; position: absolute; left: 50%; top: -20px; transform: translateX(-50%); font-size: .66rem; font-weight: 800; white-space: nowrap; color: #1d150b; background: var(--gold); padding: 1px 6px; border-radius: 6px; }
.hand .tile.drawn { margin-left: calc(var(--tw) * .28); }
.hand .tile.drawn::before { content: 'New'; position: absolute; bottom: calc(var(--tw) * -.06 - 13px); left: 50%; transform: translateX(-50%); font-size: .6rem; font-weight: 800; color: var(--gold-hi); letter-spacing: .04em; }
.hand .tile.suggest .body { box-shadow: 0 0 0 2px var(--blue), 0 calc(var(--tw) * .1) 0 var(--back), 0 8px 14px rgba(0, 0, 0, .35); }
.hand .tile.suggest::before { content: '💡'; position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: .8rem; }
.hand .tile.risky .body::before { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 12%; background: repeating-linear-gradient(45deg, rgba(201, 73, 61, .85) 0 4px, transparent 4px 7px); }
.hand.locked .tile { cursor: default; }
.hand.locked .tile:hover { translate: none; }
.tile.last-discard .body { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(241, 211, 138, .55), 0 calc(var(--tw) * .1) 0 var(--back); }
.tile.win-tile .body { box-shadow: 0 0 0 2px var(--gold-hi), 0 0 18px rgba(241, 211, 138, .7), 0 calc(var(--tw) * .1) 0 var(--back); }
.tile.shake { animation: shake calc(.32s * var(--dur)) ease; }
@keyframes shake { 20% { translate: -4px 0; } 40% { translate: 4px 0; } 60% { translate: -3px 0; } 80% { translate: 2px 0; } }

.meld-group { display: inline-flex; gap: 1px; padding: 3px 4px 4px; border-radius: 8px; background: rgba(0, 0, 0, .16); position: relative; }
.meld-group .from { position: absolute; top: -9px; right: 2px; font-size: .58rem; font-weight: 700; color: var(--ink-faint); background: var(--lacquer-2); padding: 0 4px; border-radius: 4px; }
.melds { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; }
.flowers { display: flex; gap: 2px; flex-wrap: wrap; }

/* ─── Game screen ─────────────────────────────────────────────────────────── */
#gameScreen { flex-direction: column; }
.hud {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 10px; min-height: 52px;
  background: linear-gradient(180deg, #1a130e, #120d09); border-bottom: 1px solid rgba(216, 178, 90, .25); z-index: 5;
}
.hud .round { display: flex; flex-direction: column; line-height: 1.1; padding-right: 8px; border-right: 1px solid rgba(243, 236, 220, .12); min-width: 0; }
.hud .round b { font-family: var(--font-display); font-size: 1.1rem; white-space: nowrap; }
.hud .round span { font-size: .72rem; color: var(--ink-dim); white-space: nowrap; }
.scorechips { flex: 1; display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.chip {
  flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 7px; padding: 4px 8px; border-radius: 10px;
  background: rgba(255, 255, 255, .04); border: 1px solid transparent; position: relative;
}
.chip .who { min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.chip .name { font-size: .78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .pts { font-size: .9rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.chip .pts.pos { color: var(--pos); } .chip .pts.neg { color: var(--neg); }
.chip.active { border-color: rgba(241, 211, 138, .7); background: rgba(216, 178, 90, .12); }
.chip .turn { display: none; font-size: .62rem; font-weight: 800; color: var(--gold-hi); }
.chip.active .turn { display: inline; }
.chip .dealer { font-size: .6rem; font-weight: 800; color: #1d150b; background: var(--gold); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.chip.me .name::after { content: ' (you)'; color: var(--ink-faint); font-weight: 500; }
.hud .tools { display: flex; gap: 4px; }
.delta-float { position: absolute; right: 6px; top: -4px; font-weight: 800; font-size: .85rem; pointer-events: none; }

.table-wrap { flex: 1; min-height: 0; position: relative; display: flex; padding: 8px; }
.table {
  flex: 1; min-height: 0; position: relative; border-radius: 22px; overflow: hidden;
  display: grid; gap: 4px; padding: 8px;
  grid-template-columns: minmax(64px, auto) 1fr minmax(64px, auto);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "north north north" "west center east" "south south south";
  background:
    radial-gradient(100% 80% at 50% 45%, var(--felt-hi) 0%, var(--felt) 45%, var(--felt-lo) 100%);
  box-shadow: 0 0 0 6px var(--lacquer-2), 0 0 0 7px rgba(216, 178, 90, .35), 0 0 0 12px var(--lacquer), 0 20px 60px rgba(0, 0, 0, .6) ;
}
/* subtle woven felt texture (inline SVG noise, ~300 bytes) */
.table::before { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .22; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .6 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }
.seat { position: relative; display: flex; gap: 6px; min-width: 0; min-height: 0; z-index: 1; }
.seat.north { grid-area: north; justify-content: center; align-items: center; flex-wrap: wrap; }
.seat.west { grid-area: west; flex-direction: column; align-items: center; justify-content: center; }
.seat.east { grid-area: east; flex-direction: column; align-items: center; justify-content: center; }
.seat.south { grid-area: south; flex-direction: column; align-items: stretch; gap: 4px; }
.nameplate {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px 4px 4px; border-radius: 999px;
  background: rgba(10, 14, 12, .62); border: 1px solid rgba(243, 236, 220, .12); max-width: 100%;
}
.nameplate .np-name { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.nameplate .np-meta { font-size: .66rem; color: var(--ink-dim); white-space: nowrap; }
.nameplate.active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(216, 178, 90, .2), 0 0 18px rgba(241, 211, 138, .25); }
.nameplate .np-turn { display: none; font-size: .64rem; font-weight: 800; color: #1d150b; background: var(--gold); padding: 1px 6px; border-radius: 6px; }
.nameplate.active .np-turn { display: inline; }
.nameplate .np-dealer { font-size: .62rem; font-weight: 800; color: #1d150b; background: var(--gold-hi); padding: 0 5px; border-radius: 4px; }
.nameplate .np-off { font-size: .62rem; color: #ffb3aa; }
.opp-hand { display: flex; gap: 1px; }
.seat.west .opp-hand, .seat.east .opp-hand { flex-direction: column; gap: 0; }
.seat.west .opp-hand .tile, .seat.east .opp-hand .tile { height: calc(var(--tw) * .62); }
.seat.west .opp-hand .tile .body, .seat.east .opp-hand .tile .body { inset: 0 0 2px 0; }
.opp-count { font-size: .66rem; color: var(--ink-dim); }
.seat.west .melds, .seat.east .melds { flex-direction: column; align-items: center; }
.seat.north .melds { justify-content: center; }
.revealed { display: flex; gap: 1px; flex-wrap: wrap; justify-content: center; }
.seat.west .revealed, .seat.east .revealed { max-width: calc(var(--t-opp) * 4 + 6px); }
.seat.west .flowers, .seat.east .flowers { max-width: calc(var(--t-meld) * 2.6); justify-content: center; }

.center { grid-area: center; position: relative; min-height: 0; min-width: 0; z-index: 1; container-type: size;
  display: grid; gap: 6px; align-items: center; justify-items: center;
  grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr auto 1fr;
  grid-template-areas: "rw rn re" "rw compass re" "rw rs re"; }
/* River tiles are sized from the centre box (container query units), so ~25
   discards per player always fit: sides 3 per row, top/bottom 7 per row. */
.center { --tr: clamp(15px, min(calc(100cqw / 14), calc(100cqh / 16.2)), 42px); }
.river { --t-river: var(--tr); display: flex; flex-wrap: wrap; gap: 2px; align-content: flex-start; justify-content: center; padding: 3px; border-radius: 10px; transition: background .2s; overflow: hidden; }
.river.n { grid-area: rn; width: calc(var(--tr) * 7 + 20px); align-self: start; }
/* your own discards start next to you and grow toward the centre */
.river.s { grid-area: rs; width: calc(var(--tr) * 7 + 20px); align-self: end; flex-wrap: wrap-reverse; align-content: flex-start; }
.river.w { grid-area: rw; width: calc(var(--tr) * 3 + 10px); justify-self: end; align-content: center; max-height: 100%; }
.river.e { grid-area: re; width: calc(var(--tr) * 3 + 10px); justify-self: start; align-content: center; max-height: 100%; }
.river .tile.mini { --tw: var(--tr); }
.river.fresh { background: rgba(241, 211, 138, .1); box-shadow: 0 0 0 1px rgba(241, 211, 138, .3); }
.compass {
  grid-area: compass; position: relative; width: clamp(86px, calc(var(--tr) * 4.2), 150px); aspect-ratio: 1; border-radius: 22px;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, .08), rgba(0, 0, 0, .25)); border: 1px solid rgba(216, 178, 90, .35);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1px;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .35);
}
.compass .pw { font-family: var(--font-cjk); font-size: clamp(1.5rem, 4.2vmin, 2.3rem); font-weight: 700; line-height: 1; color: var(--gold-hi); }
.compass .pwl { font-size: .58rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-dim); }
.compass .wall { font-size: .74rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-dim); }
/* Seat winds sit on the compass rim, facing their players */
.compass .cw { position: absolute; font-family: var(--font-cjk); font-weight: 700; font-size: .8rem; line-height: 1; color: var(--ink-faint);
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: rgba(0, 0, 0, .3); }
.compass .cw.on { color: #1d150b; background: var(--gold); box-shadow: 0 0 10px rgba(241, 211, 138, .7); }
.compass .cw.s { bottom: -10px; left: 50%; translate: -50% 0; } .compass .cw.n { top: -10px; left: 50%; translate: -50% 0; }
.compass .cw.w { left: -10px; top: 50%; translate: 0 -50%; } .compass .cw.e { right: -10px; top: 50%; translate: 0 -50%; }
.compass .arrow { display: none; }

.my-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.my-row .left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 3px; padding-top: 22px; min-height: calc(var(--t-hand) * 1.4 + 22px); }
.actionbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; min-height: 50px; padding: 0 4px 2px; }
.act {
  min-height: 46px; min-width: 88px; padding: 8px 16px; border-radius: 12px; cursor: pointer; font-weight: 800; letter-spacing: .3px; font-size: .95rem;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  color: #fff; border: 1px solid rgba(255, 255, 255, .3); box-shadow: 0 4px 12px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .2);
  transition: transform .12s ease, filter .12s ease;
}
.act:hover { filter: brightness(1.1); }
.act:active { transform: scale(.97); }
.act .zh { font-family: var(--font-cjk); font-size: 1.05em; opacity: .9; }
.act.win { background: linear-gradient(180deg, #d55a4c, #a8352b); border-color: #ffb3aa; }
.act.kong { background: linear-gradient(180deg, #c18a35, #94661f); }
.act.pung { background: linear-gradient(180deg, #4e78b5, #34588c); }
.act.chow { background: linear-gradient(180deg, #3f9a72, #2a7253); }
.act.discard { background: linear-gradient(180deg, #e2bf6c, #b98f38); color: #1d150b; }
.act.pass { background: rgba(255, 255, 255, .08); border-color: rgba(243, 236, 220, .3); }
.act.unavailable { background: transparent; border: 1px dashed rgba(243, 236, 220, .35); color: var(--ink-dim); box-shadow: none; font-weight: 600; }
.act.unavailable::before { content: '⊘'; }
.status {
  font-size: .86rem; color: var(--ink); text-align: center; padding: 4px 12px; border-radius: 999px;
  background: rgba(10, 14, 12, .55); border: 1px solid rgba(243, 236, 220, .1); max-width: 100%;
}
.status b { color: var(--gold-hi); }
.timer-ring { width: 26px; height: 26px; flex: none; rotate: -90deg; }
.timer-ring circle { fill: none; stroke-width: 3.2; }
.timer-ring .bg { stroke: rgba(255, 255, 255, .15); } .timer-ring .fg { stroke: var(--gold); stroke-linecap: round; stroke-dasharray: 97.39; transition: stroke-dashoffset .34s linear; }
.timer { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: .85rem; color: var(--ink-dim); }
.timer.urgent { color: #ffb3aa; } .timer.urgent .fg { stroke: #f08a7e; }
.spectator-badge { position: absolute; top: 8px; left: 50%; translate: -50% 0; z-index: 4; }
.emote-pop { position: absolute; z-index: 30; font-size: 2rem; pointer-events: none; }

/* ─── Toasts / live region ────────────────────────────────────────────────── */
#toasts { position: fixed; left: 50%; top: 64px; translate: -50% 0; z-index: 600; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; width: min(520px, 92vw); }
.toast { pointer-events: auto; padding: 9px 14px; border-radius: 12px; background: rgba(18, 22, 20, .96); border: 1px solid var(--panel-line); box-shadow: 0 10px 30px rgba(0, 0, 0, .45); font-size: .88rem; text-align: center; }
.toast.warn { border-color: rgba(240, 138, 126, .6); }
.toast.call { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--gold-hi); padding: 6px 18px; }

/* ─── Dialogs ─────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 400; display: none; align-items: center; justify-content: center; padding: 14px; }
.modal.open { display: flex; }
.modal .scrim { position: absolute; inset: 0; background: rgba(4, 6, 5, .66); }
.modal .dialog {
  position: relative; width: min(520px, 100%); max-height: min(92dvh, 900px); overflow: auto; border-radius: 18px;
  background: linear-gradient(180deg, #1d2421, #141917); border: 1px solid var(--panel-line);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6); display: flex; flex-direction: column;
}
.modal .dialog.wide { width: min(760px, 100%); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 16px 10px; background: inherit; border-bottom: 1px solid rgba(243, 236, 220, .08); }
.dialog-head h2 { font-family: var(--font-display); font-size: 1.45rem; font-weight: 700; }
.dialog-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.dialog-foot { position: sticky; bottom: 0; display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 16px; background: inherit; border-top: 1px solid rgba(243, 236, 220, .08); }
.dialog-foot .btn { flex: 1; }
table.grid { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.grid th { text-align: left; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; padding: 6px; border-bottom: 1px solid rgba(243, 236, 220, .12); }
table.grid td { padding: 7px 6px; border-bottom: 1px solid rgba(243, 236, 220, .06); vertical-align: top; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.tbl-scroll { overflow-x: auto; }
details.rules-sec { border: 1px solid rgba(243, 236, 220, .1); border-radius: 12px; padding: 8px 12px; }
details.rules-sec summary { cursor: pointer; font-weight: 700; min-height: 32px; display: flex; align-items: center; }
.pattern-row { display: grid; grid-template-columns: 74px 1fr auto; gap: 8px; align-items: baseline; padding: 6px 0; border-bottom: 1px solid rgba(243, 236, 220, .06); }
.pattern-row .zh { font-family: var(--font-cjk); font-weight: 700; font-size: 1rem; }
.pattern-row .en b { display: block; font-size: .88rem; } .pattern-row .en span { font-size: .78rem; color: var(--ink-dim); }
.pattern-row .v { font-weight: 800; color: var(--gold-hi); white-space: nowrap; }
.pattern-row .v.off { color: var(--ink-faint); font-weight: 600; }
.pattern-row input { width: 64px; min-height: 34px; padding: 4px 6px; border-radius: 8px; background: rgba(0, 0, 0, .3); border: 1px solid rgba(243, 236, 220, .2); color: var(--ink); text-align: right; font: inherit; }

/* ─── Hand result ─────────────────────────────────────────────────────────── */
#resultModal .dialog { width: min(720px, 100%); }
.result-title { text-align: center; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.result-title .big { font-family: var(--font-display); font-weight: 700; font-size: clamp(1.7rem, 5vw, 2.3rem); color: var(--gold-hi); }
.result-title .how { color: var(--ink-dim); }
.win-hand { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: flex-end; padding: 8px; border-radius: 12px; background: radial-gradient(120% 120% at 50% 40%, var(--felt-hi), var(--felt-lo)); }
.win-hand .grp { display: inline-flex; gap: 1px; }
.win-hand .tile { --tw: clamp(28px, 6.2vw, 44px); }
.win-hand .label { width: 100%; text-align: center; font-size: .72rem; color: var(--ink-dim); }
.calc { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: .9rem; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.calc .k { color: var(--ink-dim); } .calc .v { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.calc .tot { border-top: 1px solid rgba(243, 236, 220, .14); padding-top: 6px; font-weight: 800; color: var(--gold-hi); }
.next-info { text-align: center; font-size: .85rem; color: var(--ink-dim); }
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 450; overflow: hidden; }
.fx-rays { position: absolute; left: 50%; top: 42%; width: 140vmax; height: 140vmax; translate: -50% -50%; opacity: 0;
  background: repeating-conic-gradient(from 0deg, rgba(241, 211, 138, .08) 0 6deg, transparent 6deg 16deg);
  -webkit-mask-image: radial-gradient(closest-side, #000 10%, transparent 70%); mask-image: radial-gradient(closest-side, #000 10%, transparent 70%); }
.fx-glow { position: absolute; left: 50%; top: 40%; width: 60vmin; height: 60vmin; translate: -50% -50%; border-radius: 50%; background: radial-gradient(closest-side, rgba(241, 211, 138, .35), transparent); opacity: 0; }
.spark { position: absolute; width: 7px; height: 7px; border-radius: 50%; background: radial-gradient(circle, #fff7d6, #e9c46a 60%, transparent 70%); }
.coin { position: fixed; z-index: 460; width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff1c2, #d8b25a 55%, #9b7428); box-shadow: 0 2px 4px rgba(0, 0, 0, .4); pointer-events: none; }
.skip-fx { position: fixed; right: 16px; top: 64px; z-index: 470; }

/* ─── Standings ───────────────────────────────────────────────────────────── */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 8px 0; }
.pod { display: flex; flex-direction: column; align-items: center; width: 96px; gap: 4px; }
.pod .bar { width: 100%; border-radius: 10px 10px 0 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; font-family: var(--font-display); font-weight: 700; font-size: 1.4rem;
  background: linear-gradient(180deg, rgba(216, 178, 90, .35), rgba(216, 178, 90, .05)); border: 1px solid rgba(216, 178, 90, .35); border-bottom: 0; transform-origin: bottom; }
.pod.p1 .bar { height: 86px; } .pod.p2 .bar { height: 62px; } .pod.p3 .bar { height: 44px; }
.pod .nm { font-size: .82rem; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod .sc { font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.stat { padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.stat b { display: block; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: .74rem; color: var(--ink-dim); }

/* ─── Chat / voice / emotes ───────────────────────────────────────────────── */
.chat-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 88vw); z-index: 380; display: flex; flex-direction: column;
  background: #141917; border-left: 1px solid var(--panel-line); box-shadow: -10px 0 40px rgba(0, 0, 0, .5); transform: translateX(105%); transition: transform .22s ease; visibility: hidden; }
.chat-panel.open { transform: none; visibility: visible; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.chat-msg .from { font-size: .7rem; font-weight: 700; color: var(--gold-hi); }
.chat-msg .text { background: rgba(255, 255, 255, .07); border-radius: 10px; padding: 5px 9px; font-size: .86rem; word-break: break-word; }
.chat-msg.me { align-items: flex-end; text-align: right; }
.chat-msg.system .text { background: rgba(216, 178, 90, .1); color: var(--gold-hi); font-size: .78rem; text-align: center; }
.chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid rgba(243, 236, 220, .08); }
.unread { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--red); color: #fff; font-size: .66rem; font-weight: 800; display: flex; align-items: center; justify-content: center; padding: 0 4px; }
#emoteBar { position: absolute; z-index: 30; display: none; flex-wrap: wrap; gap: 4px; width: 216px; padding: 8px; border-radius: 14px; background: #141917; border: 1px solid var(--panel-line); right: 10px; top: 56px; }
#emoteBar button { width: 40px; height: 40px; font-size: 1.3rem; border-radius: 10px; border: 1px solid rgba(243, 236, 220, .1); background: rgba(255, 255, 255, .05); cursor: pointer; }
:root { --voicebtm: 120px; }
.voice-btn { position: fixed; right: 14px; bottom: var(--voicebtm); z-index: 50; width: 52px; height: 52px; border-radius: 50%; border: 1px solid rgba(243, 236, 220, .3); background: #1d2421; color: #fff; font-size: 1.3rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .5); }
.voice-btn .vlabel { position: absolute; top: -16px; left: 50%; transform: translateX(-50%); font-size: .58rem; font-weight: 700; white-space: nowrap; color: var(--ink-dim); }
.voice-btn.ready { background: #24563f; } .voice-btn.live { background: #2f9d68; box-shadow: 0 0 0 4px rgba(79, 178, 134, .3); }
#voiceSpeaking { position: fixed; right: 14px; bottom: calc(var(--voicebtm) + 62px); z-index: 50; padding: 4px 10px; border-radius: 10px; background: #1d2421; border: 1px solid rgba(79, 178, 134, .5); font-size: .72rem; font-weight: 700; }
#voiceUnlock { position: fixed; right: 14px; bottom: calc(var(--voicebtm) + 100px); z-index: 51; padding: 8px 12px; border-radius: 12px; border: 1px solid rgba(216, 178, 90, .6); background: #2a2210; color: var(--gold-hi); font-weight: 700; cursor: pointer; }

/* ─── Tutorial ────────────────────────────────────────────────────────────── */
.tut-tiles { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; }
.tut-tiles .tile { --tw: 34px; }
.tut-tiles .gap { width: 10px; }
.tut-dots { display: flex; gap: 6px; justify-content: center; }
.tut-dots i { width: 7px; height: 7px; border-radius: 50%; background: rgba(243, 236, 220, .25); }
.tut-dots i.on { background: var(--gold); width: 18px; border-radius: 4px; }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .hud .round { padding-right: 6px; }
  .hud .round span.extra { display: none; }
  .hud .tools .lbl { display: none; }
  .chip { padding: 3px 5px; gap: 5px; }
  .chip .wind { width: 22px; height: 22px; font-size: .8rem; }
  .chip .dealer { display: none; }
  .chip.dealer-seat .wind { box-shadow: 0 0 0 2px var(--gold); }
  .table { grid-template-columns: minmax(48px, auto) 1fr minmax(48px, auto); padding: 6px; border-radius: 16px; }
  .nameplate .np-meta { display: none; }
  .nameplate .np-name { max-width: 76px; }
  .seat.west .nameplate, .seat.east .nameplate { flex-direction: column; padding: 4px; border-radius: 12px; gap: 2px; }
}
@media (max-width: 480px) {
  .scorechips .chip .name { display: none; }
  .scorechips { gap: 3px; }
  .chip { min-width: 52px; }
  .field { grid-template-columns: 1fr; gap: 6px; }
  .field .hint { margin-top: 0; }
  .scorechips .chip { justify-content: center; }
  .table-wrap { padding: 4px; }
  .hud { gap: 5px; padding: 4px 6px; }
  .hud .round b { font-size: .95rem; }
  .act { min-width: 72px; padding: 8px 12px; font-size: .88rem; }
  :root { --voicebtm: 34dvh; }
}
@media (max-width: 480px) {
  .hud .tools .tool-extra { display: none; }   /* Scores & Rules live in the menu on phones */
  .center { --tr: clamp(15px, min(calc(100cqw / 11.6), calc(100cqh / 19)), 30px); }
  .river.w, .river.e { width: calc(var(--tr) * 2 + 8px); }
}
/* Short landscape phones: rivers get the full centre height; the compass
   shrinks to a corner badge; my nameplate sits beside the hand. */
@media (max-height: 520px) and (orientation: landscape) {
  .hud { min-height: 42px; padding: 2px 8px; }
  .table { padding: 4px 8px; gap: 2px; }
  .hand { padding-top: 16px; min-height: calc(var(--t-hand) * 1.36 + 16px); }
  .seat.north { flex-wrap: nowrap; }
  .seat.south { flex-direction: row; flex-wrap: wrap; align-items: flex-end; justify-content: center; column-gap: 8px; row-gap: 0; }
  .seat.south .my-row, .seat.south .my-row .left { display: contents; }
  .seat.south .nameplate { order: 0; align-self: center; }
  .seat.south .nameplate .np-name .faint { display: none; }
  .seat.south .hand { order: 1; }
  .seat.south .melds { order: 2; flex-wrap: nowrap; }
  .seat.south .flowers { order: 3; max-width: calc(var(--t-meld) * 2.4); }
  .seat.south .status { display: none; }   /* narration still reaches the live region + toasts */
  .seat.south .actionbar { order: 4; flex-basis: 100%; min-height: 44px; }
  .center { grid-template-columns: 1fr auto 1fr; grid-template-rows: 1fr 1fr; grid-template-areas: "rw rn re" "rw rs re";
    --tr: clamp(14px, min(calc(100cqw / 19), calc(100cqh / 8.8)), 30px); }
  .river.n, .river.s { width: calc(var(--tr) * 9 + 24px); }
  .river.w, .river.e { width: calc(var(--tr) * 4 + 12px); }
  .compass { position: absolute; left: 0; top: 0; width: 58px; border-radius: 12px; z-index: 2; }
  .compass .pwl, .compass .cw { display: none; }
  .compass .pw { font-size: 1.3rem; }
}

/* Animation setting: off → no motion at all; reduced → only short fades */
html[data-motion="off"] { --dur: 0; }
html[data-motion="off"] *, html[data-motion="off"] *::before, html[data-motion="off"] *::after { animation: none !important; transition: none !important; }
html[data-motion="reduced"] .hand .tile, html[data-motion="reduced"] .compass .arrow { transition: none; }
html[data-motion="reduced"] .tile.shake { animation: none; outline: 2px solid #f08a7e; }
