/* ------------------------------------------------------------------ */
/* Tokens                                                             */
/* ------------------------------------------------------------------ */
:root {
  --ink: #0a1511;
  --ink-2: #0e1f18;
  --felt: #10251d;
  --cream: #f5eeda;
  --cream-2: #e9dcc2;
  --paper: #f7f0df;
  --paper-deep: #ebdfc5;
  --dark-text: #1e2c24;
  --muted: #a4b3a8;
  --muted-2: #7f9187;
  --gold: #d9b567;
  --gold-bright: #f2d493;
  --gold-deep: #a67d32;
  --mint: #8ec9a6;
  --coral: #dd7b5d;
  --green: #2f7d51;
  --line: rgba(245, 238, 218, 0.12);
  --line-strong: rgba(245, 238, 218, 0.22);
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Segoe UI", Inter, system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
  --shadow-deep: 0 30px 60px rgba(0, 0, 0, 0.42);
  --radius: 24px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  padding: 0;
  color: var(--cream);
  background:
    radial-gradient(1100px 720px at 72% -12%, rgba(217, 181, 103, 0.17), transparent 58%),
    radial-gradient(1000px 700px at -8% 108%, rgba(58, 131, 96, 0.24), transparent 62%),
    linear-gradient(155deg, #0f241b 0%, #0a1712 52%, #07100c 100%);
  font-family: var(--sans);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.017) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.017) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 78%);
  -webkit-mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 78%);
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ */
/* Shell                                                              */
/* ------------------------------------------------------------------ */
.app {
  position: relative;
  z-index: 1;
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 26px 30px 18px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 2px 2px 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  position: relative;
  width: 48px;
  height: 48px;
  flex: none;
  border-radius: 14px;
  background: linear-gradient(150deg, #fffaf0 0%, #f0e2c6 62%, #dcc9a4 100%);
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    inset 0 -3px 6px rgba(120, 96, 54, 0.18);
  transform: rotate(-8deg);
}

.brand-pip {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #25342b;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.28);
}
.bp1 { top: 11px; left: 11px; }
.bp2 { top: 11px; right: 11px; }
.bp3 { top: 20px; left: 20px; }
.bp4 { bottom: 11px; left: 11px; }
.bp5 { bottom: 11px; right: 11px; }

.brand-text h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 31px;
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1;
}
.brand-text h1 .dot { color: var(--gold); }
.brand-text p {
  margin: 5px 0 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.masthead-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.record {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}
.record-label {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted-2);
}
#recordValue { font-weight: 700; color: var(--gold-bright); }

.chip-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.035);
  color: var(--cream);
  border-radius: 999px;
  padding: 9px 14px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease, color 0.18s ease;
}
.chip-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--line-strong);
}
.chip-btn:active { transform: translateY(1px); }
.chip-btn[aria-pressed="true"] {
  border-color: rgba(217, 181, 103, 0.55);
  background: rgba(217, 181, 103, 0.12);
  color: var(--gold-bright);
}
.chip-primary {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  border-color: rgba(255, 255, 255, 0.35);
  color: #1c2a22;
}
.chip-primary:hover {
  background: linear-gradient(180deg, #ffe4ad, #e2c176);
  border-color: rgba(255, 255, 255, 0.55);
}
.chip-btn.is-confirming {
  background: rgba(221, 123, 93, 0.14);
  border-color: rgba(221, 123, 93, 0.5);
  color: #ffd7c8;
}

/* ------------------------------------------------------------------ */
/* Table layout                                                       */
/* ------------------------------------------------------------------ */
.table {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(355px, 0.78fr);
  gap: 22px;
  flex: 1;
  align-items: stretch;
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 24px 26px 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(700px 380px at 50% -10%, rgba(255, 255, 255, 0.055), transparent 65%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0.012));
  box-shadow:
    var(--shadow-deep),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
  overflow: hidden;
}
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.26);
}

.turn-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.turn-who {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 0 4px rgba(142, 201, 166, 0.12), 0 0 14px rgba(142, 201, 166, 0.65);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.status-dot.is-cpu {
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(221, 123, 93, 0.12), 0 0 14px rgba(221, 123, 93, 0.6);
  animation: pulse-cpu 1.4s ease-in-out infinite;
}
.status-dot.is-over {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(217, 181, 103, 0.14), 0 0 14px rgba(217, 181, 103, 0.6);
}
.rolls {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.14);
  white-space: nowrap;
}

/* ------------------------------------------------------------------ */
/* Dice                                                               */
/* ------------------------------------------------------------------ */
.dice-tray {
  min-height: 168px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.1vw, 21px);
  padding: 38px 12px 30px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.055);
  background:
    radial-gradient(ellipse at 50% 34%, rgba(255, 255, 255, 0.055), transparent 68%),
    rgba(0, 0, 0, 0.16);
  box-shadow:
    inset 0 14px 34px rgba(0, 0, 0, 0.3),
    inset 0 -1px 0 rgba(255, 255, 255, 0.04);
}

.die {
  position: relative;
  flex: none;
  width: 74px;
  height: 74px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  background: linear-gradient(152deg, #fffdf7 0%, #f2e6cd 56%, #ddcda9 100%);
  box-shadow:
    0 14px 24px rgba(0, 0, 0, 0.36),
    0 2px 0 rgba(255, 255, 255, 0.6) inset,
    0 -4px 8px rgba(116, 92, 51, 0.18) inset;
  cursor: pointer;
  outline: none;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  will-change: transform;
}

.die .pip {
  position: absolute;
  width: 14%;
  height: 14%;
  border-radius: 50%;
  background: #233229;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25);
}
.die .p0 { top: 17%; left: 17%; }
.die .p1 { top: 17%; left: 43%; }
.die .p2 { top: 17%; left: 69%; }
.die .p3 { top: 43%; left: 17%; }
.die .p4 { top: 43%; left: 43%; }
.die .p5 { top: 43%; left: 69%; }
.die .p6 { top: 69%; left: 17%; }
.die .p7 { top: 69%; left: 43%; }
.die .p8 { top: 69%; left: 69%; }

.die.is-empty {
  background: rgba(255, 255, 255, 0.035);
  border: 1px dashed rgba(245, 238, 218, 0.2);
  box-shadow: none;
  cursor: default;
}
.die.is-empty::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18%;
  height: 2px;
  border-radius: 2px;
  background: rgba(245, 238, 218, 0.22);
  transform: translate(-50%, -50%);
}
.die.is-empty .pip { display: none; }

.die.is-held {
  transform: translateY(-13px);
  border-color: rgba(242, 212, 147, 0.95);
  box-shadow:
    0 0 0 4px rgba(217, 181, 103, 0.16),
    0 22px 30px rgba(0, 0, 0, 0.42),
    0 2px 0 rgba(255, 255, 255, 0.7) inset;
}
.die.is-held::after {
  content: "HELD";
  position: absolute;
  left: 50%;
  bottom: -21px;
  transform: translateX(-50%);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: var(--gold-bright);
  white-space: nowrap;
}

.die.is-static { cursor: default; }
.die.is-rolling {
  animation: die-tumble 0.42s ease-in-out infinite;
  pointer-events: none;
}
.die.just-landed { animation: die-land 0.3s ease-out; }

.die:focus-visible {
  box-shadow:
    0 0 0 3px var(--ink),
    0 0 0 6px var(--gold-bright),
    0 14px 24px rgba(0, 0, 0, 0.36);
}

/* ------------------------------------------------------------------ */
/* Controls                                                           */
/* ------------------------------------------------------------------ */
.play-controls {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-top: 2px;
}
.roll-btn {
  flex: none;
  min-width: 196px;
  padding: 15px 26px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 14px;
  background: linear-gradient(180deg, #f8dfaa 0%, #e3c079 48%, #cfa657 100%);
  color: #1b2a21;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 14px 26px rgba(0, 0, 0, 0.34),
    0 1px 0 rgba(255, 255, 255, 0.75) inset,
    0 -3px 0 rgba(148, 112, 46, 0.28) inset;
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}
.roll-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow:
    0 18px 30px rgba(0, 0, 0, 0.4),
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 -3px 0 rgba(148, 112, 46, 0.28) inset;
}
.roll-btn:active:not(:disabled) { transform: translateY(1px); }
.roll-btn:disabled {
  cursor: default;
  opacity: 0.36;
  filter: saturate(0.55);
  box-shadow: none;
}
.roll-btn:focus-visible {
  outline: 2px solid var(--gold-bright);
  outline-offset: 3px;
}

.prompt {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
  max-width: 390px;
}
.prompt strong { color: var(--cream); font-weight: 600; }

/* ------------------------------------------------------------------ */
/* Insight / coach                                                    */
/* ------------------------------------------------------------------ */
.insight {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(4, 11, 8, 0.3);
  overflow: hidden;
}
.insight-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid rgba(245, 238, 218, 0.07);
  background: rgba(255, 255, 255, 0.018);
}
.insight-tag {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-bright);
}
.insight-note {
  font-size: 10.5px;
  color: var(--muted-2);
  letter-spacing: 0.04em;
}
.insight-body {
  padding: 14px 16px 16px;
  min-height: 118px;
  font-size: 13px;
  line-height: 1.5;
}

.coach { display: flex; flex-direction: column; gap: 11px; }
.coach-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.coach-label {
  flex: none;
  width: 82px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.coach-value {
  margin-left: auto;
  flex: none;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.coach-choice {
  font-weight: 600;
  color: var(--cream);
  letter-spacing: 0.01em;
}
.coach-points {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--mint);
}
.coach-alt {
  margin: 2px 0 0;
  padding-top: 10px;
  border-top: 1px dashed rgba(245, 238, 218, 0.09);
  font-size: 11px;
  color: var(--muted-2);
  line-height: 1.6;
}
.coach-alt b { color: var(--muted); font-weight: 600; }

.mini-dice { display: flex; gap: 5px; flex-wrap: wrap; }
.mini-die {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: linear-gradient(160deg, #fdf7e8, #e7d8b8);
  color: #26342b;
  font-size: 12px;
  font-weight: 800;
  font-family: var(--mono);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.85);
}
.mini-die.none {
  background: transparent;
  border: 1px dashed rgba(245, 238, 218, 0.22);
  color: var(--muted-2);
  box-shadow: none;
  font-size: 10px;
  font-weight: 500;
}

.bonus-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.meter-track {
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  max-width: 120px;
}
.meter-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8ec9a6, #f2d493);
  transition: width 0.4s ease;
}
.meter-label {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted-2);
  white-space: nowrap;
}

.insight-hint {
  color: var(--muted);
  line-height: 1.65;
  max-width: 46ch;
}
.insight-hint b { color: var(--cream); font-weight: 600; }

.ai-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
}
.ai-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  animation: line-in 0.25s ease-out both;
}
.ai-line .tag {
  flex: none;
  width: 58px;
  color: var(--muted-2);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ai-line .dice-vals { color: var(--cream); letter-spacing: 0.08em; }
.ai-line .ev { margin-left: auto; color: var(--gold-bright); }
.ai-line.decision .dice-vals { color: var(--mint); font-weight: 700; }
.ai-line .cat-name { color: var(--mint); font-weight: 700; font-family: var(--sans); }

.ai-final {
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px dashed rgba(245, 238, 218, 0.09);
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: 12.5px;
  color: var(--cream);
}
.ai-final .score {
  margin-left: auto;
  font-family: var(--serif);
  font-size: 19px;
  color: var(--gold-bright);
}

.thinking-dots { display: inline-flex; gap: 4px; align-items: center; }
.thinking-dots i {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--gold);
  animation: dot-bounce 1.1s ease-in-out infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }

/* ------------------------------------------------------------------ */
/* Scorecard                                                          */
/* ------------------------------------------------------------------ */
.score-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 19px 18px 17px;
  border-radius: var(--radius);
  color: var(--dark-text);
  background:
    radial-gradient(900px 420px at 20% -15%, rgba(255, 255, 255, 0.7), transparent 60%),
    linear-gradient(165deg, #fbf6e8 0%, #f3ead6 52%, #eaddc2 100%);
  box-shadow:
    0 26px 54px rgba(0, 0, 0, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.45);
  overflow: hidden;
}
.score-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  opacity: 0.5;
  background-image: radial-gradient(rgba(80, 60, 28, 0.12) 0.55px, transparent 0.55px);
  background-size: 5px 5px;
}
.score-panel > * { position: relative; z-index: 1; }

.scorecard-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 1px 5px 12px;
  border-bottom: 1px solid rgba(35, 48, 38, 0.16);
}
.scorecard-title h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.025em;
}
.scorecard-title p {
  margin: 4px 0 0;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #7d8375;
}
.mini-legend {
  display: flex;
  gap: 11px;
  padding-top: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7d8375;
  white-space: nowrap;
}
.legend-you::before,
.legend-cpu::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
.legend-you::before { background: #3c7f5a; }
.legend-cpu::before { background: #c76a4d; }

.scorecard-scroll { overflow: visible; }
.scorecard-foot {
  margin: auto 2px 0;
  padding-top: 12px;
  border-top: 1px solid rgba(35, 48, 38, 0.1);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #8b8b78;
  text-align: center;
}

.scorecard {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}
.scorecard .cat-col { width: 54%; }
.scorecard thead th {
  padding: 10px 7px 7px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #878a7b;
  text-align: right;
  border-bottom: 1px solid rgba(35, 48, 38, 0.1);
}
.scorecard thead th.cat-col { text-align: left; padding-left: 6px; }
.scorecard.you-turn thead th:nth-child(2) { color: #2f6d4e; }
.scorecard.cpu-turn thead th:nth-child(3) { color: #b15a3f; }

.scorecard tbody th {
  padding: 4px 8px 4px 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: #2b3a30;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.scorecard tbody td { padding: 0 2px; }

.cat-row { height: 29px; }
.cat-row + .cat-row th,
.cat-row + .cat-row td { border-top: 1px solid rgba(35, 48, 38, 0.065); }

.score-cell {
  display: block;
  width: 100%;
  min-height: 27px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
  color: #26352b;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.score-cell.is-open { color: #a6a896; font-weight: 500; }
.score-cell.is-preview {
  color: #9d7429;
  background: rgba(199, 158, 76, 0.1);
  border: 1px dashed rgba(160, 120, 48, 0.28);
  font-weight: 700;
}
.score-cell.is-preview.is-zero { color: #b3a58c; }
.score-cell.is-active { cursor: pointer; }
.score-cell.is-active:hover {
  background: #20342a;
  border-color: transparent;
  color: var(--cream);
  box-shadow: 0 4px 10px rgba(28, 44, 34, 0.22);
}
.score-cell.is-filled { color: #1d2b22; }
.score-cell.is-filled.is-zero { color: #a0a594; font-weight: 500; }
.score-cell.is-flash { animation: cell-flash 1s ease-out; }
.score-cell:focus-visible {
  outline: 2px solid #2f6d4e;
  outline-offset: 1px;
}
.score-cell[disabled] { cursor: default; }

.section-row th {
  padding: 12px 6px 4px;
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #8a8a77;
  text-align: left;
  border-bottom: 1px solid rgba(35, 48, 38, 0.08);
}
.section-row th::after {
  content: "";
  display: inline-block;
  width: 20px;
  height: 1px;
  margin-left: 8px;
  vertical-align: 3px;
  background: rgba(35, 48, 38, 0.18);
}

.summary-row th {
  padding: 6px 6px 6px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: #66705f;
  text-align: left;
  border-top: 1px solid rgba(35, 48, 38, 0.08);
}
.summary-row td {
  padding: 5px 8px;
  text-align: right;
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 600;
  color: #4b564a;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid rgba(35, 48, 38, 0.08);
}
.summary-row td.is-earned { color: #2f7d51; font-weight: 800; }
.summary-row td.is-pending { color: #938e7d; font-weight: 500; font-size: 10.5px; }
.summary-row td.is-flash { animation: cell-flash 1s ease-out; }

.total-row th {
  padding: 10px 10px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--cream);
  text-align: left;
  background: linear-gradient(100deg, #1f3529, #182a20);
  border-radius: 10px 0 0 10px;
}
.total-row td {
  padding: 7px 10px;
  text-align: right;
  background: linear-gradient(100deg, #1f3529, #182a20);
  color: var(--gold-bright);
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.total-row td:last-child { border-radius: 0 10px 10px 0; }
.total-row { filter: drop-shadow(0 5px 8px rgba(30, 44, 34, 0.16)); }

/* ------------------------------------------------------------------ */
/* Footer                                                             */
/* ------------------------------------------------------------------ */
.footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 2px 0;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(164, 179, 168, 0.56);
}
.footer-right { text-align: right; }

/* ------------------------------------------------------------------ */
/* Modals                                                             */
/* ------------------------------------------------------------------ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(3, 8, 6, 0.68);
  backdrop-filter: blur(9px);
  animation: fade-in 0.18s ease-out;
}
.modal[hidden] { display: none; }

.modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  padding: 32px 34px 30px;
  border-radius: 24px;
  color: var(--dark-text);
  background:
    radial-gradient(700px 300px at 15% -10%, rgba(255, 255, 255, 0.8), transparent 60%),
    linear-gradient(168deg, #fcf7eb, #f0e5d0);
  box-shadow: 0 50px 100px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.85);
  animation: modal-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-close {
  position: absolute;
  top: 14px;
  right: 15px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(35, 48, 38, 0.14);
  background: rgba(255, 255, 255, 0.36);
  color: #475348;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: rgba(35, 48, 38, 0.08); }

.eyebrow {
  margin: 0 0 8px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #9b7837;
}
.modal-card h2 {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: 31px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: #1b2a21;
}
.rules-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  margin-bottom: 22px;
}
.modal-card h3 {
  margin: 18px 0 7px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #22342a;
}
.modal-card h3:first-child { margin-top: 0; }
.modal-card p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.65;
  color: #4a564b;
}
.modal-card ul {
  margin: 0 0 10px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.65;
  color: #4a564b;
}
.modal-card li { margin-bottom: 4px; }
.modal-card strong, .modal-card b { color: #22342a; }
.rule-note {
  padding: 9px 11px;
  border-left: 2px solid rgba(155, 120, 55, 0.45);
  background: rgba(155, 120, 55, 0.06);
  border-radius: 0 6px 6px 0;
  font-size: 12px !important;
  color: #5a6357 !important;
}

.btn-gold,
.btn-ghost-wide {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  padding: 13px 22px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}
.btn-gold {
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: linear-gradient(180deg, #f5d999, #d7ad5c);
  color: #1b2a21;
  box-shadow: 0 8px 18px rgba(120, 90, 38, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
.btn-gold:hover { transform: translateY(-1px); filter: brightness(1.03); }
.btn-ghost-wide {
  width: 100%;
  border: 1px solid rgba(35, 48, 38, 0.16);
  background: rgba(255, 255, 255, 0.28);
  color: #2a3a2f;
}
.btn-ghost-wide:hover { background: rgba(255, 255, 255, 0.55); }

.over-card { width: min(560px, 100%); text-align: center; }
.over-card h2 { margin-bottom: 4px; }
.final-scores {
  display: flex;
  gap: 12px;
  margin: 22px 0 16px;
}
.final-score {
  flex: 1;
  padding: 16px 12px 14px;
  border-radius: 16px;
  background: rgba(35, 48, 38, 0.055);
  border: 1px solid rgba(35, 48, 38, 0.1);
}
.final-score .who {
  display: block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #7c8374;
}
.final-score .num {
  display: block;
  margin-top: 5px;
  font-family: var(--serif);
  font-size: 42px;
  line-height: 1;
  color: #22342a;
}
.final-score.is-winner {
  background: linear-gradient(160deg, #21382b, #16271e);
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(30, 44, 34, 0.25);
}
.final-score.is-winner .who { color: rgba(245, 238, 218, 0.6); }
.final-score.is-winner .num { color: var(--gold-bright); }
.final-detail {
  margin: 0 0 22px;
  font-size: 11.5px;
  line-height: 1.7;
  color: #66705f;
}
.over-actions {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

/* ------------------------------------------------------------------ */
/* Loading                                                            */
/* ------------------------------------------------------------------ */
.loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(700px 450px at 50% 40%, rgba(217, 181, 103, 0.08), transparent 60%),
    #0a1511;
  transition: opacity 0.35s ease, visibility 0.35s ease;
}
.loading.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.loading p {
  margin: 20px 0 0;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.loading-die {
  position: relative;
  width: 62px;
  height: 62px;
  border-radius: 15px;
  background: linear-gradient(150deg, #fffdf7, #e9d9b6);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.45);
  animation: loading-tumble 1.6s ease-in-out infinite;
}
.loading-die span {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #233229;
}
.loading-die span:nth-child(1) { top: 14px; left: 14px; }
.loading-die span:nth-child(2) { top: 14px; right: 14px; }
.loading-die span:nth-child(3) { top: 26px; left: 26px; }
.loading-die span:nth-child(4) { bottom: 14px; left: 14px; }
.loading-die span:nth-child(5) { bottom: 14px; right: 14px; }

/* ------------------------------------------------------------------ */
/* Animations                                                         */
/* ------------------------------------------------------------------ */
@keyframes die-tumble {
  0% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-12px) rotate(-8deg); }
  55% { transform: translateY(2px) rotate(5deg); }
  80% { transform: translateY(-5px) rotate(-3deg); }
  100% { transform: translateY(0) rotate(0deg); }
}
@keyframes die-land {
  0% { transform: scale(1.08); }
  55% { transform: scale(0.97); }
  100% { transform: scale(1); }
}
@keyframes cell-flash {
  0% { background: rgba(217, 181, 103, 0.55); color: #1c2a22; }
  100% { background: transparent; }
}
@keyframes line-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes pulse-cpu {
  0%, 100% { box-shadow: 0 0 0 4px rgba(221, 123, 93, 0.12), 0 0 10px rgba(221, 123, 93, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(221, 123, 93, 0.16), 0 0 20px rgba(221, 123, 93, 0.7); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(12px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes loading-tumble {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50% { transform: rotate(10deg) translateY(-10px); }
}

/* ------------------------------------------------------------------ */
/* Responsive                                                         */
/* ------------------------------------------------------------------ */
@media (max-width: 980px) {
  .table { grid-template-columns: 1fr; }
  .stage { min-height: 0; }
  .footer { padding-top: 12px; }
}

@media (max-width: 720px) {
  .app { padding: 18px 16px 14px; }
  .masthead { align-items: flex-start; flex-direction: column; gap: 14px; padding-bottom: 16px; }
  .masthead-actions { width: 100%; justify-content: flex-start; }
  .brand-text h1 { font-size: 27px; }
  .stage { padding: 18px 16px; border-radius: 20px; }
  .score-panel { border-radius: 20px; padding: 16px 13px 14px; }
  .dice-tray { min-height: 128px; padding: 28px 8px 24px; gap: 8px; }
  .die { width: 56px; height: 56px; border-radius: 12px; }
  .die.is-held { transform: translateY(-9px); }
  .die.is-held::after { bottom: -18px; font-size: 7px; }
  .play-controls { align-items: stretch; flex-direction: column; gap: 10px; }
  .roll-btn { width: 100%; min-width: 0; }
  .prompt { max-width: none; }
  .insight-body { min-height: 0; }
  .rules-grid { grid-template-columns: 1fr; gap: 8px; }
  .modal-card { padding: 26px 22px; }
  .modal-card h2 { font-size: 26px; }
  .final-score .num { font-size: 34px; }
  .footer { flex-direction: column; gap: 4px; }
  .footer-right { text-align: left; }
}

@media (max-width: 430px) {
  .brand-mark { width: 41px; height: 41px; }
  .brand-pip { width: 6px; height: 6px; }
  .bp1, .bp2 { top: 9px; }
  .bp1, .bp4 { left: 9px; }
  .bp2, .bp5 { right: 9px; }
  .bp4, .bp5 { bottom: 9px; }
  .bp3 { top: 17px; left: 17px; }
  .chip-btn { padding: 8px 11px; font-size: 11px; }
  .record { padding: 6px 10px; }
  .die { width: 49px; height: 49px; }
  .dice-tray { gap: 6px; }
  .scorecard tbody th { font-size: 11.5px; }
  .score-cell { font-size: 11.5px; padding: 0 5px; }
  .summary-row th, .summary-row td { font-size: 10.5px; }
  .final-scores { gap: 8px; }
}

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