@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;700;900&family=Noto+Sans+SC:wght@400;500;700&family=Playfair+Display:wght@700;900&display=swap');

/* ═══════════════════════════════
   TOKENS
═══════════════════════════════ */
:root {
  --ink:    #09091a;
  --ink2:   #10112a;
  --ink3:   #181932;
  --ink4:   #20224a;
  --gold:   #c8a84b;
  --goldb:  #e8cc7a;
  --golddim:rgba(200,168,75,.12);
  --ivory:  #ede5d0;
  --ivory2: #a09070;
  --ivory3: #5a5040;
  --green:  #3ec87a;
  --red:    #e05050;
  --r:      10px;
  --rl:     16px;
  --sc:     #4a8fd4; /* per-section color, overridden by JS */
}

*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { scroll-behavior:smooth; }

body {
  font-family:'Noto Sans SC', system-ui, sans-serif;
  background:var(--ink);
  color:var(--ivory);
  min-height:100vh;
  display:flex; justify-content:center; align-items:flex-start;
  overflow-x:hidden;
}

/* grain + glow */
.grain {
  position:fixed; inset:0; z-index:9999; pointer-events:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity:.025;
}
.ambient-glow {
  position:fixed; inset:0; z-index:0; pointer-events:none;
  background:
    radial-gradient(ellipse 60% 50% at 15% 10%, rgba(74,143,212,.12) 0%, transparent 100%),
    radial-gradient(ellipse 50% 40% at 85% 90%, rgba(155,89,182,.08) 0%, transparent 100%),
    radial-gradient(ellipse 40% 60% at 50% 50%, rgba(200,168,75,.04) 0%, transparent 100%);
}

/* ═══════════════════════════════
   SCREENS
═══════════════════════════════ */
.screen {
  display:none;
  flex-direction:column;
  align-items:center;
  width:100%; max-width:680px;
  padding:40px 22px 90px;
  position:relative; z-index:1;
}
#quiz-screen { padding-top:0; }

/* ═══════════════════════════════
   BUTTONS
═══════════════════════════════ */
.btn {
  display:inline-flex; align-items:center; justify-content:center;
  gap:6px; border:none; border-radius:var(--r);
  font-family:'Noto Sans SC', sans-serif;
  font-weight:700; cursor:pointer; transition:all .15s;
  position:relative; overflow:hidden;
}
.btn::after { content:''; position:absolute; inset:0; background:rgba(255,255,255,0); transition:.15s; }
.btn:hover::after { background:rgba(255,255,255,.08); }
.btn:active { transform:scale(.97); }

.btn-gold {
  background:var(--gold); color:#0a0a18;
  padding:14px 36px; font-size:15px;
  box-shadow:0 4px 20px rgba(200,168,75,.35);
}
.btn-gold:hover { background:var(--goldb); box-shadow:0 6px 28px rgba(200,168,75,.5); transform:translateY(-1px); }

.btn-sc {
  background:var(--sc); color:#fff;
  padding:10px 22px; font-size:13px;
  box-shadow:0 3px 14px rgba(0,0,0,.3);
}
.btn-sc:hover { filter:brightness(1.15); }

.btn-ghost-sm {
  background:transparent; color:var(--ivory2);
  border:1px solid rgba(255,255,255,.12);
  padding:10px 20px; font-size:13px;
}
.btn-ghost-sm:hover { border-color:rgba(200,168,75,.4); color:var(--ivory); }

/* ═══════════════════════════════
   SHARED UTILS
═══════════════════════════════ */
.rule { display:inline-block; width:28px; height:1px; background:var(--gold); opacity:.5; }
@keyframes fadeUp   { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }
@keyframes slideUp  { from{opacity:0;transform:translateY(8px)}  to{opacity:1;transform:translateY(0)} }
@keyframes shake    { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
@keyframes pulse    { from{opacity:1} to{opacity:.4} }
@keyframes heartLose{ 0%{transform:scale(1)} 30%{transform:scale(1.5)} 100%{transform:scale(1)} }
.shake { animation:shake .4s ease both; }

/* ═══════════════════════════════
   LOGIN
═══════════════════════════════ */
.login-ghost {
  position:absolute; top:10px; left:50%;
  transform:translateX(-50%);
  font-size:clamp(160px,38vw,300px);
  color:rgba(200,168,75,.04);
  pointer-events:none; user-select:none;
  font-family:'Playfair Display', serif;
  line-height:1;
}
.login-eyebrow {
  display:flex; align-items:center; gap:10px;
  font-size:11px; letter-spacing:3px; color:var(--gold); opacity:.8;
  text-transform:uppercase; margin-bottom:18px;
  animation:fadeUp .5s ease both;
}
.login-title {
  text-align:center; margin-bottom:28px;
  animation:fadeUp .5s .06s ease both;
}
.login-ch {
  display:block;
  font-family:'Playfair Display','Noto Serif SC',serif;
  font-size:clamp(38px,9vw,62px); font-weight:900;
  color:var(--ivory); text-shadow:0 0 50px rgba(200,168,75,.25);
  line-height:1.1;
}
.login-sub-title {
  display:block; font-size:14px; color:var(--ivory2); letter-spacing:2px; margin-top:6px;
}
.login-card {
  width:100%; max-width:380px;
  background:var(--ink2); border:1px solid rgba(200,168,75,.15);
  border-radius:var(--rl); padding:28px 24px;
  animation:fadeUp .5s .12s ease both;
}
.login-hint { font-size:13px; color:var(--ivory2); text-align:center; margin-bottom:20px; letter-spacing:.5px; }
.form-field { margin-bottom:16px; }
.form-label { display:block; font-size:11px; font-weight:700; color:var(--gold); letter-spacing:2px; text-transform:uppercase; margin-bottom:7px; }
.form-input {
  width:100%; padding:13px 16px;
  background:var(--ink3); border:1px solid rgba(255,255,255,.08); border-radius:var(--r);
  color:var(--ivory); font-family:'Noto Sans SC',sans-serif; font-size:15px; outline:none;
  transition:border-color .2s, box-shadow .2s;
}
.form-input::placeholder { color:var(--ivory3); }
.form-input:focus { border-color:rgba(200,168,75,.5); box-shadow:0 0 0 3px rgba(200,168,75,.08); }
.login-err { font-size:13px; color:var(--red); min-height:18px; margin-bottom:10px; text-align:center; }
#login-btn { width:100%; padding:15px; font-size:16px; margin-top:4px; }
.login-note { margin-top:18px; font-size:12px; color:var(--ivory3); letter-spacing:.5px; animation:fadeUp .5s .2s ease both; }

/* ═══════════════════════════════
   STORY
═══════════════════════════════ */
.story-top { display:flex; align-items:center; gap:10px; margin-bottom:28px; flex-direction:column; }
.story-crown { font-size:32px; animation:fadeUp .5s ease both; }
.story-eyebrow { font-size:12px; color:var(--gold); letter-spacing:3px; opacity:.7; text-transform:uppercase; }
.story-box {
  width:100%; max-width:540px;
  background:var(--ink2); border:1px solid rgba(200,168,75,.1);
  border-radius:var(--rl); padding:28px 26px;
  margin-bottom:28px;
}
.story-para {
  font-family:'Noto Serif SC', serif;
  font-size:16px; line-height:1.9; color:var(--ivory2);
  margin-bottom:14px; opacity:0;
  animation:fadeUp .7s ease forwards;
}
.story-para:last-child { margin-bottom:0; color:var(--ivory); font-weight:600; font-size:17px; }
.story-actions { display:flex; gap:12px; align-items:center; }
.story-go { opacity:0; pointer-events:none; transition:opacity .4s; }

/* ═══════════════════════════════
   MAP
═══════════════════════════════ */
.map-header {
  width:100%; display:flex; justify-content:space-between; align-items:center;
  padding:0 4px; margin-bottom:20px;
}
.map-player { display:flex; align-items:center; gap:8px; font-size:14px; font-weight:600; }
.map-player-icon { font-size:20px; }
.map-score-chip {
  background:var(--golddim); border:1px solid rgba(200,168,75,.2);
  padding:5px 14px; border-radius:99px;
  font-size:13px; font-weight:700; color:var(--gold);
}
.map-title {
  font-family:'Noto Serif SC',serif;
  font-size:clamp(22px,5vw,30px); font-weight:900; margin-bottom:6px;
  animation:fadeUp .4s ease both;
}
.map-sub { font-size:13px; color:var(--ivory2); margin-bottom:32px; animation:fadeUp .4s .06s ease both; }

.map-path {
  display:flex; align-items:center; gap:10px;
  width:100%; overflow-x:auto;
  padding:8px 0 20px;
  animation:fadeUp .4s .1s ease both;
}
.map-arrow { font-size:22px; color:var(--ivory3); flex-shrink:0; }

.stage-card {
  flex-shrink:0;
  width:130px;
  background:var(--ink2); border:1px solid rgba(255,255,255,.06);
  border-radius:var(--rl); padding:16px 12px 14px;
  display:flex; flex-direction:column; align-items:center; gap:6px;
  text-align:center; position:relative; overflow:hidden;
  transition:transform .2s, box-shadow .2s, border-color .2s;
}
.stage-card::before {
  content:''; position:absolute; top:0; left:0; right:0; height:3px;
  background:var(--sc);
}
.stage-card.unlocked { cursor:pointer; border-color:rgba(255,255,255,.1); }
.stage-card.unlocked:hover { transform:translateY(-3px); box-shadow:0 8px 24px rgba(0,0,0,.4); border-color:var(--sc); }
.stage-card.done { border-color:var(--sc); background:var(--ink3); }
.stage-card.locked { opacity:.45; cursor:not-allowed; }
.princess-card { opacity:.35; cursor:default; }

.stage-icon { font-size:28px; margin-bottom:2px; }
.stage-name { font-size:13px; font-weight:700; color:var(--ivory); }
.stage-sub  { font-size:11px; color:var(--ivory2); }
.stage-star { font-size:11px; color:var(--gold); font-weight:700; }
.stage-lock { font-size:10px; color:var(--ivory3); margin-top:2px; }

.lb-entry-btn { margin-top:28px; }

/* ═══════════════════════════════
   SECTION INTRO
═══════════════════════════════ */
.si-header {
  display:flex; align-items:center; gap:16px;
  margin-bottom:20px; align-self:flex-start;
  animation:fadeUp .4s ease both;
}
.si-icon-wrap {
  width:64px; height:64px; border-radius:16px;
  background:rgba(255,255,255,.05); border:1px solid var(--sc);
  display:flex; align-items:center; justify-content:center;
  font-size:30px; flex-shrink:0;
}
.si-gate { font-family:'Noto Serif SC',serif; font-size:18px; font-weight:700; color:var(--sc); }
.si-sub  { font-size:13px; color:var(--ivory2); margin-top:3px; }

.si-enemy-line {
  align-self:flex-start; margin-bottom:20px;
  font-size:13px; animation:fadeUp .4s .06s ease both;
}
.si-enemy-label { color:var(--ivory2); }
.si-enemy { color:var(--red); font-weight:700; font-size:15px; }

.si-story-box {
  width:100%; background:var(--ink2);
  border:1px solid rgba(255,255,255,.07); border-left:3px solid var(--sc);
  border-radius:0 var(--r) var(--r) 0;
  padding:20px 18px; margin-bottom:28px;
  animation:fadeUp .4s .1s ease both;
}
.si-line {
  font-family:'Noto Serif SC',serif;
  font-size:15px; line-height:1.85; color:var(--ivory2);
  margin-bottom:10px; opacity:0;
  animation:fadeUp .5s ease forwards;
}
.si-line:last-child { color:var(--gold); font-weight:600; margin-bottom:0; }
.si-actions { display:flex; gap:12px; }

/* ═══════════════════════════════
   QUIZ HUD
═══════════════════════════════ */
.quiz-hud {
  position:sticky; top:0; z-index:20;
  width:100%; background:linear-gradient(to bottom, var(--ink) 70%, transparent);
  padding:14px 0 8px;
  display:flex; align-items:center; gap:10px;
}
.hud-left  { flex-shrink:0; }
.hud-mid   { flex:1; display:flex; justify-content:center; }
.hud-right { flex-shrink:0; display:flex; align-items:center; gap:8px; }

.hud-timer {
  font-family:'Playfair Display',serif;
  font-size:22px; font-weight:700; color:var(--gold);
  min-width:64px; letter-spacing:1px;
}
.hud-timer.warn   { color:#ff9800; }
.hud-timer.urgent { color:var(--red); animation:pulse .5s infinite alternate; }

.hud-hearts { display:flex; gap:2px; }
.heart { font-size:16px; transition:transform .2s; }
.heart.dead { filter:grayscale(1); opacity:.35; }
.shake-hearts { animation:shake .4s ease; }

.hud-combo {
  font-size:13px; font-weight:700; color:var(--ivory2);
  background:rgba(255,255,255,.05); border-radius:99px;
  padding:3px 10px; min-width:40px; text-align:center;
  transition:all .2s;
}
.hud-combo.fire { color:#ff9800; background:rgba(255,152,0,.12); }
.hud-combo.mega { color:var(--gold); background:var(--golddim); animation:pulse .6s infinite alternate; }

.hud-score-wrap {
  font-size:13px; font-weight:700; color:var(--gold);
  background:var(--golddim); border:1px solid rgba(200,168,75,.2);
  padding:3px 12px; border-radius:99px;
}

/* ═══════════════════════════════
   PROGRESS BAR
═══════════════════════════════ */
.q-prog-track {
  width:100%; height:3px;
  background:rgba(255,255,255,.06); border-radius:99px; overflow:hidden;
  margin-bottom:16px;
}
.q-prog-fill {
  height:100%;
  background:linear-gradient(90deg, var(--sc), var(--gold));
  border-radius:99px; transition:width .4s ease;
  box-shadow:0 0 6px var(--sc);
}

/* ═══════════════════════════════
   QUIZ CONTENT
═══════════════════════════════ */
.quiz-content { width:100%; display:flex; flex-direction:column; }
.q-meta-row { display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; }
.q-sec-tag  { font-size:11px; font-weight:700; letter-spacing:1px; }
.q-num-label{ font-size:11px; color:var(--ivory3); letter-spacing:1px; text-transform:uppercase; }

.q-card {
  width:100%; background:var(--ink2);
  border:1px solid rgba(200,168,75,.1); border-radius:var(--rl);
  padding:22px 22px 22px 28px; margin-bottom:14px;
  position:relative; animation:fadeUp .3s ease both;
}
.q-card-bar {
  position:absolute; left:0; top:16px; bottom:16px;
  width:3px; background:linear-gradient(to bottom, var(--sc), transparent);
  border-radius:0 2px 2px 0;
}
.q-card p { font-size:clamp(14px,2.4vw,16px); font-weight:500; line-height:1.8; color:var(--ivory); }

/* options */
#q-options { display:flex; flex-direction:column; gap:9px; margin-bottom:14px; }

.opt-btn {
  display:flex; align-items:flex-start; gap:12px;
  padding:13px 16px; width:100%;
  background:var(--ink2); border:1px solid rgba(255,255,255,.06);
  border-left:3px solid rgba(255,255,255,.05);
  border-radius:var(--r);
  color:var(--ivory); font-family:'Noto Sans SC',sans-serif;
  font-size:14px; cursor:pointer; text-align:left;
  transition:all .15s;
  animation:slideUp .3s ease both;
}
.opt-btn:hover:not(:disabled) { background:var(--ink3); border-left-color:var(--sc); transform:translateX(2px); }
.opt-key {
  width:26px; height:26px; border-radius:6px;
  background:rgba(200,168,75,.07); border:1px solid rgba(200,168,75,.2);
  color:var(--gold); font-size:11px; font-weight:700; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
  font-family:'Playfair Display',serif;
}
.opt-txt { flex:1; line-height:1.5; padding-top:2px; }

.opt-btn.correct { background:rgba(62,200,122,.08); border-color:rgba(62,200,122,.25); border-left-color:var(--green); }
.opt-btn.correct .opt-key { background:var(--green); border-color:var(--green); color:#fff; }
.opt-btn.wrong   { background:rgba(224,80,80,.08);  border-color:rgba(224,80,80,.25);  border-left-color:var(--red); }
.opt-btn.wrong   .opt-key { background:var(--red);   border-color:var(--red);   color:#fff; }

/* explanation */
#q-exp-box {
  width:100%; background:var(--ink2);
  border:1px solid rgba(255,255,255,.07); border-radius:var(--r);
  overflow:hidden; margin-bottom:14px;
  animation:fadeUp .3s ease both;
}
.exp-verdict { padding:10px 16px; font-size:13px; font-weight:700; }
.exp-verdict.correct { background:rgba(62,200,122,.1); color:var(--green); }
.exp-verdict.wrong   { background:rgba(224,80,80,.1);  color:var(--red); }
.exp-body { padding:14px 16px; font-size:13px; line-height:1.75; color:var(--ivory2); }

.q-next { width:100%; padding:15px; font-size:15px; }

/* score popup */
.score-popup {
  position:fixed; top:40%; left:50%; transform:translate(-50%,-50%);
  font-size:24px; font-weight:900; color:var(--gold);
  text-shadow:0 0 20px rgba(200,168,75,.8);
  pointer-events:none; z-index:100;
  animation:scoreFloat 1.1s ease forwards;
}
@keyframes scoreFloat {
  0%   { opacity:1; transform:translate(-50%,-50%) scale(1); }
  100% { opacity:0; transform:translate(-50%,-110%) scale(1.4); }
}

/* ═══════════════════════════════
   SECTION RESULT
═══════════════════════════════ */
#sec-result-screen.pass { --sc: #3ec87a; }
#sec-result-screen.fail { --sc: #e05050; }

.sr-gate { font-size:12px; color:var(--sc); letter-spacing:2px; text-transform:uppercase; margin-bottom:16px; animation:fadeUp .4s ease both; }
.sr-icon { font-size:64px; margin-bottom:12px; animation:fadeUp .4s .06s ease both; }
.sr-result { font-family:'Noto Serif SC',serif; font-size:clamp(22px,5vw,30px); font-weight:900; margin-bottom:10px; color:var(--sc); animation:fadeUp .4s .1s ease both; }
.sr-story  { font-size:14px; color:var(--ivory2); line-height:1.7; text-align:center; max-width:480px; margin-bottom:28px; animation:fadeUp .4s .15s ease both; }

.sr-stats {
  display:flex; gap:24px; margin-bottom:32px;
  animation:fadeUp .4s .2s ease both;
}
.sr-stat { display:flex; flex-direction:column; align-items:center; gap:4px; }
.sr-stat-num { font-family:'Playfair Display',serif; font-size:36px; font-weight:700; color:var(--ivory); }
.sr-stat-lbl { font-size:12px; color:var(--ivory2); }

.sr-actions { display:flex; gap:12px; }

/* ═══════════════════════════════
   VICTORY
═══════════════════════════════ */
.v-princess { font-size:80px; margin-bottom:12px; animation:stickerPop .7s cubic-bezier(.17,.89,.32,1.28) both; filter:drop-shadow(0 4px 24px rgba(200,168,75,.4)); }
@keyframes stickerPop { 0%{transform:scale(0) rotate(-20deg);opacity:0} 60%{transform:scale(1.2) rotate(6deg)} 100%{transform:scale(1) rotate(0);opacity:1} }

.v-title { font-family:'Noto Serif SC',serif; font-size:clamp(22px,5vw,30px); font-weight:900; color:var(--ivory); margin-bottom:6px; animation:fadeUp .4s .2s ease both; }
.v-sub   { font-size:13px; color:var(--ivory2); margin-bottom:20px; animation:fadeUp .4s .25s ease both; text-align:center; }

.v-score-big { font-family:'Playfair Display',serif; font-size:80px; font-weight:700; color:var(--gold); line-height:1; text-shadow:0 0 40px rgba(200,168,75,.4); animation:fadeUp .4s .3s ease both; }
.v-score-label { font-size:13px; color:var(--ivory2); margin-bottom:6px; animation:fadeUp .4s .33s ease both; }
.v-time-bonus  { font-size:13px; color:var(--green); margin-bottom:24px; animation:fadeUp .4s .36s ease both; }

.v-stats { display:flex; gap:28px; margin-bottom:32px; animation:fadeUp .4s .4s ease both; flex-wrap:wrap; justify-content:center; }
.v-stat  { display:flex; flex-direction:column; align-items:center; gap:4px; }
.v-stat span { font-family:'Playfair Display',serif; font-size:28px; font-weight:700; color:var(--ivory); }
.v-stat small { font-size:11px; color:var(--ivory2); }

.v-actions { display:flex; gap:12px; flex-wrap:wrap; justify-content:center; animation:fadeUp .4s .45s ease both; }

/* ═══════════════════════════════
   LEADERBOARD
═══════════════════════════════ */
.lb-header { text-align:center; margin-bottom:24px; animation:fadeUp .4s ease both; width:100%; }
.lb-title  { font-family:'Noto Serif SC',serif; font-size:24px; font-weight:900; margin-bottom:6px; }
.lb-sub    { font-size:13px; color:var(--ivory2); }

.lb-list {
  width:100%; background:var(--ink2);
  border:1px solid rgba(200,168,75,.1); border-radius:var(--rl);
  padding:12px; margin-bottom:20px;
  max-height:65vh; overflow-y:auto;
  animation:fadeUp .4s .06s ease both;
}
.lb-loading, .lb-empty { text-align:center; color:var(--ivory2); font-size:14px; padding:20px 0; }

.lb-row {
  display:flex; align-items:center; gap:12px;
  padding:12px 10px; border-radius:var(--r);
  border-bottom:1px solid rgba(255,255,255,.04);
  transition:background .15s;
}
.lb-row:last-child { border-bottom:none; }
.lb-row:hover { background:var(--ink3); }
.lb-row.me { background:var(--golddim); border:1px solid rgba(200,168,75,.2); margin:-1px 0; }

.lb-rank  { font-size:20px; min-width:32px; text-align:center; }
.lb-info  { flex:1; display:flex; flex-direction:column; gap:2px; }
.lb-name  { font-size:14px; font-weight:600; color:var(--ivory); }
.lb-meta  { font-size:11px; color:var(--ivory3); }
.lb-score { font-family:'Playfair Display',serif; font-size:22px; font-weight:700; color:var(--gold); white-space:nowrap; }
.lb-score small { font-family:'Noto Sans SC',sans-serif; font-size:12px; color:var(--ivory2); }

.lb-actions { display:flex; gap:12px; flex-wrap:wrap; justify-content:center; animation:fadeUp .4s .12s ease both; }

/* ═══════════════════════════════
   CONFETTI
═══════════════════════════════ */
.confetti-piece {
  position:fixed; pointer-events:none; z-index:9998;
  animation:confettiFall linear forwards;
}
@keyframes confettiFall {
  0%   { transform:translateY(0) rotate(0deg);    opacity:1; }
  100% { transform:translateY(65vh) rotate(540deg); opacity:0; }
}

/* ═══════════════════════════════
   RESPONSIVE
═══════════════════════════════ */
@media(max-width:480px){
  .screen    { padding-left:16px; padding-right:16px; }
  .q-card    { padding:18px 16px 18px 22px; }
  .opt-btn   { font-size:13px; padding:11px 12px; }
  .v-score-big { font-size:64px; }
  .map-path  { gap:6px; }
  .stage-card{ width:112px; padding:12px 8px 12px; }
}
