/* Palette follows Telegram's theme params, with sane values for a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --surface: var(--tg-theme-secondary-bg-color, #1e2c3a);
  --text: var(--tg-theme-text-color, #f5f7fa);
  --muted: var(--tg-theme-hint-color, #7d8b99);
  --accent: var(--tg-theme-button-color, #45a3f5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --good: #3fbf7f;
  --bad: #e5624a;
  /* Seats at a table: you are always --good, rivals take these in the
     order the standings list them. Three seats is the match limit.
     Each seat has two shades: the solid one fills a lane under white
     text, the light one writes numbers on a dark or tinted row. A single
     shade cannot do both -- whichever way it goes, one side stops being
     readable. */
  --seat-1: #e5624a;
  --seat-1-ink: #ff9d82;
  --seat-2: #c08bf0;
  --seat-2-ink: #d7b2f8;
  --cell: #2a3b4d;
  --cell-active: var(--accent);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/*
 * `hidden` means hidden, whatever else an element's display says.
 *
 * The attribute's default rule is a plain `display: none` from the user-agent
 * sheet, so any `display` of ours outranks it and the element stays on screen
 * with the attribute set. That is how the match review came to show the round
 * and the summary at once: both had a display of their own, neither had this.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Screens -------------------------------------------------------------- */
.screen {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  gap: 10px;
}

/* Home ----------------------------------------------------------------- */
.home__head { padding: 8px 2px 2px; }
.home__greeting { font-size: 26px; font-weight: 800; letter-spacing: -.01em; margin-bottom: 14px; }
.home__stats { display: flex; gap: 8px; }
.home__stat {
  flex: 1; background: var(--surface); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
}
.home__stat-value { display: block; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.home__stat-label { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.home__actions { display: flex; flex-direction: column; gap: 8px; }
.home__rules { font-size: 12px; color: var(--muted); text-align: center; padding-top: 2px; }

/* Round length ---------------------------------------------------------- */
.duration { background: var(--surface); border-radius: var(--radius); padding: 11px 13px; }
.duration__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.duration__label { font-size: 13px; color: var(--muted); }
.duration__field { display: flex; align-items: baseline; gap: 5px; }
.duration__input {
  width: 64px; background: var(--cell); color: var(--text);
  border: 0; border-radius: 8px; padding: 6px 8px;
  font-size: 16px; font-weight: 700; text-align: right;
  font-family: inherit; font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.duration__input::-webkit-outer-spin-button,
.duration__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.duration__unit { font-size: 12px; color: var(--muted); }

.duration__presets { display: flex; gap: 5px; }
.duration__preset {
  flex: 1; border: 0; border-radius: 8px; padding: 7px 0;
  background: var(--cell); color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.duration__preset.is-active { background: var(--accent); color: var(--accent-text); }

.btn {
  border: 0; border-radius: 13px; padding: 15px;
  font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.btn--primary { background: var(--accent); color: var(--accent-text); }
.btn--ghost { background: var(--surface); color: var(--text); }
.btn:disabled { opacity: .5; }

.home__history { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.home__history-title { font-size: 13px; color: var(--muted); padding-left: 2px; }

.history { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.history__row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 12px; padding: 11px 13px;
}
.history__level {
  width: 40px; height: 36px; flex: 0 0 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--cell); border-radius: 10px;
  font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.history__row.is-done .history__level { background: var(--good); color: #fff; }
.history__body { flex: 1; min-width: 0; }
.history__main { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.history__meta { font-size: 12px; color: var(--muted); margin-top: 1px; }
/* The inactivity clock. Dim by default; the side that owes the move is the
   one being warned, and only that one gets the colour. */
.history__clock { font-size: 12px; color: var(--muted); margin-top: 3px; }
.history__clock.is-yours { color: var(--bad); }
.history__status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.history__status.is-done { color: var(--good); font-weight: 600; }
.history__empty { color: var(--muted); font-size: 14px; padding: 18px 2px; text-align: center; }

/* Waiting on a rival ---------------------------------------------------
   The one line that says the page is alive: who is being waited on and how
   much of their clock is left. */
.waitline {
  font-size: 13px; color: var(--muted); text-align: center;
  padding: 10px 2px 2px;
}
.waitline__clock { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 600; }
/* The moment the gate opens, the button has to be seen to have changed. */
@keyframes readyPulse {
  0% { box-shadow: 0 0 0 0 rgba(69, 163, 245, 0.55); }
  100% { box-shadow: 0 0 0 14px rgba(69, 163, 245, 0); }
}
.is-ready { animation: readyPulse 1.1s ease-out 2; }

/* HUD ---------------------------------------------------------------- */
.hud { display: flex; gap: 8px; align-items: stretch; }
.hud__back {
  flex: 0 0 38px; width: 38px;
  background: var(--surface); color: var(--text);
  border: 0; border-radius: var(--radius);
  font-size: 26px; line-height: 1; cursor: pointer;
  font-family: inherit; padding: 0 0 3px;
}
.hud__stat {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: center;
}
.hud__label { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hud__value { display: block; font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud__stat--timer .hud__value { transition: color .2s ease; }
/* Last 20 seconds: the countdown turns red and pulses, so time pressure is felt
   without having to watch the number. */
.hud__stat--timer.is-urgent .hud__value { color: var(--bad); animation: tick 1s ease infinite; }
@keyframes tick { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* Progress ------------------------------------------------------------ */
.progress { display: flex; align-items: center; gap: 10px; }
.progress__bar { flex: 1; height: 8px; background: var(--surface); border-radius: 99px; overflow: hidden; }
.progress__fill { height: 100%; width: 100%; background: var(--good); border-radius: 99px; transition: width .5s linear, background .3s ease; }
.progress__fill.is-urgent { background: var(--bad); }
.progress__text { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Current word -------------------------------------------------------- */
.current {
  min-height: 46px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 700; letter-spacing: .10em;
  text-transform: uppercase;
  transition: color .15s ease, transform .15s ease;
}
.current__placeholder { font-size: 14px; font-weight: 400; letter-spacing: 0; text-transform: none; color: var(--muted); }
.current.is-valid { color: var(--good); }
.current.is-known { color: var(--muted); }
.current.is-bad { color: var(--bad); }
.current.pop { transform: scale(1.08); }

/* Board --------------------------------------------------------------- */
.board-wrap {
  flex: 1 1 auto;
  display: flex; align-items: center; justify-content: center;
  min-height: 0;
  /* Lets the board size itself against this box rather than the viewport --
     the viewport does not know how much the hud and the bar have taken. */
  container-type: size;
}
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  /* Fallback for browsers without container queries; the line below wins. */
  width: min(100%, 62dvh);
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  touch-action: none;
}
.board__trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
.board__trail line { stroke: var(--accent); stroke-width: 2.6; stroke-linecap: round; opacity: .75; }

.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--cell);
  border-radius: var(--radius);
  font-size: clamp(20px, 6.4dvh, 34px);
  font-weight: 700;
  text-transform: uppercase;
  transition: transform .12s ease, background .12s ease, color .12s ease;
  z-index: 1;
}
.cell.is-active { background: var(--cell-active); color: var(--accent-text); transform: scale(.93); }
.cell.is-hint { box-shadow: inset 0 0 0 2px var(--good); }
.cell.flash-good { background: var(--good); color: #fff; }
.cell.flash-bad { background: var(--bad); color: #fff; }

/* Bottom bar ---------------------------------------------------------- */
/* Fixed height on purpose: anything that grows here shifts the board, and a
   shifted board makes the drag hit-testing point at the wrong cells. */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; flex: 0 0 52px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0 14px;
}
.bar__count { display: flex; align-items: baseline; gap: 6px; }
.bar__found { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bar__found.is-bumped { animation: bump .3s ease; }
.bar__total {
  font-size: 13px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bar { gap: 8px; }
.bar__count { flex: 0 1 auto; min-width: 0; }
.hint--icon {
  flex: 0 0 auto;
  width: 34px; padding: 0;
  font-size: 20px; line-height: 1;
}

@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.35); color: var(--good); } 100% { transform: scale(1); } }

.hint {
  flex: 0 0 auto;
  background: var(--accent); color: var(--accent-text);
  border: 0; border-radius: 99px; padding: 6px 12px;
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
  white-space: nowrap;
}
.hint:disabled { opacity: .45; }

/* Word sheet ----------------------------------------------------------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 5;
  display: flex; flex-direction: column;
  max-height: 52dvh;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .45);
}
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet__title { font-size: 14px; color: var(--muted); }
.sheet__close {
  border: 0; background: var(--surface); color: var(--text);
  width: 30px; height: 30px; border-radius: 8px;
  font-size: 20px; line-height: 1; cursor: pointer; font-family: inherit;
}

/* Match review --------------------------------------------------------- */
.review { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; flex: 1; }
.review__round { background: var(--surface); border-radius: 14px; padding: 13px; }
.review__meta { font-size: 12px; color: var(--muted); }
.review__body { display: flex; gap: 12px; align-items: flex-start; }

/* Small read-only copy of the board that was played. */
.mini {
  position: relative;
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px;
  flex: 0 0 116px; width: 116px;
}
.mini__trail {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 2;
}
.mini__cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--cell); border-radius: 5px;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
}
.review__words { flex: 1; min-width: 0; }
.review__tabs { display: flex; gap: 5px; margin-bottom: 8px; }
.review__tab {
  border: 0; border-radius: 8px; padding: 5px 10px;
  background: var(--cell); color: var(--muted);
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.review__tab.is-active { background: var(--accent); color: var(--accent-text); }
.review__list {
  display: flex; flex-direction: column; gap: 3px;
  max-height: 150px; overflow-y: auto;
  scroll-behavior: smooth;
}
.review__empty { font-size: 13px; color: var(--muted); }

/* Word list ----------------------------------------------------------- */
/* Fixed share of the viewport with its own scroll. Height must not depend on
   how many words are listed -- a growing list would move the board. */
.words {
  flex: 1 1 auto;
  min-height: 0;
  display: flex; flex-direction: column; gap: 3px;
  overflow-y: auto;
  padding: 2px 1px;
  scroll-behavior: smooth;
}
.words__word {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); color: var(--muted);
  border-radius: 8px; padding: 6px 11px;
  font-size: 14px; text-transform: uppercase; letter-spacing: .04em;
  transition: background .18s ease, color .18s ease, transform .18s ease;
  cursor: pointer;
}
.words__word::after {
  content: attr(data-len);
  font-size: 11px; opacity: .55; letter-spacing: 0;
}
.words__word.is-found {
  /* Tinted rather than filled: the rivals' numbers sit on this row in
     their own colours, and orange on solid green cannot be read. */
  background: rgba(63, 191, 127, 0.22);
  box-shadow: inset 2px 0 0 var(--good);
  color: #fff; font-weight: 600;
}
/* The word the list is currently centred on -- its path is drawn on the board. */
.words__word.is-focused {
  background: var(--accent); color: var(--accent-text); font-weight: 700;
  transform: scale(1.015);
}
.words__word.is-focused::after { opacity: .8; }

/* Cells taking part in the focused word.
   Order matters as much as position: without step numbers and distinct ends,
   a highlighted path shows where a word lives but not how to trace it. */
.cell.is-preview {
  box-shadow: inset 0 0 0 2px var(--accent);
  position: relative;
}
/* Step number, so the order of the path is unambiguous. */
.cell.is-preview::after {
  content: attr(data-step);
  position: absolute; top: 3px; left: 5px;
  font-size: 10px; font-weight: 700; line-height: 1;
  color: var(--accent); opacity: .85;
}
.cell.is-start {
  background: var(--accent); color: var(--accent-text);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cell.is-start::after { color: var(--accent-text); opacity: .9; }
/* The end of the path gets a ring rather than a fill, so start and finish
   never read as the same thing. */
.cell.is-end {
  box-shadow: inset 0 0 0 3px var(--good);
}
.cell.is-end::after { color: var(--good); }

.board__trail line.preview {
  stroke: var(--accent); opacity: .8; stroke-width: 2.2;
}
.board__trail line.preview-head { stroke: var(--good); }
/* Direction markers: one small triangle per leg, pointing the way. */
.board__trail polygon.arrow, .mini__trail polygon.arrow { fill: var(--accent); opacity: .95; }
.board__trail polygon.arrow-head, .mini__trail polygon.arrow-head { fill: var(--good); }
.mini__trail line.preview { stroke: var(--accent); opacity: .8; stroke-width: 2.2; }
.mini__trail line.preview-head { stroke: var(--good); }

.mini__cell { position: relative; }
.mini__cell.is-preview { box-shadow: inset 0 0 0 2px var(--accent); }
.mini__cell.is-start { background: var(--accent); color: var(--accent-text); }
.mini__cell.is-end { box-shadow: inset 0 0 0 2px var(--good); }
/* Step numbers would not fit on the small board; a dot marks the order's start. */
.mini__cell.is-start::after {
  content: ""; position: absolute; top: 2px; right: 2px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent-text);
}

/* Toast --------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 16dvh; transform: translate(-50%, 12px);
  background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 99px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  /* Above the end-of-board overlay: the one message that matters -- "your
     rival is done" -- arrives precisely while that overlay is up. */
  z-index: 40;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* Level complete ------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
}
.overlay__card {
  background: var(--surface); border-radius: 20px; padding: 26px 30px;
  text-align: center; width: min(88%, 320px);
  animation: pop .25s ease;
}
.overlay__title { font-size: 21px; font-weight: 700; }
.overlay__score { font-size: 38px; font-weight: 800; color: var(--good); margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.overlay__sub { font-size: 14px; color: var(--muted); margin-bottom: 14px; }

.overlay__btn {
  width: 100%; border: 0; border-radius: 12px; padding: 13px;
  background: var(--accent); color: var(--accent-text);
  font-size: 16px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.overlay__btn--ghost { background: transparent; color: var(--muted); margin-top: 6px; padding: 10px; }

/* --- multiplayer ------------------------------------------------------- */

.hint--ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid rgba(255,255,255,0.10);
}

.standings {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 12px;
}

.standings--overlay {
  padding: 0;
  margin-bottom: 12px;
}

.standings--plain {
  padding: 0;
}

.standings__empty {
  padding: 10px 12px;
  border: 1px dashed rgba(255,255,255,0.14);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.standings__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface);
}

/* Inset, not an outline: an outline is drawn outside the row and the
   scrolling container it sits in cuts it off. */
.standings__row.is-me {
  box-shadow: inset 0 0 0 1px var(--accent);
}

.standings__place {
  flex: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.standings__body {
  flex: 1 1 auto;
  min-width: 0;
}

.standings__name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.standings__rounds {
  display: flex;
  gap: 6px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* A round the viewer has not played yet: the rival's result stays server-side. */
.standings__cell.is-locked {
  opacity: 0.45;
}

.standings__score {
  flex: 0 0 auto;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.history__code {
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

/* --- score bonuses ----------------------------------------------------- */

/* A bonus has to register at a glance mid-drag, so the cell is ringed in the
   bonus colour -- the badge alone is too small to notice while tracing. */
.cell.is-x2, .cell.is-x3, .mini__cell.is-x2, .mini__cell.is-x3 { --bonus: #7fc4ff; }
.cell.is-w2, .cell.is-w3, .mini__cell.is-w2, .mini__cell.is-w3 { --bonus: #ffc861; }

.cell.has-bonus { box-shadow: inset 0 0 0 2px var(--bonus); }
/* The rarer multipliers get a heavier ring. */
.cell.is-x3, .cell.is-w3 { box-shadow: inset 0 0 0 3px var(--bonus); }

.cell__bonus {
  position: absolute; right: 4px; bottom: 3px;
  font-size: 10px; font-weight: 800; line-height: 1;
  letter-spacing: 0;
  color: var(--bonus);
  pointer-events: none;
}

.mini__cell.has-bonus { box-shadow: inset 0 0 0 1px var(--bonus); }
.mini__cell .cell__bonus { right: 1px; bottom: 0; font-size: 6px; }

/* What the current path would pay, shown beside the word being traced. */
.current__points {
  margin-left: 10px;
  font-size: 15px; font-weight: 700;
  letter-spacing: 0;
  color: var(--good);
}

/* Deployment label ------------------------------------------------------ */
/* Shown only on the test deployment -- see APP_ENV on the server. */
.env-badge { display: none; }
body.is-test .env-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bad);
  color: #fff;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
}

/* Player list ----------------------------------------------------------- */
.players {
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
  min-height: 0;
}
.players__row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-radius: 12px; padding: 9px 12px;
}
.players__body { flex: 1 1 auto; min-width: 0; }
.players__name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.players__meta { font-size: 12px; color: var(--muted); }
.players__action {
  flex: 0 0 auto;
  border: 0; border-radius: 99px; padding: 6px 12px;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.players__action:disabled { background: var(--cell); color: var(--muted); cursor: default; }
.players__empty {
  padding: 10px 12px; border-radius: 12px;
  background: var(--surface); color: var(--muted);
  font-size: 13px; text-align: center;
}
#invite-sheet .players { max-height: 34dvh; margin-bottom: 10px; }

/* Tab bar --------------------------------------------------------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 8;
  display: flex;
  background: var(--surface);
  border-top: 1px solid rgba(255, 255, 255, .06);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar__tab {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 4px 7px;
  font-size: 11px; font-family: inherit; cursor: pointer;
}
.tabbar__tab svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar__tab.is-active { color: var(--accent); }

/* Standing screens sit above the bar; a round and a review never do. */
/* The tab screens scroll as a whole page; only the board screen must not, and
   it is the reason `overflow: hidden` sits on the body at all. The tab bar is
   fixed, so the padding is what keeps the last row clear of it. */
.screen--home, .screen--tab {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.screen--tab { gap: 12px; }
.tab__head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.tab__title { margin: 0; font-size: 20px; font-weight: 700; }
.tab__sub { font-size: 13px; color: var(--muted); }

/* Inside a scrolling screen a list grows to its content and the screen scrolls;
   a list that scrolled on its own would trap the gesture in a small box. */
.screen--home .history,
.screen--tab .history,
.screen--tab .players {
  flex: 0 0 auto;
  max-height: none;
  overflow-y: visible;
}

/* Nothing in a scrolling screen may be squeezed to make it fit. */
.screen--home > *, .screen--tab > * { flex-shrink: 0; }

/* One friend ------------------------------------------------------------ */
.friend__start {
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}
#screen-friend .tab__head { align-items: center; }
#screen-friend .hud__back { flex: 0 0 auto; }
#screen-friend .tab__title { flex: 1 1 auto; }
.players__row { cursor: pointer; }
.players__row--static { cursor: default; }

/* Who the match was against: the first thing looked for in a list of games. */
.history__rivals {
  font-size: 13px;
  color: var(--text);
  margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Rating movement under a player's match total. */
.standings__rating {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.standings__rating.is-up { color: var(--good, #34c759); }
.standings__rating.is-down { color: var(--bad, #ff453a); }

/* Live matches on the home screen, split by whose move it is. */
.home__live {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 18px 0 4px;
}

.home__group-title {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

#home-you .history__status {
  color: var(--good, #34c759);
  font-weight: 700;
}

/* The new-match dialog: a sheet that sits in the middle, not a full page. */
.sheet--dialog {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  max-height: none;
  border-radius: 18px;
  margin: 0 12px;
  /* The spread shadow dims the whole page around the dialog, which saves a
     backdrop element that would exist only to be painted. */
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .55);
}

.new-sheet__start { width: 100%; margin-top: 14px; }

.new-sheet__hint {
  margin: 10px 2px 2px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

/* A route the player never walked: the board shows one way the word could be
   built, so it is drawn dashed and dimmed. A solid line means "this is how you
   found it" and must not be spent on a guess. */
.mini.is-guess .mini__trail line { stroke-dasharray: 3 3; opacity: .45; }
.mini.is-guess .mini__trail polygon { opacity: .4; }
.mini.is-guess .mini__cell.is-preview { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .28); }

/* The match page -------------------------------------------------------
   Built as a duel: you on the left, them on the right, the running total
   between you, and one board at a time under a round switcher. */
.versus {
  display: grid;
  /* The back button is a column of its own. Floated over the header it landed
     on the player's own face -- there is nothing to float above here. */
  grid-template-columns: auto 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.versus .hud__back {
  flex: none; width: auto;
  background: transparent;
  padding: 2px 4px; font-size: 22px; line-height: 1;
}
.versus__player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.versus__player--rival { flex-direction: row; justify-content: flex-end; }
.versus__player--rival .versus__who { text-align: right; }
.versus__rivals { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; min-width: 0; }
/* Two rivals share the height one had: smaller faces, tighter text. */
.versus__rivals.is-stacked .versus__face { width: 30px; height: 30px; font-size: 14px; }
.versus__rivals.is-stacked .versus__name { font-size: 13px; }
.versus__rivals.is-stacked .versus__rating { font-size: 11px; }
.versus__face {
  flex: 0 0 auto;
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--cell); color: var(--text);
  font-size: 17px; font-weight: 700;
  box-shadow: inset 0 0 0 2px var(--bad);
}
.versus__face.is-me { box-shadow: inset 0 0 0 2px var(--good); }
.versus__who { display: flex; flex-direction: column; min-width: 0; }
.versus__name {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.versus__rating { font-size: 12px; color: var(--muted); }
.versus__tally { display: flex; flex-direction: column; align-items: center; }
.versus__tally-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.versus__tally-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Round switcher. A locked step is a board that has not been opened yet. */
.steps { display: flex; align-items: center; justify-content: center; gap: 6px; }
.steps__step {
  width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: var(--cell); color: var(--muted);
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: transform .16s ease, background .16s ease, color .16s ease;
}
.steps__step--total { width: auto; border-radius: 17px; padding: 0 12px; font-size: 13px; }
.steps__step.is-active {
  background: var(--accent); color: var(--accent-text);
  transform: scale(1.14);
}
.steps__step.is-live { box-shadow: inset 0 0 0 2px var(--good); color: var(--text); }
.steps__step.is-locked { opacity: .4; cursor: default; }

/* Points and words, side by side. */
.duel { margin-bottom: 11px; }
.duel__label {
  font-size: 11px; color: var(--muted); text-align: center;
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px;
}
.duel__bar { display: flex; gap: 4px; height: 30px; }
.duel__half {
  display: flex; align-items: center;
  border-radius: 8px; padding: 0 9px;
  font-size: 14px; font-weight: 700; color: #fff;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  transition: flex-grow .3s ease;
}
.duel__half--mine { background: var(--good); }
.duel__half--theirs { background: var(--bad); justify-content: flex-end; }
.duel__half--blank { background: var(--cell); color: var(--muted); justify-content: flex-end; }
/* A rival who has not closed this board yet: their place is kept, empty. */
.duel__half--pending {
  background: var(--cell); color: var(--muted); justify-content: center;
  border: 1px dashed rgba(255,255,255,0.18);
}
.duel__counts { display: flex; justify-content: center; gap: 14px; }
.duel__count { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.duel__count--mine { color: var(--good); }
.duel__count--theirs { color: var(--bad); }
.duel__count--blank { color: var(--muted); }
.duel__bar + .duel__label { margin-top: 9px; }
.duel__note { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }

/* Which colour is whose, above the columns that use them. */
.seatkey {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px;
  margin-top: 9px; font-size: 12px; color: var(--muted);
}
.seatkey__item { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.seatkey__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* A word line: what it paid me, the word, what it paid them. */
.duel__row { justify-content: stretch; gap: 8px; padding: 6px 9px; }
.duel__row::after { content: none; }
.duel__points {
  flex: 0 0 34px;
  font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}
.duel__points--mine { color: var(--good); text-align: left; }
.duel__points--theirs { color: var(--seat, var(--bad)); text-align: right; }
.duel__wordtext {
  flex: 1; min-width: 0; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Three columns of numbers leave the word less room, so it takes less. */
.review__list--crowded .duel__points { flex: 0 0 27px; font-size: 12px; }
.review__list--crowded .duel__wordtext { font-size: 13px; letter-spacing: 0; }
/* Found by me: the row is mine, so the numbers read against it in white. */
.words__word.is-found .duel__points--mine { color: #fff; }
.words__word.is-focused .duel__points { color: var(--accent-text); }
/* Nobody got it -- present, but not competing for attention. */
.words__word.is-missed { opacity: .55; }

/* The match page scrolls in its middle only; the buttons stay put. */
.screen--review { padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
.screen--review .review { flex: 1; min-height: 0; }
.screen--review .standings { flex: 1; min-height: 0; overflow-y: auto; }
.review__actions { display: flex; flex-direction: column; gap: 8px; }
.review__actions .btn { width: 100%; }

/* The "итог" tab: the match score, the verdict, and what it paid. */
.summary {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 13px 16px;
  margin-bottom: 10px;
}
.summary__verdict {
  margin-top: 14px;
  font-size: 24px; font-weight: 800; text-align: center; letter-spacing: -.01em;
}
.summary__verdict.is-win { color: var(--good); }
.summary__verdict.is-loss { color: var(--bad); }
.summary__verdict.is-draw { color: var(--text); }
.summary__verdict.is-open { color: var(--muted); font-size: 19px; font-weight: 700; }
.summary__under {
  margin-top: 5px;
  font-size: 13px; color: var(--muted); text-align: center;
}

/* Remark on a word hardly anyone finds -- see rarityNote() on the client. */
.current__rare {
  margin-left: 10px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.02em; text-transform: none;
  color: var(--bonus);
}

/* The daily board card on the home screen ------------------------------- */
.daily {
  margin: 16px 0 0;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
}
.daily__head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.daily__title { margin: 0; font-size: 15px; font-weight: 700; }
.daily__reset { font-size: 12px; color: var(--muted); }
.daily__body { margin-top: 6px; font-size: 13px; color: var(--muted); }
.daily__btn { margin-top: 12px; width: 100%; }
.daily__table:not(:empty) { margin-top: 12px; }

/* Daily quests ---------------------------------------------------------- */
.quests__list { margin-top: 10px; display: grid; gap: 10px; }
.quest {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: baseline;
}
.quest.is-done { opacity: 0.55; }
.quest__title { font-size: 13px; }
.quest__reward { font-size: 12px; font-weight: 700; color: var(--good); }
.quest.is-done .quest__reward { color: var(--muted); font-weight: 600; }
.quest__bar {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 2px;
  background: var(--cell);
  overflow: hidden;
}
.quest__fill { display: block; height: 100%; background: var(--accent); }
.quest.is-done .quest__fill { background: var(--good); }
.quest__count { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }

/* The round length is fixed by the opponent's match -- see lockDuration(). */
.duration__input:disabled { opacity: 0.55; }
.duration__presets.is-locked { opacity: 0.4; pointer-events: none; }

/* How a match ended, in the list of games -- see outcomeOf(). */
.history__status.is-win { color: var(--good); font-weight: 700; }
.history__status.is-loss { color: var(--bad); }
.history__status.is-draw { color: var(--muted); }

/* What inviting people has come to: brought in, and of those, played. */
.invites {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}
