/* Layout: one centered column — woven tilet band on top. Setup is a stack of compact sections;
   the game is a single screen: game bar, scoreboard, word strip, the letter stage, and an action dock.
   On phones the game fills the viewport exactly and the dock sits under the thumb. Single night-stage theme. */
:root {
  --night: #12142a;
  --panel: #1c1f3a;
  --panel-2: #262a4d;
  --line: #363b68;
  --cream: #f4eee3;
  --muted: #a4a6c6;
  --p1: #f5b43c;      /* saffron */
  --p2: #63c9e4;      /* highland sky */
  --good: #4fcf8e;
  --bad: #f2604f;
  --tilet-red: #c93a2a;
  --tilet-green: #2f9d62;
  --pc: var(--p1);    /* active player colour, set from JS */

  --display: "Big Shoulders Display", "Noto Sans Ethiopic", Impact, "Arial Narrow", sans-serif;
  --body: "Figtree", "Noto Sans Ethiopic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --eth: "Noto Sans Ethiopic", "Abyssinica SIL", "Nyala", "Kefa", sans-serif;

  --radius: 14px;
  --tilet-h: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--pc) 10%, transparent), transparent 70%),
    var(--night);
  color: var(--cream);
  font: 16px/1.5 var(--body);
  -webkit-tap-highlight-color: transparent;
}
.am, [lang="am"] { font-family: var(--eth); }
button, input { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--pc); outline-offset: 3px; }
svg { flex: none; }

/* woven border band, like the edge of a netela */
.tilet {
  height: var(--tilet-h);
  background:
    linear-gradient(135deg, var(--night) 25%, transparent 25%) -9px 0/18px 18px,
    linear-gradient(225deg, var(--night) 25%, transparent 25%) -9px 0/18px 18px,
    linear-gradient(315deg, var(--night) 25%, transparent 25%) 0 0/18px 18px,
    linear-gradient(45deg, var(--night) 25%, transparent 25%) 0 0/18px 18px,
    linear-gradient(90deg, var(--tilet-green) 0 33%, var(--p1) 33% 66%, var(--tilet-red) 66%) 0 0/54px 18px;
  border-bottom: 3px solid var(--p1);
}

.wrap {
  max-width: 760px;
  margin: 0 auto;
  padding-inline: 16px;
  padding-block: 20px 48px;
  display: grid;
  gap: 24px;
}

/* ---------- masthead ---------- */
.masthead { display: grid; gap: 4px; }
.logo {
  margin: 0;
  font: 900 clamp(44px, 9vw, 72px)/0.9 var(--display);
  letter-spacing: .01em;
  text-transform: uppercase;
}
.logo span { color: var(--p1); }
.logo small { font: 700 .45em/1 var(--eth); color: var(--muted); vertical-align: .35em; margin-left: .2em; }
.tagline { margin: 0; color: var(--muted); max-width: 52ch; text-wrap: balance; }
.appbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.appbar:not(:has(> :not([hidden]):not(:empty))) { display: none; }
.appbar .muted { margin: 0; font-size: 13px; }

.label {
  margin: 0;
  font: 700 12px/1 var(--body);
  text-transform: uppercase;
  letter-spacing: .14em;
  color: var(--muted);
}
.muted { color: var(--muted); }
.note, .hint { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--cream);
  padding: 10px 18px; border-radius: 10px; cursor: pointer; font-weight: 700;
  transition: transform .1s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.start {
  background: var(--p1); color: var(--night); border: 0;
  font: 900 26px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  padding: 16px 28px;
}
.btn.good { background: var(--good); color: var(--night); border: 0; }
.btn.bad { background: var(--bad); color: var(--night); border: 0; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
label.btn { display: inline-block; }
.iconbtn { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; }
.iconbtn svg, .linkbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.linkbtn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; cursor: pointer;
  color: var(--p1); font-weight: 700; font-size: 14px; padding: 6px 2px;
}
.linkbtn svg { width: 17px; height: 17px; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  border: 0; background: none; padding: 8px 16px; border-radius: 7px; cursor: pointer; font-weight: 600; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.seg button[aria-pressed="true"] { background: var(--p1); color: var(--night); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1; }

/* ---------- setup ---------- */
.setup { display: grid; gap: 26px; }
.sec { display: grid; gap: 12px; scroll-margin-top: 16px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.pfield {
  min-width: 0;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; cursor: text;
}
.pfield input { background: none; border: 0; outline: none; width: 100%; font-weight: 700; font-size: 17px; min-width: 0; color: var(--cream); }
.pfield:focus-within { border-color: currentColor; }
.p1 { color: var(--p1); }
.p2 { color: var(--p2); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; flex: none; }
.vs { font: 900 20px var(--display); color: var(--muted); text-transform: uppercase; }

.topics { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.topic {
  text-align: left; cursor: pointer; position: relative;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; align-content: start; gap: 4px; min-width: 0; min-height: 84px;
  transition: border-color .15s, transform .15s;
}
.topic:hover { border-color: var(--muted); }
.topic:active { transform: scale(.98); }
.topic[aria-pressed="true"] { border-color: var(--p1); box-shadow: inset 0 0 0 1px var(--p1); }
.topic[aria-pressed="true"]::after {
  content: ""; position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--p1) no-repeat center/12px
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2312142a' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E");
}
.topic .tname { font: 900 24px/1.05 var(--display); text-transform: uppercase; letter-spacing: .02em; padding-right: 22px; text-wrap: balance; overflow-wrap: anywhere; }
.topic .tname.am { font: 700 19px/1.25 var(--eth); text-transform: none; }
.topic .tmeta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; column-gap: 6px; min-width: 0; }
.topic .tsample { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; max-width: 100%; }
.topic .tsample::before { content: "· "; }
.topic.custom .tcount { color: var(--p2); }
.topic.new { border-style: dashed; background: transparent; align-content: center; }
.topic.new .tname { color: var(--p1); }

/* options: one card of rows */
.options { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.opt-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: default;
}
label.opt-row { cursor: pointer; }
.opt-text { display: grid; gap: 1px; min-width: 0; }
.opt-name { font-weight: 700; }
.opt-sub { font-size: 13px; color: var(--muted); }
.opt-row .seg { flex: none; }
.opt-row .seg button { padding: 7px 12px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; margin: 0; cursor: pointer;
  width: 46px; height: 28px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line);
  position: relative; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.switch:checked { background: var(--p1); border-color: var(--p1); }
.switch:checked::after { transform: translateX(18px); background: var(--night); }
.opt-voice { padding: 12px 14px; display: grid; gap: 10px; }
.voice-status { margin: 0; font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.voice-status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; transform: translateY(-1px); }
.voice-status.ok::before { background: var(--good); }
.voice-status.warn::before { background: var(--p1); }
.voice-status.bad::before { background: var(--bad); }
.miccheck { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* how to play */
.howto-wrap summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.howto-wrap summary::-webkit-details-marker { display: none; }
.howto-wrap summary::after { content: "+"; font: 700 22px/1 var(--body); color: var(--p1); }
.howto-wrap[open] summary::after { content: "–"; }
.howto {
  margin: 0; padding: 14px 16px 14px 36px;
  background: var(--panel); border-radius: var(--radius); border: 1px dashed var(--line);
  display: grid; gap: 6px; color: var(--muted); font-size: 15px;
}
.howto li::marker { color: var(--p1); font-weight: 700; }

.startrow { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.start-msg { margin: 0; color: var(--bad); font-weight: 600; flex: 1 1 240px; min-width: 0; }
.start-msg:empty { display: none; }

/* ---------- game ---------- */
.game { display: flex; flex-direction: column; gap: 12px; }
.gamebar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.gb-mid { display: grid; justify-items: center; text-align: center; min-width: 0; line-height: 1.2; }
.gb-topic { font: 900 20px/1.1 var(--display); text-transform: uppercase; letter-spacing: .03em; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gb-topic.am { font: 700 17px/1.3 var(--eth); text-transform: none; }
.gb-round { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#soundBtn { padding-inline: 10px; }
#soundBtn .off { display: none; }
#soundBtn[aria-pressed="false"] .on { display: none; }
#soundBtn[aria-pressed="false"] .off { display: inline; }
#soundBtn[aria-pressed="false"] { color: var(--muted); }

.board { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pcard {
  background: var(--panel); border: 2px solid transparent; border-radius: var(--radius);
  padding: 10px 14px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px;
  transition: border-color .3s, opacity .3s; opacity: .6; min-width: 0;
}
.pcard.active { border-color: currentColor; opacity: 1; }
.pname { font-weight: 700; color: var(--cream); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pscore { font: 900 32px/1 var(--display); font-variant-numeric: tabular-nums; grid-row: span 2; text-align: right; }
.plives { display: flex; gap: 3px; }
.plives svg { width: 16px; height: 16px; }
.plives .lost { opacity: .18; }
.pstreak { grid-column: 1 / -1; font-size: 12px; color: var(--muted); min-height: 1.4em; line-height: 1.4; }
.pcard.hit { animation: shake .4s; }
@keyframes shake { 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }

/* words played: one scrolling line, newest first */
.trail {
  list-style: none; margin: 0; padding: 0 0 2px; display: flex; gap: 6px; min-height: 30px;
  overflow-x: auto; scrollbar-width: none;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.trail::-webkit-scrollbar { display: none; }
.trail li {
  flex: none; font-size: 14px; font-weight: 600; padding: 3px 10px; border-radius: 99px;
  border: 1px solid currentColor; display: inline-flex; gap: 6px; align-items: baseline; white-space: nowrap;
}
.trail li b { font: 900 15px var(--display); text-transform: uppercase; }
.trail li.am b { font: 700 14px var(--eth); }
.trail li.miss { color: var(--muted); text-decoration: line-through; border-style: dashed; }
.trail li .w { color: var(--cream); }
.trail li.trail-empty { border: 0; padding: 3px 0; color: var(--muted); font-weight: 400; }

.stage {
  background: var(--panel); border-radius: 18px; padding: 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border-top: 4px solid var(--pc); transition: border-color .4s, background-color .4s;
  min-height: 0;
}
.turnline { font: 900 28px/1 var(--display); text-transform: uppercase; color: var(--pc); text-align: center; text-wrap: balance; }

.ring-wrap { position: relative; width: min(240px, 70vw); aspect-ratio: 1; max-width: 100%; flex: none; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring-bg { stroke: var(--panel-2); }
.ring-fg { stroke: var(--pc); stroke-linecap: round; stroke-dasharray: 628.32; stroke-dashoffset: 0; transition: stroke .3s; }
.ring-wrap.danger .ring-fg { stroke: var(--bad); }
.letter {
  position: absolute; inset: 0; display: grid; place-items: center;
  font: 900 clamp(72px, 22vw, 128px)/1 var(--display);
  text-transform: uppercase; color: var(--cream);
}
.letter.am { font: 900 clamp(64px, 18vw, 108px)/1 var(--eth); }
.letter.spin { color: var(--muted); }
.letter.land { animation: land .45s cubic-bezier(.2,1.6,.4,1); }
@keyframes land { from { transform: scale(.6); } to { transform: scale(1); } }
.secs {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  font: 700 15px var(--body); color: var(--muted); font-variant-numeric: tabular-nums;
}
.ring-wrap.danger .secs { color: var(--bad); }
.family { font-size: 20px; letter-spacing: .3em; color: var(--muted); min-height: 1.4em; text-align: center; }
.family:empty { display: none; }

/* fixed-height message area so nothing below it moves */
.status { display: grid; align-content: center; justify-items: center; gap: 4px; min-height: 92px; width: 100%; text-align: center; }
.heard { font-size: 19px; font-weight: 600; max-width: 100%; overflow-wrap: anywhere; }
.heard:empty { display: none; }
.heard.interim { color: var(--muted); font-style: italic; }
.feedback { font-weight: 600; max-width: 40ch; text-wrap: balance; font-size: 15px; }
.feedback:empty { display: none; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback.warn { color: var(--p1); }
.feedback .big { display: block; font: 900 40px/1.05 var(--display); text-transform: uppercase; }
.feedback .big.am { font: 900 34px/1.2 var(--eth); text-transform: none; }

/* flashes tint the stage instead of glowing outside it */
.stage.flash-good { animation: fgood .8s; }
.stage.flash-bad { animation: fbad .8s; }
@keyframes fgood { 0% { background-color: color-mix(in srgb, var(--good) 30%, var(--panel)); } 100% { background-color: var(--panel); } }
@keyframes fbad { 0% { background-color: color-mix(in srgb, var(--bad) 30%, var(--panel)); } 100% { background-color: var(--panel); } }

/* ---------- action dock ---------- */
.dock { display: grid; gap: 10px; }
.listen { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; color: var(--muted); font-size: 14px; min-height: 21px; }
.micdot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.listen.on .micdot { background: var(--bad); animation: pulse 1.1s infinite; }
.listen.on { color: var(--cream); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--bad) 70%, transparent); } 100% { box-shadow: 0 0 0 12px transparent; } }

.actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.act {
  display: grid; justify-items: center; gap: 4px; padding: 8px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-weight: 700; font-size: 13px; border-radius: 12px;
}
.act svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.act:hover, .act[aria-pressed="true"] { color: var(--cream); background: var(--panel); }
.act:active { transform: scale(.95); }
.micbtn {
  width: 76px; height: 76px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center;
  background: var(--pc); color: var(--night); box-shadow: 0 6px 20px color-mix(in srgb, var(--pc) 35%, transparent);
  transition: background .3s, transform .1s;
}
.micbtn svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.micbtn:active { transform: scale(.94); }
.micbtn.live { animation: micpulse 1.4s infinite; }
.micbtn.off { background: var(--panel-2); color: var(--muted); box-shadow: none; }
@keyframes micpulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--pc) 60%, transparent); } 100% { box-shadow: 0 0 0 18px transparent; } }

.typebox { display: flex; gap: 8px; width: 100%; }
.typebox input {
  flex: 1; min-width: 0; background: var(--night); border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font-size: 16px; /* 16px stops iOS zooming in on focus */
}
.typebox input:focus { outline: none; border-color: var(--pc); }

.judge {
  background: var(--panel-2); border: 1px solid var(--p1); border-radius: var(--radius);
  padding: 14px; text-align: center; display: grid; gap: 12px;
}
.judge p { margin: 0; }
.judge-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.judge-btns .btn { padding: 14px; font-size: 17px; }
.remember { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; color: var(--muted); cursor: pointer; }
.remember input { accent-color: var(--p1); width: 18px; height: 18px; }
.dock.judging .actions, .dock.judging .typebox, .dock.judging .listen { display: none; }
.dock:has(.typebox:not([hidden])) .listen { display: none; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--night) 82%, transparent); backdrop-filter: blur(6px);
}
.overlay canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sheet {
  position: relative; background: var(--panel); border-radius: 18px; padding: 26px 22px; width: min(460px, 100%);
  display: grid; gap: 14px; text-align: center; border-top: 4px solid var(--pc);
}
.sheet h2 { margin: 0; font: 900 44px/1 var(--display); text-transform: uppercase; color: var(--pc); text-wrap: balance; }
.sheet .muted, .sheet .hint { margin: 0; }
.sheet-btns { display: grid; gap: 10px; }
.sheet-btns .btn { width: 100%; }
.final { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.final > div { background: var(--panel-2); border-radius: 12px; padding: 12px; min-width: 0; }
.final .fs { font: 900 32px/1 var(--display); font-variant-numeric: tabular-nums; }
.final .fn { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.final .fx { font-size: 13px; color: var(--muted); }

/* word editor */
.sheet.editor { text-align: left; width: min(560px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow-y: auto; gap: 12px; }
.ed-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.ed-head > div { min-width: 0; display: grid; gap: 6px; }
.sheet.editor h2 { font-size: 36px; overflow-wrap: anywhere; color: var(--cream); }
.sheet.editor h2.am { font: 700 28px/1.2 var(--eth); }
.ed-name { display: grid; gap: 6px; }
.ed-name input { background: var(--night); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 700; font-size: 16px; }
.ed-name input:focus { outline: none; border-color: var(--p1); }
.sheet.editor .seg { justify-self: start; }
.ed-msg { margin: 0; font-weight: 600; min-height: 1.4em; }
.ed-msg.good { color: var(--good); }
.ed-msg.warn { color: var(--p1); }
.ed-msg.bad { color: var(--bad); }
.mywords { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.mywords li { display: inline-flex; align-items: center; gap: 2px; background: var(--panel-2); border-radius: 99px; padding: 3px 4px 3px 12px; font-weight: 600; font-size: 14px; max-width: 100%; }
.mywords li span { overflow-wrap: anywhere; min-width: 0; }
.mywords li.empty { background: none; padding: 0; color: var(--muted); font-weight: 400; }
.mywords .x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; width: 30px; height: 30px; border-radius: 50%; }
.mywords .x:hover { background: var(--line); color: var(--cream); }
.ed-foot { display: grid; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }
.ed-foot-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.ed-foot-btns .danger { margin-left: auto; }

/* ---------- mobile navigator (setup) ---------- */
.bottomnav { display: none; }

/* ================= phones ================= */
@media (max-width: 720px) {
  .wrap { gap: 20px; padding-block: 16px 32px; }
  .logo { font-size: 44px; }
  .tagline { font-size: 14px; }

  /* setup */
  .setup { gap: 22px; }
  .topics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .topic { padding: 10px 12px; min-height: 74px; }
  .topic .tname { font-size: 20px; }
  .topic .tname.am { font-size: 17px; }
  .topic .tmeta { font-size: 12px; }
  .topic .tsample { display: none; }
  .pfield { padding: 10px 12px; gap: 8px; }
  .pfield input { font-size: 16px; }
  .vs { font-size: 16px; }
  .opt-row { padding: 11px 12px; }
  .opt-row .seg button { padding: 7px 10px; }
  .opt-sub { font-size: 12px; }

  body.on-setup .wrap { padding-block-end: calc(92px + env(safe-area-inset-bottom, 0px)); }
  body.on-setup .startrow { display: none; }
  body.on-setup .bottomnav {
    display: grid; grid-template-columns: repeat(4, 1fr) auto; align-items: stretch;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
  .bottomnav a {
    display: grid; justify-items: center; gap: 2px; padding: 6px 2px; border-radius: 10px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 700; letter-spacing: .02em;
  }
  .bottomnav a svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottomnav a.active { color: var(--p1); background: color-mix(in srgb, var(--p1) 10%, transparent); }
  .navstart {
    display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; align-self: center;
    background: var(--p1); color: var(--night); border: 0; border-radius: 12px; cursor: pointer;
    padding: 12px 16px; font: 900 20px/1 var(--display); text-transform: uppercase; letter-spacing: .04em;
  }
  .navstart svg { width: 18px; height: 18px; }
  .navstart:active { transform: scale(.97); }
  /* when Start can't go, the reason shows just above the bar */
  body.on-setup .startrow:has(.start-msg:not(:empty)) { display: block; }
  body.on-setup .startrow .start { display: none; }
  body.on-setup .start-msg:not(:empty) {
    position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); z-index: 5;
    background: var(--panel-2); border: 1px solid var(--bad); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  }

  /* game: exactly one screen, nothing scrolls */
  html:has(body.in-game), body.in-game { height: 100%; overflow: hidden; }
  body.in-game { display: flex; flex-direction: column; --tilet-h: 8px; }
  body.in-game .tilet { flex: none; border-bottom-width: 2px; }
  body.in-game .wrap {
    flex: 1; min-height: 0; width: 100%;
    display: flex; flex-direction: column; gap: 0;
    padding-block: 8px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  body.in-game .masthead { display: none; }
  .game { flex: 1; min-height: 0; gap: 8px; }
  .gamebar .iconbtn { min-height: 38px; }
  .gb-topic { font-size: 18px; }
  .pcard { padding: 8px 12px; }
  .pscore { font-size: 28px; }
  .pstreak { min-height: 0; }
  .pstreak:empty { display: none; }
  /* the stage is a size container: the dial takes whatever height the other stage rows leave */
  .stage { flex: 1; padding: 10px 12px; gap: 6px; border-radius: 16px; container-type: size; overflow: hidden; }
  .turnline { font-size: 24px; flex: none; }
  .ring-wrap {
    --ring: clamp(96px, calc(100cqh - var(--stage-rest, 150px)), min(62vw, 260px));
    width: var(--ring);
  }
  .stage:has(.family:not(:empty)) .ring-wrap { --stage-rest: 178px; }
  .letter { font-size: calc(var(--ring) * .5); }
  .letter.am { font-size: calc(var(--ring) * .42); }
  .secs { font-size: 13px; bottom: 13%; }
  .family { font-size: 17px; letter-spacing: .22em; min-height: 0; }
  .status { min-height: 76px; flex: none; }
  .heard { font-size: 17px; }
  .feedback { font-size: 14px; }
  .feedback .big { font-size: 34px; }
  .dock { flex: none; gap: 8px; }
  .micbtn { width: 72px; height: 72px; }

  /* overlays become bottom sheets, within thumb reach */
  .overlay { place-items: end center; padding: 0; }
  .sheet {
    width: 100%; border-radius: 20px 20px 0 0;
    padding: 22px 18px calc(20px + env(safe-area-inset-bottom, 0px));
    animation: sheetup .25s ease-out;
  }
  .sheet h2 { font-size: 38px; }
  .sheet.editor { width: 100%; max-height: calc(100dvh - 24px); }
  .sheet.editor h2 { font-size: 30px; }
  .final .fs { font-size: 28px; }
  @keyframes sheetup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
}

/* short phones (or landscape): shrink the stage further */
@media (max-width: 720px) and (max-height: 680px) {
  .board .pcard { padding: 6px 10px; }
  .pscore { font-size: 24px; }
  .trail { min-height: 26px; }
  .trail li { font-size: 13px; padding: 2px 8px; }
  .turnline { font-size: 20px; }
  .status { min-height: 64px; }
  .micbtn { width: 64px; height: 64px; }
  .act { padding: 4px 8px; }
}

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