/* Riichi Online. Parlour palette: felt, lacquered wood, ivory, one gold accent, one vermilion. */

@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 400; font-display: swap; src: url("/static/fonts/ZenKakuGothicNew-Regular.woff2") format("woff2"); }
@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 500; font-display: swap; src: url("/static/fonts/ZenKakuGothicNew-Medium.woff2") format("woff2"); }
@font-face { font-family: "Zen Kaku Gothic New"; font-weight: 700; font-display: swap; src: url("/static/fonts/ZenKakuGothicNew-Bold.woff2") format("woff2"); }
@font-face { font-family: "Dela Gothic One"; font-weight: 400; font-display: swap; src: url("/static/fonts/DelaGothicOne-Impact.woff2") format("woff2"); } /* subset: call and win lettering only */
@font-face { font-family: "Shippori Mincho B1"; font-weight: 600; font-display: swap; src: url("/static/fonts/ShipporiMinchoB1-SemiBold.woff2") format("woff2"); }

:root {
  /* colour */
  --felt-hi: #1f5139;
  --felt: #17402f;
  --felt-lo: #0c261b;
  --wood: #6b4528;
  --wood-hi: #8a5b36;
  --wood-lo: #3b2514;
  --ivory: #f4eddc;
  --ivory-lo: #e6dcc2;
  --paper: #f3ecda;
  --ink: #16140f;
  --ink-soft: #4a4538;
  --gold: #d2ab5a;
  --gold-lo: #a98531;
  --verm: #c4382d;
  --verm-hi: #e0554a;
  --indigo: #1b2340;
  --indigo-hi: #2a3563;
  --jade: #6fcf97;
  --night: #0a1511;
  --text: #ece6d4;
  --text-dim: #a9b3a5;
  --line: rgba(236, 230, 212, 0.14);
  --glass: rgba(8, 22, 16, 0.62);
  /* type scale 11 / 12 / 14 / 16 / 20 / 28 / 44 */
  --f-1: 11px; --f0: 12px; --f1: 14px; --f2: 16px; --f3: 20px; --f4: 28px; --f5: 44px;
  /* spacing scale 4 / 8 / 12 / 16 / 24 / 32 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --ui: "Zen Kaku Gothic New", system-ui, -apple-system, "Segoe UI", sans-serif;
  --disp: "Shippori Mincho B1", "Hiragino Mincho ProN", "Noto Serif JP", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --rail: 68px;
  --mini: 26px;
  --r: 10px;
  --w: 24px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--night);
  color: var(--text);
  font: 400 var(--f1)/1.45 var(--ui);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.mono { font-family: var(--mono); }
h1, h2, p, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
.ico { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- shared controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 48px; padding: 0 var(--s4); border-radius: var(--r);
  background: rgba(236, 230, 212, 0.08); border: 1px solid var(--line); color: var(--text);
  font-weight: 700; font-size: var(--f1); letter-spacing: 0.01em; transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover { background: rgba(236, 230, 212, 0.14); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; }
.btn.primary:hover { background: #dfba70; }
.btn.small { min-height: 44px; padding: 0 var(--s3); font-size: var(--f0); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.linkbtn { background: none; border: 0; color: var(--text-dim); text-decoration: underline; text-underline-offset: 3px; min-height: 44px; padding: 0 var(--s2); font-size: var(--f0); align-self: flex-start; }
.linkbtn:hover { color: var(--text); }

.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
.spin.sm { width: 14px; height: 14px; border-width: 2px; display: inline-block; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: var(--s4); color: var(--text-dim); }

.wind {
  display: inline-grid; place-items: center; width: 24px; height: 24px; flex: none; border-radius: 50%;
  background: var(--ivory); color: var(--ink); font: 600 14px/1 var(--disp);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}
.wind.lg { width: 40px; height: 40px; font-size: 22px; }
.tag { font-style: normal; font-size: var(--f-1); font-weight: 700; padding: 1px 6px; border-radius: 99px; background: rgba(236, 230, 212, 0.14); color: var(--text); margin-left: var(--s1); letter-spacing: 0.04em; }
.tag.gold { background: rgba(210, 171, 90, 0.2); color: var(--gold); }
.rbody .tag { background: var(--ink); color: #fff7e0; border: 1px solid var(--ink); padding: 2px 9px; font-size: var(--f0); letter-spacing: 0.06em; }
.eyebrow { font-size: var(--f0); text-transform: uppercase; letter-spacing: 0.14em; color: var(--text-dim); font-weight: 500; }

/* ---------- landing ---------- */
body.screen-landing, body.screen-lobby, body.screen-boot {
  background:
    radial-gradient(1200px 700px at 78% -10%, rgba(210, 171, 90, 0.1), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(31, 81, 57, 0.7), transparent 60%),
    var(--night);
  overflow-y: auto;
}
.landing {
  min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: var(--s6) 48px;
  align-items: center; max-width: 1040px; margin: 0 auto; padding: var(--s5) max(var(--s5), env(safe-area-inset-right)) var(--s5) max(var(--s5), env(safe-area-inset-left));
}
.brand { position: relative; display: grid; gap: var(--s3); align-content: center; }
.mark {
  width: 72px; height: 92px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(#fbf6e8, var(--ivory-lo)); color: var(--verm); font: 600 44px/1 var(--disp);
  box-shadow: 0 7px 0 #9c8f6c, 0 14px 22px rgba(0, 0, 0, 0.5); transform: rotate(-4deg); margin-bottom: var(--s3);
}
.title { font: 600 var(--f5)/1.05 var(--disp); letter-spacing: 0.02em; display: flex; align-items: baseline; gap: var(--s3); }
.title-sub { font: 400 var(--f3)/1 var(--ui); color: var(--gold); letter-spacing: 0.22em; text-transform: uppercase; }
.lede { color: var(--text-dim); max-width: 36ch; font-size: var(--f2); }
.credit { color: rgba(169, 179, 165, 0.7); font-size: var(--f-1); max-width: 46ch; }
.card {
  background: linear-gradient(180deg, rgba(244, 237, 220, 0.075), rgba(244, 237, 220, 0.035));
  border: 1px solid var(--line); border-radius: 16px; padding: var(--s5); display: grid; gap: var(--s4);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.field { display: grid; gap: var(--s1); }
.flabel { font-size: var(--f0); color: var(--text-dim); font-weight: 500; letter-spacing: 0.04em; }
.fhint { font-size: var(--f0); color: rgba(169, 179, 165, 0.8); }
.inp {
  width: 100%; min-height: 48px; padding: 0 var(--s3); border-radius: var(--r); border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.28); color: var(--text); font-size: 16px;
}
.inp::placeholder { color: rgba(169, 179, 165, 0.55); }
.inp:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(210, 171, 90, 0.2); }
.code-inp { text-align: center; letter-spacing: 0.4em; font: 600 var(--f3) var(--mono); text-transform: uppercase; }
.fgroup { display: grid; gap: var(--s2); }
.fgroup.tight { gap: var(--s1); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); }
.seg-b { display: grid; justify-items: center; align-content: center; gap: 0; min-height: 44px; padding: 4px var(--s2); border: 0; border-radius: 9px; background: transparent; color: var(--text-dim); }
.seg-b:hover { color: var(--text); }
.seg-b.on { background: var(--ivory); color: var(--ink); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5) inset, 0 2px 6px rgba(0, 0, 0, 0.3); }
.seg-l { font-weight: 700; font-size: var(--f1); }
.seg-s { font-size: var(--f-1); opacity: 0.75; }
.swrow { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 48px; cursor: pointer; position: relative; }
.swtext { display: grid; }
.swl { font-weight: 500; }
.sws { font-size: var(--f0); color: var(--text-dim); }
.sw-in { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw { width: 48px; height: 28px; border-radius: 99px; background: rgba(0, 0, 0, 0.4); border: 1px solid var(--line); position: relative; flex: none; transition: background 0.2s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-dim); transition: transform 0.2s, background 0.2s; }
.sw-in:checked + .sw { background: rgba(210, 171, 90, 0.3); border-color: var(--gold); }
.sw-in:checked + .sw::after { transform: translateX(20px); background: var(--gold); }
.sw-in:focus-visible + .sw { outline: 2px solid var(--gold); outline-offset: 2px; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border-bottom: 1px solid var(--line); }
.tab { min-height: 44px; border: 0; background: none; color: var(--text-dim); font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--text); border-bottom-color: var(--gold); }
.panel { display: grid; gap: var(--s3); }
.err { color: #ffb3a8; background: rgba(196, 56, 45, 0.16); border: 1px solid rgba(196, 56, 45, 0.45); border-radius: var(--r); padding: var(--s2) var(--s3); font-size: var(--f0); }
.resume { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: var(--r); background: rgba(210, 171, 90, 0.1); border: 1px solid rgba(210, 171, 90, 0.3); font-size: var(--f0); }

/* ---------- lobby ---------- */
.lobby { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: var(--s6) 48px; align-items: center; max-width: 1040px; margin: 0 auto; padding: var(--s5) max(var(--s5), env(safe-area-inset-right)) var(--s5) max(var(--s5), env(safe-area-inset-left)); }
.lobby-head { display: grid; gap: var(--s3); justify-items: start; }
.code { display: flex; gap: var(--s2); }
.code span { display: grid; place-items: center; width: 44px; height: 58px; border-radius: 8px; background: linear-gradient(#fbf6e8, var(--ivory-lo)); color: var(--ink); font: 600 var(--f4)/1 var(--mono); box-shadow: 0 4px 0 #9c8f6c, 0 8px 14px rgba(0, 0, 0, 0.4); }
.row { display: flex; flex-wrap: wrap; }
.row.gap { gap: var(--s2); }
.linkbox { font-size: var(--f0); color: var(--text-dim); max-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chips li { padding: 4px 10px; border-radius: 99px; border: 1px solid var(--line); font-size: var(--f0); color: var(--text-dim); }
.lobby-body { display: grid; gap: var(--s3); }
.h2 { font: 600 var(--f3)/1.2 var(--disp); }
.seats { display: grid; gap: var(--s2); }
.seatcard { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); min-height: 60px; border-radius: 12px; background: rgba(244, 237, 220, 0.06); border: 1px solid var(--line); }
.seatcard.empty { border-style: dashed; background: transparent; }
.seatcard.empty .wind { opacity: 0.4; }
.seatcard.me { border-color: rgba(210, 171, 90, 0.6); }
.sc-main { display: grid; flex: 1; min-width: 0; }
.sc-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sc-state { font-size: var(--f0); color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px; }
.sc-state.off { color: #e9a79f; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #7a7f78; display: inline-block; }
.dot.on { background: var(--jade); }
.hostbar { display: grid; gap: var(--s3); margin-top: var(--s2); }
.hostbtns { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.hostbtns .btn.primary { min-width: 160px; }
.hint { flex-basis: 100%; font-size: var(--f0); color: var(--text-dim); }
.waiting { display: flex; align-items: center; gap: var(--s2); color: var(--text-dim); margin-top: var(--s2); }

@media (max-width: 760px) {
  .landing, .lobby { grid-template-columns: 1fr; align-items: start; gap: var(--s5); }
  .mark { width: 52px; height: 66px; font-size: 32px; margin-bottom: 0; }
  .title { font-size: var(--f4); }
  .credit { display: none; }
}
@media (max-height: 520px) and (min-width: 761px) {
  .landing, .lobby { gap: var(--s4) 32px; padding-top: var(--s3); padding-bottom: var(--s3); }
  .card { padding: var(--s3) var(--s4); gap: var(--s2); }
  .mark { width: 52px; height: 66px; font-size: 32px; margin-bottom: 0; }
  .lede { font-size: var(--f1); }
  .credit { display: none; }
  .code span { width: 38px; height: 48px; font-size: var(--f3); }
  .seatcard { min-height: 52px; padding-top: 4px; padding-bottom: 4px; }
}

/* ---------- overlays ---------- */
#banner { position: fixed; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 60; max-width: calc(100vw - 24px); }
.bn { display: flex; align-items: center; gap: var(--s2); padding: 6px var(--s3); border-radius: 99px; background: rgba(10, 21, 17, 0.92); border: 1px solid var(--gold); color: var(--text); font-size: var(--f0); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); }
.bn.warn { border-color: var(--verm-hi); border-radius: 14px; padding: var(--s2) var(--s3); }
#toast { position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; display: grid; gap: var(--s2); justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { padding: var(--s2) var(--s3); border-radius: var(--r); background: rgba(10, 21, 17, 0.94); border: 1px solid var(--line); color: var(--text); font-size: var(--f1); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); animation: rise 0.22s ease-out; }
.toast.out { opacity: 0; transition: opacity 0.25s; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }
#rotate { position: fixed; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; z-index: 50; pointer-events: none; }
.rotcard { pointer-events: auto; display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: 14px; background: rgba(10, 21, 17, 0.94); border: 1px solid var(--gold); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }
.rotcard .ico { width: 28px; height: 28px; color: var(--gold); }
.rottext { display: grid; flex: 1; font-size: var(--f0); line-height: 1.3; color: var(--text-dim); }
.rottext b { color: var(--text); font-size: var(--f1); }

/* ---------- table: sizing ---------- */
body { text-rendering: geometricPrecision; }
body.screen-table { background: var(--wood-lo); overflow: hidden; }
.table {
  --vh: calc((100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 100); /* one percent of the height the table can really use (a notch and the home bar are cut off) */
  --vw: calc(100vw - env(safe-area-inset-left) - env(safe-area-inset-right));
  --tw: clamp(20px, min(11.6 * var(--vh), (var(--vw) - var(--rail) - 56px) / 15), 66px);
  /* M4.1: ponds are 3 rows of 8, a side pond spans the whole cluster height (it no longer adds to the centre row), so the ponds grow with the height
     left after the hand, the top hand and the centre band. --capow keeps a 13-tile side hand (plus melds) between the top hand and the timer. */
  --capow: calc((100 * var(--vh) - var(--hand-h) - 24px) / 17.2);
  --rw: clamp(11px, min((100 * var(--vh) - var(--hand-h) - var(--capow) * 1.34 - 170px) / 8, (var(--vw) - var(--rail) - 540px) / 8), 46px);
  --ow: calc(min(var(--rw) * 1.05, var(--capow)));
  --mw: calc(var(--tw) * 0.62);
  --hand-h: calc(var(--tw) * 1.3334 + 30px);
  --flank: calc(var(--ow) * 1.4 + 12px);
  position: relative; width: 100vw; height: 100vh; height: 100dvh;
  display: grid; grid-template-columns: minmax(0, 1fr) var(--rail);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: linear-gradient(180deg, var(--wood-hi), var(--wood) 30%, var(--wood-lo));
  user-select: none; -webkit-user-select: none;
}
@supports (height: 1dvh) { .table { --vh: calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) / 100); } }
.felt {
  grid-column: 1; margin: 6px 0 6px 6px; border-radius: 12px; position: relative; overflow: hidden;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(ellipse at 50% 42%, var(--felt-hi), var(--felt) 52%, var(--felt-lo) 100%);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35), inset 0 0 60px rgba(0, 0, 0, 0.5), 0 0 0 2px var(--wood-lo);
}
.felt::before { /* faint woven grain */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.012) 0 2px, transparent 2px 5px), repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.03) 0 2px, transparent 2px 5px);
}
.toprow { display: flex; justify-content: center; padding-top: 4px; position: relative; }
.midwrap { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; min-height: 0; position: relative; }
.flank { display: flex; align-items: center; justify-content: center; padding: 0 3px; }
.cluster { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; grid-template-rows: auto minmax(0, 1fr) auto; justify-items: center; align-items: center; align-self: stretch; min-height: 0; padding: 2px 0; }
.orient { position: relative; flex: none; }
.orient > * { position: absolute; left: 0; top: 0; }
.pond.r2 { grid-area: 1 / 2; }
.pond.r3 { grid-area: 1 / 1 / 4 / 2; }
.pond.r1 { grid-area: 1 / 3 / 4 / 4; }
.pond.r0 { grid-area: 3 / 2; }
.center { grid-area: 2 / 2; width: 100%; height: 100%; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; justify-items: center; align-items: center; padding: 0 6px; }
.midrow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; justify-items: center; width: 100%; gap: 6px; min-height: 0; }

/* ---------- tiles ---------- */
.tile {
  position: relative; flex: none; width: var(--w); height: calc(var(--w) * 1.3334); border-radius: calc(var(--w) * 0.13);
  background: linear-gradient(165deg, #fffaf0 0%, var(--ivory) 55%, var(--ivory-lo) 100%);
  box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 calc(var(--w) * 0.13) calc(var(--w) * 0.14) rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}
.tile.haku::after { content: ""; position: absolute; inset: 15% 19%; border: calc(var(--w) * 0.055) solid #2a4b94; border-radius: calc(var(--w) * 0.05); pointer-events: none; }
.tile img { display: block; width: 100%; height: 100%; padding: 7% 9%; pointer-events: none; -webkit-user-drag: none; }
.tile.back {
  background: linear-gradient(150deg, #3f8d72, #2a6a53 60%, #235a46);
  box-shadow: 0 calc(var(--w) * 0.075) 0 #d9cfae, 0 calc(var(--w) * 0.13) calc(var(--w) * 0.14) rgba(0, 0, 0, 0.45), inset 0 0 0 calc(var(--w) * 0.07) rgba(255, 255, 255, 0.1);
}
.cell { position: relative; flex: none; width: var(--w); height: calc(var(--w) * 1.3334); }
.cell.side { width: calc(var(--w) * 1.3334); height: var(--w); align-self: flex-end; }
.cell.side .tile { position: absolute; left: calc(var(--w) * 0.1667); top: calc(var(--w) * -0.1667); transform: rotate(90deg); }
.cell.side.stack { height: calc(var(--w) * 2); }
.cell.side.stack .tile { top: calc(var(--w) * 0.8333); }
.cell.side.stack .tile.up { top: calc(var(--w) * -0.1667); }
.cell.gap { margin-left: calc(var(--w) * 0.4); }
.cell.last .tile { box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 2px var(--gold), 0 0 14px rgba(210, 171, 90, 0.8); }
.cell.tsumogiri .tile { filter: brightness(0.9); }
.cell.fresh .tile { animation: drop 0.28s ease-out; }
@keyframes drop { from { transform: translateY(-14px) scale(1.12); opacity: 0.2; } }
.cell.side.fresh .tile { animation: none; }

/* ponds */
.pond-in { --w: var(--rw); width: max-content; display: grid; align-content: start; gap: 2px; min-width: calc(var(--rw) * 8.34); min-height: calc(var(--rw) * 4 + 4px); } /* M4.1: 8 tiles a row (+ one sideways riichi tile), 3 rows */
.prow { display: flex; align-items: flex-end; min-height: calc(var(--rw) * 1.3334); gap: 0; }
/* opponent hands */
.oh-in { --w: var(--ow); width: max-content; display: flex; align-items: flex-end; gap: calc(var(--ow) * 0.5); }
.backs { display: flex; }
.oh-in .meld { --w: calc(var(--ow) * 0.9); }
.meld { display: flex; align-items: flex-end; flex: none; }
.meld.own { --w: var(--mw); }
.mymelds { --w: var(--mw); display: flex; align-items: flex-end; gap: calc(var(--mw) * 0.4); }

/* ---------- plates + centre info ---------- */
.plate {
  --a: rgba(236, 230, 212, 0.14);
  display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 4px; border-radius: 99px; max-width: 100%;
  background: var(--glass); border: 1px solid var(--a); font-size: var(--f0); line-height: 1.1; min-width: 0;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.plate.rel1, .plate.rel3 { flex-direction: column; border-radius: 14px; padding: 6px 4px; gap: 3px; width: 64px; text-align: center; }
.plate.turn { --a: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 14px rgba(210, 171, 90, 0.5); }
.plate.riichi { background: rgba(120, 25, 20, 0.5); }
.plate.off { opacity: 0.6; }
.windwrap { position: relative; display: inline-flex; margin-right: 7px; }
.plate.rel1 .windwrap, .plate.rel3 .windwrap { margin-right: 0; }
.windwrap .wind { width: 22px; height: 22px; font-size: 13px; }
.plate.dealer .wind { background: #fff2c9; box-shadow: 0 0 0 2px var(--verm), inset 0 -2px 0 rgba(0, 0, 0, 0.15); }
.oya { position: absolute; top: -6px; right: -8px; padding: 0 3px; border-radius: 4px; background: var(--verm); color: #fff; font: 600 11px/14px var(--disp); }
.pname { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12ch; }
.plate.rel1 .pname, .plate.rel3 .pname { max-width: 60px; font-size: var(--f-1); }
.pscore { font: 700 var(--f1) var(--mono); color: var(--gold); letter-spacing: -0.02em; }
.plate.rel1 .pscore, .plate.rel3 .pscore { font-size: var(--f0); }
.rstick { width: 30px; height: 4px; border-radius: 2px; background: #f4eddc; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--verm); position: relative; }
.rstick::after { content: ""; position: absolute; left: 50%; top: 50%; width: 5px; height: 5px; border-radius: 50%; background: var(--verm); transform: translate(-50%, -50%); }
.pstat { font-size: var(--f-1); text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
.plate.off .pstat { color: #f0a69d; }
.info { display: grid; grid-template-columns: auto auto; align-items: center; justify-content: center; gap: 4px 12px; padding: 4px 10px; border-radius: 12px; background: rgba(0, 0, 0, 0.18); border: 1px solid rgba(236, 230, 212, 0.08); }
.round { display: flex; align-items: baseline; gap: 6px; grid-row: 1 / 3; }
.rk { font: 600 clamp(24px, calc(var(--rw) * 1.9), 56px)/1 var(--disp); color: var(--ivory); }
.rn { font: 600 clamp(16px, calc(var(--rw) * 1.1), 32px)/1 var(--disp); color: var(--gold); }
.rl { display: none; }
.counters { display: flex; gap: 10px; }
.ctr { display: grid; justify-items: center; line-height: 1.05; }
.ctr small { font-size: var(--f-1); color: var(--text-dim); letter-spacing: 0.04em; }
.ctr b { font: 700 var(--f1) var(--mono); }
.dora { grid-column: 2; display: flex; align-items: center; gap: 4px; --w: calc(var(--rw) * 0.95); }
.dlb { font-size: var(--f-1); color: var(--text-dim); }
.dt { display: flex; gap: 2px; }
.ds { display: block; width: var(--w); height: calc(var(--w) * 1.3334); }
.ds .tile { --w: calc(var(--rw) * 0.95); }

/* ---------- bottom: hand ---------- */
.bottom { position: relative; padding: 2px 8px 6px; display: grid; gap: 4px; }
.timer { display: flex; align-items: center; gap: var(--s2); height: 12px; padding: 0 var(--s2); }
.tb { flex: 1; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, 0.35); display: flex; overflow: hidden; }
.tb-main { display: block; height: 100%; background: var(--gold); }
.tb-bank { display: block; height: 100%; background: var(--verm-hi); }
.timer.low .tb-main { background: var(--verm-hi); }
.tt { font: 500 var(--f-1) var(--mono); color: var(--text-dim); min-width: 8ch; text-align: right; }
.handrow { display: flex; align-items: flex-end; justify-content: center; gap: 16px; min-height: calc(var(--tw) * 1.3334 + 16px); padding-top: 14px; }
.handbox { --w: var(--tw); display: flex; align-items: flex-end; gap: 1px; }
.tile.hand { cursor: default; transition: transform 0.12s ease-out, filter 0.15s; touch-action: manipulation; }
.tile.hand.drawn { margin-left: calc(var(--tw) * 0.32); }
.table.myturn .tile.hand:not(.dim) { cursor: pointer; }
@media (hover: hover) { .table.myturn .tile.hand:not(.dim):hover { transform: translateY(-4px); } }
.tile.hand.sel { transform: translateY(calc(var(--tw) * -0.28)); box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 2px var(--gold), 0 8px 18px rgba(0, 0, 0, 0.5); }
.tile.hand.dim { filter: brightness(0.5) saturate(0.7); }
.tile.hand.good { box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 2px var(--jade), 0 0 12px rgba(111, 207, 151, 0.55); }
.tile.hand.best { box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 3px var(--jade), 0 0 18px rgba(111, 207, 151, 0.8); }
.tile.hand.rok:not(.sel) { box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 2px var(--verm-hi), 0 0 12px rgba(224, 85, 74, 0.55); }
.uk { position: absolute; top: calc(var(--tw) * -0.17); left: 50%; transform: translateX(-50%); min-width: 18px; padding: 0 4px; border-radius: 99px; background: var(--jade); color: #07210f; font: 700 var(--f-1)/16px var(--mono); text-align: center; pointer-events: none; }

/* tools rail */
.tools { grid-column: 2; display: flex; flex-direction: column; align-items: center; gap: var(--s2); padding: 8px 4px; z-index: 5; }
.tool { width: 44px; min-height: 44px; border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.14); background: rgba(0, 0, 0, 0.28); color: var(--ivory); display: grid; justify-items: center; align-content: center; gap: 1px; padding: 0; font-size: var(--f-1); font-weight: 500; }
.tool span { line-height: 1; }
.tool:hover { background: rgba(0, 0, 0, 0.42); }
.tool[aria-pressed="true"] { background: rgba(210, 171, 90, 0.22); border-color: var(--gold); color: var(--gold); }
.tool[aria-pressed="false"] { opacity: 0.75; }
.codechip { font: 600 var(--f-1) var(--mono); letter-spacing: 0.04em; color: rgba(244, 237, 220, 0.75); padding: 2px 0 4px; }

/* hints */
.hints {
  position: absolute; left: calc(var(--flank) + 6px + env(safe-area-inset-left)); bottom: calc(var(--hand-h) + 14px + env(safe-area-inset-bottom)); z-index: 4; width: min(236px, 34vw); display: grid; gap: 6px;
  padding: 8px 10px; border-radius: 12px; background: var(--glass); border: 1px solid rgba(111, 207, 151, 0.3); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.hh { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.hh small, .waits small { font-size: var(--f-1); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.1em; }
.hs { font: 700 var(--f2)/1 var(--ui); color: var(--text); }
.hs.tp { color: var(--jade); }
.hnote { font-size: var(--f0); color: var(--text-dim); line-height: 1.3; }
.waits { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.wt { display: inline-flex; align-items: flex-end; gap: 2px; }
.wt i { font: 600 var(--f-1) var(--mono); font-style: normal; color: var(--text); }
.hints .wt .tile { --w: 18px; }
.furiten { display: flex; align-items: center; gap: 6px; font-size: var(--f0); color: #ffcf8a; font-weight: 700; }
.furiten .ico { width: 16px; height: 16px; }

/* actions */
.abar { position: absolute; right: calc(var(--rail) + var(--flank) + env(safe-area-inset-right)); bottom: calc(var(--hand-h) + 14px + env(safe-area-inset-bottom)); z-index: 6; display: flex; flex-direction: row; align-items: flex-end; justify-content: flex-end; gap: var(--s2); max-width: min(520px, 62vw); pointer-events: none; }
.abar > * { pointer-events: auto; }
.actions { display: flex; flex-direction: row-reverse; flex-wrap: wrap; justify-content: flex-start; gap: var(--s2); max-width: 350px; }
.abtn {
  position: relative; min-width: 76px; min-height: 52px; padding: 0 var(--s4); border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.22);
  background: var(--indigo); color: var(--ivory); display: grid; justify-items: center; align-content: center; gap: 0;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12); font-weight: 700; animation: rise 0.18s ease-out;
}
.abtn .al { font-size: var(--f2); line-height: 1.1; }
.abtn .kb { display: none; font: 500 var(--f-1)/1 var(--mono); opacity: 0.6; }
@media (hover: hover) and (pointer: fine) { .abtn .kb { display: block; } }
.abtn:hover { background: var(--indigo-hi); }
.abtn:active { transform: translateY(1px); }
.abtn.win { background: var(--gold); color: #1a1408; border-color: #f0d28c; min-width: 96px; box-shadow: 0 0 0 3px rgba(210, 171, 90, 0.3), 0 6px 18px rgba(0, 0, 0, 0.5); animation: pulse 1.4s ease-in-out infinite; }
.abtn.win:hover { background: #e2bd75; }
.abtn.riichi { background: var(--verm); border-color: #ef8a80; }
.abtn.riichi:hover { background: var(--verm-hi); }
.abtn.riichi.on { background: #fff2c9; color: var(--verm); border-color: var(--verm); }
.abtn.pass { background: rgba(0, 0, 0, 0.45); }
.abtn.discard { background: var(--ivory); color: var(--ink); border-color: #fff; }
.abtn.discard:hover { background: #fff; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(210, 171, 90, 0.12), 0 6px 18px rgba(0, 0, 0, 0.5); } }
.table.picking .actions { visibility: hidden; }
.claimnote { white-space: nowrap; margin-bottom: 10px; display: flex; align-items: center; gap: var(--s2); padding: 2px 8px 2px 10px; border-radius: 99px; background: var(--glass); border: 1px solid rgba(210, 171, 90, 0.5); font-size: var(--f0); }
.claimnote .tile { --w: 18px; }
.claimnote[hidden] { display: none; }
.picker { position: absolute; right: calc(var(--rail) + var(--flank) + env(safe-area-inset-right)); bottom: calc(var(--hand-h) + 14px + env(safe-area-inset-bottom)); z-index: 7; display: grid; gap: var(--s2); padding: var(--s3); border-radius: 14px; background: rgba(10, 21, 17, 0.96); border: 1px solid var(--gold); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6); max-width: min(360px, 60vw); }
.ptitle { font: 600 var(--f2) var(--disp); }
.popts { display: flex; flex-wrap: wrap; gap: var(--s2); }
.popt { display: flex; align-items: center; gap: var(--s2); min-height: 52px; padding: 4px var(--s3) 4px var(--s2); border-radius: 12px; background: rgba(236, 230, 212, 0.09); border: 1px solid var(--line); }
.popt:hover { border-color: var(--gold); background: rgba(210, 171, 90, 0.15); }
.pn { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: rgba(236, 230, 212, 0.16); font: 700 var(--f-1) var(--mono); }
.pt { display: flex; gap: 2px; }
.pt .tile { --w: 24px; }
.pl { font-size: var(--f0); font-weight: 700; color: var(--gold); }
.pcancel { min-height: 44px; justify-self: end; }
.autoplay-note { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 8; max-width: min(520px, 70vw); padding: 6px var(--s3); border-radius: 12px; background: rgba(120, 25, 20, 0.88); border: 1px solid #ef8a80; font-size: var(--f0); text-align: center; }

/* ---------- modals ---------- */
#modal { position: relative; z-index: 70; }
.scrim { position: fixed; inset: 0; display: grid; place-items: center; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: rgba(4, 12, 9, 0.66); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade 0.2s ease-out; }
@keyframes fade { from { opacity: 0; } }
.mcard {
  width: min(900px, 100%); max-height: 100%; overflow: hidden; display: grid; border-radius: 16px;
  background: linear-gradient(180deg, #f8f2e2, var(--paper)); color: var(--ink); border: 1px solid #fff8e4;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 4px rgba(107, 69, 40, 0.6);
}
.rbody { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; max-height: 100%; }
.winc, .drawc, .rbody.final { padding: var(--s4) var(--s5) var(--s3); display: grid; gap: var(--s3); align-content: start; min-height: 0; overflow: hidden; }
.mhead { display: grid; gap: 2px; }
.mhead .eyebrow { color: var(--ink-soft); }
.mtitle { font: 600 var(--f4)/1.1 var(--disp); display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.mtitle small { font: 500 var(--f2) var(--ui); color: var(--verm); }
.mcols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--s5); min-height: 0; }
.mleft { display: grid; gap: var(--s3); align-content: start; min-width: 0; }
.mright { display: grid; gap: var(--s2); align-content: start; grid-template-rows: minmax(0, auto) auto; min-height: 0; min-width: 0; }
.hbox { padding: var(--s3); border-radius: 12px; background: linear-gradient(var(--felt), var(--felt-lo)); box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5); }
.hrow { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s2) var(--s3); }
.trow { display: flex; --w: var(--mini); }
.rbody { --mini: clamp(22px, 3.3vw, 34px); }
.trow .tile, .dts .tile { --w: var(--mini); }
.tile.mini { --w: var(--mini); }
.tile.winning { box-shadow: 0 calc(var(--w) * 0.075) 0 #a99b74, 0 0 0 2px var(--gold), 0 0 10px rgba(210, 171, 90, 0.7); }
.tile.sep { margin-left: var(--s1); }
.dgroup { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); }
.dlab { display: flex; align-items: center; gap: var(--s2); }
.dlab small { font-size: var(--f-1); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-soft); }
.dts { display: flex; gap: 2px; }
.yaku { display: grid; gap: 0; max-height: min(34vh, 220px); overflow-y: auto; border-top: 1px solid rgba(22, 20, 15, 0.18); }
.yaku li { display: flex; justify-content: space-between; gap: var(--s3); padding: 6px 2px; border-bottom: 1px solid rgba(22, 20, 15, 0.12); font-weight: 500; }
.yaku b { font-family: var(--mono); font-size: var(--f1); color: var(--verm); }
.note { color: var(--ink-soft); font-size: var(--f0); }
.score { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2) var(--s3); padding-top: var(--s1); }
.sc1 { display: flex; gap: var(--s2); }
.sc1 b { font: 600 var(--f3)/1 var(--disp); }
.lim { padding: 2px 10px; border-radius: 99px; background: var(--verm); color: #fff; font-weight: 700; font-size: var(--f0); letter-spacing: 0.06em; text-transform: uppercase; }
.val { margin-left: auto; display: grid; justify-items: end; line-height: 1.1; }
.val small { font-size: var(--f-1); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-soft); }
.val b { font: 600 var(--f4)/1.1 var(--disp); }
.deltas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s2); }
.dl { display: grid; gap: 0; padding: 6px var(--s2); border-radius: 10px; background: rgba(22, 20, 15, 0.06); border: 1px solid rgba(22, 20, 15, 0.1); min-width: 0; }
.dl.me { border-color: rgba(168, 133, 49, 0.8); background: rgba(210, 171, 90, 0.16); }
.dn { display: flex; align-items: center; gap: 6px; font-size: var(--f0); font-weight: 700; min-width: 0; }
.dn .wind { width: 18px; height: 18px; font-size: 11px; background: var(--ink); color: var(--ivory); }
.dv { font: 700 var(--f2)/1.2 var(--mono); }
.dl.up .dv { color: #1b7a43; }
.dl.down .dv { color: var(--verm); }
.ds2 { font: 500 var(--f0) var(--mono); color: var(--ink-soft); }
.tabs.small { max-width: 420px; border-color: rgba(22, 20, 15, 0.18); }
.tabs.small .tab { color: var(--ink-soft); }
.tabs.small .tab.on { color: var(--ink); border-bottom-color: var(--verm); }
.mfoot { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s5) var(--s3); }
.cd { flex: 1; height: 4px; border-radius: 2px; background: rgba(22, 20, 15, 0.12); overflow: hidden; }
.cd-bar { display: block; height: 100%; background: var(--verm); }
.cdtxt { font-size: var(--f0); color: var(--ink-soft); }
.mcard .btn { background: rgba(22, 20, 15, 0.07); border-color: rgba(22, 20, 15, 0.2); color: var(--ink); }
.mcard .btn:hover { background: rgba(22, 20, 15, 0.12); }
.mcard .btn.primary { background: var(--ink); border-color: var(--ink); color: var(--ivory); }
.mcard .btn.primary:hover { background: #2a261c; }
.dtext { font-size: var(--f2); color: var(--ink-soft); max-width: 60ch; }
.dhands { display: grid; gap: var(--s3); max-height: 34vh; overflow-y: auto; padding: var(--s2); border-radius: 12px; background: linear-gradient(var(--felt), var(--felt-lo)); }
.dhand { display: grid; gap: 4px; color: var(--text); min-width: 0; }
@media (orientation: landscape) { .dhands { grid-template-columns: repeat(2, minmax(0, 1fr)); --mini: clamp(14px, 2.15vw, 30px); } .dhands .dhand { gap: 2px; } }
.who { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }
.standings { display: grid; gap: var(--s2); }
.st { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-radius: 12px; background: rgba(22, 20, 15, 0.06); border: 1px solid rgba(22, 20, 15, 0.1); min-height: 48px; }
.st.me { border-color: rgba(168, 133, 49, 0.9); background: rgba(210, 171, 90, 0.18); }
.st .rk { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--ink); color: var(--ivory); font: 600 var(--f2) var(--disp); }
.st.r1 .rk { background: var(--gold); color: #1a1408; }
.sn { flex: 1; display: flex; align-items: center; gap: var(--s2); font-weight: 700; min-width: 0; }
.sn .wind { background: var(--ink); color: var(--ivory); width: 22px; height: 22px; font-size: 12px; }
.sp { font: 700 var(--f3) var(--mono); }
.facts { display: flex; flex-wrap: wrap; gap: var(--s2); }
body.modal-open .table .abar, body.modal-open .table .picker { visibility: hidden; }

/* ---------- short landscape phones ---------- */
@media (max-height: 460px) {
  .felt { margin: 4px 0 4px 4px; }
  .plate { padding: 2px 6px 2px 3px; }
  .info { padding: 1px 10px; gap: 0 12px; }
  .hints { bottom: calc(var(--hand-h) + 16px + env(safe-area-inset-bottom)); gap: 2px; padding: 4px 10px; }
  .rk { font-size: clamp(22px, calc(var(--rw) * 1.55), 40px); }
  .center { row-gap: 1px; }
  .claimnote { margin-bottom: 6px; padding: 2px 6px 2px 8px; gap: 5px; font-size: var(--f-1); }
  .claimnote .tile { --w: 16px; }
  .windwrap .wind { width: 20px; height: 20px; font-size: 12px; }
  .ctr b { font-size: var(--f0); }
  .winc, .drawc, .rbody.final { padding: var(--s3) var(--s4) var(--s2); gap: var(--s2); }
  .mtitle { font-size: var(--f3); }
  .mfoot { padding: 4px var(--s4) var(--s2); }
  .mcols { gap: var(--s4); }
  .yaku { max-height: 24vh; }
  .yaku li { padding: 3px 2px; }
  .dv { font-size: var(--f1); }
  .val b { font-size: var(--f3); }
  .dhands { max-height: 36vh; }
  .dtext { font-size: var(--f1); }
}

/* ---------- large desktop: scale the table up (kept late so it wins the cascade) ---------- */
@media (min-width: 1100px) and (min-height: 700px) {
  :root { --f-1: 12px; --f0: 14px; --f1: 16px; --f2: 18px; --f3: 22px; }
  .table {
    --tw: clamp(20px, min(11.6 * var(--vh), (var(--vw) - var(--rail) - 56px) / 15), 76px);
    --rw: clamp(11px, min((100 * var(--vh) - var(--hand-h) - var(--capow) * 1.34 - 322px) / 8, (var(--vw) - var(--rail) - 640px) / 8), 58px);
  }
  .windwrap .wind { width: 28px; height: 28px; font-size: 16px; }
  .plate.rel1, .plate.rel3 { width: 84px; }
  .plate.rel1 .pname, .plate.rel3 .pname { max-width: 78px; }
  .hints { width: 280px; }
  .pname { font-size: var(--f1); }
  .pscore { font-size: var(--f2); }
  .plate.rel1 .pname, .plate.rel3 .pname { font-size: var(--f0); }
  .plate.rel1 .pscore, .plate.rel3 .pscore { font-size: var(--f1); }
  .plate .wind { width: 28px; height: 28px; }
}

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

/* ---------- sakuga layer (M3). Transform and opacity only; positions come from the CSSOM, never inline attributes ---------- */
.tool.wide { width: auto; min-width: 44px; padding: 0 5px; }
#fx { position: fixed; inset: 0; z-index: 67; pointer-events: none; overflow: hidden; }
.fx-label, .fx-win {
  --c: var(--verm); position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; line-height: 1;
  font-family: "Dela Gothic One", var(--ui); font-weight: 400; will-change: transform, opacity; text-align: center;
}
.k-riichi, .k-ron { --c: var(--verm); }
.k-pon, .k-tsumo { --c: var(--gold); }
.k-chi { --c: #3fae78; }
.k-kan { --c: #5a6cc8; }
.fx-label .jp, .fx-win .jp {
  color: var(--ivory); -webkit-text-stroke: 0.1em var(--ink); paint-order: stroke fill; letter-spacing: 0.02em;
  text-shadow: 0.06em 0.07em 0 var(--c), 0.1em 0.12em 0 var(--ink);
}
.fx-label .jp, .fx-win .jp { white-space: nowrap; }
.fx-label .jp { font-size: clamp(34px, 13vmin, 84px); }
.fx-label .lat, .fx-win .lat {
  margin-top: 0.5em; padding: 3px 10px; border-radius: 99px; border: 2px solid var(--ink); background: var(--c); color: var(--ivory);
  font: 700 var(--f0)/1 var(--ui); letter-spacing: 0.22em; text-transform: uppercase; white-space: nowrap;
}
.k-pon .lat, .k-tsumo .lat { color: var(--ink); }
.fx-win .jp { font-size: clamp(64px, 30vmin, 190px); }
.fx-win .jp.lim { font-size: clamp(34px, 15vmin, 96px); margin-top: 0.12em; color: #ffe39a; -webkit-text-stroke-width: 0.045em; letter-spacing: 0.06em; text-shadow: 0.06em 0.07em 0 var(--verm), 0.1em 0.12em 0 var(--ink); }
.fx-win.t5 .jp.lim { font-size: clamp(44px, 20vmin, 124px); }
.fx-win .who { margin-top: 6px; font: 700 var(--f1)/1.2 var(--ui); color: var(--ivory); text-shadow: 0 1px 3px #000; max-width: 80vw; overflow-wrap: anywhere; }
.fx-flash { position: absolute; inset: 0; background: #fff; opacity: 0; }
.fx-dim { position: absolute; inset: 0; background: radial-gradient(circle at 50% 46%, rgba(10, 21, 17, 0.1), rgba(10, 21, 17, 0.72)); opacity: 0; }

body.fx-full .fx-label { animation: fx-slam 1.1s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
body.fx-full .fx-win { animation: fx-slam-win 1.6s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
body.fx-full .fx-win.limit { animation-duration: 1.9s; }
body.fx-full .fx-win.t5 { animation-duration: 2.3s; }
body.fx-full .fx-flash { animation: fx-flash 0.22s ease-out both; }
body.fx-full .fx-flash.hit { background: var(--ivory); animation-name: fx-flash-soft; }
body.fx-full .fx-flash.gold { background: var(--gold); animation-duration: 0.4s; }
body.fx-full .fx-dim { animation: fx-dim 1.6s ease-out both; }
body.fx-calm .fx-label, body.fx-calm .fx-win { animation: fx-fade 0.9s ease both; }
@keyframes fx-slam {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-8deg) scale(2.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(0.88); }
  22% { transform: translate(-50%, -50%) rotate(-4deg) scale(1.08); }
  34% { transform: translate(-50%, -50%) rotate(-4deg) scale(1); }
  76% { opacity: 1; transform: translate(-50%, -52%) rotate(-4deg) scale(1.02); }
  100% { opacity: 0; transform: translate(-50%, -58%) rotate(-4deg) scale(1.06); }
}
@keyframes fx-slam-win {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-7deg) scale(3); }
  9% { opacity: 1; transform: translate(-50%, -50%) rotate(-5deg) scale(0.86); }
  18% { transform: translate(-50%, -50%) rotate(-4deg) scale(1.1); }
  28% { transform: translate(-50%, -50%) rotate(-4deg) scale(1); }
  80% { opacity: 1; transform: translate(-50%, -51%) rotate(-4deg) scale(1.03); }
  100% { opacity: 0; transform: translate(-50%, -54%) rotate(-4deg) scale(1.08); }
}
@keyframes fx-fade { 0% { opacity: 0; } 22% { opacity: 1; } 72% { opacity: 1; } 100% { opacity: 0; } }
@keyframes fx-flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }
@keyframes fx-flash-soft { 0% { opacity: 0.4; } 100% { opacity: 0; } }
@keyframes fx-dim { 0% { opacity: 0; } 8% { opacity: 1; } 78% { opacity: 1; } 100% { opacity: 0; } }

body.fx-full .felt.fx-shake { animation: fx-shake 0.22s steps(2, end); }
body.fx-full .felt.fx-shake-big { animation: fx-shake-big 0.34s steps(2, end); }
@keyframes fx-shake { 0% { transform: translate(2px, -1px); } 25% { transform: translate(-2px, 1px); } 50% { transform: translate(1px, 1px); } 75% { transform: translate(-1px, -1px); } 100% { transform: none; } }
@keyframes fx-shake-big { 0% { transform: translate(5px, -3px); } 20% { transform: translate(-5px, 2px); } 40% { transform: translate(3px, 3px); } 60% { transform: translate(-3px, -2px); } 80% { transform: translate(1px, 1px); } 100% { transform: none; } }

/* riichi tile slams in sideways, the stick drops, the dora indicator flips */
body.fx-full .cell.side.fresh .tile { animation: fx-tile-slam 0.34s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
@keyframes fx-tile-slam {
  0% { opacity: 0.1; transform: translateY(-42px) rotate(90deg) scale(1.9); }
  62% { opacity: 1; transform: translateY(2px) rotate(90deg) scale(0.94); }
  100% { transform: rotate(90deg); }
}
body.fx-full .rstick.drop { animation: fx-stick 0.5s cubic-bezier(0.3, 1.5, 0.55, 1) both; }
@keyframes fx-stick { 0% { opacity: 0; transform: translateY(-46px) rotate(-30deg) scale(1.9); } 55% { opacity: 1; transform: translateY(2px) rotate(3deg) scale(1); } 100% { transform: none; } }
body.fx-full .ds.flip { perspective: 240px; }
body.fx-full .ds.flip .tile { animation: fx-flip 0.5s ease-out both; }
@keyframes fx-flip { 0% { transform: rotateY(90deg) scale(1.35); filter: brightness(1.7); } 100% { transform: none; filter: none; } }

/* own discard flick: a ghost tile flies from the hand to the pond while the real one lands */
.tile.fx-flick { position: fixed; margin: 0; z-index: 1; animation: fx-flick 0.26s cubic-bezier(0.3, 0, 0.7, 1) both; will-change: transform, opacity; }
@keyframes fx-flick { 0% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(-16deg) scale(0.8); } }

/* sakuga button reaction: squash while held, overshoot on release */
body.fx-full .abtn { transition: transform 0.14s cubic-bezier(0.3, 1.6, 0.5, 1); }
body.fx-full .abtn.sk-down { transform: scale(1.06, 0.8); transition-duration: 0.06s; }
body.fx-full .abtn.sk-pop { animation: fx-pop 0.42s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes fx-pop { 0% { transform: scale(0.84, 1.18); } 45% { transform: scale(1.08, 0.92); } 100% { transform: none; } }

/* turn timer, last 5 seconds: sakuga progress look (candy stripes, hard outline, bounce) */
body.fx-full .timer.low .tb { box-shadow: 0 0 0 2px var(--ink), 2px 3px 0 2px rgba(224, 85, 74, 0.6); animation: fx-bar 0.45s ease-in-out infinite alternate; }
body.fx-full .timer.low .tb-main { background: repeating-linear-gradient(-45deg, var(--verm-hi) 0 6px, #ffc2b5 6px 12px); }
@keyframes fx-bar { from { transform: scaleY(1.3); } to { transform: scaleY(1.9); } }

@media (prefers-reduced-motion: reduce) {
  /* the global rule above would end the label fade at once, so give the calm label its own time */
  body.fx-calm .fx-label, body.fx-calm .fx-win { animation-duration: 0.9s !important; }
}

/* ---------- M4: chat, reactions, full screen ---------- */
.chatbtn { position: relative; }
.chatbtn .badge { position: absolute; top: -5px; right: -5px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px; background: var(--verm); color: #fff; font: 700 11px/18px var(--mono); font-style: normal; text-align: center; pointer-events: none; box-shadow: 0 0 0 2px var(--night); }
.btn.lobbychat { display: inline-flex; align-items: center; gap: var(--s2); }

.chat-scrim { position: absolute; left: 0; right: 0; top: 0; bottom: var(--hand-h); z-index: 3; background: rgba(4, 10, 7, 0.28); }
.chat-scrim.in-lobby { position: fixed; inset: 0; z-index: 29; background: rgba(4, 10, 7, 0.45); }
.chatpanel {
  position: absolute; z-index: 30; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden;
  left: calc(env(safe-area-inset-left) + 6px); top: calc(env(safe-area-inset-top) + 6px);
  bottom: calc(var(--hand-h) + env(safe-area-inset-bottom) + 14px); width: min(340px, 44vw);
  background: rgba(10, 21, 17, 0.97); border: 1px solid rgba(210, 171, 90, 0.55); border-radius: 14px; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
  user-select: text; -webkit-user-select: text;
}
.chatpanel.in-lobby { position: fixed; z-index: 30; left: auto; top: auto; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); width: min(360px, calc(100vw - 24px)); height: min(440px, calc(100vh - 24px)); }
@supports (height: 1dvh) { .chatpanel.in-lobby { height: min(440px, calc(100dvh - 24px)); } }
.chat-head { display: flex; align-items: center; gap: 2px; padding: 0 4px 0 12px; border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; font: 700 var(--f1)/1 var(--ui); }
.chat-ico { width: 44px; height: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: var(--text); display: grid; place-items: center; }
.chat-ico[aria-pressed="true"] { background: rgba(210, 171, 90, 0.22); color: var(--gold); }
.chat-body { min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr); }
.chat-log, .chat-mutes { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 8px 10px; display: grid; gap: 6px; align-content: start; }
.chat-msg { font-size: var(--f1); line-height: 1.35; overflow-wrap: anywhere; }
.chat-msg .cn { color: var(--gold); margin-right: 6px; }
.chat-msg.me .cn { color: var(--jade); }
.chat-empty { color: var(--text-dim); font-size: var(--f0); padding: 6px 2px; }
.mute-row { width: 100%; min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.25); color: var(--text); }
.mute-row[aria-checked="true"] { border-color: var(--verm-hi); color: #f0a69d; }
.mute-row .ms { font-size: var(--f0); color: var(--text-dim); }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px; padding: 6px; border-top: 1px solid var(--line); }
.chat-in { min-width: 0; min-height: 44px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); color: var(--text); font-size: 16px; }
.chat-in::placeholder { color: var(--text-dim); }
.chat-count { font-size: var(--f-1); color: var(--text-dim); min-width: 5ch; text-align: right; }
.chat-send { min-width: 56px; min-height: 44px; padding: 0 12px; border-radius: 10px; border: 0; background: var(--gold); color: #1a1408; font-weight: 700; }

.reactpick {
  position: absolute; z-index: 25; top: calc(env(safe-area-inset-top) + 8px); right: calc(env(safe-area-inset-right) + var(--rail) + 8px);
  display: grid; grid-template-columns: repeat(4, 44px); gap: 4px; padding: 6px; border-radius: 14px;
  background: rgba(10, 21, 17, 0.96); border: 1px solid var(--gold); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.6);
}
.rbtn { width: 44px; height: 44px; padding: 0; border: 0; border-radius: 10px; background: rgba(255, 255, 255, 0.06); font-size: 24px; line-height: 1; display: grid; place-items: center; }
.rbtn:hover, .rbtn:active { background: rgba(210, 171, 90, 0.25); }

.fx-react { position: absolute; transform: translate(-50%, -50%); display: grid; justify-items: center; gap: 2px; pointer-events: none; animation: fx-react-fade 1.8s ease both; }
.fx-react .em { font-size: clamp(28px, 9vmin, 52px); line-height: 1; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5)); }
.fx-react .who { max-width: 12ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 3px 7px; border-radius: 99px; background: var(--glass); color: var(--ivory); font: 700 var(--f-1)/1 var(--ui); }
body.fx-full .fx-react { animation: fx-react-pop 1.8s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes fx-react-fade { 0% { opacity: 0; } 15% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes fx-react-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.25); }
  22% { transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -64%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -90%) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  body .fx-react { animation: fx-react-fade 1.8s ease both !important; }
}

.tool.fsbtn { padding: 0 2px; }
.tool.fsbtn span, .tool.wide span { white-space: nowrap; }
.tool.fsbtn span { font-size: 10px; }

/* ---------- M4: landscape fills the screen edge to edge ---------- */
@media (orientation: landscape) {
  .felt { margin: 0; border-radius: 0 12px 12px 0; }
  .toprow { padding-top: 1px; }
  .bottom { padding-bottom: calc(var(--tw) * 0.1); }
}
@media (orientation: landscape) and (max-height: 440px) {
  .table {
    --tw: clamp(20px, max(min(11.6 * var(--vh), (var(--vw) - var(--rail) - 24px) / 14.4), min(44px, (var(--vw) - var(--rail) - 24px) / 14.4)), 66px);
    --hand-h: calc(var(--tw) * 1.3334 + 24px);
    --capow: calc((100 * var(--vh) - var(--hand-h) - 14px) / 15.4);
    --ow: calc(min(var(--rw), var(--capow))); /* a full 13-tile side hand then fits between the top row and the hand with a few px to spare */
    --rw: clamp(11px, min((100 * var(--vh) - var(--hand-h) - var(--capow) * 1.34 - 142px) / 8, (var(--vw) - var(--rail) - 520px) / 8), 40px);
  }
  .handrow { padding-top: 8px; min-height: 0; gap: 0; }
  .mymelds:not(:empty) { margin-left: 12px; }
  .bottom { padding-left: 4px; padding-right: 4px; }
  .tools { gap: 3px; padding: 4px; }
  /* the top player's plate sits beside their wall, the info strip is one line: the centre column then fits */
  .midwrap { position: static; }
  .plate.rel2 { position: absolute; top: 2px; right: calc(50% + var(--ow) * 8.2 + 6px); z-index: 2; }
  .midrow { grid-row: 2; }
  .plate.rel0 { grid-row: 3; }
  .info { grid-template-columns: auto auto auto; gap: 0 12px; padding: 1px 10px; }
  .round { grid-row: auto; }
  .dora { grid-column: auto; }
}
@media (orientation: landscape) and (max-height: 349px) {
  .codechip { display: none; }
  .table { --rw: clamp(11px, min((100 * var(--vh) - var(--hand-h) - var(--capow) * 1.34 - 134px) / 8, (var(--vw) - var(--rail) - 520px) / 8), 40px); }
}

/* the chat input moves to the top of the drawer on short landscape screens, so a soft keyboard does not hide it */
@media (orientation: landscape) and (max-height: 460px) {
  .chatpanel:not(.in-lobby) { grid-template-rows: auto auto minmax(0, 1fr); }
  .chatpanel:not(.in-lobby) .chat-form { grid-row: 2; border-top: 0; border-bottom: 1px solid var(--line); }
  .chatpanel:not(.in-lobby) .chat-body { grid-row: 3; }
}

/* short landscape phones: the action bar is ONE row to the right of the player's own pond (never over plates, centre info or the
   hint strip), and the hint strip stops before that pond; the claimed tile is already lit in the pond, so the note is dropped */
@media (orientation: landscape) and (max-height: 460px) {
  .abar { max-width: none; right: calc(var(--rail) + var(--flank) - 8px + env(safe-area-inset-right)); bottom: calc(var(--hand-h) + 16px + env(safe-area-inset-bottom)); }
  .abar .claimnote { display: none; }
  .tile.hand.sel { transform: translateY(calc(var(--tw) * -0.24)); } /* a picked tile rises into the timer bar by 2px at 932x430 with the full lift */
  .abar .actions { flex-wrap: nowrap; gap: 2px; max-width: none; }
  .abar .abtn { flex: 0 0 auto; min-width: 44px; min-height: 46px; padding: 0 2px; }
  .abar .abtn.win { min-width: 44px; }
  .abar .abtn .al { font-size: var(--f0); white-space: nowrap; }
  .hints { width: min(236px, 34vw, calc((var(--vw) - var(--rail)) / 2 - var(--rw) * 3.9 - var(--flank) - 18px)); }
  .hints .hnote { display: none; } /* M4.1: the one-line shanten stays, the long tip sentence would run under the bigger side pond */
}
/* narrow ones (iPhone SE, Galaxy S8, a notched phone whose safe areas eat the width): when the middle column is too narrow for a
   one-line info strip between the side plates, the strip stacks in two rows; the top plate may not run past the left edge */
.midrow { container-type: inline-size; }
@media (orientation: landscape) and (max-height: 440px) {
  .plate.rel2 { top: 0; max-width: calc(50% - var(--ow) * 8.2 - 10px); overflow: hidden; }
  @container (max-width: 450px) {
    .info { grid-template-columns: auto auto; gap: 1px 8px; padding: 1px 8px; }
    .round { grid-row: 1 / 3; }
    .dora { grid-column: 2; }
    .counters { gap: 8px; }
    .ctr { display: flex; align-items: baseline; gap: 3px; }
  }
}
@media (orientation: landscape) and (max-height: 440px) and (max-width: 700px) {
  .abar { right: calc(var(--rail) + var(--flank) - 9px + env(safe-area-inset-right)); }
  .abar .actions { gap: 1px; }
  .abar .abtn .al { font-size: var(--f-1); }
}

/* ---------- portrait phones: a first-class layout ----------
   Top to bottom: tools rail, the table (ponds, plates, centre info), a hint strip, one action row, the hand in two rows of seven.
   Sizes come from the width first and are then capped by the height that is really left, so a tall phone gets bigger ponds and a
   short one (iPhone SE) a smaller table, never a blank band. */
@media (orientation: portrait) and (max-width: 820px) {
  :root { --head: 48px; }
  .table {
    --rail: 0px;
    --tw: clamp(32px, min((100vw - 30px) / 7 - 1px, 6.6 * var(--vh)), 56px); /* 7 tiles + the 10px drawn gap fit the felt (4px margin) and the hand padding (6px) at every width, 320 included */
    --mw: calc(var(--tw) * 0.5);
    --hand-h: calc(var(--tw) * 2.6668 + 51px);
    --stack: 8px; /* nothing on offer: only a small gap above the timer, the cluster takes all the rest of the height */
    --avail: calc(100 * var(--vh) - var(--head) - var(--hand-h) - var(--stack) - 8px);
    --ow: clamp(9px, min(3.1vw, calc(var(--avail) / 35)), 14px);
    --flank: calc(var(--ow) * 1.4 + 6px);
    --cw: 112px; /* centre panel column */
    --dw: clamp(14px, min(var(--rw) * 0.9, calc((var(--cw) - 10px) / 5)), 22px); /* dora tile */
    --rw-w: calc(((100vw - 8px - 2 * var(--flank) - var(--cw)) / 2 - 8px) / 4); /* a side pond is 3 rows deep (8 tiles a row) */
    --rw-h: calc((var(--avail) - 175px) / 16.1); /* top + bottom pond 3 rows each, side pond 8 tiles tall, plates and gaps */
    --rw: clamp(9px, min(var(--rw-w), var(--rw-h)), 30px);
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--head) minmax(0, 1fr);
  }
  .table.hinting { --stack: 40px; } /* the hint strip (about 32px) sits right above the timer */
  /* an action (or the rotate hint) opens its row between the hint strip and the hand: one action row (52px) plus its gaps */
  .table.hasact, .table.rot { --stack: 62px; }
  .table.hinting.hasact, .table.hinting.rot { --stack: 94px; }
  .tools { grid-column: 1; grid-row: 1; flex-direction: row; justify-content: flex-end; align-items: center; gap: 4px; padding: 2px 6px; }
  .codechip { padding: 0 4px; margin-right: auto; }
  .tool.wide { width: 44px; min-width: 44px; padding: 0; }
  .tool.wide span { display: none; } /* portrait: the icon alone, the label stays in aria */
  .felt { grid-column: 1; grid-row: 2; margin: 0 4px 4px; }
  .midwrap { margin-bottom: var(--stack); }
  .flank { padding: 0 1px; }
  .toprow { padding-top: 3px; }

  /* the hand: 7 tiles a row, two rows, the drawn tile set apart at the end; melds follow in the same flow */
  .bottom { padding: 2px 6px 6px; }
  .handrow { display: flex; flex-wrap: wrap; align-content: flex-end; align-items: flex-end; justify-content: flex-start; gap: 3px 1px;
    width: calc(7 * (var(--tw) + 1px) + 10px); max-width: 100%; margin: 0 auto; padding-top: 14px; min-height: calc(var(--tw) * 2.6668 + 17px); }
  .handbox { display: contents; }
  .tile.hand { --w: var(--tw); }
  .tile.hand.drawn { margin-left: 10px; }
  .mymelds { flex-wrap: wrap; align-items: flex-end; gap: 4px 8px; max-width: 100%; margin-left: 8px; }

  /* the cluster is one grid: plates, ponds and the info panel each get a cell, any spare height is spread between the rows */
  .center, .midrow { display: contents; }
  .cluster { grid-template-rows: repeat(6, auto); row-gap: 2px; align-content: space-evenly; padding: 0; }
  .plate.rel2 { grid-area: 1 / 1 / 2 / 4; }
  .pond.r2 { grid-area: 2 / 1 / 3 / 4; }
  .pond.r3 { grid-area: 3 / 1; }
  .info { grid-area: 3 / 2; }
  .pond.r1 { grid-area: 3 / 3; }
  .plate.rel3 { grid-area: 4 / 1; }
  .plate.rel1 { grid-area: 4 / 3; }
  .pond.r0 { grid-area: 5 / 1 / 6 / 4; }
  .plate.rel0 { grid-area: 6 / 1 / 7 / 4; }
  .plate.rel1, .plate.rel3 { width: 64px; padding: 4px 2px; }
  .plate.rel1 .pname, .plate.rel3 .pname { max-width: 58px; }
  .plate.rel1:not(.off) .pstat, .plate.rel3:not(.off) .pstat { display: none; }
  .plate.rel0 .pname { max-width: 18ch; }
  .plate.rel0, .plate.rel2 { max-width: none; padding-top: 2px; padding-bottom: 2px; }
  .oh-in .meld { --w: var(--ow); }
  .pond-in { box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.13); border-radius: 4px; background: rgba(0, 0, 0, 0.13); } /* a faint discard area, so an empty pond still reads as a place on the table */
  .info { grid-template-columns: auto; justify-items: center; gap: 2px; max-width: 100%; padding: 4px 6px; }
  .round, .dora { grid-column: 1; grid-row: auto; }
  .dora { --w: var(--dw); flex-direction: column; gap: 2px; }
  .ds .tile { --w: var(--dw); }
  .rk { font-size: clamp(22px, calc(var(--rw) * 1.7), 40px); }
  .counters { gap: 8px; }
  .rbody { --mini: clamp(18px, 5.4vw, 30px); }
  .mcols { grid-template-columns: 1fr; gap: var(--s3); }
  .deltas { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* hint strip above the action row, action row above the hand: fixed rows, so nothing moves when a button appears */
  .abar { left: 6px; right: 6px; bottom: calc(var(--hand-h) + 4px + env(safe-area-inset-bottom)); max-width: none; height: 52px; flex-direction: row; align-items: stretch; justify-content: flex-end; gap: 6px; }
  .abar .actions.empty { display: none; }
  .abar .actions { flex: 1; min-width: 0; flex-wrap: nowrap; flex-direction: row-reverse; justify-content: flex-start; gap: 6px; max-width: none; }
  .abar .abtn { flex: 1 1 0; min-width: 44px; min-height: 52px; padding: 0 4px; }
  .abar .abtn.win { min-width: 44px; flex-grow: 1.4; }
  .abar .abtn .al { font-size: var(--f1); white-space: nowrap; }
  .claimnote { margin: 0; align-self: center; padding: 3px 8px; }
  .claimnote > span { display: none; }
  .claimnote .tile { --w: 22px; }
  .hints {
    left: 6px; right: 6px; width: auto; top: auto; bottom: calc(var(--hand-h) + 4px + env(safe-area-inset-bottom));
    display: flex; flex-wrap: nowrap; align-items: center; gap: 2px 12px; padding: 2px 10px; min-height: 28px; overflow: hidden; border-radius: 10px;
  }
  .table.hasact .hints, .table.rot .hints { bottom: calc(var(--hand-h) + 60px + env(safe-area-inset-bottom)); }
  .hints .hh { gap: 8px; }
  .hints .hnote { display: none; }
  .hints .waits { flex-wrap: nowrap; }
  .hints .wt .tile { --w: 16px; }
  .picker { left: 6px; right: 6px; bottom: calc(var(--hand-h) + 4px + env(safe-area-inset-bottom)); max-width: none; }

  /* the once-only landscape hint takes the action row while no action is on offer */
  .rotslot { display: flex; flex: 1; min-width: 0; align-items: center; pointer-events: auto; }
  .rotslot[hidden], .table.hasact .rotslot { display: none; }
  .rotcard { width: 100%; gap: 8px; padding: 0 2px 0 10px; height: 52px; border-radius: 12px; box-shadow: none; }
  .rotcard .ico { width: 22px; height: 22px; flex: none; }
  .rottext { font-size: 12px; line-height: 1.25; }
  .rottext b { font-size: 13px; }
  .rotclose { flex: none; width: 44px; height: 44px; border-radius: 10px; border: 0; background: transparent; color: var(--text); display: grid; place-items: center; padding: 0; }
  .rotclose .ico { width: 18px; height: 18px; color: var(--text); }

  /* chat and reactions may cover the opponents' area, never the hand, the hint strip or the action row */
  .chat-scrim { bottom: calc(var(--hand-h) + var(--stack)); }
  .chatpanel:not(.in-lobby) { left: 6px; right: 6px; width: auto; top: calc(env(safe-area-inset-top) + var(--head) + 4px); bottom: calc(var(--hand-h) + var(--stack) + 4px); }
  .reactpick { top: calc(env(safe-area-inset-top) + var(--head) + 4px); right: 8px; }
}
/* a soft keyboard (or a very short screen) leaves no room for the table, so the open chat takes the whole height */
@media (orientation: portrait) and (max-width: 820px) and (max-height: 560px) {
  .chat-scrim { bottom: 0; }
  .chatpanel:not(.in-lobby) { bottom: calc(env(safe-area-inset-bottom) + 6px); }
}

/* soft keyboard on iOS and on Chrome for Android (both shrink only the visual viewport): script sets --kb and the html.kb class, the open chat sits above the keyboard */
html.kb .chat-scrim { bottom: 0; }
html.kb .chatpanel:not(.in-lobby) { bottom: calc(var(--kb, 0px) + 6px); }
html.kb .chatpanel.in-lobby { bottom: calc(var(--kb, 0px) + 12px); height: min(440px, calc(100dvh - var(--kb, 0px) - 24px)); }

/* ---------- sound button (M4.2) ----------
   The speaker button is the 7th tool, so it is kept small where the rail is already full. Portrait: icon only, 36px wide, and on phones up to
   400px wide the rail gap and the code chip padding shrink a little, so the other tools keep the width they had before this button.
   Short landscape (320-340px high): the button is icon only and 34px high, and the rail gap is 2px, so all seven tools fit without scrolling. */
@media (orientation: portrait) and (max-width: 820px) {
  .tool.sfxbtn { width: 36px; min-width: 36px; flex: none; }
}
@media (orientation: portrait) and (max-width: 400px) {
  .tools { gap: 2px; padding: 2px 4px; }
  .codechip { padding: 0 2px; }
}
@media (orientation: portrait) and (max-width: 340px) {
  .codechip { display: none; } /* 320px wide: the room code (also in the URL and the lobby) gives its room to the seven tools, which keep full 44px taps */
}
@media (orientation: landscape) and (max-height: 340px) {
  .tools { gap: 2px; }
  .tool.sfxbtn { min-height: 34px; }
  .tool.sfxbtn span { display: none; }
}

/* ---------- M4.3: assist strip that cannot grow, and a timer row that keeps its height ----------
   1. The timer row used to vanish (hidden = display none) while it was not the player's turn. The hint strip and the action row are
      anchored to --hand-h, which counts the timer row, but the table cluster is measured from the real bottom block. Without the timer
      the bottom block is one row shorter, so the cluster dropped about 16-25px onto the hint strip (own pill half under BANTUAN on a
      Galaxy S9, and pill over the hints on short landscape). The row now stays in the layout and is only invisible. */
.timer[hidden] { display: flex !important; visibility: hidden; }

/* 2. The long furiten sentence made the strip three or four lines tall (over ponds, plates and the own pill). The label stays, the
      sentence moves to the title, and the strip is a short fixed block on small screens. */
@media (orientation: landscape) and (max-height: 460px) {
  .hints { display: flex; flex-wrap: wrap; align-items: center; align-content: center; gap: 1px 8px; padding: 3px 8px; overflow: hidden; }
  .hints .hh { gap: 6px; }
  .hints .fx { display: none; }
  .hints .furiten { font-size: var(--f-1); gap: 3px; }
  .hints .furiten .ico { width: 13px; height: 13px; }
  .hints .wt .tile { --w: 15px; }
  .hints .waits { gap: 0 6px; }
}
@media (orientation: portrait) and (max-width: 820px) {
  .hints .fx { display: none; }
  .hints .furiten { flex: none; white-space: nowrap; font-size: var(--f-1); gap: 3px; }
  .hints .hh, .hints .waits { flex: none; }
  .hints .waits small { display: none; }
}

/* 3. Very short landscape (320px high): the own pill sat 6-7px into the action row at 658x320 and 568x320. It rises 10px; the free band
      under the centre info is 25px or more, so nothing else moves. On narrow screens the strip stops 16px earlier, so it ends before the pill. */
@media (orientation: landscape) and (max-height: 349px) {
  .plate.rel0 { position: relative; top: -10px; }
}
@media (orientation: landscape) and (max-height: 460px) and (max-width: 700px) {
  .hints.big { width: min(236px, 34vw, calc((var(--vw) - var(--rail)) / 2 - var(--rw) * 3.9 - var(--flank) - 34px)); }
  .hints.big .waits small { display: none; }
  .hints .wt .tile { --w: 14px; }
}

@media (orientation: portrait) and (max-width: 380px) {
  .hints { gap: 2px 8px; padding: 2px 8px; }
  .hints .waits { gap: 2px 6px; }
}
@media (orientation: landscape) and (max-height: 349px) {
  .hints { padding: 2px 8px; gap: 0 6px; }
  .hints .wt .tile { --w: 13px; }
}

/* 4. Short landscape showed no tip for the picked tile (the whole note was display:none). It comes back as one line that cuts off with
      an ellipsis, so it can never grow the strip; on short screens it is dropped while the strip already has waits or a warning. */
.hnote .hn-short { display: none; }
@media (orientation: landscape) and (max-height: 460px) {
  .hints .hnote { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: var(--f-1); line-height: 1.25; }
  .hints .hnote .hn-long { display: none; }
  .hints .hnote .hn-short { display: inline; }
}
@media (orientation: landscape) and (max-height: 460px) {
  .hints.big .hnote { display: none; }
}
