:root {
  --bg: #f6f3ee;
  --panel: #fffdf9;
  --ink: #27231d;
  --muted: #726c61;
  --line: #cfc7bb;
  --path: #1d6f78;
  --branch: #d99100;
  --dead: #b44b5c;
  --start: #4b8a2f;
  --goal: #7a39bb;
  --tile: #fff;
  --ok: #3b7d31;
  --warn: #b06216;
  --shadow: 0 10px 30px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, Arial, sans-serif;
  background: radial-gradient(circle at top, #fffdf9, var(--bg));
  color: var(--ink);
}
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  padding: 20px;
  min-height: 100vh;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
}
h1 { font-size: 1.4rem; margin: 0 0 10px; }
h2 { font-size: 1rem; margin: 18px 0 10px; }
p, li { color: var(--muted); line-height: 1.45; }
.controls, .dice-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
  align-items: center;
}
button {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  background: var(--path);
  color: white;
  cursor: pointer;
  font-weight: 600;
}
button.secondary { background: #ece6dc; color: var(--ink); }
button.ghost { background: #f5efe5; color: var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
.legend, .players-list { display: grid; gap: 10px; margin-top: 10px; }
.legend-item, .player-row {
  display: flex; align-items: center; gap: 10px; font-size: .94rem;
}
.swatch, .token-dot {
  width: 18px; height: 18px; border-radius: 999px; border: 1px solid rgba(0,0,0,.12);
}
.token-dot.big { width: 22px; height: 22px; }
.info-box {
  padding: 12px; border-radius: 14px; background: #f5efe5; border: 1px solid #e1d8ca; font-size: .94rem; line-height: 1.4;
}
.board-wrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 16px; overflow: auto;
}
svg { width: 100%; height: auto; display: block; min-height: 720px; }
.tile-label {
  font-size: 12px; font-weight: 700; fill: var(--ink); text-anchor: middle; dominant-baseline: middle; pointer-events: none;
}
.caption { font-size: 12px; fill: var(--muted); }
.meta-list { display: grid; gap: 8px; padding-left: 18px; }
code { background: #f3ede2; padding: 2px 6px; border-radius: 6px; }
.status {
  padding: 12px; border-radius: 14px; background: #f8f3eb; border: 1px solid #e7ddcf; min-height: 74px;
  white-space: pre-line;
}
.dice {
  width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; background: white; border: 1px solid #d8cfc1;
  font-size: 1.35rem; font-weight: 800; box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; background: #f3ede3; border-radius: 999px; font-size: .84rem;
  color: var(--muted);
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(29,23,18,.45); display: none; align-items: center; justify-content: center; padding: 18px; z-index: 50;
}
.modal-backdrop.show { display: flex; }
.modal {
  width: min(760px, 100%); background: var(--panel); border-radius: 22px; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0,0,0,.22); padding: 20px;
}
.modal h3 { margin: 0 0 8px; }
.answers { display: grid; gap: 10px; margin-top: 14px; }
.answer-btn {
  width: 100%; text-align: left; border-radius: 16px; padding: 14px 16px; background: #f8f3ea; color: var(--ink); border: 1px solid #e3d8c9;
}
.answer-btn:hover { background: #f1e9dc; }
.answer-btn.correct { background: #e1f0d9; border-color: #b8d8ad; }
.answer-btn.wrong { background: #f7dfe2; border-color: #e0aeb6; }
.branch-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.branch-card {
  border: 1px solid #dfd3c3; border-radius: 18px; padding: 16px; background: #f8f2e8;
}
.branch-card h4 { margin: 0 0 6px; font-size: 1.1rem; }
.small { font-size: .9rem; color: var(--muted); }
.result-box {
  margin-top: 14px; border-radius: 16px; padding: 14px; background: #f3ede3; border: 1px solid #dfd3c3;
}
.inline-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.footer-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
@media (max-width: 980px) { .app { grid-template-columns: 1fr; } }
@media (max-width: 600px) { .branch-grid { grid-template-columns: 1fr; } }

.setup-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: #f8f3eb;
  border: 1px solid #e7ddcf;
  margin-bottom: 14px;
}
.setup-box select {
  border: 1px solid #d8cfc1;
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
  font: inherit;
}
.setup-box select:disabled {
  background: #eee8dd;
  color: var(--muted);
}
.dice-buttons {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin: 8px 0 14px;
}
.dice-key-btn {
  border-radius: 14px;
  min-height: 44px;
  padding: 10px 0;
  background: #f5efe5;
  color: var(--ink);
  border: 1px solid #ddd2c3;
}
.dice-key-btn:hover {
  background: #eee5d7;
}
.dice-key-btn:disabled {
  background: #eee8dd;
  color: var(--muted);
  border-color: #e0d7ca;
}
@media (max-width: 600px) {
  .dice-buttons { grid-template-columns: repeat(3, 1fr); }
}

.player-names {
  display: grid;
  gap: 8px;
}
.player-name-input {
  width: 100%;
  border: 1px solid #d8cfc1;
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
  font: inherit;
}
.player-name-input:disabled {
  background: #eee8dd;
  color: var(--muted);
}

.setup-panel { display: block; }
.setup-panel.is-hidden {
  display: none;
}

.turn-pill { display:flex; align-items:center; gap:8px; }
.turn-badge-token { width:16px; height:16px; border-radius:999px; border:2px solid white; box-shadow:0 0 0 1px rgba(0,0,0,.12); background:#ccc; }

.status-chip { display:inline-flex; align-items:center; gap:6px; padding:3px 8px; border-radius:999px; font-size:12px; font-weight:700; margin-left:8px; }
.status-chip.dead-end { background:#f6d9de; color:#7e2436; border:1px solid #d9a4ae; }

.modal-dice-grid { display:grid; grid-template-columns:repeat(3, minmax(56px, 1fr)); gap:10px; margin-top:16px; }
.modal-dice-btn { min-height:52px; border-radius:14px; border:1px solid rgba(0,0,0,.18); background:#fff; color:#1f2937; font-size:18px; font-weight:800; line-height:1; display:flex; align-items:center; justify-content:center; cursor:pointer; }
.modal-hint { margin-top:12px; font-size:13px; color:#5b6472; }
