/* Farkle score keeper. Mobile first: one column, main buttons along the bottom edge. */
:root {
  --bg: #fff6e5;
  --bg2: #ffe9c2;
  --card: #ffffff;
  --ink: #1c1726;
  --muted: #625a6e;
  --line: #ead8b8;
  --hi: #ffcf33;
  --hi-ink: #1c1726;
  --go: #0b8a5e;
  --go-ink: #ffffff;
  --farkle: #d93a24;
  --farkle-ink: #ffffff;
  --chip: #ffffff;
  --chip-big: #fff0cc;
  --shadow: 0 2px 0 rgba(28, 23, 38, .9);
  --radius: 16px;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16131f;
    --bg2: #1f1a2c;
    --card: #231d31;
    --ink: #f7f0e3;
    --muted: #b3a9c2;
    --line: #3a3150;
    --hi: #ffcf33;
    --hi-ink: #1c1726;
    --go: #1fbf86;
    --go-ink: #08130e;
    --farkle: #ff5a40;
    --farkle-ink: #1a0905;
    --chip: #2c2540;
    --chip-big: #3a2f52;
    --shadow: 0 2px 0 rgba(0, 0, 0, .7);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.3;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
button, input, a, label { touch-action: manipulation; }
input { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

#app { height: 100%; }
.screen {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--st) + 8px) calc(var(--sr) + 14px) 0 calc(var(--sl) + 14px);
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- buttons ---------- */
.btn {
  min-height: 48px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  padding: 0 18px;
  font-weight: 800;
  font-size: 18px;
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform .06s ease, box-shadow .06s ease;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.btn:disabled { opacity: .45; }
.btn-big { min-height: 60px; font-size: 22px; letter-spacing: .02em; }
.btn-go { background: var(--go); color: var(--go-ink); }
.btn-farkle { background: var(--farkle); color: var(--farkle-ink); }
.btn-ink { background: var(--ink); color: var(--bg); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--line); }
.icon-btn {
  width: 44px; height: 44px; min-width: 44px;
  display: inline-grid; place-items: center;
  border-radius: 12px; border: 0; background: transparent;
}
.icon-btn:active { background: var(--bg2); }
.icon-btn:disabled { opacity: .25; }
.icon-btn.sm svg { width: 20px; height: 20px; }

.bottom-bar {
  margin-top: auto;
  display: flex;
  gap: 10px;
  padding: 10px 0 calc(var(--sb) + 12px);
  background: linear-gradient(to bottom, transparent, var(--bg) 12px);
  position: sticky;
  bottom: 0;
}
.bottom-bar .btn { flex: 1; }

/* ---------- setup ---------- */
#setup { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.setup-head { text-align: center; padding: 10px 0 6px; }
.setup-head h1 { margin: 6px 0 0; font-size: 44px; font-weight: 900; letter-spacing: -.02em; }
.tag { margin: 0; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .18em; font-size: 12px; }
.logo { display: flex; justify-content: center; gap: 10px; }
.die {
  width: 46px; height: 46px; border-radius: 11px; background: var(--card);
  border: 2.5px solid var(--ink); box-shadow: var(--shadow);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 6px;
}
.die i { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); place-self: center; }
.die.d5 { transform: rotate(-10deg); }
.die.d5 i:nth-child(1) { grid-area: 1 / 1; } .die.d5 i:nth-child(2) { grid-area: 1 / 3; }
.die.d5 i:nth-child(3) { grid-area: 2 / 2; } .die.d5 i:nth-child(4) { grid-area: 3 / 1; }
.die.d5 i:nth-child(5) { grid-area: 3 / 3; }
.die.d1 { transform: rotate(8deg); background: var(--farkle); }
.die.d1 i { grid-area: 2 / 2; width: 11px; height: 11px; background: #fff; }

.card {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 12px 0 0;
}
.card h2, .sheet h2 { margin: 2px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
.player-list { list-style: none; margin: 0; padding: 0; }
.player-row { display: flex; align-items: center; gap: 2px; padding: 3px 0; border-bottom: 1px solid var(--line); }
.pnum {
  width: 28px; height: 28px; min-width: 28px; border-radius: 50%; display: grid; place-items: center;
  background: var(--hi); color: var(--hi-ink); font-weight: 900; font-size: 15px; margin-right: 6px;
}
.pname, .add-row input, .field input[type=number] {
  font: inherit; font-size: 18px; font-weight: 700; color: var(--ink);
  background: transparent; border: 0; min-height: 44px; min-width: 0; flex: 1; padding: 0 4px; border-radius: 10px;
}
.pname:focus, .add-row input:focus, .field input[type=number]:focus { outline: 2px solid var(--hi); background: var(--bg); }
.add-row { display: flex; gap: 8px; margin-top: 10px; }
.add-row input { border: 2px solid var(--line); padding: 0 12px; background: var(--bg); }
.del { color: var(--farkle); }
.hint { color: var(--muted); font-size: 15px; margin: 8px 0 0; }

.field { display: flex; align-items: center; gap: 12px; min-height: 52px; border-bottom: 1px solid var(--line); }
.field:last-child { border-bottom: 0; }
.field > span { flex: 1; font-weight: 700; }
.field small { display: block; font-weight: 500; color: var(--muted); font-size: 14px; }
.field input[type=number] { flex: 0 0 116px; text-align: right; border: 2px solid var(--line); background: var(--bg); padding: 0 10px; }
.switch input {
  -webkit-appearance: none; appearance: none; margin: 0;
  width: 56px; height: 34px; min-width: 56px; border-radius: 34px; background: var(--line); position: relative;
  transition: background .15s;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch input:checked { background: var(--go); }
.switch input:checked::after { transform: translateX(22px); }
.switch input:focus { outline: none; }
.switch input:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
.switch { cursor: pointer; padding: 6px 0; }
#setup .bottom-bar { margin-top: 14px; }

/* ---------- game ---------- */
#game { overflow: hidden; }
.top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.top-title { text-align: center; line-height: 1.1; }
.round { display: block; font-weight: 900; font-size: 18px; }
.goal { font-size: 13px; color: var(--muted); font-weight: 700; }

.scoreboard {
  list-style: none; margin: 6px 0 0; padding: 0;
  flex: 0 1 auto; min-height: 96px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 6px;
}
.sb-btn {
  width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 8px;
  padding: 7px 12px 9px; min-height: 48px; text-align: left;
  border: 2px solid var(--line); border-radius: 14px; background: var(--card);
}
.sb-name { font-weight: 800; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-total { font-weight: 900; font-size: 22px; font-variant-numeric: tabular-nums; }
.sb-bar { grid-column: 1 / -1; height: 5px; border-radius: 5px; background: var(--bg2); margin-top: 5px; overflow: hidden; }
.sb-bar i { display: block; height: 100%; background: var(--go); border-radius: 5px; transition: width .3s ease; }
.sb-row.current .sb-btn { background: var(--hi); color: var(--hi-ink); border-color: var(--ink); box-shadow: var(--shadow); }
.sb-row.current .sb-bar { background: rgba(28, 23, 38, .15); }
.sb-row.current .sb-bar i { background: var(--hi-ink); }
.sb-row.current .sb-name::before { content: "🎲 "; }
.badge {
  display: inline-block; vertical-align: 2px; margin-left: 6px; padding: 1px 7px; border-radius: 20px;
  font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; border: 1.5px solid currentColor;
}
.badge.off { color: var(--muted); }
.badge.fk { color: var(--farkle); border: 0; letter-spacing: 0; padding: 0; font-size: 13px; }
.badge.tg { background: var(--go); color: var(--go-ink); border-color: var(--go); }
.sb-row.current .badge { color: var(--hi-ink); }
.sb-row.current .badge.fk { color: #b0200c; }

.turn {
  margin-top: 10px; padding: 10px 14px 10px; border-radius: 18px;
  background: var(--card); border: 2.5px solid var(--ink); box-shadow: 0 3px 0 var(--ink);
  text-align: center; position: relative;
  flex: 1 1 0; min-height: min-content; max-height: 260px; display: flex; flex-direction: column; justify-content: center;
}
.turn.shake { animation: shake .45s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-1deg); }
  40% { transform: translateX(7px) rotate(1deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}
.final-banner {
  margin: 8px 0 0; padding: 6px 10px; border-radius: 10px; text-align: center;
  background: var(--farkle); color: var(--farkle-ink); font-weight: 800; font-size: 14px;
}
.turn-who { font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-name { color: var(--ink); }
.turn-suffix { color: var(--muted); }
.turn-sub { display: flex; flex-direction: column; align-items: center; }
.sub-value { font-size: 52px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.sub-after { font-size: 15px; font-weight: 700; color: var(--muted); margin-top: 2px; }
.sub-after.warn { color: var(--farkle); }
.parts { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; min-height: 0; margin-top: 4px; }
.parts:empty { display: none; }
.part {
  border: 0; border-radius: 20px; padding: 0 10px; min-height: 30px; font-size: 14px; font-weight: 800;
  background: var(--bg2); color: var(--ink);
}
.part.pend { display: inline-flex; align-items: center; opacity: .6; }

.entry { margin-top: 10px; }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 8px; }
.seg-btn {
  flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 800; font-size: 16px; color: var(--muted);
}
.seg-btn[aria-selected=true] { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chip {
  min-height: 48px; border-radius: 12px; border: 2px solid var(--line); background: var(--chip);
  font-weight: 900; font-size: 17px; font-variant-numeric: tabular-nums; padding: 0 2px;
}
.chip.big { background: var(--chip-big); }
.chip.clear { font-size: 14px; color: var(--farkle); border-style: dashed; }
.chip:active, .key:active { transform: scale(.94); background: var(--hi); color: var(--hi-ink); }
.pad-display { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
#pad-value {
  flex: 1; text-align: right; font-size: 30px; font-weight: 900; padding: 0 12px; min-height: 48px; line-height: 48px;
  border-radius: 12px; background: var(--card); border: 2px solid var(--line); font-variant-numeric: tabular-nums;
}
.pad-add { min-width: 96px; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.key {
  min-height: 46px; border-radius: 12px; border: 2px solid var(--line); background: var(--chip);
  font-size: 22px; font-weight: 900;
}
.game-bar { margin-top: 0; }
.btn-undo { flex: 0 0 76px !important; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; }
.btn-undo svg { width: 22px; height: 22px; }
#farkle-btn { flex: 1.1; }
#bank-btn { flex: 1.3; white-space: nowrap; padding: 0 8px; }
#bank-btn.need { font-size: 18px; }
.scoreboard.compact .sb-btn { min-height: 44px; padding: 5px 12px 6px; }
.scoreboard.compact .sb-bar { height: 4px; margin-top: 3px; }
.scoreboard.compact { gap: 4px; }

/* short phones: tighten the turn card */
@media (max-height: 700px) {
  .sub-value { font-size: 40px; }
  .turn { padding: 6px 12px; }
  .chip, .key { min-height: 44px; }
  .btn-big { min-height: 54px; }
}

/* ---------- setup: mode and rules ---------- */
.mode-seg { margin-bottom: 2px; }
.mode-seg .seg-btn { min-height: 60px; display: flex; flex-direction: column; justify-content: center; line-height: 1.15; }
.mode-seg .seg-btn small { font-size: 12px; font-weight: 600; color: var(--muted); }
.mode-seg .seg-btn[aria-checked=true] { background: var(--hi); color: var(--hi-ink); box-shadow: var(--shadow); }
.mode-seg .seg-btn[aria-checked=true] small { color: var(--hi-ink); }
.rule { gap: 8px; padding: 4px 0; }
.rule-text { flex: 1; font-weight: 700; min-width: 0; cursor: pointer; }
.rule.off .rule-text > span { color: var(--muted); }
.field.rule input[type=number] { flex: 0 0 96px; }
.field.rule input[type=number]:disabled { opacity: .4; }
.sw { display: grid; place-items: center; min-width: 56px; min-height: 44px; cursor: pointer; }
.sw input {
  -webkit-appearance: none; appearance: none; margin: 0;
  width: 56px; height: 34px; border-radius: 34px; background: var(--line); position: relative; transition: background .15s;
}
.sw input::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.sw input:checked { background: var(--go); }
.sw input:checked::after { transform: translateX(22px); }
.sw input:focus { outline: none; }
.sw input:focus-visible { outline: 3px solid var(--hi); outline-offset: 2px; }
.rules-reset { width: 100%; margin-top: 10px; font-size: 16px; }

/* ---------- play mode ---------- */
body[data-mode=play] .scoreboard { max-height: 30vh; max-height: 30dvh; }
.final-banner + .play, .scoreboard + .final-banner { margin-top: 8px; }
.play { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; margin-top: 10px; }
.handoff, .table {
  flex: 1 1 auto; min-height: 0; border-radius: 20px; background: var(--card);
  border: 2.5px solid var(--ink); box-shadow: 0 3px 0 var(--ink); padding: 12px 14px;
  display: flex; flex-direction: column;
}
.handoff { justify-content: center; text-align: center; gap: 4px; }
.ho-kicker { margin: 0; text-transform: uppercase; letter-spacing: .16em; font-weight: 800; color: var(--muted); font-size: 14px; }
.ho-name { margin: 0; font-size: 48px; font-weight: 900; line-height: 1.05; word-break: break-word; color: var(--ink); }
.ho-info { margin: 4px 0 0; font-weight: 700; color: var(--muted); font-size: 17px; }
.ho-last {
  margin: 0 auto 14px; padding: 6px 14px; border-radius: 30px; background: var(--bg2); font-weight: 800; font-size: 15px;
}
.play-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.play-name { font-size: 22px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-total { text-align: right; white-space: nowrap; }
.play-total b { font-size: 40px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.play-total small { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-top: -4px; }
.dice {
  --d: min(25vw, 13vh, 104px);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 10px auto 4px;
  width: calc(3 * var(--d) + 24px); max-width: 100%;
}
.pdie {
  width: var(--d); height: var(--d); border-radius: 20%; padding: 0;
  background: #fffdf8; border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
  display: grid; grid-template: repeat(3, calc(var(--d) * .24)) / repeat(3, calc(var(--d) * .24)); place-content: center;
  transition: transform .12s ease, background .12s, box-shadow .12s;
}
.pdie i { width: calc(var(--d) * .15); height: calc(var(--d) * .15); border-radius: 50%; background: #1c1726; place-self: center; }
.p1 { grid-area: 1 / 1; } .p3 { grid-area: 1 / 3; } .p4 { grid-area: 2 / 1; } .p5 { grid-area: 2 / 2; }
.p6 { grid-area: 2 / 3; } .p7 { grid-area: 3 / 1; } .p9 { grid-area: 3 / 3; }
.pdie[data-face="1"] i { background: var(--farkle); width: calc(var(--d) * .2); height: calc(var(--d) * .2); }
.pdie.picked { background: var(--hi); transform: translateY(-6px) rotate(-3deg); box-shadow: 0 8px 0 var(--ink); }
.pdie.dead { opacity: .45; box-shadow: 0 2px 0 var(--ink); }
.pdie:disabled { cursor: default; }
.dice.rolling .pdie { animation: tumble .32s linear infinite; }
.dice.rolling .pdie:nth-child(2n) { animation-duration: .27s; animation-direction: reverse; }
.dice.rolling .pdie:nth-child(3n) { animation-duration: .36s; }
@keyframes tumble {
  0% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(4px, -10px) rotate(90deg); }
  50% { transform: translate(-3px, 2px) rotate(180deg); }
  75% { transform: translate(3px, -6px) rotate(270deg); }
  100% { transform: translate(0, 0) rotate(360deg); }
}
.dice.farkled .pdie { opacity: .6; border-color: var(--farkle); box-shadow: 0 4px 0 var(--farkle); }
.dice.shake { animation: shake .45s; }
.play-msg { margin: 8px 0 0; text-align: center; font-weight: 800; font-size: 17px; min-height: 1.3em; color: var(--muted); }
.play-msg.good { color: var(--go); }
.play-msg.bad { color: var(--farkle); font-size: 20px; }
.play-msg.hot { color: var(--farkle); }
.kept { margin-top: auto; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 12px; padding-top: 8px; }
.kept:empty { display: none; }
.kept-row { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 12px; background: var(--bg2); }
.kept-dice { display: flex; gap: 3px; }
.mdie {
  width: 22px; height: 22px; border-radius: 5px; background: #fffdf8; border: 1.5px solid var(--ink); padding: 2px;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}
.mdie i { width: 4px; height: 4px; border-radius: 50%; background: #1c1726; place-self: center; }
.kept-pts { font-weight: 900; font-variant-numeric: tabular-nums; font-size: 15px; }
#roll-btn, #pbank-btn { flex: 1 1 0; min-width: 0; white-space: nowrap; padding: 0 6px; font-size: 20px; overflow: hidden; text-overflow: ellipsis; }
@media (max-height: 700px) {
  .dice { --d: min(24vw, 12vh, 92px); gap: 10px; width: calc(3 * var(--d) + 20px); }
  .ho-name { font-size: 40px; }
  .play-total b { font-size: 32px; }
}

/* ---------- game over ---------- */
#over { overflow-y: auto; position: relative; text-align: center; }
.over-head { padding: 30px 0 10px; position: relative; }
.over-kicker { margin: 0; text-transform: uppercase; letter-spacing: .2em; font-weight: 800; color: var(--muted); font-size: 14px; }
.over-head h1 { margin: 6px 0 0; font-size: 46px; font-weight: 900; line-height: 1.05; word-break: break-word; }
.over-score {
  display: inline-block; margin: 12px 0 0; font-size: 30px; font-weight: 900; padding: 4px 18px;
  background: var(--hi); color: var(--hi-ink); border: 2.5px solid var(--ink); border-radius: 40px; box-shadow: var(--shadow);
}
.confetti {
  position: absolute; inset: 0 0 auto 0; height: 260px; pointer-events: none; opacity: .9;
  background:
    radial-gradient(circle at 12% 20%, var(--farkle) 0 5px, transparent 6px),
    radial-gradient(circle at 85% 14%, var(--go) 0 6px, transparent 7px),
    radial-gradient(circle at 70% 40%, var(--hi) 0 5px, transparent 6px),
    radial-gradient(circle at 22% 55%, var(--hi) 0 4px, transparent 5px),
    radial-gradient(circle at 92% 62%, var(--farkle) 0 4px, transparent 5px),
    radial-gradient(circle at 6% 80%, var(--go) 0 5px, transparent 6px),
    radial-gradient(circle at 50% 6%, var(--farkle) 0 4px, transparent 5px);
}
.standings { list-style: none; padding: 0; margin: 22px 0 0; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.standings li {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 52px;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px;
}
.standings li.first { border-color: var(--ink); background: var(--hi); color: var(--hi-ink); }
.standings .rk { font-weight: 900; width: 24px; }
.standings .nm { flex: 1; font-weight: 800; font-size: 18px; }
.standings .pt { font-weight: 900; font-size: 20px; font-variant-numeric: tabular-nums; }
.over-actions { display: flex; gap: 10px; margin-top: 14px; }
.over-actions .btn { flex: 1; font-size: 16px; }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(10, 6, 20, .45); z-index: 10; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; margin: 0 auto; max-width: 560px;
  background: var(--card); border-radius: 22px 22px 0 0; border: 2px solid var(--ink); border-bottom: 0;
  padding: 8px calc(var(--sr) + 16px) calc(var(--sb) + 14px) calc(var(--sl) + 16px);
  max-height: 88vh; max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 8px; animation: rise .2s ease-out;
}
.sheet.tall { height: 88vh; height: 88dvh; }
.sheet-grab { width: 44px; height: 5px; border-radius: 5px; background: var(--line); margin: 0 auto 4px; flex: none; }
.sheet h2 { margin-top: 4px; }
.sheet-item {
  min-height: 54px; text-align: left; padding: 0 16px; font-weight: 800; font-size: 18px;
  background: var(--bg); border: 2px solid var(--line); border-radius: 14px;
}
.sheet-item.danger { color: var(--farkle); }
.sheet-row { display: flex; gap: 10px; }
.sheet-row .btn { flex: 1; }
.sheet-close { margin-top: 4px; flex: none; }
@keyframes rise { from { transform: translateY(40%); opacity: .3; } }
@keyframes fade { from { opacity: 0; } }

#history-tabs { overflow-x: auto; flex: none; }
#history-tabs .seg-btn { flex: 1 0 auto; padding: 0 12px; white-space: nowrap; }
.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.h-row {
  display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 0 12px; text-align: left;
  background: var(--bg); border: 2px solid var(--line); border-radius: 12px; font-variant-numeric: tabular-nums;
}
.h-round { color: var(--muted); font-weight: 800; width: 38px; }
.h-pts { flex: 1; font-weight: 900; font-size: 18px; }
.h-pts.fk { color: var(--farkle); }
.h-pts.neg { color: var(--farkle); }
.h-total { font-weight: 800; color: var(--muted); }
.h-edit { font-size: 13px; font-weight: 800; padding: 3px 9px; border-radius: 8px; background: var(--bg2); }

.rules { overflow-y: auto; flex: 1; }
.rules table { width: 100%; border-collapse: collapse; font-size: 17px; }
.rules td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.rules td:last-child { text-align: right; font-weight: 900; font-variant-numeric: tabular-nums; }
.rules ul { padding-left: 20px; margin: 12px 0 0; }
.rules li { margin-bottom: 6px; font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sb) + 92px); transform: translateX(-50%);
  max-width: calc(100% - 32px); width: max-content; z-index: 20; pointer-events: none;
  background: var(--ink); color: var(--bg); font-weight: 800; font-size: 15px; text-align: center;
  padding: 10px 16px; border-radius: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
}
.toast.show { animation: pop .25s ease-out; }
@keyframes pop { from { transform: translateX(-50%) translateY(10px) scale(.96); opacity: 0; } }

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

/* ---------- presets and house rules ---------- */
.preset-seg .seg-btn { min-height: 48px; }
.preset-seg .seg-btn[aria-selected=true] { background: var(--hi); color: var(--hi-ink); box-shadow: var(--shadow); }
#rules-changed { margin: 2px 0 0; }
.ho-offer {
  margin: 14px 0 0; padding: 10px 12px 12px; border-radius: 14px; background: var(--hi); color: var(--hi-ink);
  font-weight: 800; font-size: 17px; border: 2px solid var(--ink);
}
.ho-offer p { margin: 0 0 8px; }
.take-btn { width: 100%; min-height: 54px; font-size: 20px; }
.pass-btn { margin-top: 8px; width: 100%; font-size: 16px; min-height: 46px; flex: none; }
.kept-row.passed, .kept-row.bonus { font-weight: 800; font-size: 14px; }
.kept-row.bonus { background: var(--hi); color: var(--hi-ink); }
.offer {
  display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 6px;
  font-weight: 800; font-size: 15px;
}
.offer-take { min-height: 44px; font-size: 16px; padding: 0 12px; }
.part.passed { background: var(--hi); color: var(--hi-ink); }
.bonus-chips { grid-template-columns: repeat(2, 1fr); margin-top: 6px; }
.bonus-chips:empty { display: none; }
.chip.bonus { background: var(--hi); color: var(--hi-ink); border-color: var(--ink); font-size: 16px; }
.game-bar.four .btn-big { font-size: 18px; padding: 0 4px; }
.game-bar.four .btn-undo { flex: 0 0 60px !important; }
#pass-btn { flex: 0.9; }

/* ---------- lucky and poison dice ---------- */
/* Gold with a star, blue with a crossed drop: told apart by colour, brightness and the mark. */
.pdie.lucky { background: #f2b705; border-color: #5c3d00; }
.pdie.poison { background: #1d4fa8; border-color: #0b1f45; }
.pdie.poison i { background: #fff !important; }
.pdie.lucky.picked, .pdie.poison.picked { outline: 4px solid var(--ink); outline-offset: 2px; }
.pdie .mark { position: absolute; top: 3%; right: 3%; width: 34%; height: 34%; stroke-width: 2; }
.pdie { position: relative; }
.pdie.lucky .mark { fill: #fff6d0; stroke: #5c3d00; }
.pdie.poison .mark { fill: #8fd0ff; stroke: #0b1f45; }
.mdie.lucky { background: #f2b705; border-color: #5c3d00; }
.mdie.poison { background: #1d4fa8; }
.mdie.poison i { background: #fff; }
.kept-row.lucky-row { background: #f2b705; color: #1c1726; font-weight: 800; }
.set-total { margin: 0; text-align: right; font-weight: 800; font-size: 14px; color: var(--muted); }
.play-hint { margin: 4px 0 0; text-align: center; font-weight: 700; font-size: 14px; color: var(--muted); }
.play-hint.forced {
  color: var(--ink); background: var(--bg2); border-radius: 12px; padding: 6px 10px; font-size: 15px; font-weight: 800;
}
.play-msg.lucky-msg { color: #9a6a00; }
@media (prefers-color-scheme: dark) { .play-msg.lucky-msg { color: #f2b705; } }
.special-chips { grid-template-columns: repeat(2, 1fr); margin-top: 6px; }
.special-chips:empty { display: none; }
.chip.special { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 16px; }
.chip.special .mark { width: 20px; height: 20px; stroke-width: 2; }
.chip.special.lucky { background: #f2b705; color: #1c1726; border-color: #5c3d00; }
.chip.special.lucky .mark { fill: #fff6d0; stroke: #5c3d00; }
.chip.special.poison { background: #1d4fa8; color: #fff; border-color: #0b1f45; }
.chip.special.poison .mark { fill: #8fd0ff; stroke: #0b1f45; }
.face-keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.face-key { min-height: 52px; }
.special-parts { justify-content: flex-start; }
.part.toggle { min-height: 44px; opacity: .55; }
.part.toggle.on { opacity: 1; background: var(--hi); color: var(--hi-ink); }
.blocked-note { color: var(--farkle) !important; }
.pdie.next { animation: nudge 1.2s ease-in-out infinite; outline: 3px dashed var(--ink); outline-offset: 3px; }
@keyframes nudge { 50% { outline-color: transparent; } }  /* blink the outline; the die itself stays still */
.table { overflow-y: auto; }
.ho-note { margin: 12px 0 0; font-weight: 700; color: var(--muted); font-size: 16px; }
.ho-offer .take-btn + .take-btn { margin-top: 8px; }
.track-pass { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.tp-kicker { margin: 0; font-size: 22px; font-weight: 900; }
.tp-text { margin: 0; font-weight: 700; color: var(--muted); }
.tp-btn { min-height: 52px; font-size: 18px; }
.sb-row.out .sb-btn { opacity: .5; border-style: dashed; }
.sb-row.out .sb-name { text-decoration: line-through; text-decoration-thickness: 2px; }
.badge.out { color: var(--muted); border-color: var(--muted); }
.standings li.out { opacity: .55; }
.final-banner.raised { background: var(--go); color: var(--go-ink); }
.ho-offer .take-btn { font-size: 18px; padding: 0 8px; }
.game-bar { margin-top: auto; }
.pass-note { margin: 8px 0 0; text-align: center; font-weight: 800; font-size: 15px; color: var(--muted); }
#pbank-btn.long { font-size: 18px; letter-spacing: 0; }
