/* ===== Tokens ===== */
:root {
  --green: #58cc02;
  --green-dark: #46a302;
  --green-bg: #d7ffb8;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-bg: #ffdfe0;
  --blue: #1cb0f6;
  --yellow: #ffc800;
  --ink: #3c3c3c;
  --ink-soft: #777;
  --line: #e5e5e5;
  --bg: #f7f7f7;
  --card: #fff;
  --theme: var(--blue);
  --theme-dark: #1899d6;
  --radius: 16px;
  --font: 'Nunito', ui-rounded, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-weight: 700;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font-family: inherit; }

/* ===== HUD ===== */
.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 2px solid var(--line);
  z-index: 5;
}
.hud-level {
  font-weight: 900;
  color: #fff;
  background: var(--theme);
  padding: 6px 12px;
  border-radius: 12px;
  white-space: nowrap;
  font-size: 15px;
}
.progress {
  flex: 1;
  height: 16px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--theme);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.hud-streak { color: #ff9600; white-space: nowrap; font-size: 16px; font-weight: 900; }
.btn-home {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  background: var(--card);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-home:active { transform: translateY(2px); border-bottom-width: 2px; }

/* ===== Screens ===== */
.play { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.play[hidden], .home[hidden] { display: none; }

/* ===== Home ===== */
.home {
  flex: 1;
  overflow-y: auto;
  padding: 28px 16px 40px;
  background:
    radial-gradient(circle at 15% 8%, rgba(28,176,246,0.10), transparent 40%),
    radial-gradient(circle at 90% 20%, rgba(255,75,154,0.10), transparent 40%),
    radial-gradient(circle at 50% 100%, rgba(88,204,2,0.10), transparent 50%),
    var(--bg);
}
.home-inner { max-width: 480px; margin: 0 auto; text-align: center; }
.logo { width: 132px; height: auto; display: block; margin: 0 auto 6px; animation: logo-bob 2.4s ease-in-out infinite; }
@keyframes logo-bob { 50% { transform: translateY(-5px); } }
.home-title { font-size: 36px; font-weight: 900; line-height: 1.05; margin: 4px 0 6px; letter-spacing: -0.01em; }
.home-tagline { margin: 0 0 22px; font-size: 17px; color: var(--ink-soft); }

.best-card {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-bottom-width: 5px;
  border-radius: 20px;
  padding: 14px 18px;
  margin-bottom: 26px;
}
.best-flame { font-size: 40px; line-height: 1; }
.best-label { font-size: 13px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.06em; color: #ff9600; }
.best-value { font-size: 34px; font-weight: 900; line-height: 1.05; }
.best-sub { font-size: 13px; color: var(--ink-soft); }
.best-new {
  display: inline-block;
  margin-left: 6px;
  background: #ff9600;
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1);
}
.best-new[hidden] { display: none; }
@keyframes pop-in { from { transform: scale(0.3); opacity: 0; } }

.home-heading { font-size: 20px; font-weight: 900; margin: 0 0 4px; text-align: left; }
.home-hint { margin: 0 0 14px; font-size: 14px; color: var(--ink-soft); text-align: left; font-weight: 600; }
.level-cards { display: flex; flex-direction: column; gap: 12px; }
.level-card {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 2px solid var(--line);
  border-bottom: 5px solid color-mix(in srgb, var(--theme) 45%, var(--line));
  border-radius: 18px;
  padding: 12px 14px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.08s;
}
.level-card:hover { border-color: color-mix(in srgb, var(--theme) 40%, var(--line)); }
.level-card:active { transform: translateY(3px); border-bottom-width: 2px; }
.level-card-badge {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--theme);
  box-shadow: 0 4px 0 var(--theme-dark);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}
.level-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.level-card-name { font-size: 18px; font-weight: 900; }
.level-card-sub { font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.level-card-side {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--theme) 16%, #fff);
  color: var(--theme-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
}
.level-card-side.done { background: var(--theme); color: #fff; }

/* ===== "Next up" moment between levels ===== */
.toast {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  z-index: 22;
  background: var(--card);
  border: 2px solid var(--line);
  border-bottom: 6px solid var(--theme-dark);
  border-radius: 22px;
  padding: 18px 26px;
  text-align: center;
  width: max-content;
  max-width: calc(100% - 32px);
  animation: pop-in 0.35s cubic-bezier(.3,1.6,.5,1);
}
.toast[hidden] { display: none; }
.toast-title { font-size: 22px; font-weight: 900; }
.toast-sub { font-size: 16px; color: var(--theme-dark); margin-top: 4px; }

/* ===== Board path ===== */
.scroller {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
}
.path {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column-reverse; /* Level 1 at the bottom, climbing up */
}
.section { --theme: var(--blue); }

/* The board is as tall as its winding path; sizes inside use container units (cqi = 1% of board width). */
.board {
  position: relative;
  width: 100%;
  container-type: inline-size;
}
.trail, .overlay, .stones {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.trail-line {
  fill: none;
  stroke: color-mix(in srgb, var(--theme) 28%, #fff);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 22;
}

/* Stones: chunky raised circles, all in the level's one theme colour.
   Ahead = light tint of the theme; passed = full theme colour. */
.stone {
  position: absolute;
  width: 15.333%; /* 92 of 600 board units */
  aspect-ratio: 1;
}
.stone-face {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--theme) 30%, #fff);
  box-shadow: 0 1.3cqi 0 color-mix(in srgb, var(--theme) 50%, #fff),
              inset 0 -0.8cqi 0 rgba(0,0,0,0.06);
  color: color-mix(in srgb, var(--theme-dark) 85%, #000);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5.2cqi;
  font-weight: 900;
  transition: background 0.3s, box-shadow 0.3s, color 0.3s;
}
.stone.passed .stone-face {
  background: var(--theme);
  box-shadow: 0 1.3cqi 0 var(--theme-dark), inset 0 -0.8cqi 0 rgba(0,0,0,0.08);
  color: #fff;
}
.stone.start .stone-face {
  background: #fff;
  box-shadow: 0 1.3cqi 0 color-mix(in srgb, var(--theme) 50%, #fff), inset 0 0 0 0.8cqi var(--theme);
  color: var(--theme-dark);
  font-size: 4.2cqi;
}
.stone.final .stone-face {
  background: var(--yellow);
  box-shadow: 0 1.3cqi 0 #e0a800;
  color: #fff;
  font-size: 7cqi;
}
.stone-badge {
  position: absolute;
  right: -8%;
  top: -8%;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0.6cqi solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stone-badge svg { width: 72%; height: 72%; }
.stone-badge-ladder { background: var(--green); }
.stone-badge-snake { background: var(--red); }

/* Level banner: where the path enters a level */
.banner {
  margin: 4px 0 10px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--theme);
  box-shadow: 0 5px 0 var(--theme-dark);
  color: #fff;
}
.banner-title { font-size: 18px; font-weight: 900; line-height: 1.15; }
.banner-sub { font-size: 13px; opacity: 0.9; }

/* Playing piece: the outer element moves; the body hops and squashes. */
.token {
  position: absolute;
  width: 9.5cqi;
  aspect-ratio: 1;
  transform: translate(-50%, -62%);
  z-index: 3;
  pointer-events: none;
}
.token-body {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  border: 0.9cqi solid var(--ink);
  box-shadow: 0 1cqi 0 rgba(0,0,0,0.25);
  transform-origin: 50% 100%;
  position: relative;
}
/* Two little eyes for a bit of character. */
.token-body::before, .token-body::after {
  content: '';
  position: absolute;
  top: 34%;
  width: 18%;
  height: 26%;
  border-radius: 50%;
  background: var(--ink);
}
.token-body::before { left: 26%; }
.token-body::after { right: 26%; }

/* ===== Dock ===== */
.dock {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 2px solid var(--line);
  z-index: 5;
}
.dock-msg { flex: 1; font-size: 15px; color: var(--ink-soft); }

.btn {
  border: 0;
  border-radius: var(--radius);
  font-weight: 900;
  font-size: 17px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 14px 22px;
  cursor: pointer;
  color: #fff;
}
.btn:disabled { cursor: default; opacity: 0.5; }
.btn-roll {
  background: var(--green);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Die face: 3x3 pip grid */
.die {
  width: 34px;
  height: 34px;
  background: #fff;
  border-radius: 8px;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 4px;
}
.pip { width: 7px; height: 7px; border-radius: 50%; background: var(--ink); place-self: center; }

/* ===== Question sheet ===== */
.sheet-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.sheet-backdrop[hidden], .modal-backdrop[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  background: var(--card);
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sheet-body { padding: 20px 16px 8px; }
.q-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag {
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-soft);
}
.tag-ladder { background: var(--green-bg); color: var(--green-dark); }
.tag-snake { background: var(--red-bg); color: var(--red-dark); }
.tag-final { background: #fff4c2; color: #9a7200; }
.q-prompt { font-size: 20px; font-weight: 800; line-height: 1.35; margin: 0 0 14px; }
.q-not { color: var(--red-dark); text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 3px; }
.q-options { display: flex; flex-direction: column; gap: 10px; }
.option {
  text-align: left;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
}
.option.selected { border-color: var(--blue); background: #ddf4ff; color: #1899d6; }
.option.correct { border-color: var(--green); background: var(--green-bg); color: var(--green-dark); }
.option.wrong { border-color: var(--red); background: var(--red-bg); color: var(--red-dark); }
.option:disabled { cursor: default; }

.feedback {
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 2px solid var(--line);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}
.feedback-inner { display: flex; flex-direction: column; gap: 12px; }
.feedback-text { display: none; }
.feedback.is-correct { background: var(--green-bg); border-top-color: transparent; }
.feedback.is-wrong { background: var(--red-bg); border-top-color: transparent; }
.feedback.is-correct .feedback-text, .feedback.is-wrong .feedback-text { display: block; }
.feedback-title { font-size: 22px; font-weight: 900; }
.is-correct .feedback-title { color: var(--green-dark); }
.is-wrong .feedback-title { color: var(--red-dark); }
.feedback-missed { margin-top: 6px; font-size: 15px; color: var(--red-dark); }
.feedback-expl { margin: 6px 0; font-size: 15px; font-weight: 600; line-height: 1.45; }
.feedback-src { font-size: 13px; color: inherit; opacity: 0.75; }
.btn-check { background: var(--green); width: 100%; }
.is-wrong .btn-check { background: var(--red); }

/* ===== Modal ===== */
.modal-backdrop { align-items: center; padding: 16px; }
.modal {
  background: var(--card);
  border-radius: 24px;
  padding: 28px 22px 22px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}
.modal h2 { margin: 6px 0; font-size: 26px; font-weight: 900; }
.modal p { color: var(--ink-soft); margin: 0 0 18px; }
.modal-trophy { font-size: 56px; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }
.btn-primary { background: var(--green); }
.btn-secondary { background: var(--card); color: var(--blue); border: 2px solid var(--line); }

/* ===== Dice roll ===== */
.dice-stage {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dice-stage[hidden] { display: none; }
.dice-backdrop { position: absolute; inset: 0; background: rgba(20, 30, 50, 0.25); }
.dice-spot {
  --size: 110px;
  --half: 55px;
  position: relative;
  width: var(--size);
  height: var(--size);
  perspective: 700px;
}
/* preserve-3d all the way down so perspective reaches the cube and faces sort correctly */
.dice-throw { width: 100%; height: 100%; transform-style: preserve-3d; }
.cube {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
}
.cube-core {
  position: absolute;
  inset: 0;
  background: #dcdcdc;
}
.cube-face {
  position: absolute;
  inset: 0;
  background: #fff;
  border-radius: 18px;
  border: 4px solid #dcdcdc;
  box-shadow: inset 0 -8px 0 #ededed;
  display: grid;
  grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 14px;
  backface-visibility: hidden;
}
.cube-pip { width: 20px; height: 20px; border-radius: 50%; background: var(--theme, #1cb0f6); place-self: center; }
.dice-shadow {
  position: absolute;
  left: 10%; right: 10%;
  bottom: -26px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.25);
  filter: blur(3px);
}
.dice-label {
  position: absolute;
  left: 50%;
  top: calc(100% + 34px);
  transform: translateX(-50%) scale(0.5);
  opacity: 0;
  font-size: 44px;
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 2px rgba(0,0,0,0.15);
  text-shadow: 0 4px 0 rgba(0,0,0,0.2);
  transition: transform 0.2s cubic-bezier(.3,1.6,.5,1), opacity 0.15s;
}
.dice-label.show { opacity: 1; transform: translateX(-50%) scale(1); }



@media (min-width: 700px) {
  .sheet { border-radius: 24px; margin-bottom: 24px; }
  .feedback-inner { flex-direction: row; align-items: center; }
  .feedback-text { flex: 1; }
  .btn-check { width: auto; min-width: 160px; align-self: flex-end; }
}
