:root {
  --ink: #16243a;
  --muted: #5a687f;
  --bg: #f2f6fa;
  --surface: #ffffff;
  --line: #d8e1ec;
  --navy: #1f3a5f;
  --blue: #2563eb;
  --blue-light: #eff6ff;
  --teal: #1f8a7e;
  --sun: #f4a261;
  --coral: #d9603f;
  --rail: #b8743c;
  --green: #2ecc71;
  --display: "Bricolage Grotesque", system-ui, -apple-system, sans-serif;
  --body: "Lexend", system-ui, -apple-system, sans-serif;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 30px rgba(31, 58, 95, 0.08);
  --shadow-sm: 0 3px 10px rgba(31, 58, 95, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body { font-family: var(--body); background-color: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column; }

header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; box-shadow: var(--shadow-sm); }
.header-inner { max-width: 1200px; margin: 0 auto; padding: 0.8rem 1.2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 0.6rem; text-decoration: none; color: var(--ink); }
.brand-icon { width: 40px; height: 40px; background: linear-gradient(135deg, var(--blue), var(--navy)); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.3rem; }
.brand-text h1 { font-family: var(--display); font-size: 1.3rem; font-weight: 800; line-height: 1.1; color: var(--navy); }
.brand-text p { font-size: 0.75rem; color: var(--muted); }

.controls-bar { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.select-wrap select {
  font-family: var(--body); font-size: 0.85rem; font-weight: 500; padding: 0.45rem 1.8rem 0.45rem 0.75rem;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%235a687f%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.4-12.8z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat; background-position: right 0.6rem top 50%; background-size: 0.65rem auto;
}

.icon-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.45rem 0.75rem; cursor: pointer; color: var(--ink); font-size: 0.85rem; font-weight: 600;
  display: flex; align-items: center; gap: 0.3rem; text-decoration: none;
}
.icon-btn:hover { background: var(--bg); border-color: var(--blue); }

main {
  max-width: 1100px; width: 100%; margin: 1.5rem auto; padding: 0 1rem; flex: 1;
  display: grid; grid-template-columns: 290px 1fr; gap: 1.5rem; align-items: start;
}
@media (max-width: 880px) { main { grid-template-columns: 1fr; gap: 1rem; } }

/* Ladder */
.ladder-card {
  background: var(--surface); border-radius: var(--radius-lg); padding: 1.25rem;
  border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.ladder-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.ladder-title { font-family: var(--display); font-size: 1.1rem; font-weight: 800; color: var(--navy); display: flex; align-items: center; gap: 0.4rem; }
.score-badge { background: var(--blue-light); color: var(--blue); border: 1px solid rgba(37,99,235,0.3); padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; }

.ladder-view {
  position: relative; height: 380px; background: linear-gradient(180deg, #dbeafe 0%, #eff6ff 50%, #f8fafc 100%);
  border-radius: var(--radius-md); border: 1px solid #bfdbfe; overflow: hidden; display: flex; justify-content: center;
}
.ladder-svg { width: 100%; height: 100%; }
.ladder-rails { stroke: var(--rail); stroke-width: 8; stroke-linecap: round; }
.ladder-rung { stroke: var(--rail); stroke-width: 6; stroke-linecap: round; transition: all 0.3s; }
.ladder-rung.reached { stroke: var(--blue); filter: drop-shadow(0 0 5px rgba(37,99,235,0.6)); }
.cloud-top { position: absolute; top: 10px; background: rgba(255,255,255,0.95); padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.8rem; font-weight: 700; color: var(--blue); border: 1px solid #bfdbfe; }
.mascot-avatar { position: absolute; width: 52px; height: 52px; transition: bottom 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); z-index: 10; pointer-events: none; }

/* Stage Card */
.stage-card {
  background: var(--surface); border-radius: var(--radius-lg); padding: 1.8rem;
  border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1.5rem; text-align: center;
}

.maths-equation-box {
  background: var(--blue-light); border: 2px solid rgba(37,99,235,0.3); border-radius: var(--radius-md);
  padding: 1.8rem 1rem; display: flex; align-items: center; justify-content: center; gap: 1rem;
}
.maths-equation { font-family: var(--display); font-size: clamp(2.4rem, 6vw, 3.8rem); font-weight: 800; color: var(--navy); }
.maths-input-slot {
  min-width: 100px; min-height: 70px; border: 3px dashed var(--blue); border-radius: var(--radius-md);
  background: #fff; display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 2.8rem; font-weight: 800; color: var(--blue); padding: 0 0.8rem;
}

/* Keypad */
.keypad-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; max-width: 340px; margin: 0 auto; width: 100%;
}
.key-btn {
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius-md);
  padding: 1rem; font-family: var(--display); font-size: 1.7rem; font-weight: 800; color: var(--navy);
  cursor: pointer; transition: all 0.15s ease; box-shadow: var(--shadow-sm); user-select: none;
}
.key-btn:hover { border-color: var(--blue); background: var(--blue-light); transform: translateY(-2px); }
.key-btn:active { transform: translateY(1px); }
.key-action { font-size: 1.1rem; background: var(--bg); color: var(--muted); }
.key-submit { background: var(--blue); color: #fff; border-color: var(--blue); }
.key-submit:hover { background: #1d4ed8; color: #fff; }

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(31,58,95,0.65);
  backdrop-filter: blur(4px); z-index: 999; display: flex; align-items: center; justify-content: center;
  padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-card { background: #fff; border-radius: var(--radius-lg); max-width: 460px; width: 100%; padding: 2.2rem; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }

#confetti-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1000; }

