:root {
  --bg: #f4eddf;
  --card: #fffdf8;
  --ink: #253247;
  --muted: #607089;
  --blue: #3578e5;
  --green: #22a06b;
  --orange: #ff9f1c;
  --pink: #e85d9e;
  --purple: #7d5fff;
  --red: #ef476f;
  --path: #556a80;
  --shadow: 0 10px 24px rgba(37, 50, 71, 0.15);
}
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: "Trebuchet MS", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(135deg, #e5f6ff, var(--bg));
}
button, input { font: inherit; }
button { cursor: pointer; border: 0; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
.hidden { display: none !important; }
.app-shell { width: 100vw; height: 100vh; padding: 12px; }
.card { background: rgba(255,253,248,.97); border: 3px solid white; border-radius: 20px; box-shadow: var(--shadow); padding: 12px; }
.eyebrow { margin: 0 0 3px; color: var(--red); font-weight: 900; text-transform: uppercase; letter-spacing: .1em; font-size: .85rem; }
.start-screen { width: min(760px, 94vw); margin: 7vh auto; text-align: center; font-size: 1.25rem; padding: 24px; }
.start-screen h1 { margin: 0 0 8px; font-size: 4rem; }
.player-settings { display: flex; justify-content: center; gap: 26px; border: 3px dashed #ffd166; border-radius: 18px; padding: 14px; margin: 18px 0; }
.player-settings legend, .player-settings label { font-weight: 900; }
.player-settings input { transform: scale(1.35); margin-right: 8px; }
.name-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 0 18px; text-align: left; }
.name-field { display: grid; gap: 5px; font-weight: 900; font-size: 1rem; }
.name-field input { width: 100%; border: 3px solid #d8e2ef; border-radius: 12px; padding: 10px 12px; font-weight: 900; color: var(--ink); }
.name-field input:focus { outline: 4px solid rgba(53,120,229,.22); border-color: var(--blue); }
.game-screen { height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: 64px minmax(0, 1fr); gap: 10px; }
.top-bar { grid-column: 1 / 3; display: grid; grid-template-columns: 210px minmax(0,1fr) 132px; align-items: center; gap: 10px; padding: 6px 12px; }
.top-bar h2 { margin: 0; font-size: 1.25rem; }
.game-info { display: grid; gap: 1px; text-align: center; font-weight: 900; }
.info-line, .info-status { margin: 0; font-size: .9rem; color: var(--ink); }
.info-line span { color: var(--red); text-transform: uppercase; letter-spacing: .04em; margin-left: 10px; }
.info-line span:first-child { margin-left: 0; }
.model-sentence { margin: 0; font-size: clamp(1.05rem, 1.55vw, 1.45rem); color: #14345f; line-height: 1; }
.info-status { color: var(--muted); }
h3 { margin: 0 0 8px; font-size: 1.25rem; }
.primary-button, .secondary-button, .danger-button { padding: 9px 14px; border-radius: 13px; color: white; font-size: 1.05rem; font-weight: 900; box-shadow: 0 4px 0 rgba(0,0,0,.16); }
.primary-button { background: var(--blue); }
.secondary-button { background: var(--green); width: 100%; margin-top: 8px; }
.danger-button { background: var(--red); }
.board-area { position: relative; min-height: 0; overflow: hidden; padding: 8px; }
.board { position: relative; width: 100%; height: 100%; border-radius: 18px; background: radial-gradient(circle at 20% 18%, rgba(255,255,255,.72), transparent 26%), linear-gradient(180deg, #d9f5ff, #e9f9dc); overflow: hidden; }
.control-panel { min-height: 0; display: grid; grid-template-rows: auto auto minmax(0, 1fr); gap: 10px; overflow-y: auto; padding-bottom: 4px; }
.compact-card { min-width: 0; }
.scoreboard { display: grid; gap: 8px; }
.player-score { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 13px; background: #f1f6ff; font-size: 1.05rem; font-weight: 900; }
.player-score.active { outline: 4px solid #ffd166; }
.token-dot { width: 23px; height: 23px; border-radius: 50%; display: inline-block; margin-right: 6px; vertical-align: middle; border: 3px solid white; box-shadow: 0 2px 5px rgba(0,0,0,.25); }
.time-table { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.time-row { display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 6px; padding: 6px; border-radius: 11px; background: #fff3d8; font-size: .9rem; font-weight: 800; }
.time-row.selected { background: #d8f8e8; outline: 3px solid var(--green); }
.time-number { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: white; background: var(--orange); }
.prediction-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.prediction-button { min-height: 48px; border-radius: 13px; color: white; background: var(--purple); font-size: 1.55rem; font-weight: 900; }
.prediction-button.selected { background: var(--orange); outline: 4px solid #ffe066; }
.dice-row { display: grid; grid-template-columns: 84px 1fr; gap: 8px; align-items: center; margin-top: 8px; }
.dice { display: grid; place-items: center; width: 78px; height: 78px; border-radius: 18px; background: white; border: 4px solid var(--ink); font-size: 3rem; font-weight: 900; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
.dice.rolling { animation: diceRoll .16s linear infinite; }
@keyframes diceRoll { 0%{transform:rotate(0) scale(1)} 50%{transform:rotate(10deg) scale(1.08)} 100%{transform:rotate(-10deg) scale(1)} }
.path-layer { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
.path-layer marker path { fill: #335c81; stroke: white; stroke-width: .8; }
.connector-outline, .connector { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.connector-outline { stroke: rgba(255,255,255,.92); stroke-width: 4.5; opacity: .94; }
.connector { stroke: #335c81; stroke-width: 2.4; opacity: .9; marker-end: url(#arrowHead); filter: drop-shadow(0 1px 1px rgba(37,50,71,.16)); }
.space { position: absolute; width: 119px; min-height: 65px; transform: translate(-50%, -50%); border-radius: 18px; border: 4px solid #ffffff; background: linear-gradient(180deg, #ffffff 0%, #f6fbff 72%, #e8f3ff 100%); box-shadow: 0 8px 0 rgba(51,92,129,.18), 0 12px 22px rgba(0,0,0,.18); display: grid; place-items: center; text-align: center; padding: 12px 8px 8px; font-size: .84rem; line-height: 1.08; font-weight: 1000; z-index: 3; transition: transform .2s ease, box-shadow .2s ease, outline .2s ease; }
.space::before { content: ""; position: absolute; inset: 0 0 auto; height: 12px; border-radius: 14px 14px 0 0; background: linear-gradient(90deg, var(--blue), var(--purple)); }
.space-label { position: relative; z-index: 2; }
.space.start { background: linear-gradient(180deg, #fff4a8, #ffd166); border-color: #ff9f1c; color: #5a3600; font-size: 1.22rem; letter-spacing: .06em; box-shadow: 0 8px 0 rgba(255,159,28,.32), 0 0 0 7px rgba(255,209,102,.28), 0 14px 26px rgba(0,0,0,.2); }
.space.start::before { background: linear-gradient(90deg, #ff9f1c, #ef476f); }
.space.branch-option { outline: 7px solid var(--pink); animation: branchPulse 1s ease-in-out infinite; cursor: pointer; }
.space.branch-option:hover { transform: translate(-50%, -50%) scale(1.18); box-shadow: 0 0 0 14px rgba(232,93,158,.22); }
.space.active-land { animation: landPulse .9s ease; outline: 7px solid var(--green); }
.space.start-bonus { animation: startGlow 1s ease; }
@keyframes branchPulse { 50% { box-shadow: 0 0 0 11px rgba(232,93,158,.28); } }
@keyframes landPulse { 50% { transform: translate(-50%, -50%) scale(1.15); } }
@keyframes startGlow { 50% { box-shadow: 0 0 0 18px rgba(255,159,28,.45); transform: translate(-50%, -50%) scale(1.12); } }
.token { position: absolute; width: 38px; height: 38px; border-radius: 50%; border: 4px solid white; z-index: 6; display: grid; place-items: center; color: white; font-weight: 900; box-shadow: 0 6px 12px rgba(0,0,0,.3); transform: translate(-50%, -50%); transition: left .55s ease, top .55s ease, transform .25s ease; }
.token::after { content: ""; position: absolute; top: -9px; width: 18px; height: 10px; border-left: 3px solid rgba(37,50,71,.28); }
.token.moving { transform: translate(-50%, -76%) scale(1.14); }
.floating-message { position: absolute; top: 22px; left: 50%; transform: translateX(-50%); z-index: 20; background: var(--ink); color: white; padding: 12px 20px; border-radius: 999px; font-size: 1.25rem; font-weight: 900; animation: floatPop 1.4s ease forwards; }
@keyframes floatPop { 0%{opacity:0; transform:translate(-50%,20px) scale(.8)} 20%,80%{opacity:1; transform:translate(-50%,0) scale(1)} 100%{opacity:0; transform:translate(-50%,-20px) scale(.95)} }
.results-splash { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; background: rgba(37,50,71,.6); z-index: 50; }
.results-card { width: min(650px, 92vw); max-height: calc(100vh - 32px); overflow-y: auto; overscroll-behavior: contain; text-align: center; padding: clamp(16px, 2.4vw, 28px); }
.results-card h2 { margin: 0 0 10px; font-size: clamp(2.1rem, 4.5vw, 3rem); }
.results-list { display: grid; gap: 8px; margin: 12px 0 16px; }
.result-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 14px; background: #f1f6ff; font-size: clamp(1rem, 2.4vw, 1.25rem); font-weight: 900; }
@media (max-width: 1300px) { html, body { overflow: auto; } .app-shell { height: auto; } .game-screen { grid-template-columns: 1fr; grid-template-rows: auto 760px auto; } .top-bar { grid-column: auto; grid-template-columns: 1fr; text-align: center; } .name-fields { grid-template-columns: 1fr; } }

.space.bonus-space {
  border-color: #ffd166;
  background: linear-gradient(180deg, #fffaf0, #fff0b8);
  box-shadow: 0 7px 16px rgba(0,0,0,.18), 0 0 0 5px rgba(255, 209, 102, .35);
}
.bonus-badge {
  position: absolute;
  top: 16px;
  right: -13px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #7a4d00;
  background: #ffd166;
  border: 3px solid white;
  box-shadow: 0 4px 10px rgba(0,0,0,.22);
  font-size: 1.2rem;
}
.space.bonus-claimed { animation: starClaim .95s ease; }
@keyframes starClaim { 50% { transform: translate(-50%, -50%) scale(1.18) rotate(2deg); box-shadow: 0 0 0 20px rgba(255, 209, 102, .5); } }
.prediction-celebration {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(circle, rgba(255,255,255,.62), rgba(255,209,102,.16) 45%, rgba(53,120,229,.16));
  animation: celebrationFade 1.8s ease forwards;
}
.celebration-banner {
  padding: 18px 34px;
  border-radius: 999px;
  color: white;
  background: linear-gradient(135deg, var(--pink), var(--purple), var(--blue));
  border: 5px solid white;
  box-shadow: 0 14px 34px rgba(37,50,71,.35);
  font-size: clamp(2rem, 5vw, 4.8rem);
  font-weight: 1000;
  text-align: center;
  text-shadow: 0 4px 0 rgba(0,0,0,.18);
  animation: bannerPop 1.45s cubic-bezier(.2,1.4,.35,1) forwards;
}
.celebration-banner strong { color: #ffe066; }
.sparkle {
  position: absolute;
  left: var(--x);
  top: var(--y);
  color: hsl(var(--hue), 90%, 55%);
  font-size: clamp(1.2rem, 2.3vw, 2.6rem);
  animation: sparkleBurst 1.35s ease var(--delay) forwards;
  opacity: 0;
}
@keyframes celebrationFade { 0%{opacity:0} 12%,82%{opacity:1} 100%{opacity:0} }
@keyframes bannerPop { 0%{transform:scale(.35) rotate(-4deg)} 22%{transform:scale(1.1) rotate(2deg)} 72%{transform:scale(1) rotate(0)} 100%{transform:scale(.98)} }
@keyframes sparkleBurst { 0%{opacity:0; transform:translateY(20px) scale(.2) rotate(0)} 20%{opacity:1} 100%{opacity:0; transform:translateY(-44px) scale(1.35) rotate(220deg)} }
@media (prefers-reduced-motion: reduce) {
  .prediction-celebration { animation: celebrationFade 1.8s ease forwards; }
  .celebration-banner { animation: none; }
  .sparkle { display: none; }
  .space.branch-option, .space.active-land, .space.start-bonus, .space.bonus-claimed, .dice.rolling { animation: none; }
}

.bonus-ceremony { display: grid; gap: 10px; margin: 8px 0 14px; }
.bonus-card {
  position: relative;
  overflow: hidden;
  padding: clamp(12px, 2vw, 18px);
  border-radius: 22px;
  border: 4px solid #fff;
  background: radial-gradient(circle at 18% 20%, rgba(255, 209, 102, .42), transparent 30%), linear-gradient(135deg, #fff7d6, #f1f6ff 58%, #f8e8ff);
  box-shadow: 0 10px 24px rgba(37, 50, 71, .18);
}
.bonus-card::before { content: "★"; position: absolute; right: 16px; top: 4px; color: rgba(255,159,28,.35); font-size: 5rem; transform: rotate(14deg); }
.bonus-step-label { margin: 0 0 4px; color: var(--red); font-weight: 1000; text-transform: uppercase; letter-spacing: .08em; }
.bonus-card h3 { margin: 0; color: #14345f; font-size: clamp(1.8rem, 4.5vw, 3.2rem); line-height: 1; }
.bonus-subtitle { margin: 4px 0 6px; color: var(--purple); font-size: clamp(1.1rem, 2.5vw, 1.35rem); font-weight: 1000; }
.bonus-points { margin: 3px auto 6px; width: max-content; padding: 6px 18px; border-radius: 999px; color: #7a4d00; background: #ffd166; border: 4px solid white; font-size: clamp(1.6rem, 4vw, 2.15rem); font-weight: 1000; text-shadow: 0 2px 0 rgba(255,255,255,.6); box-shadow: 0 0 0 7px rgba(255, 209, 102, .25); }
.bonus-explanation { margin: 0 0 8px; color: var(--muted); font-size: 1rem; font-weight: 900; }
.bonus-winners { margin: 0; color: var(--green); font-size: clamp(1.25rem, 3.6vw, 1.7rem); font-weight: 1000; }
.bonus-pop { animation: bonusPop .55s cubic-bezier(.2, 1.5, .35, 1); }
.bonus-ranking { display: grid; gap: 6px; padding: 10px; border-radius: 18px; background: #fffdf8; border: 3px dashed #ffd166; }
.bonus-ranking h3 { margin: 0; color: var(--ink); font-size: 1.05rem; }
.bonus-rank-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 10px; border-radius: 13px; background: #f1f6ff; font-weight: 1000; will-change: transform; }
.bonus-rank-row.rank-up { animation: rankUpGlow .75s ease; }
.bonus-rank-row.rank-down { animation: rankDownNudge .75s ease; }
.bonus-rank-row small { color: var(--red); font-size: .82rem; }
.final-result-row { animation: finalReveal .5s ease both; }
@keyframes bonusPop { 0% { transform: scale(.9) rotate(-1deg); opacity: .55; } 70% { transform: scale(1.03) rotate(1deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
@keyframes finalReveal { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes rankUpGlow { 0%, 100% { box-shadow: none; } 35% { box-shadow: 0 0 0 6px rgba(34,160,107,.18), 0 8px 18px rgba(34,160,107,.22); } }
@keyframes rankDownNudge { 35% { opacity: .85; } }
@media (prefers-reduced-motion: reduce) {
  .bonus-pop, .final-result-row, .bonus-rank-row.rank-up, .bonus-rank-row.rank-down { animation: none; }
}

@media (max-height: 720px) {
  .results-splash { padding: 10px; }
  .results-card { max-height: calc(100vh - 20px); }
  .bonus-card::before { font-size: 3.8rem; }
}
@media (max-width: 560px) {
  .result-row, .bonus-rank-row { flex-direction: column; align-items: center; gap: 4px; }
}
