:root {
  --paper: #f3ecdf;
  --ink: #1c2430;
  --muted: #5c564c;
  --line: #e2d6c4;
  --panel: #fffaf3;
  --g1: #2f6f4e;
  --s: #c47b2b;
  --g2: #1f6f8b;
  --cp: #243056;
  --mitosis: #6b3fa0;
  --chance: #d7f0f8;
  --healthy: #2c6eaa;
  --cancer: #c23b3b;
  --shadow: 0 16px 40px rgba(48, 36, 22, 0.08);
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 250, 243, 0.4), rgba(243, 236, 223, 0.9)),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(36, 48, 86, 0.04) 28px),
    repeating-linear-gradient(90deg, transparent, transparent 27px, rgba(36, 48, 86, 0.04) 28px),
    var(--paper);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h1 { font-size: 2.4rem; letter-spacing: -0.03em; }
h2 { font-size: 1.35rem; }
p { line-height: 1.45; }

.eyebrow {
  margin: 0 0 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: var(--muted);
}
.lede { font-size: 1.12rem; max-width: 42rem; }
.fine, .hint { color: var(--muted); font-size: 0.92rem; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.15rem;
}
.setup, .reflect { max-width: 980px; margin: 0 auto; padding: 2rem 1.2rem 3rem; }
.choices, .name-grid, .row-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.choice {
  flex: 1 1 240px;
  text-align: left;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem;
}
.choice span { display: block; color: var(--muted); }
.choice strong { display: block; margin: 0.2rem 0 0.35rem; font-size: 1.15rem; }
.choice.is-selected { border-color: var(--cp); background: #f4f7fb; }
.choice-kicker { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; }
.field { display: flex; flex-direction: column; gap: 0.3rem; flex: 1 1 180px; font-size: 0.92rem; }
.field.stack { margin-top: 0.8rem; }
input, select, textarea {
  background: #fff;
  border: 1px solid #d9cbb8;
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}
input::placeholder, textarea::placeholder { color: #a3988a; }
textarea { min-height: 4.5rem; resize: vertical; width: 100%; }
.checkline { display: flex; gap: 0.5rem; align-items: center; margin: 0.8rem 0; }
.primary, .ghost, .roster button {
  border-radius: 999px;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
}
.primary { background: var(--cp); color: white; }
.primary:disabled { opacity: 0.6; }
.ghost, .roster button { background: transparent; border-color: #cabbab; }
a.ghost {
  display: inline-flex;
  align-items: center;
  color: inherit;
  font: inherit;
  text-decoration: none;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem 1rem;
  align-items: end;
  flex-wrap: wrap;
  padding: 1rem 1.2rem 0.4rem;
}
.topbar h1 { font-size: 1.8rem; }
.top-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
  gap: 1rem;
  padding: 0.6rem 1.2rem 2rem;
  min-width: 0;
}
.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(88px, 1fr));
  grid-template-rows: repeat(4, minmax(104px, auto));
  gap: 0.55rem;
  margin-top: 0.8rem;
}
.space {
  position: relative;
  border-radius: 14px;
  min-height: 104px;
  padding: 0.45rem 0.5rem 0.4rem;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}
.space.is-g1 { background: #e7f3ec; }
.space.is-s { background: #fff1df; }
.space.is-g2 { background: #e5f3f7; }
.space.is-checkpoint { background: #e7eaf4; }
.space.is-mitosis { background: #f3eafb; }
.space.is-chance { box-shadow: inset 0 0 0 3px #8ecae6; }
.space-name { font-size: 0.82rem; font-weight: 700; }
.arrow { position: absolute; top: 0.35rem; right: 0.45rem; color: var(--muted); }
.need {
  font-family: var(--serif);
  font-size: 1.5rem;
  line-height: 1;
  color: var(--mitosis);
}
.chance-tag {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #1f6f8b;
}
.tokens { display: flex; gap: 0.25rem; margin-top: auto; min-height: 1.6rem; }
.token {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
}
.token.is-current { outline: 3px solid #111; outline-offset: 1px; }
.legend { display: flex; flex-wrap: wrap; gap: 0.7rem 1rem; padding: 0; margin: 0.8rem 0 0; list-style: none; }
.chip-row { display: grid; grid-template-columns: repeat(8, 0.85rem); gap: 0.35rem; margin: 0.45rem 0 0; }
.legend li { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.swatch { width: 0.9rem; height: 0.9rem; border-radius: 3px; display: inline-block; }
.swatch.g1 { background: #2f6f4e; }
.swatch.s { background: #c47b2b; }
.swatch.g2 { background: #1f6f8b; }
.swatch.cp { background: #243056; }
.swatch.m { background: #6b3fa0; }
.swatch.chance { background: #d7f0f8; box-shadow: inset 0 0 0 2px #1f6f8b; }
.trays { display: flex; justify-content: space-between; gap: 1rem; align-items: end; flex-wrap: wrap; margin-top: 0.9rem; }
.trays h3 { font-size: 1rem; }
.chip, .chip.spent {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  display: inline-block;
}
.chip.red { background: var(--cancer); }
.chip.spent { background: transparent; border: 1px dashed #cabbab; }
.tallies { display: flex; gap: 0.8rem; margin: 0; }
.tallies div { min-width: 4.5rem; }
.tallies dt { font-size: 0.75rem; color: var(--muted); }
.tallies dd { margin: 0; font-family: var(--serif); font-size: 1.6rem; }
.side { display: flex; flex-direction: column; gap: 0.8rem; }
.dice { display: flex; gap: 0.45rem; margin: 0.6rem 0; }
.die {
  width: 58px;
  height: 58px;
  border-radius: 12px;
  background: white;
  border: 1px solid #d9cbb8;
  display: grid;
  place-items: center;
}
.die.is-empty { background: transparent; }
.pips { display: grid; grid-template-columns: repeat(3, 12px); grid-template-rows: repeat(3, 12px); }
.pip { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); align-self: center; justify-self: center; }
.pip.off { background: transparent; }
.dice.is-rolling .die { animation: shake 0.7s linear; }
@keyframes shake {
  0% { transform: rotate(-8deg) translateY(0); }
  25% { transform: rotate(8deg) translateY(-3px); }
  50% { transform: rotate(-6deg); }
  75% { transform: rotate(6deg) translateY(-2px); }
  100% { transform: rotate(0); }
}
.outcome { min-height: 3.2rem; }
.flags { color: #8a3b12; font-size: 0.92rem; }
.phase-block { margin-top: 0.75rem; }
.phase-block h3 { font-size: 1rem; margin-bottom: 0.25rem; }
.track { display: grid; grid-template-columns: 7rem 1fr; gap: 0.4rem; align-items: center; margin: 0.2rem 0; font-size: 0.85rem; }
.boxes { display: flex; flex-wrap: wrap; gap: 0.2rem; }
.box { width: 0.95rem; height: 0.95rem; border: 1.5px solid #8d8376; border-radius: 3px; display: inline-block; }
.box.on { background: var(--cp); border-color: var(--cp); }
.roster { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.roster li { display: flex; gap: 0.55rem; align-items: center; padding: 0.45rem 0; border-top: 1px solid var(--line); }
.roster li.is-current strong { text-decoration: underline; text-underline-offset: 3px; }
.roster small { display: block; color: var(--muted); }
.roster button { padding: 0.35rem 0.6rem; }
.log { margin: 0.4rem 0 0; padding-left: 1.1rem; color: var(--muted); }
.log li { margin: 0.25rem 0; }
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(28, 36, 48, 0.46);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 5;
}
.card {
  width: min(560px, 100%);
  background: #fffaf3;
  border-radius: 18px;
  padding: 1.2rem 1.2rem 1rem;
  box-shadow: var(--shadow);
  border-top: 8px solid var(--cp);
}
.card.wide { width: min(720px, 100%); max-height: min(84vh, 860px); overflow: auto; }
.card.kind-chance { border-top-color: #1f6f8b; background: #f3fbfe; }
.card.kind-result-healthy { border-top-color: var(--healthy); }
.card.kind-result-cancer { border-top-color: var(--cancer); }
.card.kind-result-stopped { border-top-color: #8a8175; }
.rules, .teacher ul { padding-left: 1.1rem; }
.rules li, .teacher li { margin: 0.45rem 0; }
.result-block { margin: 0.8rem 0; }
.bar { display: flex; height: 0.9rem; border-radius: 999px; overflow: hidden; background: #efe6d8; }
.sense { display: grid; gap: 0.55rem; margin-top: 0.8rem; }
.sense-head, .sense-row { display: grid; grid-template-columns: 9rem 1fr 1fr; gap: 0.5rem; align-items: start; }
.sense-head { color: var(--muted); font-size: 0.85rem; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #d4a017;
  outline-offset: 2px;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; }
  .board-wrap, .side { min-width: 0; max-width: 100%; }
  .board-wrap { overflow-x: auto; }
  .board { min-width: 640px; }
  h1 { font-size: 2rem; }
}
@media (max-width: 720px) {
  .sense-head { display: none; }
  .sense-row { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: start; }
  .track { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .dice.is-rolling .die { animation: none; }
}
