:root {
  --felt-1: #1f7a4f;
  --felt-2: #11452c;
  --felt-3: #0b2f1e;
  --on-felt: #f4efe1;
  --on-felt-muted: rgba(244, 239, 225, 0.68);
  --paper: #fbf8ef;
  --paper-line: #e6dfcc;
  --paper-shade: #f3eedf;
  --ink: #1f2a44;
  --ink-muted: #7a7f8c;
  --ink-faint: #b4b3ad;
  --accent: #e7a92c;
  --accent-strong: #c98a10;
  --good: #2f8f5b;
  --bad: #c2453a;
  --die: #fffdf7;
  --die-edge: #d9d2bf;
  --pip: #1f2a44;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.18);
  /* chart series (validated categorical order on the paper surface) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --chart-text-2: #52514e;
  --chart-muted: #898781;
  --chart-grid: #e6dfcc;
  --chart-axis: #c3c2b7;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

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

html, body { margin: 0; }

body {
  min-height: 100vh;
  font-family: var(--font);
  color: var(--on-felt);
  background-color: var(--felt-2);
  background-image:
    radial-gradient(ellipse at 50% 0%, var(--felt-1) 0%, var(--felt-2) 55%, var(--felt-3) 100%);
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px 20px 8px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.02em; }
.tagline { margin: 0; color: var(--on-felt-muted); font-size: 0.85rem; }
.brand-die {
  width: 38px; height: 38px; border-radius: 9px;
  background:
    radial-gradient(circle at 28% 28%, var(--pip) 0 3.5px, transparent 4px),
    radial-gradient(circle at 50% 50%, var(--pip) 0 3.5px, transparent 4px),
    radial-gradient(circle at 72% 72%, var(--pip) 0 3.5px, transparent 4px),
    var(--die);
  box-shadow: inset 0 -3px 0 var(--die-edge), 0 4px 10px rgba(0, 0, 0, 0.3);
  transform: rotate(-8deg);
  /* the logo die takes quick taps (Glaube easter egg): no double-tap zoom, selection or highlight */
  touch-action: manipulation; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.brand-die.tapped { animation: logo-tap 0.3s ease-out; }
@keyframes logo-tap {
  40% { transform: rotate(8deg) scale(1.1); }
  100% { transform: rotate(-8deg); }
}
.top-actions { display: flex; align-items: center; gap: 14px; }
body[data-view="sim"] .play-only { visibility: hidden; }

/* ---------- tabs ---------- */
.tabs {
  display: inline-flex; gap: 4px; padding: 4px;
  border-radius: 999px; background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.tab {
  border: 0; cursor: pointer; border-radius: 999px;
  padding: 8px 18px; font-weight: 600; color: var(--on-felt-muted); background: transparent;
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tab:hover { color: var(--on-felt); }
.tab[aria-selected="true"] { background: var(--paper); color: var(--ink); }
.tab:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; cursor: pointer; border-radius: 999px; white-space: nowrap;
  padding: 9px 18px; font-weight: 600;
  transition: transform 0.08s ease, background-color 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn-ghost {
  background: rgba(255, 255, 255, 0.1);
  color: var(--on-felt);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.18); }
.btn-roll {
  min-width: 220px;
  padding: 14px 28px;
  font-size: 1.1rem;
  color: #3a2700;
  background: linear-gradient(180deg, #f6c556, var(--accent));
  box-shadow: 0 4px 0 var(--accent-strong), 0 8px 18px rgba(0, 0, 0, 0.3);
}
.btn-roll:hover { background: linear-gradient(180deg, #f9cf6b, #ecb23d); }
.btn-roll:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-strong), 0 4px 10px rgba(0, 0, 0, 0.3); }
.btn-roll:disabled {
  cursor: default; opacity: 0.45; transform: none;
  box-shadow: 0 4px 0 var(--accent-strong);
}

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 24px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 12px 20px 24px;
  align-items: start;
}
.play { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- stats ---------- */
/* three + two tiles, or all five in a row where they fit */
.stats { container-type: inline-size; }
.stats-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.stats-grid .stat { grid-column: span 2; }
.stats-grid .stat:nth-child(n + 4) { grid-column: span 3; }
@container (min-width: 600px) {
  .stats-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .stats-grid .stat, .stats-grid .stat:nth-child(n + 4) { grid-column: auto; }
}
.stat {
  min-width: 0;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--on-felt-muted); }
.stat-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 0.85rem; font-weight: 500; color: var(--on-felt-muted); }
#stat-handicap.has-loss { color: #ffb4a8; }
#stat-luck.lucky { color: #a9f0c6; }
#stat-luck.unlucky { color: #ffb4a8; }

/* ---------- dice tray ---------- */
.tray {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  padding: 26px 20px 24px;
  border-radius: 20px;
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0.22));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 2px 18px rgba(0, 0, 0, 0.35);
}
.roll-pips { display: flex; gap: 8px; align-items: center; font-size: 0.8rem; color: var(--on-felt-muted); }
.roll-pips .pip-dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
}
.roll-pips .pip-dot.used { background: var(--accent); border-color: var(--accent); }
.dice { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; padding: 10px 0 16px; }
.tray-actions { display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }

/* buttons and the timeline: side by side where the tray is wide enough, stacked otherwise */
.tray { container: tray / inline-size; }
.tray-bottom { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 18px; }
@container tray (max-width: 539px) {
  .tray-tools .btn-text { display: none; }
  .tray-tools .btn { padding: 7px; }
}
@container tray (max-width: 520px) {
  .tray-hint { min-height: 2.6em; }
}
@container tray (min-width: 600px) {
  .tray-bottom { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 28px; }
  .tray-bottom .tray-actions { flex-direction: column; align-items: stretch; width: 300px; } /* fixed: the label changes */
  .tray-bottom .timeline { max-width: none; }
}
/* timeline: luck of every roll (diverging around zero) and handicap of every decision
   (hanging down, same scale), 13 rounds of 3 roll slots */
.timeline { position: relative; width: 100%; max-width: 520px; min-width: 0; touch-action: pan-y; outline: none; }
.timeline:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 6px; }
.tl-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.tl-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--on-felt-muted); }
.tl-scale { font-size: 0.7rem; color: var(--on-felt-muted); font-variant-numeric: tabular-nums; }
.tl-value { margin-left: auto; font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--on-felt); }
.tl-plot { display: block; width: 100%; overflow: visible; }
#tl-luck { margin-bottom: 8px; }
.tl-plot .track { fill: rgba(255, 255, 255, 0.06); }
.tl-plot .track.current { fill: rgba(255, 255, 255, 0.11); }
.tl-plot .now { fill: rgba(231, 169, 44, 0.34); }
.tl-plot .hover { fill: rgba(255, 255, 255, 0.2); }
.tl-plot .zero { stroke: rgba(244, 239, 225, 0.38); stroke-width: 1; shape-rendering: crispEdges; }
.tl-plot .bar.up { fill: #a9f0c6; }
.tl-plot .bar.down, .tl-plot .bar.loss { fill: #ffb4a8; }
.tl-plot .stub { fill: rgba(244, 239, 225, 0.6); }
.tl-plot .round { fill: var(--on-felt-muted); font-size: 10px; text-anchor: middle; font-variant-numeric: tabular-nums; }
.tl-plot .round.current { fill: var(--on-felt); font-weight: 700; }
.tl-plot .fresh { transform-box: fill-box; transform-origin: 50% 100%; animation: tl-grow 0.35s ease-out; }
.tl-plot .fresh.down, .tl-plot .fresh.loss { transform-origin: 50% 0; }
@keyframes tl-grow { from { transform: scaleY(0); } }
.tl-tooltip { top: auto; bottom: calc(100% + 8px); min-width: 210px; max-width: 280px; }
.tip-row .key.up { background: var(--good); }
.tip-row .key.down { background: var(--bad); }
.tip-row .key.flat { background: var(--chart-muted); }
.tip-best { margin-top: 4px; padding-left: 20px; color: var(--chart-text-2); font-size: 0.78rem; }
/* small pill buttons: tips (held down) and undo */
.tray-tools { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; }
.btn-undo, .btn-peek {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 13px 6px 11px;
  font-size: 0.85rem;
  color: var(--on-felt);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.22);
}
.btn-undo svg, .btn-peek svg { width: 16px; height: 16px; flex: none; }
.btn-undo:hover, .btn-peek:hover { background: rgba(255, 255, 255, 0.14); }
.btn-undo:disabled, .btn-peek:disabled { cursor: default; opacity: 0.4; transform: none; }
.btn-peek { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
.btn-peek.active, .btn-peek.active:hover {
  color: #3a2700; background: var(--accent); border-color: var(--accent); transform: translateY(1px);
}
.btn-peek.on-paper { color: var(--ink); background: var(--paper-shade); border-color: var(--paper-line); }
.btn-peek.on-paper:hover { background: #efe6cc; }
.btn-peek.on-paper.active { color: #3a2700; background: var(--accent); border-color: var(--accent-strong); }
.tray-hint { margin: 0; min-height: 1.3em; line-height: 1.3; color: var(--on-felt-muted); font-size: 0.92rem; text-align: center; }
/* easter egg: typing "glaube" shows this slider, it tilts the dice towards better rolls */
.glaube {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 3.5em; align-items: center; gap: 4px 14px;
  width: 100%; max-width: 420px; margin-top: -10px;
  animation: glaube-in 0.6s ease-out;
}
.glaube label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.glaube output { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.glaube-note { grid-column: 1 / -1; margin: 0; text-align: center; font-size: 0.8rem; color: var(--on-felt-muted); }
@keyframes glaube-in {
  from { opacity: 0; transform: translateY(-6px); filter: drop-shadow(0 0 0 transparent); }
  50% { filter: drop-shadow(0 0 10px var(--accent)); }
  to { opacity: 1; transform: none; filter: drop-shadow(0 0 0 transparent); }
}

.die {
  --size: 72px;
  position: relative;
  width: var(--size); height: var(--size);
  padding: calc(var(--size) * 0.14);
  border: 0; border-radius: 22%;
  background: var(--die);
  box-shadow: inset 0 -5px 0 var(--die-edge), 0 6px 14px rgba(0, 0, 0, 0.35);
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.die:disabled { cursor: default; }
.die:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.die.blank { background: rgba(255, 253, 247, 0.16); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2); }
.die.held {
  transform: translateY(-10px);
  box-shadow: inset 0 -5px 0 var(--die-edge), 0 0 0 4px var(--accent), 0 14px 22px rgba(0, 0, 0, 0.35);
}
.die.held::after {
  content: "gehalten";
  position: absolute; left: 50%; bottom: -26px; transform: translateX(-50%);
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent);
}
.die.suggest::before {
  content: "★";
  position: absolute; top: -10px; right: -10px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.8rem; color: #3a2700; background: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
.die.rolling { animation: tumble 0.5s ease-out; }
@keyframes tumble {
  0% { transform: translateY(-18px) rotate(-25deg) scale(0.92); }
  45% { transform: translateY(4px) rotate(14deg); }
  75% { transform: translateY(-3px) rotate(-5deg); }
  100% { transform: none; }
}
.pip { width: calc(var(--size) * 0.15); height: calc(var(--size) * 0.15); margin: auto; border-radius: 50%; background: var(--pip); visibility: hidden; }
.pip.on { visibility: visible; }

/* mini dice used in text */
.mini-dice { display: inline-flex; gap: 3px; vertical-align: middle; }
.mini-die {
  --size: 20px;
  width: var(--size); height: var(--size); border-radius: 5px; padding: 2.5px;
  background: var(--die); box-shadow: inset 0 -2px 0 var(--die-edge);
  display: inline-grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
}

/* the dice of a roll with a decision: kept dice ringed (as in the tray), re-rolled ones faded,
   or followed by the category entered; used by the decision panel and the history */
.roll-choice {
  --die-max: 18px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 3px 10px; min-width: 0;
  container-type: inline-size;
}
.roll-choice .mini-dice { gap: 4px; }
/* full size where it fits, smaller on the narrowest phones (five dice and four gaps fill the box) */
.roll-choice .mini-die {
  --size: min(var(--die-max), (100cqw - 16px) / 5);
  padding: calc(var(--size) * 0.11); border-radius: calc(var(--size) * 0.22);
}
.mini-die.kept { box-shadow: inset 0 -2px 0 var(--die-edge), 0 0 0 2px var(--accent); }
.mini-die.rerolled { opacity: 0.3; }
.roll-cat { min-width: 0; overflow-wrap: anywhere; line-height: 1.25; }
.roll-points { color: var(--on-felt-muted); font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }

/* ---------- panels ---------- */
.panel {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.panel h2 { margin: 0 0 10px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--on-felt-muted); }
.feedback-empty { color: var(--on-felt-muted); font-size: 0.92rem; }

.choice-grid { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px 14px; align-items: center; }
.choice-label { font-size: 0.85rem; color: var(--on-felt-muted); }
.choice-what { font-weight: 600; min-width: 0; }
.choice-what .roll-choice { --die-max: 24px; gap: 4px 12px; }
.choice-ev { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.verdict {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 12px;
  padding: 5px 12px; border-radius: 999px; font-weight: 700; font-size: 0.88rem;
}
.verdict.ok { background: rgba(47, 143, 91, 0.25); color: #a9f0c6; }
.verdict.loss { background: rgba(194, 69, 58, 0.25); color: #ffc2b9; }
.feedback-meta { font-size: 0.8rem; color: var(--on-felt-muted); margin-bottom: 10px; }

/* the decision panel while "Optionen" is held */
.feedback.peeking { border-color: rgba(231, 169, 44, 0.45); background: rgba(231, 169, 44, 0.1); }
.feedback.peeking h2 { color: #f5d08a; }
.options { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.options li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center;
  padding: 5px 8px; border-radius: 8px; font-size: 0.9rem;
}
.options li.best { background: rgba(231, 169, 44, 0.16); }
.options .roll-choice { --die-max: 20px; }
.options .opt-ev, .options .opt-delta { font-variant-numeric: tabular-nums; text-align: right; }
.options .opt-delta { color: #ffc2b9; min-width: 4.5em; }
.options li.best .opt-delta { color: #f5d08a; }

/* game over */
.gameover { border-color: rgba(231, 169, 44, 0.5); background: rgba(0, 0, 0, 0.3); text-align: center; padding: 22px 16px; }
.gameover h2 { color: #f5d08a; font-size: 0.9rem; }
.final-score { font-size: 3rem; font-weight: 800; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.final-grid { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; margin: 16px 0; }
.final-grid div { background: rgba(255, 255, 255, 0.06); border-radius: 10px; padding: 8px; }
.final-grid span { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--on-felt-muted); }
.final-grid strong { font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.final-note { font-size: 0.82rem; color: var(--on-felt-muted); margin: 0 0 14px; }

/* log: every roll with your decision and the optimal one */
.log summary { cursor: pointer; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--on-felt-muted); }
.log-legend {
  display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 12px 0 8px;
  font-size: 0.78rem; color: var(--on-felt-muted);
}
.log-legend > span { display: inline-flex; align-items: center; gap: 7px; }
.log-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 0.86rem; }
.log-table .c-round { width: 1.9em; }
.log-table .c-roll { width: 2.4em; }
.log-table .c-loss { width: 4.4em; }
.log-table thead th {
  padding: 4px 6px 6px; text-align: left; font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--on-felt-muted);
}
.log-table thead th.num { text-align: right; }
.log-table td, .log-table tbody th { padding: 6px; vertical-align: middle; }
.log-table tbody { border-top: 1px solid rgba(255, 255, 255, 0.1); }
.log-table tr.miss > td { background: rgba(194, 69, 58, 0.14); }
.log-table .log-round { vertical-align: top; padding-top: 9px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.log-table .log-roll { color: var(--on-felt-muted); font-size: 0.76rem; white-space: nowrap; }
.log-table .log-loss { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.log-loss.ok { color: #a9f0c6; }
.log-loss.bad { color: #ffc2b9; }
.log-empty { color: var(--on-felt-muted); }
.log-legend .mini-die { --size: 18px; padding: 2px; border-radius: 4px; }

/* ---------- score sheet ---------- */
.sheet {
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  position: sticky; top: 16px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-sub { display: block; font-size: 0.8rem; color: var(--ink-muted); }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores .col-pts { width: 96px; }
.scores .col-ev { width: 0; }
.sheet.peek .scores .col-ev { width: 70px; }
.scores th, .scores td { padding: 7px 8px; border-bottom: 1px dashed var(--paper-line); text-align: left; }
.scores th { font-weight: 500; }
.scores td.pts { text-align: right; font-weight: 700; font-size: 1.02rem; white-space: nowrap; }
/* distance of an upper-section score from three of that face */
.scores .par { margin-right: 6px; font-size: 0.78rem; font-weight: 600; }
.scores .par.up { color: var(--good); }
.scores .par.down { color: var(--bad); }
.scores .par.even { color: var(--ink-muted); }
/* preliminary: faded like the points, full strength while the row is hovered */
.scores tr.cat.open .par { opacity: 0.45; font-weight: 500; }
.scores tr.cat.selectable:hover .par, .scores tr.cat.selectable:focus-visible .par { opacity: 1; font-weight: 600; }
.scores td.ev { text-align: right; font-size: 0.8rem; color: var(--ink-muted); white-space: nowrap; }
.scores tbody + tbody tr:first-child th,
.scores tbody + tbody tr:first-child td { border-top: 2px solid var(--paper-line); }
.scores .subtotal th, .scores .subtotal td { background: var(--paper-shade); font-size: 0.9rem; }
.scores .subtotal small { color: var(--ink-muted); font-weight: 400; }
.scores .total th, .scores .total td { font-weight: 800; font-size: 1.1rem; border-bottom: 0; border-top: 2px solid var(--ink); }
.scores tr.cat.filled td.pts { color: var(--ink); }
/* points an open row would get: light, so they read as preliminary */
.scores tr.cat.open td.pts { color: #9fb0d2; font-weight: 500; }
.scores tr.cat.open.zero td.pts { color: #dcd9d0; }
.scores tr.cat.selectable { cursor: pointer; }
.scores tr.cat.selectable:hover th, .scores tr.cat.selectable:hover td,
.scores tr.cat.selectable:focus-visible th, .scores tr.cat.selectable:focus-visible td { background: #f1ead4; }
.scores tr.cat.selectable:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: -2px; }
.scores tr.cat.selectable:hover td.pts, .scores tr.cat.selectable:focus-visible td.pts { color: #2a4a8a; font-weight: 700; }
.scores tr.cat.just-filled th, .scores tr.cat.just-filled td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #fde6b0; } to { background: transparent; } }
.scores tr.cat.best-cat th::after {
  content: "★"; margin-left: 6px; color: var(--accent-strong); font-size: 0.85rem;
}
.scores tr.cat.best-cat th, .scores tr.cat.best-cat td { background: #fcefcf; }
.scores td.ev.best { color: var(--accent-strong); font-weight: 700; }
.scores td.ev.neg { color: var(--bad); }
.sheet-note { margin: 12px 0 0; font-size: 0.75rem; color: var(--ink-muted); }
kbd {
  font-family: inherit; font-size: 0.72rem; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--paper-line); background: #fff; color: var(--ink);
}


/* ---------- simulation ---------- */
.sim-layout {
  display: grid; gap: 16px;
  max-width: 1120px; margin: 0 auto; padding: 12px 20px 24px;
}
.sim-controls { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 28px; padding: 18px 20px; }
.control { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.control-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.control-head label, .control-label {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--on-felt-muted);
}
.control-head output { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.control-note { margin: 2px 0 0; font-size: 0.85rem; line-height: 1.45; color: var(--on-felt-muted); }
.control-note em { font-style: italic; }
.range-ends { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--on-felt-muted); }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), rgba(255, 255, 255, 0.25));
}
input[type="range"]::-moz-range-track {
  height: 6px; border-radius: 999px; background: linear-gradient(90deg, var(--accent), rgba(255, 255, 255, 0.25));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--paper); border: 3px solid var(--accent); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}
input[type="range"]:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; border-radius: 6px; }

.segmented {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px;
  border-radius: 12px; background: rgba(0, 0, 0, 0.22); border: 1px solid rgba(255, 255, 255, 0.08);
}
.segmented button {
  border: 0; border-radius: 9px; padding: 8px 6px; cursor: pointer; font-weight: 600;
  color: var(--on-felt-muted); background: transparent; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.segmented button:hover { color: var(--on-felt); }
.segmented button[aria-checked="true"] { background: var(--paper); color: var(--ink); }
.segmented button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.sim-run { min-width: 0; width: 100%; margin-top: 8px; }
.sim-run.is-stop { background: linear-gradient(180deg, #f3a497, #e07a68); color: #3b0d06; box-shadow: 0 4px 0 #b9503f, 0 8px 18px rgba(0, 0, 0, 0.3); }
.progress { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.3s ease; }
.progress-text { font-size: 0.82rem; color: var(--on-felt-muted); font-variant-numeric: tabular-nums; min-height: 1.2em; }

.sim-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.stat-sub { font-size: 0.75rem; color: var(--on-felt-muted); min-height: 1em; }

.card {
  position: relative;
  background: var(--paper); color: var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px 16px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.card h2 { margin: 0; font-size: 1.1rem; }
.card-sub { margin: 2px 0 0; font-size: 0.82rem; color: var(--chart-text-2); }
.chart-tools { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; font-size: 0.85rem; color: var(--chart-text-2); }
.chart-tools select {
  margin-left: 6px; font: inherit; padding: 4px 8px; border-radius: 8px;
  border: 1px solid var(--chart-axis); background: #fff; color: var(--ink);
}
.chart-tools .check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.chart-tools input[type="checkbox"] { accent-color: var(--series-1); width: 16px; height: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 4px 0 8px; font-size: 0.85rem; color: var(--chart-text-2); min-height: 1.2em; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-item strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.line-key { width: 16px; height: 2px; border-radius: 1px; background: var(--chart-text-2); display: inline-block; }
.g0 { fill: var(--series-1); background: var(--series-1); }
.g1 { fill: var(--series-2); background: var(--series-2); }
.g2 { fill: var(--series-3); background: var(--series-3); }
.g3 { fill: var(--series-4); background: var(--series-4); }

.chart { position: relative; width: 100%; min-height: 260px; border-radius: 8px; }
.chart:focus-visible { outline: 2px solid var(--series-1); outline-offset: 4px; }
.chart svg { display: block; overflow: visible; }
.chart-empty { display: grid; place-items: center; height: 260px; color: var(--chart-muted); font-size: 0.95rem; }
.chart .grid line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .grid .tick-mark { stroke: var(--chart-axis); }
.chart .tick { fill: var(--chart-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis-label { fill: var(--chart-muted); font-size: 11px; }
.chart .baseline { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .hover-band { fill: rgba(31, 42, 68, 0.07); }
.chart .ref-line { fill: none; stroke: var(--chart-text-2); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .mean-line { stroke: var(--ink); stroke-width: 1; shape-rendering: crispEdges; }
.chart .mean-label { fill: var(--ink); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .overlay { fill: transparent; cursor: crosshair; }

.chart-tooltip {
  position: absolute; z-index: 5; pointer-events: none;
  min-width: 190px; padding: 10px 12px; border-radius: 10px;
  background: #fff; color: var(--ink); font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(11, 11, 11, 0.08);
}
.tip-head { color: var(--chart-text-2); margin-bottom: 2px; }
.tip-main { margin-bottom: 6px; color: var(--chart-text-2); }
.tip-main strong { font-size: 1.1rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.tip-row { display: grid; grid-template-columns: 14px 4.6em minmax(0, 1fr); gap: 6px; align-items: center; color: var(--chart-text-2); }
.tip-row strong { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.tip-row .key { width: 12px; height: 2px; border-radius: 1px; }
.tip-row .key.ref { background: var(--chart-text-2); }

.sim-bottom { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { padding: 7px 8px; border-bottom: 1px solid var(--chart-grid); text-align: left; white-space: nowrap; }
.data-table thead th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--chart-muted); font-weight: 600; }
.data-table thead th.no-case { text-transform: none; font-size: 0.85rem; }
.data-table tbody th { font-weight: 500; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.total th, .data-table tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 0; }
.data-table td.empty { color: var(--chart-muted); border-bottom: 0; }
#sim-runs tbody tr { cursor: pointer; }
#sim-runs tbody tr:hover td { background: #f3eedf; }
#sim-runs tbody tr.selected td { background: #e9eefa; }
#sim-runs tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--series-1); }
#sim-runs tbody tr:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }
.data-table .actions { text-align: right; padding-right: 0; }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; color: var(--chart-text-2);
  width: 30px; height: 30px; border-radius: 8px; font-size: 1rem; line-height: 1;
}
.icon-btn:hover { background: #ece5d2; color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--ink); font-weight: 700; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:focus-visible { outline: 2px solid var(--series-1); }

/* ---------- footer / toast ---------- */
.footer { max-width: 1120px; margin: 0 auto; padding: 8px 20px 28px; font-size: 0.8rem; color: var(--on-felt-muted); }
.footer a { color: var(--on-felt); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2b1b1b; color: #ffd9d3; padding: 10px 18px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: 0.9rem; max-width: calc(100% - 32px);
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .sim-controls { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .sim-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sim-bottom { grid-template-columns: minmax(0, 1fr); }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  /* single column: keep the score sheet close to the dice */
  .play { display: contents; }
  .stats { order: 1; }
  .tray { order: 2; }
  .feedback { order: 3; }
  .gameover { order: 4; }
  .sheet { order: 6; position: static; }
  .log { order: 7; }
}
@media (max-width: 560px) {
  .topbar { padding: 14px 16px 4px; }
  .layout { padding: 10px 16px 20px; gap: 16px; }
  .footer { padding: 8px 16px 24px; }
  .tagline { display: none; }
  .topbar { flex-wrap: wrap; row-gap: 10px; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; }
  .sim-layout { padding: 10px 16px 20px; }
  .sim-controls { padding: 16px; }
  .card { padding: 14px 14px 12px; }
  .brand h1 { font-size: 1.35rem; }
  .brand-die { width: 30px; height: 30px; }
  .top-actions { gap: 10px; }
  .btn-ghost { padding: 8px 12px; }
  .tray { padding: 20px 12px 18px; gap: 14px; }
  .scores th, .scores td { padding: 6px 6px; }
  .sheet-note { display: none; }
  .stat { padding: 9px 12px; }
  .stat-label { letter-spacing: 0.05em; }
  .stat-value { font-size: 1.25rem; }
  .dice { gap: 9px; }
  /* five dice and four gaps in one row, smaller only where the tray is narrower than that */
  .die { --size: min(54px, (100cqw - 36px) / 5); }
  .tray-actions { flex-direction: column; align-items: stretch; width: 100%; gap: 10px; }
  .btn-roll { min-width: 0; width: 100%; }
  .tray-tools { top: 10px; right: 10px; }
  .final-grid { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); }
  .log { padding: 14px 10px; }
  .log-table td, .log-table tbody th { padding: 6px 4px; }
  .log .roll-cat { font-size: 0.8rem; }
  .mini-die.kept { box-shadow: inset 0 -1.5px 0 var(--die-edge), 0 0 0 1.5px var(--accent); }
  .log-table .c-round { width: 1.5em; }
  .log-table .c-roll { width: 2.1em; }
  .log-table .c-loss { width: 4.3em; }
}

@media (prefers-reduced-motion: reduce) {
  .die.rolling, .scores tr.cat.just-filled th, .scores tr.cat.just-filled td { animation: none; }
  .tl-plot .fresh { animation: none; }
  .glaube, .brand-die.tapped { animation: none; }
}

.muted { color: var(--on-felt-muted); font-weight: 400; }
