:root {
  --bg: #0f1117; --bg-soft: #161923; --card: #1a1e2b; --card-hover: #212636; --line: #2a3042;
  --text: #e8eaf0; --muted: #969db4; --accent: #6ea8fe; --accent-warm: #f0b354;
  --good: #6ee7a8; --bad: #f08c8c;
  --radius: 12px; --tabbar: 58px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); overflow: hidden;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button, input, select { font: inherit; color: inherit; }
#app { height: 100dvh; display: flex; flex-direction: column; overflow-x: clip; }
.view { display: none; flex: 1; min-height: 0; padding: 8px 12px 8px; }
.view.on { display: flex; flex-direction: column; }

/* ------------------------------------------------ tab bar (phone bottom, laptop top) */
nav.tabs { order: 2; height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; background: #12151e; border-top: 1px solid var(--line); flex: none; }
nav.tabs button { flex: 1; background: none; border: 0; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 3px; font-size: 11.5px; font-weight: 600; cursor: pointer; }
nav.tabs button svg { width: 22px; height: 22px; }
nav.tabs button.on { color: var(--accent-warm); }
nav.tabs .brand { display: none; }
@media (min-width: 900px) {
  nav.tabs { order: 0; height: 52px; padding: 0 16px; border-top: 0; border-bottom: 1px solid var(--line); justify-content: flex-start; gap: 6px; }
  nav.tabs .brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 17px; margin-right: 22px; color: var(--text); text-decoration: none; }
  nav.tabs .brand img { width: 26px; height: 26px; border-radius: 6px; }
  nav.tabs button { flex: none; flex-direction: row; font-size: 14px; padding: 0 14px; gap: 8px; border-radius: 9px; height: 38px; align-self: center; }
  nav.tabs button.on { background: rgba(240,179,84,.12); }
  nav.tabs button svg { width: 18px; height: 18px; }
  .view { padding: 14px 18px 14px; }
}

/* ------------------------------------------------ common bits */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; text-decoration: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 16px; cursor: pointer;
  font-weight: 650; transition: background .12s, transform .08s, border-color .12s; white-space: nowrap; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .38; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1424; }
.btn.warm { background: var(--accent-warm); border-color: var(--accent-warm); color: #24180a; }
.btn.danger { background: #3a1f26; border-color: #6b2c38; color: #ffc2c9; }
.btn.ghost { background: transparent; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn.big { min-height: 62px; font-size: 21px; font-weight: 850; letter-spacing: .02em; flex-direction: column; gap: 0; line-height: 1.1; border-radius: 14px; }
.btn .sub { font-size: 12.5px; font-weight: 600; letter-spacing: 0; opacity: .75; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; min-height: 40px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 650; font-size: 14px; padding: 4px 6px; }
.seg button[aria-pressed="true"] { background: rgba(240,179,84,.14); border-color: var(--accent-warm); color: var(--accent-warm); }
.seg.mini button { min-height: 34px; font-size: 13px; padding: 2px 10px; white-space: nowrap; flex: none; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.panel p { margin: 0; }
.label { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.good { color: var(--good); } .bad { color: var(--bad); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.num { font-variant-numeric: tabular-nums; }
.q { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg-soft); color: var(--muted);
  font-size: 12px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; vertical-align: middle; flex: none; }
.pop { position: fixed; z-index: 70; max-width: min(320px, calc(100vw - 32px)); background: #232838; border: 1px solid #3a4258; border-radius: 10px;
  padding: 10px 12px; font-size: 13.5px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.switch { position: relative; width: 48px; height: 28px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #2f3548; border-radius: 14px; transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent-warm); }
.switch input:checked + span::after { transform: translateX(20px); }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; min-height: 0; }
.txt { font-size: 16px; background: var(--bg-soft); color: var(--text); border: 1px solid var(--line); border-radius: 8px; min-height: 42px; padding: 0 12px; width: 100%; min-width: 0; }
.txt.code { text-transform: uppercase; letter-spacing: .2em; font-weight: 700; }
.code-big { font-size: 40px; font-weight: 800; letter-spacing: .2em; padding-left: .2em; color: var(--accent-warm); font-variant-numeric: tabular-nums; text-align: center; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2a3042; padding: 9px 14px; border-radius: 10px; font-size: 13.5px; z-index: 80; max-width: calc(100vw - 32px); }
@media (min-width: 900px) { .toast { bottom: 24px; } }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--muted)); flex: none; }

/* ------------------------------------------------ setup */
.setup { width: 100%; max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; padding-bottom: 4px; }
.hero { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 4px 0 2px; }
.hero h1 { margin: 0; font-size: 34px; letter-spacing: .04em; font-weight: 900; color: var(--accent-warm); }
.hero-dice { display: flex; gap: 6px; }
.hero-dice .hd { --die-size: 34px; }
.hero-dice .hd:first-child { transform: rotate(-12deg); } .hero-dice .hd:last-child { transform: rotate(9deg) translateY(4px); }
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.stepper { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px 4px 12px; }
.stepper b { min-width: 22px; text-align: center; font-size: 18px; }
.stepper .btn.small { min-width: 38px; padding: 0; font-size: 18px; }
.stepper .row { margin-left: auto; }
.names { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.names.many { grid-template-columns: repeat(4, 1fr); }
.names.many .txt { min-height: 38px; padding: 0 8px; }
.lbl-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.lbl-row .push { margin-left: auto; }
.setup .btn.big { margin-top: 4px; }
.links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.links .btn { color: var(--muted); }
.pf-open svg { border-radius: 50%; }
.panel.off { text-align: center; }
.lobby-seats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lobby-seats li { display: flex; align-items: center; gap: 10px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px 6px 12px; min-height: 46px; }

/* ------------------------------------------------ the table */
#v-play.on { align-items: stretch; }
.game { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 640px; margin: 0 auto; }
.side { display: none; }
.topbar { display: flex; align-items: center; gap: 10px; min-height: 30px; }
.rnd { font-size: 14px; color: var(--muted); } .rnd b { color: var(--text); font-size: 17px; }
.phase { flex: 1; text-align: center; font-weight: 800; font-size: 14px; line-height: 1.1; }
.phase small { display: block; font-size: 11px; font-weight: 600; color: var(--muted); }
.phase.safe { color: var(--good); } .phase.risk { color: var(--bad); }
.seats { display: grid; grid-template-columns: repeat(var(--cols, 4), 1fr); gap: 6px; }
.seat { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 5px 7px 4px; min-width: 0;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "nm nm" "sc st"; align-items: baseline; column-gap: 4px;
  border-top: 3px solid var(--c); transition: background .2s, opacity .2s; }
.seat .nm { grid-area: nm; font-size: 12.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 5px; }
.seat .nm .dot { width: 7px; height: 7px; }
.seat .lv { font-style: normal; font-size: 9.5px; font-weight: 800; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 3px; margin-left: auto; }
.seat .nm .nmt { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.seat .lv { flex-shrink: 0; }
.seat .sc { grid-area: sc; font-size: 19px; font-weight: 850; line-height: 1.15; }
.seat .st { grid-area: st; font-size: 11px; color: var(--muted); font-weight: 650; }
.seat.roller { background: #222a3d; box-shadow: 0 0 0 2px var(--c) inset; }
.seat.roller .st { color: var(--c); }
.dieic { width: 15px; height: 15px; vertical-align: -2px; }
.seat.banked { background: #1d2a22; }
.seat.banked .st { color: var(--good); font-weight: 800; }
.seat.me .nm { color: var(--accent-warm); }
.felt { position: relative; flex: 1; min-height: 190px; border-radius: 18px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; overflow: hidden;
  box-shadow: inset 0 0 0 5px #4a2f1b, inset 0 0 0 7px #2c1b0f, 0 6px 18px rgba(0,0,0,.45); padding: 34px 12px 12px; }
.msg { position: absolute; top: 10px; left: 12px; right: 12px; text-align: center; font-size: 14px; font-weight: 650; color: #eef3ea; text-shadow: 0 1px 2px rgba(0,0,0,.6); min-height: 20px; }
.msg.bad { color: #ffb4b4; } .msg.good { color: #b6f5cf; } .msg.warm { color: #ffd58e; }
.dice { display: flex; gap: 18px; align-items: center; justify-content: center; }
.dice > span { --die-size: clamp(48px, 15vw, 66px); }
.dice > span.idle { opacity: .45; }
.potbox { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.potbox .label { color: rgba(255,255,255,.7); letter-spacing: .3em; }
.potnum { font-size: clamp(54px, 17vw, 84px); font-weight: 900; color: #fff3d6; text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 22px rgba(240,179,84,.35); transition: color .2s; }
.potnum.bust { color: #ff8a8a; }
.chips { min-height: 26px; display: flex; justify-content: center; --chip-size: 22px; }
.standing { text-align: center; font-size: 14px; color: var(--muted); min-height: 20px; }
.standing b { color: var(--text); }
.actions { display: flex; gap: 8px; }
.actions .btn.big { flex: 1; }
.actions .bank { flex: 1.25 !important; }
.actions .bank.done { background: #1d2a22; border-color: #2c4636; color: var(--good); opacity: 1; }
.actions.multi { flex-direction: column; }
.banks { display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 6px; }
.bank-sm { min-height: 50px; flex-direction: column; gap: 0; padding: 2px 4px; font-size: 13px; border-top: 3px solid var(--c); }
.bank-sm span { font-size: 11.5px; font-weight: 650; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.bank-sm.done { background: #1d2a22; color: var(--good); opacity: 1; }

/* ------------------------------------------------ scores */
.page { width: 100%; max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; min-height: 0; flex: 1; }
.tablewrap { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 13.5px; }
table.scores th, table.scores td { padding: 6px 6px; text-align: right; border-bottom: 1px solid #222838; white-space: nowrap; }
table.scores thead th { position: sticky; top: 0; background: var(--bg-soft); font-size: 12px; text-align: right; max-width: 70px; overflow: hidden; text-overflow: ellipsis; z-index: 1; }
table.scores thead th .dot { width: 7px; height: 7px; margin-right: 4px; }
table.scores thead th .nmc { display: inline-block; max-width: 64px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
table.scores.wide thead th .nmc { max-width: 38px; }
table.scores.wide th, table.scores.wide td { padding: 6px 3px; }
table.scores tbody th { color: var(--muted); font-weight: 600; text-align: left; }
table.scores tbody th i { font-style: normal; font-size: 10px; color: var(--bad); margin-left: 4px; border: 1px solid #6b2c38; border-radius: 4px; padding: 0 3px; }
table.scores td.lost { color: var(--bad); font-weight: 800; }
table.scores tr.cur { background: rgba(240,179,84,.07); }
table.scores td.live { color: var(--good); }
table.scores tfoot th, table.scores tfoot td { position: sticky; bottom: 0; background: var(--bg-soft); font-weight: 850; font-size: 15px; border-top: 1px solid var(--line); }
table.scores td.lead { color: var(--accent-warm); }

/* ------------------------------------------------ settings */
.settings { gap: 10px; max-width: 560px; }
.settings .label { margin-top: 6px; }
.set-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }

/* ------------------------------------------------ sheets */
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; max-height: 82dvh; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.sheet h3 { margin: 0; font-size: 22px; color: var(--accent-warm); }
.ranks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; counter-reset: r; }
.ranks li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; background: var(--bg-soft); counter-increment: r; }
.ranks li::before { content: counter(r); color: var(--muted); width: 14px; font-weight: 700; }
.ranks li.win { background: rgba(240,179,84,.14); }
.ranks li.me .grow { color: var(--accent-warm); font-weight: 700; }
.ranks b { font-size: 17px; }
.pick-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pick { background: var(--bg-soft); border: 2px solid transparent; border-radius: 10px; padding: 6px 0; display: grid; place-items: center; cursor: pointer; }
.pick .pd { --die-size: clamp(34px, 11vw, 46px); }
.pick[aria-pressed="true"] { border-color: var(--accent-warm); background: rgba(240,179,84,.16); }
@media (min-width: 900px) { .sheet-back { align-items: center; } .sheet { border-radius: 16px; max-width: 440px; } }

/* ------------------------------------------------ laptop: table + live score sheet side by side */
@media (min-width: 900px) {
  #v-play.on { flex-direction: row; gap: 18px; justify-content: center; }
  .game { max-width: 700px; }
  .side { display: flex; flex-direction: column; gap: 8px; width: clamp(340px, 32vw, 470px); flex: none; min-height: 0; }
  .side table.scores th, .side table.scores td { padding: 5px 4px; font-size: 12.5px; }
  .seats { gap: 8px; }
  .seat .sc { font-size: 22px; }
  .seat .nm { font-size: 14px; }
  .felt { min-height: 280px; }
  .dice > span { --die-size: clamp(66px, 5.4vw, 92px); }
  .potnum { font-size: clamp(84px, 7vw, 120px); }
}
/* phone on its side: seats left, table right */
@media (max-height: 480px) and (orientation: landscape) {
  .view { padding: 6px 10px; }
  .game { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: auto 1fr auto auto; max-width: none; column-gap: 10px; row-gap: 6px; }
  .topbar { grid-column: 1; grid-row: 1; }
  .seats { grid-column: 1; grid-row: 2; align-content: start; --cols: 2 !important; grid-template-columns: 1fr 1fr; }
  .standing { grid-column: 1; grid-row: 3; }
  .felt { grid-column: 2; grid-row: 1 / 3; min-height: 0; padding-top: 28px; }
  .actions { grid-column: 2; grid-row: 3 / 5; }
  .btn.big { min-height: 50px; }
  .potnum { font-size: 52px; }
  .dice > span { --die-size: 44px; }
}
@media (max-width: 360px) {
  .seat .sc { font-size: 16px; }
  .seats.c4 .seat .lv { display: none; }
  .potnum { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) { .seat { transition: none; } }
/* rules sheet videos: the sheet is cream paper, so links and notes need dark ink */
.coach-rules-body a { color: #2a4f9e; font-weight: 650; }
.coach-rules-body .vids .muted { color: #5c5546; }
/* real-dice undo, in the top bar */
.undo-btn { min-height: 30px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-soft); color: var(--text); font-size: 13px; font-weight: 650; cursor: pointer; flex: none; }
.undo-btn[hidden] { display: none; }
/* setup halves: one column normally; side by side on a phone held sideways so Start fits above the tab bar */
.setup .sa, .setup .sb { display: contents; }
@media (max-height: 480px) and (orientation: landscape) {
  .setup.split { max-width: 780px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 16px; align-items: start; }
  .setup.split .sa, .setup.split .sb { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
  .setup.split .hero h1 { font-size: 28px; }
  .setup.split .hero-dice .hd { --die-size: 28px; }
}
/* small phones (iPhone SE size): two steppers side by side and a smaller title, so Start stays above the tab bar */
@media (max-width: 400px) and (max-height: 600px) {
  .set-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .setup { gap: 8px; }
  .hero h1 { font-size: 28px; }
  .hero-dice .hd { --die-size: 28px; }
  .names.many .txt { min-height: 34px; }
  .setup .seg button { min-height: 34px; }
}
