/* ==========================================================================
   Olympiad Prep OS — "Space Explorer / Mission Control" theme.
   Kid-friendly UI is a first-class requirement. Theme dial per profile:
   .theme-junior (grade 4 — dino-planet explorer, playful, big, bright),
   .theme-senior (grade 6 — rocket captain, cleaner, cooler, not babyish),
   .theme-parent (Mission Control — clean, functional, adult-facing).
   Original space-learning world only — no franchise/character references.
   ========================================================================== */

* { box-sizing: border-box; }

:root {
  --radius: 22px;
  --shadow: 0 6px 20px rgba(30, 30, 80, 0.12);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  margin: 0;
  font-family: var(--font);
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  background-attachment: fixed;
  position: relative;
  transition: background 0.4s;
}

/* Decorative starfield + planets, behind all content, never interactive. */
body.theme-junior::before,
body.theme-senior::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.8;
  background-image:
    radial-gradient(2px 2px at 8% 18%, rgba(255,255,255,0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 22% 62%, rgba(255,255,255,0.7), transparent 60%),
    radial-gradient(2px 2px at 38% 12%, rgba(255,255,255,0.85), transparent 60%),
    radial-gradient(1.5px 1.5px at 55% 78%, rgba(255,255,255,0.6), transparent 60%),
    radial-gradient(2px 2px at 68% 30%, rgba(255,255,255,0.9), transparent 60%),
    radial-gradient(1.5px 1.5px at 82% 68%, rgba(255,255,255,0.7), transparent 60%),
    radial-gradient(2px 2px at 92% 14%, rgba(255,255,255,0.8), transparent 60%),
    radial-gradient(1.5px 1.5px at 15% 90%, rgba(255,255,255,0.6), transparent 60%),
    radial-gradient(120px 120px at 88% 82%, var(--planet-1) 0%, transparent 72%),
    radial-gradient(90px 90px at 10% 78%, var(--planet-2) 0%, transparent 72%),
    radial-gradient(60px 60px at 78% 8%, var(--planet-3) 0%, transparent 72%);
  background-repeat: no-repeat;
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: 0.65; } to { opacity: 0.9; } }

/* ---- themes ---- */
body.theme-junior {
  --bg: linear-gradient(165deg, #2c2560 0%, #6a4bb8 38%, #b98fe0 62%, #ffd9a6 100%);
  --ink: #2b2350;
  --ink-invert: #fdfbff;
  --card: #fffdfa;
  --accent: #ff8a5b;
  --accent-2: #7c5cff;
  --good: #2fb673;
  --soft: #fff1de;
  --font-scale: 1.12;
  --radius: 26px;
  --planet-1: rgba(255, 214, 153, 0.55);
  --planet-2: rgba(124, 92, 255, 0.4);
  --planet-3: rgba(255, 140, 170, 0.45);
}
body.theme-senior {
  --bg: linear-gradient(165deg, #12163a 0%, #23306e 40%, #3e5aa8 68%, #8fd9e0 100%);
  --ink: #16203f;
  --ink-invert: #f5f8ff;
  --card: #ffffff;
  --accent: #3b6cff;
  --accent-2: #00a883;
  --good: #1f9d61;
  --soft: #eaf1ff;
  --font-scale: 1;
  --radius: 18px;
  --planet-1: rgba(0, 168, 131, 0.4);
  --planet-2: rgba(59, 108, 255, 0.4);
  --planet-3: rgba(143, 217, 224, 0.5);
}
body.theme-parent {
  --bg: linear-gradient(180deg, #eef1f8 0%, #f6f7fb 220px, #f6f7fb 100%);
  --ink: #1c2233;
  --ink-invert: #f5f7ff;
  --card: #ffffff;
  --accent: #2d5be3;
  --accent-2: #667085;
  --good: #1f9d61;
  --soft: #eef1f6;
  --font-scale: 0.95;
  --radius: 12px;
}

#app { max-width: 900px; margin: 0 auto; padding: 18px 16px 60px; font-size: calc(16px * var(--font-scale)); position: relative; z-index: 1; }
.boot { text-align: center; padding: 80px 0; font-size: 1.3em; color: #fff; }

h1, h2 { line-height: 1.15; }
.title { font-size: 1.9em; margin: 10px 0 4px; }
.subtitle { opacity: 0.75; margin: 0 0 22px; }
body.theme-junior .title, body.theme-junior .subtitle,
body.theme-senior .title, body.theme-senior .subtitle { color: var(--ink-invert); text-shadow: 0 2px 10px rgba(0,0,0,0.25); }
body.theme-junior .subtitle, body.theme-senior .subtitle { opacity: 0.9; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}

button {
  font-family: inherit;
  font-size: 1em;
  border: 0;
  border-radius: calc(var(--radius) * 0.7);
  padding: 14px 20px;
  min-height: 46px;
  cursor: pointer;
  background: var(--soft);
  color: var(--ink);
  transition: transform 0.08s, box-shadow 0.2s, filter 0.15s;
}
button:hover { filter: brightness(1.04); }
button:active { transform: scale(0.97); }
button.primary { background: var(--accent); color: #fff; font-weight: 700; box-shadow: 0 6px 16px rgba(0,0,0,0.15); }
button.primary:hover { transform: translateY(-1px); }
button.secondary { background: var(--accent-2); color: #fff; }
button.ghost { background: transparent; text-decoration: underline; opacity: 0.8; }
body.theme-junior button.ghost, body.theme-senior button.ghost { color: var(--ink-invert); }
button:disabled { opacity: 0.45; cursor: default; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.topbar .who { font-weight: 700; }
body.theme-junior .topbar .who, body.theme-senior .topbar .who { color: var(--ink-invert); }
.badge-demo {
  background: #ffe28a; color: #6b5200; font-size: 0.72em; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; letter-spacing: 0.3px;
}

/* ---- profile picker ("Choose Your Explorer") ---- */
.profiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 18px; align-items: start; }
.profile-card {
  text-align: center; padding: 32px 16px; font-size: 1.1em; border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow); cursor: pointer; border: 3px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}
.profile-card:hover { border-color: var(--accent); transform: translateY(-3px); }
.profile-card .avatar { font-size: 3.4em; display: block; margin-bottom: 8px; }
.profile-card .grade { opacity: 0.65; font-size: 0.85em; }
.profile-card .explorer-tag {
  display: inline-block; margin-top: 8px; font-size: 0.72em; font-weight: 700; letter-spacing: 0.4px;
  text-transform: uppercase; color: var(--accent-2); background: var(--soft); padding: 4px 10px; border-radius: 999px;
}
.profile-card.role-parent .explorer-tag { background: #1c2340; color: #cfe0ff; }

/* ---- PIN pad ---- */
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 26px; }
.pin-dots span { width: 20px; height: 20px; border-radius: 50%; background: var(--soft); border: 2px solid var(--accent-2); }
.pin-dots span.full { background: var(--accent); border-color: var(--accent); }
.pinpad { display: grid; grid-template-columns: repeat(3, 84px); gap: 12px; justify-content: center; }
.pinpad button { height: 64px; font-size: 1.5em; font-weight: 700; border-radius: 18px; }
.error { color: #d63b57; font-weight: 700; text-align: center; min-height: 1.4em; }

/* ---- kid home / mission picker ---- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.choice {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 26px 18px; text-align: center; cursor: pointer; border: 3px solid transparent; font-size: 1.05em;
  transition: transform 0.15s, border-color 0.15s;
}
.choice:hover { border-color: var(--accent); transform: translateY(-3px); }
.choice .big { font-size: 2.6em; display: block; margin-bottom: 6px; }
.choice.disabled { cursor: default; }
.choice.disabled:hover { border-color: transparent; transform: none; }
.choice.disabled .big, .choice.disabled strong, .choice.disabled .hint { opacity: 0.4; }
.choice .hint { display: block; font-size: 0.8em; opacity: 0.65; margin-top: 6px; }

.topic-list { display: flex; flex-wrap: wrap; gap: 10px; }
.topic-list button {
  border: 2px solid var(--soft); border-radius: 999px; padding: 10px 18px; font-weight: 600;
}
.topic-list button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.toggle-row { display: flex; align-items: center; gap: 10px; margin: 14px 0; }

/* ---- test screen ---- */
.test-head {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 10px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 18px; margin-bottom: 14px; flex-wrap: wrap;
}
.timer { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.35em; }
.timer.danger { color: #d63b57; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }
.section-tag { font-size: 0.8em; font-weight: 700; color: var(--accent-2); text-transform: uppercase; letter-spacing: 0.5px; }

.qtext { font-size: 1.25em; line-height: 1.5; margin: 10px 0 18px; }
.options { display: grid; gap: 12px; }
.option {
  display: flex; gap: 14px; align-items: center; text-align: left; padding: 18px 20px;
  font-size: 1.08em; border: 3px solid var(--soft); background: var(--card); border-radius: calc(var(--radius) * 0.7);
  min-height: 56px; transition: transform 0.1s, border-color 0.15s;
}
.option:hover { border-color: var(--accent-2); }
.option .letter {
  flex: 0 0 40px; height: 40px; display: grid; place-items: center; font-weight: 800;
  background: var(--soft); border-radius: 50%;
}
.option.chosen { border-color: var(--accent); background: var(--soft); }
.option.chosen .letter { background: var(--accent); color: #fff; }

.palette { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.palette button {
  width: 42px; height: 42px; padding: 0; border-radius: 12px; font-weight: 700; min-height: 42px;
  border: 2px solid var(--soft); background: var(--card);
}
.palette button.answered { background: var(--good); color: #fff; border-color: var(--good); }
.palette button.current { border-color: var(--accent); }

.test-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ---- mission complete / score screen ---- */
.score-hero { text-align: center; padding: 40px 20px; }
.score-hero .pct { font-size: 4em; font-weight: 900; color: var(--accent); }
.score-hero .msg { font-size: 1.3em; margin: 10px 0 4px; }
.score-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.score-table td, .score-table th { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--soft); }

.reward-row { display: flex; justify-content: center; gap: 22px; margin: 18px 0; flex-wrap: wrap; }
.reward-row .reward { text-align: center; }
.reward-row .reward .val { font-size: 1.6em; font-weight: 800; }
.reward-row .reward .lbl { font-size: 0.78em; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.4px; }
.stars-earned { font-size: 1.6em; letter-spacing: 4px; }
.stars-earned .dim { opacity: 0.25; }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti i {
  position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; opacity: 0.9;
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0.7; } }

/* ---- review ---- */
.review-item { border-left: 8px solid var(--soft); }
.review-item.wrong { border-left-color: #ffb14e; }   /* warm, not red-shaming */
.review-item.skipped { border-left-color: #b9a8ff; }
.review-item.correct { border-left-color: var(--good); }
.review-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; cursor: pointer; }
.review-head .status { font-weight: 700; }
.reason-buttons { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin: 14px 0; }
.reason-buttons button { padding: 16px 10px; font-size: 1em; font-weight: 700; background: var(--soft); }
.locked-box {
  background: var(--soft); border-radius: calc(var(--radius) * 0.6); padding: 14px 16px;
  text-align: center; font-weight: 600; opacity: 0.85;
}
.explain { background: var(--soft); border-radius: calc(var(--radius) * 0.6); padding: 14px 16px; margin-top: 10px; line-height: 1.5; }
.explain .lead { font-weight: 800; }
.reason-chip { display: inline-block; background: var(--soft); border-radius: 999px; padding: 4px 12px; font-size: 0.85em; font-weight: 700; }
.flag-row { margin-top: 12px; text-align: right; }
.flag-row button { font-size: 0.85em; padding: 8px 14px; }
.flag-row .flagged { color: #b26a00; font-weight: 700; font-size: 0.9em; }

/* ---- journey / parent ---- */
table.plain { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.plain th, table.plain td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--soft); font-size: 0.95em; }
table.plain tr.click { cursor: pointer; }
table.plain tr.click:hover { background: var(--soft); }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button.sel { background: var(--accent); color: #fff; }
.muted { opacity: 0.7; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8em; font-weight: 700; background: var(--soft); }

.journey-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.journey-stats .stat { text-align: center; padding: 18px 10px; }
.journey-stats .stat .big { font-size: 1.9em; font-weight: 800; }
.journey-stats .stat .lbl { font-size: 0.78em; opacity: 0.65; text-transform: uppercase; letter-spacing: 0.4px; }
.badges-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.badge-pill { background: var(--soft); border-radius: 999px; padding: 8px 16px; font-weight: 700; font-size: 0.9em; }

/* ---- Mission Control (parent) ---- */
body.theme-parent .mc-hero {
  background: linear-gradient(120deg, #1c2340 0%, #2d3c6b 100%); color: #eef1ff;
  border-radius: var(--radius); padding: 18px 22px; margin-bottom: 16px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
}
body.theme-parent .mc-hero .who { color: #eef1ff; font-weight: 700; }
body.theme-parent .mc-hero button.ghost { color: #cfe0ff; }

@media (max-width: 520px) {
  .pinpad { grid-template-columns: repeat(3, 30%); }
  .title { font-size: 1.5em; }
  .score-hero .pct { font-size: 3em; }
}
