/* BANK! - clean and sleek, built for a phone lying on a family table.
   Gold means money in the bank (banking, bonuses), red means the round-ending roll, blue means doubles.
   The play screen is one fixed screen: totals and leaderboard on the left, the dice pad down the right edge. */
:root {
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-2: #e7ece7;
  --line: #d3dcd5;
  --text: #0f1714;
  --muted: #5a6962;
  --gold: #9a6700;
  --gold-fill: #e7a91d;
  --gold-soft: #f7e9c4;
  --on-gold: #1b1304;
  --red: #c2362a;
  --red-soft: #f9dcd7;
  --blue: #2a58d0;
  --blue-soft: #dce5fb;
  --green: #1e7a4e;
  --focus: #2a58d0;
  --key: #ffffff;
  --shadow: 0 1px 2px rgb(15 23 20 / 0.08), 0 4px 14px rgb(15 23 20 / 0.06);

  --font-num: "Big Shoulders Display", "Bebas Neue", Oswald, "Arial Narrow", Impact, sans-serif;
  --font-ui: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 14px;
  --tap: 48px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b100e;
    --surface: #141b18;
    --surface-2: #1b2521;
    --line: #27332e;
    --text: #edf2ee;
    --muted: #8fa198;
    --gold: #f3bd46;
    --gold-fill: #f3bd46;
    --gold-soft: #3a2c0e;
    --on-gold: #1b1304;
    --red: #ff6b59;
    --red-soft: #3e1712;
    --blue: #93b3ff;
    --blue-soft: #17223c;
    --green: #5fd39a;
    --focus: #93b3ff;
    --key: #18211d;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b100e;
  --surface: #141b18;
  --surface-2: #1b2521;
  --line: #27332e;
  --text: #edf2ee;
  --muted: #8fa198;
  --gold: #f3bd46;
  --gold-fill: #f3bd46;
  --gold-soft: #3a2c0e;
  --on-gold: #1b1304;
  --red: #ff6b59;
  --red-soft: #3e1712;
  --blue: #93b3ff;
  --blue-soft: #17223c;
  --green: #5fd39a;
  --focus: #93b3ff;
  --key: #18211d;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}

h1, h2, h3, p, ol, ul, fieldset { margin: 0; }
ol, ul { padding: 0; list-style: none; }
fieldset { border: 0; padding: 0; min-width: 0; }
button, input { font: inherit; color: inherit; }
button { -webkit-user-select: none; user-select: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app { min-height: 100%; }

.label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.55rem 1.15rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease, background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-gold { background: var(--gold-fill); border-color: var(--gold-fill); color: var(--on-gold); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-big { min-height: 58px; font-size: 1.125rem; padding-inline: 1.5rem; }
.btn-sm { min-height: 38px; padding: 0.35rem 0.85rem; font-size: 0.875rem; }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn svg, .btn svg { width: 22px; height: 22px; flex: none; }

/* ---------- Page layout (home, admin, lobby) ---------- */

.page {
  max-width: 40rem;
  margin-inline: auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) var(--gutter-r) calc(env(safe-area-inset-bottom, 0px) + 40px) var(--gutter);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 2.6rem;
  line-height: 0.9;
  letter-spacing: 0.01em;
}

.logo .bang { color: var(--gold); }

.logo-hero {
  font-size: clamp(5.5rem, 34vw, 9rem);
  text-align: center;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-family: var(--font-num);
  font-weight: 800;
  font-size: 2rem;
  line-height: 1;
  letter-spacing: 0.01em;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
}

.field { display: flex; flex-direction: column; gap: 10px; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.hint { font-size: 0.875rem; color: var(--muted); }

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.0625rem;
  font-weight: 600;
}

.input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.input::placeholder { color: var(--muted); font-weight: 500; }

.inline-form { display: flex; gap: 8px; }
.inline-form .input { flex: 1; min-width: 0; }

.code-input {
  text-align: center;
  font-family: var(--font-num);
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: 0.3em;
  text-transform: uppercase;
}

/* Segmented choice (rounds) */
.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 14px;
  background: var(--surface-2);
}

.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented label {
  display: grid;
  place-items: center;
  min-height: 48px;
  border-radius: 10px;
  font-family: var(--font-num);
  font-size: 1.6rem;
  font-weight: 800;
  cursor: pointer;
}

.segmented input:checked + label { background: var(--surface); box-shadow: var(--shadow); }
.segmented input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }

/* Game type cards */
.choice-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
}

.choice-card input { position: absolute; opacity: 0; pointer-events: none; }
.choice-card .title { font-family: var(--font-num); font-size: 1.6rem; font-weight: 800; line-height: 1.05; }
.choice-card .desc { font-size: 0.8125rem; line-height: 1.35; color: var(--muted); }
.choice-card:has(input:checked) { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.choice-card:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }

@media (max-width: 360px) { .choice-cards { grid-template-columns: 1fr; } }

/* Lineup (selected players, reorderable) */
.lineup { display: flex; flex-direction: column; gap: 6px; }

.lineup-item {
  display: grid;
  grid-template-columns: var(--tap) 1.5rem minmax(0, 1fr) var(--tap);
  align-items: center;
  min-height: 54px;
  padding-right: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  touch-action: pan-y;
}

.lineup-item.is-dragging {
  position: relative;
  z-index: 2;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.22);
  transition: none;
}

.lineup-item.is-shifting { transition: transform 160ms ease; }

.lineup-item .handle {
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}

.lineup-item .seat { font-family: var(--font-num); font-size: 1.3rem; font-weight: 800; color: var(--muted); }
.lineup-item .name { overflow: hidden; font-weight: 700; font-size: 1.0625rem; text-overflow: ellipsis; white-space: nowrap; }
.lineup-empty { padding: 14px; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--muted); text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0.4rem 0.9rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.chip::before { content: "+"; color: var(--muted); font-weight: 800; }
.chip:active { transform: scale(0.97); }

/* Open games */
.room-link {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1.5px solid var(--gold-fill);
  border-radius: 16px;
  background: var(--gold-soft);
  color: var(--text);
  text-decoration: none;
}

.room-link .code { font-family: var(--font-num); font-weight: 900; font-size: 2rem; letter-spacing: 0.08em; }
.room-link .meta { display: flex; flex-direction: column; min-width: 0; font-size: 0.875rem; }
.room-link .meta strong { font-size: 1rem; }
.room-link .who { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.room-link .go { margin-left: auto; font-weight: 800; }

/* Stats */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }

.filter {
  min-height: 36px;
  padding: 0.3rem 0.8rem;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
}

.filter[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--bg); }

.stat-list { display: flex; flex-direction: column; gap: 10px; }

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
}

.stat-head { display: flex; align-items: center; gap: 12px; }
.stat-head .rank { font-family: var(--font-num); font-size: 1.5rem; font-weight: 800; color: var(--muted); min-width: 1.5ch; }
.stat-head .name { flex: 1; min-width: 0; overflow: hidden; font-size: 1.125rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.stat-head .wins { font-family: var(--font-num); font-size: 2.25rem; font-weight: 900; line-height: 1; color: var(--gold); }
.stat-head .wins small { margin-left: 4px; font-family: var(--font-ui); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 8px;
}

@media (max-width: 350px) { .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.stat { display: flex; flex-direction: column; min-width: 0; }
.stat dt { overflow: hidden; font-size: 0.625rem; font-weight: 800; letter-spacing: 0.05em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; color: var(--muted); }
.stat dd { margin: 0; font-family: var(--font-num); font-size: 1.35rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }

.stat-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.8125rem; color: var(--muted); }

.recent { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.recent li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.recent .w { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.recent .s { font-family: var(--font-num); font-size: 1.3rem; font-weight: 800; text-align: right; }
.recent .m { grid-column: 1 / -1; font-size: 0.8125rem; color: var(--muted); }

.empty { padding: 18px; border: 1.5px dashed var(--line); border-radius: 16px; color: var(--muted); text-align: center; }

/* ---------- Lobby / join ---------- */

.share-card { align-items: center; text-align: center; }

.big-code {
  font-family: var(--font-num);
  font-weight: 900;
  font-size: clamp(4rem, 24vw, 6.5rem);
  line-height: 0.9;
  letter-spacing: 0.08em;
}

.share-url { font-weight: 800; font-size: 1.125rem; word-break: break-all; }

.qr {
  width: min(220px, 60vw);
  padding: 12px;
  border-radius: 16px;
  background: #fff;
}

.qr svg { display: block; width: 100%; height: auto; }

.share-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

.roster { display: flex; flex-direction: column; gap: 6px; }

.roster li {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.roster .seat { font-family: var(--font-num); font-size: 1.3rem; font-weight: 800; color: var(--muted); min-width: 1.4ch; }
.roster .name { flex: 1; min-width: 0; overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.presence { font-size: 0.8125rem; font-weight: 800; color: var(--muted); }
.presence.is-here { color: var(--green); }
.presence.is-here::before { content: "● "; }

.pick-list { display: flex; flex-direction: column; gap: 8px; }

.pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 18px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  font-size: 1.25rem;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.pick:active { transform: scale(0.99); }

/* ---------- Play screen ---------- */

body.is-playing { overflow: hidden; }

.play {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(72px, 21vw, 112px);
  gap: 10px;
  padding:
    calc(env(safe-area-inset-top, 0px) + 8px)
    max(8px, env(safe-area-inset-right, 0px))
    calc(env(safe-area-inset-bottom, 0px) + 8px)
    max(12px, env(safe-area-inset-left, 0px));
  -webkit-user-select: none;
  user-select: none;
}

/* Players don't enter rolls, so their phones drop the dice pad and use the full width. */
.play.no-pad { grid-template-columns: minmax(0, 1fr); }
.play.no-pad .pad { display: none; }

.play-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.play-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  min-height: 48px;
}

.play-bar .icon-btn { width: 36px; flex: none; }

.undo-btn {
  flex: none;
  min-height: 44px;
  padding-inline: 0.7rem 0.85rem;
  border-color: var(--text);
  font-size: 0.9375rem;
}

.undo-btn.is-confirming { min-width: 0; }

@media (max-width: 430px) { .play:not(.no-pad) .round-word { display: none; } }
.play-bar.is-confirming .round-word { display: none; }
@media (max-width: 400px) { .play-bar.is-confirming .theme-btn { display: none; } }
.bar-gap { flex: 1; }
.undo-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.undo-btn.is-confirming { background: var(--red); border-color: var(--red); color: #fff; }

.round-pill {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 7px;
  min-width: 0;
  padding: 0.3rem 0.7rem 0.3rem 0.55rem;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.75rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.round-pill b { font-size: 1rem; }

.conn {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  flex: none;
}

.conn.is-off { background: var(--red); animation: blink 1s steps(2) infinite; }

@keyframes blink { 50% { opacity: 0.3; } }

/* The bank total. With Mirror on, the card splits into two halves and the top half is turned upside
   down for people across the table; each copy sits centered in its own half with its notes below it.
   With Mirror off there's one copy, centered, with the play-by-play underneath. */
.totals {
  position: relative;
  container-type: inline-size;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  height: clamp(200px, 31vh, 330px);
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  overflow: hidden;
}

.totals.is-mirrored {
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  height: clamp(290px, 47vh, 480px);
}

.half {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1fr);
  justify-items: center;
  min-width: 0;
  min-height: 0;
  padding: 10px 14px;
}

/* The number takes the middle row, so it is centered in its half no matter how long the notes are;
   the notes hang just below it, on the outer side (the flipped half is rotated, so its notes face out too). */
.half .total-num { grid-row: 2; }
.half .notes { grid-row: 3; align-self: start; padding-top: 6px; }
.totals.is-mirrored .notes { padding-top: 4px; }

/* With Mirror on, or on short phones, there isn't room for the "rolls next" line under each number;
   the leaderboard already marks who's rolling. */
.totals.is-mirrored .turn { display: none; }
@media (max-height: 700px) { .turn { display: none; } }

.half-flip { display: none; transform: rotate(180deg); }
.totals.is-mirrored .half-flip { display: grid; }
.totals.is-mirrored .half-main { border-top: 1px dashed var(--line); }

.total-num {
  font-family: var(--font-num);
  font-weight: 900;
  font-size: 18vh; /* fallback for browsers without container units (iOS 15) */
  line-height: 0.86;
  letter-spacing: 0.005em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transition: color 200ms ease;
}

.totals.is-mirrored .total-num { font-size: 14vh; }

.totals.is-hot .total-num { animation: flash-gold 1100ms ease-out; }
.totals.is-bust .total-num { animation: flash-red 1100ms ease-out; }

@keyframes flash-gold { 0%, 45% { color: var(--gold); } 100% { color: var(--text); } }
@keyframes flash-red { 0%, 45% { color: var(--red); } 100% { color: var(--text); } }

.notes {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
}

.ticker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  font-size: 0.875rem;
  font-weight: 700;
  text-align: center;
}

.ticker-text {
  display: -webkit-box;
  min-width: 0;
  overflow: hidden;
  font-size: 0.8125rem;
  line-height: 1.2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.ticker.is-bust .ticker-text { color: var(--red); font-weight: 800; }
.ticker.is-gold .ticker-text { color: var(--gold); }

.phase {
  flex: none;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--gold-soft);
  color: var(--gold);
}

.phase.is-danger { background: var(--red-soft); color: var(--red); }

.turn {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.turn strong { color: var(--text); }

.mirror-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
}

.totals.is-mirrored .mirror-btn { top: 50%; transform: translateY(-50%); background: var(--surface); }

.mirror-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }

/* Leaderboard */
.board-wrap {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.board-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 34px;
  padding: 2px 4px 6px;
}

.board-head .label { flex: none; }
.board-status { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; }
.board-head .hint { min-width: 0; overflow: hidden; font-size: 0.8125rem; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

/* The few seconds players have to bank themselves after each roll. */
.bank-clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 2px 9px 2px 3px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold);
  font-size: 0.875rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.clock-ring {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(var(--gold-fill) calc(var(--p, 1) * 360deg), color-mix(in srgb, var(--gold-fill) 22%, transparent) 0);
  -webkit-mask: radial-gradient(circle, transparent 5px, #000 5.5px);
  mask: radial-gradient(circle, transparent 5px, #000 5.5px);
}

.clock-text::after { content: "s"; margin-left: 1px; font-weight: 700; }
.bank-clock.is-low { background: var(--red-soft); color: var(--red); }
.bank-clock.is-low .clock-ring { background: conic-gradient(var(--red) calc(var(--p, 1) * 360deg), color-mix(in srgb, var(--red) 22%, transparent) 0); }

.board {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 4px;
}

.row {
  position: relative;
  flex: none;
  min-height: 64px;
  border-radius: 14px;
  overflow: hidden;
  touch-action: pan-y;
}

.row-track {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  padding-left: 18px;
  background: var(--gold-fill);
  color: var(--on-gold);
  font-family: var(--font-num);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0;
}

.row.is-swipeable .row-track { opacity: 1; }

.row-face {
  position: relative;
  display: grid;
  grid-template-columns: 1.6rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 64px;
  padding: 8px 12px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  will-change: transform;
}

.row.is-settling .row-face { transition: transform 220ms cubic-bezier(.2, .9, .3, 1); }
.row.is-roller .row-face { border-color: var(--text); box-shadow: inset 0 0 0 1.5px var(--text); }
.row.is-banked .row-face { background: var(--gold-soft); border-color: transparent; }

.row .rank {
  font-family: var(--font-num);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--muted);
  text-align: center;
}

.row .who { display: flex; flex-direction: column; min-width: 0; }

.row .name {
  overflow: hidden;
  font-size: clamp(1.05rem, 4.6vw, 1.35rem);
  font-weight: 800;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; min-height: 1em; }

.tag {
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.tag-roll { color: var(--text); }
.tag-you { color: var(--blue); }
.tag-banked { color: var(--gold); }
.tag-slide { color: var(--gold); }

.row .score {
  font-family: var(--font-num);
  font-size: clamp(1.7rem, 8vw, 2.3rem);
  font-weight: 900;
  line-height: 1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row .gain {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--gold);
  text-align: right;
}

.row.is-moving { transition: transform 260ms ease; }

/* Dice pad down the right edge */
.pad {
  position: relative;
  display: grid;
  grid-template-rows: repeat(12, minmax(0, 1fr));
  gap: 5px;
  min-height: 0;
}

.key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--key);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 80ms ease, background-color 120ms ease;
}

.key:active:not(:disabled) { transform: scale(0.94); background: var(--surface-2); }
.key:disabled { cursor: default; box-shadow: none; opacity: 0.35; }

.key-num {
  font-family: var(--font-num);
  font-size: clamp(1.45rem, 3.6vh, 2.2rem);
  font-weight: 900;
  line-height: 1;
}

.key-hint {
  font-size: 0.625rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  text-transform: uppercase;
}

.key-hint:empty { display: none; }
.key.is-bonus { background: var(--gold-soft); border-color: var(--gold-fill); }
.key.is-bonus .key-hint { color: var(--gold); }
.key.is-bust { background: var(--red-soft); border-color: var(--red); }
.key.is-bust .key-num, .key.is-bust .key-hint { color: var(--red); }
.key.is-double { background: var(--blue-soft); border-color: var(--blue); }
.key.is-double .key-hint, .key.is-double .key-num { color: var(--blue); }
.key-double .key-num { font-size: clamp(1rem, 2.4vh, 1.35rem); letter-spacing: 0.02em; text-transform: uppercase; }



/* Wide screens: a tablet propped up at the table */
@media (min-width: 760px) {
  .play { grid-template-columns: minmax(0, 1fr) 128px; gap: 16px; padding-inline: 20px; }
  .play-main { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); column-gap: 16px; }
  .round-pill { font-size: 0.875rem; }
  .total-num { font-size: 30vh; }
  .totals.is-mirrored .total-num { font-size: 20vh; }
  .play-bar { grid-column: 1 / -1; }
  .totals, .totals.is-mirrored { height: 100%; }
  .board-wrap { grid-column: 2; grid-row: 2; }
}

/* ---------- Final standings ---------- */

.final-hero { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.final-hero .crown { font-size: 0.875rem; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.final-hero .winner { font-family: var(--font-num); font-size: clamp(3.2rem, 16vw, 5rem); font-weight: 900; line-height: 0.95; text-wrap: balance; }
.final-hero .final-score { font-family: var(--font-num); font-size: 2rem; font-weight: 800; color: var(--gold); }

.standings { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.standings li { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; align-items: baseline; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.standings .r { font-family: var(--font-num); font-size: 1.3rem; font-weight: 800; color: var(--muted); }
.standings .n { overflow: hidden; font-weight: 800; font-size: 1.125rem; text-overflow: ellipsis; white-space: nowrap; }
.standings .v { font-family: var(--font-num); font-size: 1.6rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.standings li.is-winner .n, .standings li.is-winner .v { color: var(--gold); }

.highlights { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 10px; }
.highlight { padding: 12px 14px; border-radius: 14px; background: var(--surface-2); }
.highlight dt { font-size: 0.6875rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.highlight dd { margin: 2px 0 0; font-weight: 800; }
.highlight dd b { font-family: var(--font-num); font-size: 1.5rem; }

.actions-row { display: flex; gap: 10px; }
.actions-row .btn { flex: 1; }

/* ---------- Sheets and toasts ---------- */

.sheet {
  width: min(30rem, calc(100% - 24px));
  max-height: calc(100% - 24px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  overflow-y: auto;
}

.sheet::backdrop { background: rgb(5 10 8 / 0.6); }

.sheet-inner { display: flex; flex-direction: column; gap: 16px; padding: 22px 18px 18px; }
.sheet-title { font-family: var(--font-num); font-size: 2rem; font-weight: 900; line-height: 1; }
.sheet-text { color: var(--muted); }

.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn { justify-content: flex-start; border-radius: 14px; }

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(26rem, calc(100% - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  animation: toast-in 180ms ease-out;
}

.toast.is-error { background: var(--red); color: #fff; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.banner {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red);
  font-weight: 700;
}

.center-note { display: grid; gap: 12px; padding-top: 18vh; text-align: center; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
.totals.is-hot { animation: pop 420ms ease-out; }
.totals.is-bust { animation: shake 380ms ease-in-out; }

/* Fit the bank total to its box where container units work. Kept inside @supports because a var()
   holding an unknown unit makes the whole font-size fall back to 16px instead of to the line above. */
@supports (width: 1cqi) {
  .total-num { font-size: min(var(--fit, 34cqi), 18vh); }
  .totals.is-mirrored .total-num { font-size: min(var(--fit, 34cqi), 14vh); }
  @media (min-width: 760px) {
    .total-num { font-size: min(var(--fit, 34cqi), 30vh); }
    .totals.is-mirrored .total-num { font-size: min(var(--fit, 34cqi), 20vh); }
  }
}

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

/* Signed-in account in the host header */
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-name { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.field[hidden], .hint[hidden] { display: none; }

/* Header bits shared by pages */
.topline-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topline-end { justify-content: flex-end; margin-bottom: -20px; }
.theme-btn { color: var(--muted); }

/* End screen */
.standings .d { grid-column: 2 / -1; margin-top: -6px; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.standings .v small { font-family: var(--font-ui); font-size: 0.75rem; font-weight: 800; color: var(--muted); }
.tally { gap: 12px; }
.tally .section-title { font-size: 1.6rem; }
.waiting {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface-2);
  font-weight: 700;
  text-align: center;
}
