/* Mahjong family table.
   Tokens: teal felt, rosewood rail, ivory tiles on jade backs,
   cinnabar for 中 / dealer / wins, brass for "this is live". */
:root {
  --felt: #0e4f47;
  --felt-deep: #0a3b35;
  --felt-light: #13615a;
  --rail: #3a1d14;
  --rail-light: #5a3020;
  --ivory: #f7f1e1;
  --ivory-edge: #e3d6b6;
  --jade: #1e7a57;
  --jade-deep: #155a40;
  --cinnabar: #c4352b;
  --brass: #c9a24a;
  --brass-light: #e8cd86;
  --ink: #1c2a55;
  --text: #f4efe2;
  --muted: #b9cbc4;
  --panel: rgba(4, 30, 27, 0.55);
  --ui: "Atkinson Hyperlegible", system-ui, sans-serif;
  --cjk: "Noto Serif SC", "Songti SC", "STSong", serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ui);
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt-light) 0%, var(--felt) 45%, var(--felt-deep) 100%);
  background-color: var(--felt);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
[lang="zh"], .zh { font-family: var(--cjk); }
.hidden { display: none !important; }
.screen { position: absolute; inset: 0; }
.muted { color: var(--muted); }
.error { color: #ffb4a8; min-height: 1.4em; margin: 0; }
.error:empty { min-height: 0; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brass-light); outline-offset: 2px; }

.btn {
  border: 1px solid rgba(244, 239, 226, 0.35);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .08s;
}
.btn:hover { background: rgba(255, 255, 255, 0.13); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--brass); border-color: var(--brass); color: #2a1a06; }
.btn.primary:hover { background: var(--brass-light); }
.btn.win { background: var(--cinnabar); border-color: #e0574c; color: #fff; }
.btn.win:hover { background: #d9463b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 11px; font-size: 15px; border-radius: 8px; }
.btn .zh { font-weight: 900; margin-left: 6px; }

input {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(244, 239, 226, 0.3);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}
select { font: inherit; color: var(--text); background: rgba(0,0,0,.3); border: 1px solid rgba(244,239,226,.3); border-radius: 8px; padding: 6px 8px; }

#conn-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: var(--cinnabar); color: white; text-align: center; padding: 6px;
  font-weight: 700;
}
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: var(--ivory); color: var(--ink); padding: 10px 18px; border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 60; font-weight: 700;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------------------------------------------------- tiles */
.tile {
  --w: 50px;
  position: relative;
  width: var(--w);
  height: calc(var(--w) * 1.36);
  background: linear-gradient(180deg, #fffaf0 0%, var(--ivory) 60%, #efe6cf 100%);
  border-radius: calc(var(--w) * 0.12);
  /* thickness: ivory edge, then the jade back */
  box-shadow:
    0 calc(var(--w) * 0.05) 0 var(--ivory-edge),
    0 calc(var(--w) * 0.12) 0 var(--jade),
    0 calc(var(--w) * 0.15) calc(var(--w) * 0.12) rgba(0, 0, 0, 0.35);
  flex: none;
}
.tile svg { position: absolute; inset: 6% 7% 5%; width: 86%; height: 89%; }
.tile.back {
  background: linear-gradient(180deg, #24906a, var(--jade) 55%, var(--jade-deep));
  box-shadow:
    0 calc(var(--w) * 0.05) 0 var(--ivory-edge),
    0 calc(var(--w) * 0.08) calc(var(--w) * 0.1) rgba(0, 0, 0, 0.35);
}
.tile.back svg { inset: 0; width: 100%; height: 100%; }
.tile img { position: absolute; left: 5%; top: 4%; width: 90%; height: 92%; object-fit: contain; pointer-events: none; user-select: none; }
.tile .idx {
  position: absolute; left: 2px; top: 1px; z-index: 1;
  font: 700 calc(var(--w) * 0.26)/1 var(--ui);
  padding: 1px 3px; border-radius: 4px; background: rgba(247, 241, 225, .9);
}
.t-hand { --w: var(--hand-w, 96px); }
.t-meld { --w: calc(var(--hand-w, 96px) * 0.7); }
.t-pond { --w: 54px; }
.t-strip { --w: 32px; }
.t-oppmeld { --w: 34px; }
.t-mini { --w: 26px; }
.t-micro { --w: 20px; }
.t-result { --w: 48px; }
.t-claim { --w: 62px; }
.t-opt { --w: 30px; }

/* ---------------------------------------------------------------- home */
#home { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; overflow: auto; padding: 24px 16px; }
.home-title { margin: 0; text-align: center; font-weight: 900; line-height: 1; }
.home-title [lang="zh-CN"] { display: block; font-size: clamp(72px, 14vw, 132px); letter-spacing: 0.08em; color: var(--ivory); text-shadow: 0 4px 0 var(--jade-deep), 0 10px 30px rgba(0,0,0,.4); }
.home-sub { display: block; font-family: var(--ui); font-size: 20px; font-weight: 400; color: var(--muted); margin-top: 14px; letter-spacing: .02em; }
.home-tiles { display: flex; gap: 10px; transform: rotate(-3deg); }
.home-tiles .tile { --w: 56px; }
.home-tiles .tile:nth-child(2) { transform: translateY(-8px) rotate(4deg); }
.home-tiles .tile:nth-child(4) { transform: translateY(6px) rotate(-5deg); }
.home-card {
  width: min(380px, 100%);
  display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); padding: 22px; border-radius: 16px;
  border: 1px solid rgba(244,239,226,.12);
}
.home-card label { font-weight: 700; }
.home-or { text-align: center; color: var(--muted); margin-top: 6px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
#online { display: flex; flex-direction: column; gap: 10px; }
.home-sub { max-width: 30ch; margin-inline: auto; text-wrap: balance; line-height: 1.35; }
.home-foot { color: var(--muted); margin: 0; font-size: 14px; letter-spacing: .04em; }
.lang-switch { position: absolute; top: max(14px, env(safe-area-inset-top, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); display: flex; gap: 4px; }
.lang-btn {
  font: 600 14px var(--ui); color: var(--muted); background: transparent; cursor: pointer;
  border: 1px solid rgba(244,239,226,.18); border-radius: 999px; padding: 4px 12px;
}
.lang-btn[lang="zh-CN"] { font-family: "Noto Serif SC", serif; }
.lang-btn[aria-pressed="true"] { color: var(--ink); background: var(--ivory); border-color: var(--ivory); }
.lang-btn:focus-visible { outline: 3px solid var(--brass-light); outline-offset: 2px; }
#home { position: relative; }

/* --------------------------------------------------------------- lobby */
#lobby { overflow: auto; padding: 22px clamp(16px, 4vw, 48px) 48px; }
.lobby-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; max-width: 1180px; margin: 0 auto 20px; }
.lobby-code-label { color: var(--muted); }
.lobby-code { font-size: 54px; font-weight: 700; letter-spacing: .18em; color: var(--brass-light); line-height: 1.05; }
.lobby-hint { margin: 2px 0 0; color: var(--muted); }
.lobby-actions { display: flex; gap: 10px; }
.lobby-grid { display: grid; grid-template-columns: 380px 1fr; gap: 22px; max-width: 1180px; margin: 0 auto; align-items: start; }
@media (max-width: 900px) { .lobby-grid { grid-template-columns: minmax(0, 1fr); } }
.seats-panel, .rules-panel { min-width: 0; }
.rule-row select { max-width: 100%; min-width: 0; }
.seats-panel, .rules-panel { background: var(--panel); border-radius: 16px; padding: 18px 20px; border: 1px solid rgba(244,239,226,.1); }
.seats-panel h2, .rules-panel h2 { margin: 0 0 4px; font-size: 22px; }
.seat-square {
  position: relative; width: 300px; height: 300px; margin: 14px auto;
  background: var(--felt); border-radius: 18px;
  box-shadow: inset 0 0 0 10px var(--rail), inset 0 0 0 12px var(--rail-light), 0 10px 30px rgba(0,0,0,.35);
}
.seat-card {
  position: absolute; width: 132px; min-height: 64px; padding: 8px 10px; border-radius: 10px;
  background: var(--ivory); color: var(--ink); text-align: center; box-shadow: 0 4px 0 var(--ivory-edge), 0 6px 0 var(--jade);
}
.seat-card.empty { background: rgba(255,255,255,.08); color: var(--muted); box-shadow: none; border: 1px dashed rgba(244,239,226,.35); }
.seat-card .seat-name { font-weight: 700; font-size: 18px; overflow-wrap: anywhere; }
.seat-card .seat-meta { font-size: 14px; opacity: .8; }
.seat-card .btn { margin-top: 4px; }
.seat-card.empty .btn { color: var(--text); }
.seat-card.me { outline: 3px solid var(--brass); }
.seat-pos-0 { left: 50%; bottom: 18px; transform: translateX(-50%); }
.seat-pos-1 { right: 18px; top: 50%; transform: translateY(-50%); }
.seat-pos-2 { left: 50%; top: 18px; transform: translateX(-50%); }
.seat-pos-3 { left: 18px; top: 50%; transform: translateY(-50%); }
.seat-pos-1, .seat-pos-3 { width: 104px; }
.seat-tools { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.rules-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.preset-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preset-desc { color: var(--muted); margin: 6px 0 12px; max-width: 70ch; }
.rules-group { border-top: 1px solid rgba(244,239,226,.14); padding: 12px 0 6px; }
.rules-group > summary { cursor: pointer; font-weight: 700; font-size: 18px; list-style: none; display: flex; justify-content: space-between; }
.rules-group > summary::after { content: "+"; color: var(--brass-light); }
.rules-group[open] > summary::after { content: "–"; }
.rule-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 8px 0; align-items: center; }
.rule-row .help { grid-column: 1 / -1; color: var(--muted); font-size: 15px; margin-top: -2px; max-width: 72ch; }
.rule-row input[type="number"] { width: 76px; text-align: right; padding: 6px 8px; }
.rule-row input[type="text"] { width: 76px; padding: 6px 8px; }
.rule-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--brass); }
.rule-row select { max-width: 360px; }
.rule-row.changed > label::before { content: "●"; color: var(--brass-light); margin-right: 6px; font-size: 12px; vertical-align: 2px; }
.pattern-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.pattern-table th { text-align: left; font-weight: 400; color: var(--muted); font-size: 14px; padding: 4px 6px; }
.pattern-table td { padding: 6px; border-top: 1px solid rgba(244,239,226,.08); vertical-align: middle; }
.pattern-table td.zh { font-size: 18px; font-weight: 900; white-space: nowrap; }
.pattern-table .pdesc { color: var(--muted); font-size: 14px; }
.pattern-table input[type="number"] { width: 58px; padding: 4px 6px; text-align: right; }
.pattern-table input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brass); }
.pattern-table tr.off td:not(:first-child) { opacity: .45; }
.pattern-table .pex { display: flex; flex-direction: column; gap: 4px; margin: 8px 0 4px; }
.pattern-table .pex-label { color: var(--muted); font-size: 13px; }
.pattern-table .pex-row { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: flex-end; }
.pattern-table .pex-group { display: flex; gap: 1px; }
.t-ex { --w: 24px; }
.tile.t-ex.win { outline: 2px solid var(--brass-light); outline-offset: 1px; }
fieldset[disabled] { border: 0; padding: 0; margin: 0; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* ---------------------------------------------------------------- game */
#game { display: flex; align-items: center; justify-content: center; }
/* The stage is 900 units tall and as wide as the window's shape allows
   (fitStage sets --main-w: the width left of the rail). */
#stage {
  --main-w: 1010px;
  --stage-w: 1280px;
  position: relative; width: 1280px; height: 900px; flex: none;
  transform-origin: center center;
}
.table {
  position: absolute; left: calc((var(--main-w) - 740px) / 2); top: 4px; width: 740px; height: 740px;
  border-radius: 22px;
  background: radial-gradient(circle at 50% 50%, #12625a 0%, var(--felt) 55%, #0b433d 100%);
  box-shadow: inset 0 0 0 12px var(--rail), inset 0 0 0 14px var(--rail-light), inset 0 0 50px rgba(0,0,0,.35), 0 18px 50px rgba(0,0,0,.45);
}
.seat-layer { position: absolute; inset: 0; pointer-events: none; }
.seat-layer > * { pointer-events: auto; }
.seat-layer.rel-1 { transform: rotate(-90deg); }
.seat-layer.rel-2 { transform: rotate(180deg); }
.seat-layer.rel-3 { transform: rotate(90deg); }

/* wall */
.wall-row {
  position: absolute; left: 50%; bottom: 54px; transform: translateX(-50%);
  display: flex; flex-direction: row-reverse; gap: 1px; height: 34px; align-items: flex-end;
}
.stack { position: relative; width: 20px; height: 34px; }
.stack .tile { --w: 20px; position: absolute; left: 0; bottom: 0; }
.stack .tile.upper { bottom: 6px; }
.stack.h0 { opacity: 0; }
.stack.break-after { margin-left: 7px; }

/* pond (discards) */
/* Pinwheel: each pile starts at its owner's left edge of the centre box
   and runs on past it into the corner, so four big piles never collide. */
.pond {
  position: absolute; left: calc(50% - 52px); top: calc(50% + 58px);
  width: 336px; display: flex; flex-wrap: wrap; gap: 4px 2px; align-content: flex-start;
}
.pond .tile { --w: 54px; }
.pond.wide { width: 343px; }
.pond.wide .tile { --w: 47px; }
.pond.dense { width: 344px; }
.pond.dense .tile { --w: 41px; }
.pond .tile.claimed { opacity: .32; }
.pond .tile.latest { outline: 3px solid var(--brass-light); outline-offset: 1px; animation: settle .35s ease-out; }
@keyframes settle { from { transform: translateY(-14px) scale(1.15); } to { transform: none; } }

/* opponent strip */
.strip {
  position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%);
  display: flex; gap: 10px; align-items: flex-end; height: 50px; white-space: nowrap;
}
.strip .hand-backs { display: flex; gap: 1px; }
.strip .melds { display: flex; gap: 6px; }
.meld { display: flex; gap: 1px; align-items: flex-end; }
.meld .tile.sideways { transform: rotate(90deg) translateX(calc(var(--w) * -0.18)); margin: 0 calc(var(--w) * 0.18); }
.strip .revealed { display: flex; gap: 1px; padding: 3px 4px 6px; border-radius: 6px; background: rgba(201, 162, 74, .25); outline: 2px solid var(--brass); }
.flowers { display: flex; gap: 1px; }
.flowers .tile { --w: 20px; }

/* center box */
.center { gap: 2px !important;
  position: absolute; left: 50%; top: 50%; width: 104px; height: 104px; transform: translate(-50%, -50%);
  background: #082f2a; border-radius: 14px;
  box-shadow: inset 0 0 0 2px #1b5f55, 0 6px 18px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}
.center .live { font-size: 30px; font-weight: 700; line-height: 1; color: var(--ivory); }
.center .live-label { font-size: 12px; color: var(--muted); line-height: 1; }
.center .handno { font-size: 15px; color: var(--muted); }
.center .streak { font-size: 15px; color: var(--brass-light); font-weight: 700; }
.window-bar { position: absolute; left: 20px; right: 20px; top: 21px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
.window-bar i { display: block; height: 100%; background: var(--brass-light); transform-origin: left; }
.wind-edge {
  position: absolute; left: 50%; bottom: 2px; transform: translateX(-50%);
  font-family: var(--cjk); font-weight: 900; font-size: 15px; color: #6f9d93; line-height: 1.2;
  padding: 0 10px; border-radius: 6px;
}
.wind-edge.dealer { color: var(--cinnabar); }
.wind-edge.active { color: #2a1a06; background: var(--brass-light); box-shadow: 0 0 16px var(--brass); padding: 0 6px; }
.center-layer { position: absolute; inset: 0; }
.center-layer.rel-1 { transform: rotate(-90deg); }
.center-layer.rel-2 { transform: rotate(180deg); }
.center-layer.rel-3 { transform: rotate(90deg); }
.dice { display: flex; gap: 5px; }
.die { width: 18px; height: 18px; border-radius: 4px; box-shadow: 0 2px 0 var(--ivory-edge); background: var(--ivory); border-radius: 7px; box-shadow: 0 3px 0 var(--ivory-edge); }
.die svg { width: 100%; height: 100%; }
.dice.rolling .die { animation: roll .9s cubic-bezier(.2,.7,.3,1); }
.dice.rolling .die:nth-child(2) { animation-duration: 1.1s; }
@keyframes roll {
  0% { transform: translate(-40px, -30px) rotate(-200deg); opacity: 0; }
  60% { transform: translate(4px, 3px) rotate(20deg); opacity: 1; }
  100% { transform: none; }
}

/* name chips around the table */
.chip {
  position: absolute; display: flex; align-items: center; gap: 8px;
  background: rgba(4, 30, 27, .78); border: 1px solid rgba(244,239,226,.18);
  padding: 6px 10px; border-radius: 12px; min-width: 120px;
  max-width: max(130px, min(230px, calc((var(--main-w) - 724px) / 2 - 16px)));
}
.chip .wind { font-family: var(--cjk); font-weight: 900; font-size: 24px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; background: var(--ivory); color: var(--ink); flex: none; }
.chip .wind.dealer { background: var(--cinnabar); color: #fff; }
.chip .who { min-width: 0; }
.chip .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .sub { font-size: 13px; color: var(--muted); white-space: nowrap; }
.chip.active { border-color: var(--brass); box-shadow: 0 0 0 2px var(--brass), 0 0 22px rgba(201,162,74,.5); }
.chip.offline .nm::after { content: " (away)"; color: #ffb4a8; font-weight: 400; }
.chip .tag-rev { color: var(--brass-light); font-weight: 700; }
.chip-pos-0 { right: calc(100% + 8px); bottom: 6px; }
.chip-pos-1 { left: calc(100% + 8px); top: 50%; transform: translateY(-50%); }
.chip-pos-2 { right: calc(100% + 8px); top: 6px; }
.chip-pos-3 { right: calc(100% + 8px); top: 50%; transform: translateY(-50%); }

/* my area */
#me-area { position: absolute; left: 0; top: 734px; width: var(--stage-w); height: 166px; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
/* The prompt sits inside the table's bottom edge, just above your hand. */
#prompt-bar {
  position: absolute; left: calc(var(--main-w) / 2); bottom: calc(100% + 4px); transform: translateX(-50%);
  min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: nowrap;
  padding: 4px 14px; border-radius: 12px; white-space: nowrap; z-index: 6;
  background: rgba(6, 34, 31, .82);
}
#prompt-bar:empty { display: none; }
#prompt-bar .ptext { font-weight: 700; font-size: 18px; margin-right: 6px; }
#prompt-bar .ptext.wait { color: var(--muted); font-weight: 400; }
.claim-opt { display: inline-flex; align-items: center; gap: 8px; }
.claim-opt .mini { display: inline-flex; gap: 1px; }
#my-row { display: flex; align-items: flex-end; gap: calc(var(--hand-w, 96px) * 0.22); margin-top: 0; padding: 4px 16px 0; border-radius: 16px 16px 0 0; transition: box-shadow .2s, background .2s; }
#me-area.my-turn #my-row { background: rgba(201,162,74,.12); box-shadow: 0 -2px 0 var(--brass) inset, 0 0 26px rgba(201,162,74,.25); }
#my-melds { display: flex; gap: 8px; align-items: flex-end; }
#my-melds .flowers .tile { --w: calc(var(--hand-w, 96px) * 0.34); }
#my-hand { display: flex; gap: 4px; align-items: flex-end; padding-bottom: 16px; }
#my-melds { padding-bottom: 16px; }
#my-hand .tile { cursor: default; transition: transform .12s; }
#my-hand .tile.drawn { margin-left: calc(var(--hand-w, 96px) * 0.25); }
#my-hand .tile.use { transform: translateY(-14px); box-shadow: 0 3.2px 0 var(--ivory-edge), 0 7.7px 0 var(--jade), 0 0 0 3px var(--brass-light); }
#my-hand .tile.can { cursor: pointer; }
#my-hand .tile.can:hover { transform: translateY(-8px); }
#my-hand .tile.selected { transform: translateY(-22px); box-shadow: 0 2.7px 0 var(--ivory-edge), 0 6.5px 0 var(--jade), 0 0 0 3px var(--brass-light), 0 14px 18px rgba(0,0,0,.4); }
#my-hand .tile.ready-mark::after {
  content: ""; position: absolute; top: -9px; left: 50%; width: 9px; height: 9px; margin-left: -4.5px;
  border-radius: 50%; background: var(--brass-light); box-shadow: 0 0 8px var(--brass);
}
#my-hand .tile.reveal-pick { box-shadow: 0 2.7px 0 var(--ivory-edge), 0 6.5px 0 var(--jade), 0 0 0 3px var(--brass); }
#my-hand .tile.dim { filter: brightness(.6); }
#my-hand .tile.sent { opacity: .4; transform: translateY(-30px); }
.my-revealed-note { color: var(--brass-light); font-weight: 700; }

/* rail */
#rail {
  position: absolute; right: 8px; top: 4px; width: 258px; height: 740px;
  background: var(--panel); border-radius: 16px; border: 1px solid rgba(244,239,226,.1);
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.tally-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 6px 4px; border-radius: 8px; }
.tally-row .wind { font-family: var(--cjk); font-weight: 900; font-size: 18px; text-align: center; color: var(--muted); }
.tally-row .wind.dealer { color: var(--cinnabar); }
.tally-row .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tally-row .pts { font-weight: 700; font-variant-numeric: tabular-nums; }
.tally-row .pts.neg { color: #ffb4a8; }
.tally-row .pts.pos { color: #b9f0c9; }
.tally-row.me { background: rgba(255,255,255,.06); }
.tally-head { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
#rail-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.rail-h { margin: 6px 0 0; font-size: 15px; color: var(--muted); font-weight: 400; }
#log { list-style: none; margin: 0; padding: 0 2px 0 0; overflow-y: auto; flex: 1; font-size: 15px; display: flex; flex-direction: column; gap: 5px; }
#log li { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; color: #dfe9e4; }
#log li.k-win { color: var(--brass-light); font-weight: 700; }
#log li.k-dice, #log li.k-info { color: var(--muted); }
#log li .tile { --w: 20px; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(2, 18, 16, .55); display: flex; align-items: center; justify-content: center; z-index: 30; padding: 16px; }
.card {
  background: var(--ivory); color: var(--ink); border-radius: 18px; padding: 24px 28px;
  width: min(760px, 100%); max-height: 100%; overflow: auto;
  box-shadow: 0 6px 0 var(--ivory-edge), 0 12px 0 var(--jade), 0 30px 60px rgba(0,0,0,.5);
}
.card h2 { margin: 0 0 4px; font-size: 28px; }
.card .sub { color: #4a5578; margin: 0 0 14px; }
.card .btn { color: var(--ink); border-color: rgba(28,42,85,.3); background: rgba(28,42,85,.06); }
.card .btn.primary { background: var(--jade); border-color: var(--jade); color: #fff; }
.card .btn.win { background: var(--cinnabar); color: #fff; }
.win-hand { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 10px 0 16px; }
.win-hand .group { display: flex; gap: 2px; }
.win-hand .tile.win-tile { outline: 3px solid var(--cinnabar); outline-offset: 2px; }
.score-lines { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; margin: 0 0 6px; max-width: 460px; }
.score-lines .zh { font-weight: 900; color: var(--cinnabar); margin-left: 6px; }
.score-lines .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.score-total { font-size: 22px; font-weight: 700; margin: 8px 0 16px; }
.pay-table { width: 100%; border-collapse: collapse; margin: 6px 0 16px; }
.pay-table th { text-align: left; color: #4a5578; font-weight: 400; font-size: 14px; padding: 4px 8px; }
.pay-table td { padding: 6px 8px; border-top: 1px solid rgba(28,42,85,.12); font-variant-numeric: tabular-nums; }
.pay-table td.num { text-align: right; font-weight: 700; }
.pay-table .pos { color: #13734a; }
.pay-table .neg { color: var(--cinnabar); }
.result-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.ready-list { color: #4a5578; margin-right: auto; }
.winner-block + .winner-block { border-top: 1px solid rgba(28,42,85,.15); padding-top: 14px; }
.result-min { position: fixed; right: 18px; bottom: 18px; z-index: 31; }

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

/* compact (narrow / tall screens): the rail becomes a pop-over */
.rail-toggle { display: none; }
body.compact .rail-toggle { display: block; position: absolute; right: 12px; top: 12px; z-index: 5; }
body.compact #rail { display: none; }
body.compact.rail-open #rail {
  display: flex; position: fixed; left: auto; right: 0; top: 0; height: 100%; width: min(340px, 92vw);
  border-radius: 0; z-index: 40; background: #082f2a;
  padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
  box-shadow: -12px 0 40px rgba(0,0,0,.5);
}
#rail-close { display: none; }
body.compact.rail-open #rail-close {
  display: block; flex: none; width: 100%; padding: 16px; font-size: 19px; font-weight: 700;
  border-radius: 12px; box-shadow: 0 -10px 24px rgba(8,47,42,.9);
}
.portrait-hint { display: none; }

/* claim card: what you can do with the tile just thrown */
#claim-card {
  position: absolute; left: calc(var(--main-w) / 2); bottom: 166px; transform: translateX(-50%);
  z-index: 12; display: flex; align-items: center; gap: 18px;
  background: rgba(6, 34, 31, .96); border: 2px solid var(--brass); border-radius: 18px;
  padding: 14px 18px 18px; box-shadow: 0 16px 40px rgba(0,0,0,.5), 0 0 30px rgba(201,162,74,.25);
  animation: pop .18s ease-out;
}
@keyframes pop { from { transform: translateX(-50%) scale(.92); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
#claim-card .cc-tile { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#claim-card .cc-who { font-size: 15px; color: var(--muted); white-space: nowrap; }
#claim-card .cc-opts { display: flex; gap: 10px; align-items: stretch; flex-wrap: wrap; max-width: 680px; }
#claim-card .cc-opt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; font-size: 20px; min-width: 96px; }
#claim-card .cc-opt.ghost { border-color: rgba(244,239,226,.45); }
#claim-card .cc-opt .mini { display: flex; gap: 2px; }
#claim-card .cc-opt.chosen { outline: 3px solid var(--brass-light); }
#claim-card .cc-note { color: var(--brass-light); font-weight: 700; }
#claim-card .cc-bar { position: absolute; left: 16px; right: 16px; bottom: 7px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
#claim-card .cc-bar i { display: block; height: 100%; background: var(--brass-light); transform-origin: left; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* drawn tile sorted into the hand: a gold border all round marks it */
#my-hand .tile.new {
  outline: 4px solid var(--brass-light); outline-offset: 2px;
  box-shadow: 0 3.2px 0 var(--ivory-edge), 0 7.7px 0 var(--jade), 0 0 18px rgba(232, 205, 134, .6);
}

/* settings */
.settings-card { background: var(--felt-deep); color: var(--text); width: min(720px, 100%); }
.settings-card .sub { color: var(--muted); }
.set-group { border-top: 1px solid rgba(244,239,226,.14); padding: 10px 0 8px; }
.set-group legend { font-weight: 700; font-size: 18px; padding: 8px 0 4px; float: left; width: 100%; }
.set-choice { display: flex; gap: 10px; align-items: center; padding: 5px 0; cursor: pointer; clear: both; }
.set-choice input { width: 20px; height: 20px; accent-color: var(--brass); flex: none; }
.set-label { display: flex; flex-direction: column; gap: 6px; }
.set-preview { display: flex; gap: 3px; flex-wrap: wrap; }
.set-help { color: var(--muted); margin: -2px 0 8px 30px; max-width: 60ch; line-height: 1.45; }

#claim-card .cc-opt.draw { background: var(--ivory); color: var(--ink); border-color: var(--ivory); font-weight: 700; }
#claim-card .cc-opt.draw:hover { background: #fffaf0; }
/* click-to-pass: the table has waited a while for you */
#claim-card.nudge { animation: nudge 1.4s ease-in-out infinite; }
@keyframes nudge {
  0%, 100% { box-shadow: 0 16px 40px rgba(0,0,0,.5), 0 0 30px rgba(201,162,74,.25); }
  50% { box-shadow: 0 16px 40px rgba(0,0,0,.5), 0 0 0 6px rgba(232,200,120,.55), 0 0 46px rgba(232,200,120,.6); }
}
@media (prefers-reduced-motion: reduce) {
  #claim-card.nudge { outline: 4px solid var(--brass-light); outline-offset: 3px; }
}
#claim-card .cc-secs { position: absolute; right: 14px; top: 8px; font-weight: 700; color: var(--brass-light); font-variant-numeric: tabular-nums; }
#claim-card .cc-opt.reveal { background: transparent; border: 2px solid var(--brass); color: var(--brass-light); }
#claim-card .cc-opt.reveal:hover { background: rgba(201,162,74,.15); }

/* ------------------------------------------------- phone held upright */
/* The stage is 760 units wide (fitStage): opponents' chips in a row on
   top, the table, a row with the prompt and the scores button, then your
   hand wrapped into two rows with your melds above it. Your own chip is
   left out: your wind is on the table's edge, your score under Scores. */
body.portrait .table { left: 10px; top: 80px; }
body.portrait .chip { min-width: 0; max-width: 236px; padding: 5px 8px; }
body.portrait .chip-pos-3 { left: 0; right: auto; top: -72px; bottom: auto; transform: none; }
body.portrait .chip-pos-2 { left: 50%; right: auto; top: -72px; transform: translateX(-50%); }
body.portrait .chip-pos-1 { right: 0; left: auto; top: -72px; bottom: auto; transform: none; }
body.portrait .chip-pos-0 { display: none; }
body.portrait .rail-toggle { top: calc(80px + 740px + 12px); right: 10px; font-size: 18px; padding: 10px 14px; }
body.portrait #me-area {
  top: calc(80px + 740px + 8px); bottom: 0; height: auto; width: 760px;
  justify-content: flex-start;
}
body.portrait #prompt-bar {
  position: absolute; left: 10px; top: 0; bottom: auto; transform: none;
  white-space: normal; flex-wrap: wrap; justify-content: flex-start;
  max-width: 560px; min-height: 60px; padding: 6px 12px;
}
body.portrait #prompt-bar .ptext { font-size: 21px; }
body.portrait #prompt-bar .btn { font-size: 20px; padding: 10px 16px; }
body.portrait #my-row { flex-direction: column; align-items: center; gap: 10px; margin-top: 72px; padding: 6px 10px 0; width: 760px; }
body.portrait #my-melds { padding-bottom: 0; flex-wrap: wrap; justify-content: center; }
body.portrait #my-hand {
  flex-wrap: wrap; justify-content: center; row-gap: 24px; padding-top: 20px;
  max-width: calc(var(--hand-w) * 1.045 * var(--per-row, 7) + var(--hand-w) * 0.4);
}
body.portrait #my-hand .tile.drawn { margin-left: calc(var(--hand-w) * 0.12); }
body.portrait #claim-card { top: 470px; bottom: auto; max-width: 740px; flex-wrap: wrap; justify-content: center; }
body.portrait #claim-card .cc-opt { font-size: 22px; min-width: 120px; padding: 12px 18px; }

/* Phones: each rule's control goes under its label, full width.
   (Last in the file so it wins over the rules form's own layout.) */
@media (max-width: 600px) {
  .rule-row { grid-template-columns: minmax(0, 1fr); }
  .rule-row select { width: 100%; }
  .lobby-code { font-size: 44px; }
  .pattern-table { display: block; overflow-x: auto; }
  .seat-square { width: min(300px, 100%); }
}

/* move clock */
.clock {
  display: inline-block; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted);
  padding: 2px 9px; border-radius: 999px; background: rgba(255,255,255,.08); margin-left: 6px; font-size: 16px;
}
.clock.bank { color: #2a1a06; background: var(--brass-light); }
.clock[hidden] { display: none; }
.chip .clock { font-size: 13px; padding: 0 7px; margin: 2px 0 0; }
#claim-card .cc-clock { position: absolute; right: 12px; top: 8px; margin: 0; }
.chip .tag-away { color: #ffcf9e; font-weight: 700; }
#away-banner {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 35;
  top: max(12px, env(safe-area-inset-top, 0px));
  display: flex; gap: 14px; align-items: center; padding: 12px 16px; border-radius: 14px;
  background: var(--ivory); color: var(--ink); font-weight: 700; font-size: 17px;
  box-shadow: 0 6px 0 var(--ivory-edge), 0 18px 40px rgba(0,0,0,.5);
  max-width: calc(100vw - 32px);
}
#away-banner .btn { font-size: 17px; }
