/* 내신대비반 레슨 — 여정형 K웹툰 화면.
   지도(jr-) → 몰입 스테이지 러너(rn-) → 결과(rs-). 라이트/다크. */

:root {
  --bg: #f5f2fb; --surface: #ffffff; --ink: #1a1633; --ink-soft: #5b5570; --line: #e7e1f2;
  --brand: #7c3aed; --brand-press: #5b21b6; --pink: #ec4899; --gold: #f5b301;
  --good: #22a06b; --good-press: #17794e; --bad: #e5484d;
  --tone: rgba(124, 58, 237, .10); --shadow-btn: 0 4px 0; --radius: 16px;
  --font: "Pretendard", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14101f; --surface: #1e1830; --ink: #f2ecff; --ink-soft: #b3a9cf;
    --line: #322a49; --tone: rgba(168, 130, 255, .14);
  }
}
:root[data-theme="dark"] {
  --bg: #14101f; --surface: #1e1830; --ink: #f2ecff; --ink-soft: #b3a9cf;
  --line: #322a49; --tone: rgba(168, 130, 255, .14);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
button { font-family: inherit; }
img { max-width: 100%; }
.ep-load { text-align: center; padding: 60px 20px; font-weight: 800; color: var(--ink-soft); }

/* ══════════ 지도 화면 ══════════ */
.jr-wrap { max-width: 620px; margin: 0 auto; padding: 14px 16px 60px; }
.jr-top { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.jr-back {
  border: 2px solid var(--ink); background: var(--surface); color: var(--ink); text-decoration: none;
  border-radius: 999px; padding: 7px 14px; font-weight: 850; font-size: 12px; box-shadow: var(--shadow-btn) var(--ink);
  cursor: pointer; display: inline-block;
}
.jr-hud { margin-left: auto; display: flex; gap: 6px; }
.jr-chip {
  border: 2px solid var(--ink); background: var(--surface); border-radius: 999px;
  padding: 5px 10px; font-weight: 900; font-size: 12px; box-shadow: var(--shadow-btn) var(--ink);
}
.jr-chip.done { background: var(--good); color: #fff; }
.jr-chip-btn { cursor: pointer; }
.jr-chip-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

.jr-hero {
  position: relative; display: flex; align-items: center; gap: 12px;
  border: 3px solid var(--ink); border-radius: var(--radius); padding: 16px 84px 16px 14px;
  background:
    radial-gradient(circle at 14% 24%, rgba(255,255,255,.16) 0 2px, transparent 2px) 0 0/15px 15px,
    linear-gradient(135deg, var(--brand), var(--pink));
  color: #fff; box-shadow: 7px 7px 0 var(--ink); overflow: hidden; margin-bottom: 20px;
}
.jr-hero-char { width: 78px; height: 78px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 4px 6px rgba(0,0,0,.25)); }
.jr-hero-body { min-width: 0; }
.jr-hero-badge {
  display: inline-block; background: #fff; color: var(--brand-press); font-weight: 900;
  font-size: 11px; padding: 3px 9px; border-radius: 999px; border: 2px solid var(--ink);
}
.jr-hero-title { font-size: 17px; font-weight: 950; margin: 7px 0 3px; line-height: 1.25; }
.jr-hero-sub { font-size: 12px; font-weight: 600; opacity: .95; }
.jr-hero-ring {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  width: 56px; height: 56px; border-radius: 50%; border: 3px solid var(--ink);
  background: conic-gradient(var(--gold) calc(var(--pct,0) * 1%), rgba(255,255,255,.25) 0);
  display: grid; place-items: center;
}
.jr-hero-ring span { background: var(--brand-press); width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 950; font-size: 11px; }

/* ── 스테이지 경로 노드 ── */
.jr-path { display: flex; flex-direction: column; gap: 14px; position: relative; }
.jr-path::before {
  content: ""; position: absolute; left: 33px; top: 20px; bottom: 20px; width: 4px;
  background: var(--line); border-radius: 2px; z-index: 0;
}
.jr-node {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; text-align: left;
  border: 3px solid var(--ink); background: var(--surface); color: var(--ink);
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer; width: 100%;
  box-shadow: 5px 5px 0 var(--ink); transition: transform .06s;
}
.jr-node:active { transform: translateY(3px); box-shadow: 2px 2px 0 var(--ink); }
.jr-node.cleared { background: linear-gradient(135deg, #ecfdf5, #f0fdf4); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .jr-node.cleared { background: #16321f; } }
.jr-node.locked { opacity: .55; }
.jr-node.next { border-color: var(--brand); box-shadow: 5px 5px 0 var(--brand); }
.jr-node.shake { animation: shake .35s; }
.jr-node-icon {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; border: 2.5px solid var(--ink);
  background: var(--tone); display: grid; place-items: center; font-size: 22px;
}
.jr-node.cleared .jr-node-icon { background: var(--good); }
.jr-node-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.jr-node-title { font-weight: 950; font-size: 15px; }
.jr-stars { color: var(--gold); font-size: 13px; }
.jr-node-sub { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.jr-node-bar { height: 7px; background: var(--line); border-radius: 999px; overflow: hidden; }
.jr-node-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--pink)); border-radius: 999px; }
.jr-here {
  position: absolute; right: 12px; top: -11px; background: var(--brand); color: #fff;
  font-size: 10px; font-weight: 900; padding: 3px 8px; border-radius: 999px; border: 2px solid var(--ink);
}

/* ══════════ 몰입 스테이지 러너 ══════════ */
body[data-screen="quiz"], body[data-screen="read"], body[data-screen="result"] {
  background: linear-gradient(172deg, #fff8ed 0%, #f2eafb 46%, #e3efe9 100%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) body[data-screen="quiz"],
  :root:not([data-theme="light"]) body[data-screen="read"],
  :root:not([data-theme="light"]) body[data-screen="result"] {
    background: linear-gradient(172deg, #1a1327 0%, #14101f 60%, #10161a 100%);
  }
}
#ep-screen { max-width: 620px; margin: 0 auto; padding: calc(14px + env(safe-area-inset-top,0)) 16px calc(40px + env(safe-area-inset-bottom,0)); }

.rn-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.rn-leave {
  border: 2px solid var(--ink); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 15px; font-weight: 850; font-size: 13px; cursor: pointer;
  box-shadow: var(--shadow-btn) var(--ink);
}
.rn-leave:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.rn-count { font-weight: 800; font-size: 12px; color: var(--ink-soft); }

#rn-prog {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; height: 14px;
  border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: var(--line); margin: 0 0 16px;
}
#rn-prog::-webkit-progress-bar { background: transparent; }
#rn-prog::-webkit-progress-value { background: linear-gradient(90deg, var(--brand), var(--pink)); }
#rn-prog::-moz-progress-bar { background: linear-gradient(90deg, var(--brand), var(--pink)); }

.rn-guide, .rn-guide-slot { margin-bottom: 14px; }
.rn-guide { display: flex; align-items: flex-start; gap: 10px; }
.rn-portrait {
  width: 60px; height: 60px; flex-shrink: 0; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--surface); object-fit: contain; padding: 4px;
}
.rn-bubble {
  position: relative; flex: 1; background: var(--surface); border: 2.5px solid var(--ink);
  border-radius: 16px; padding: 11px 14px; font-weight: 750; font-size: 13.5px; line-height: 1.6;
  box-shadow: 4px 4px 0 var(--ink);
}
.rn-bubble::before { content: ""; position: absolute; left: -13px; top: 18px; border: 8px solid transparent; border-right-color: var(--ink); }
.rn-bubble::after { content: ""; position: absolute; left: -9px; top: 19px; border: 7px solid transparent; border-right-color: var(--surface); }

.rn-item { }
.rn-stem { font-weight: 850; font-size: 16px; line-height: 1.55; white-space: pre-wrap; margin-bottom: 14px; }
.rn-textarea {
  width: 100%; border: 2px solid var(--ink); border-radius: 12px; padding: 11px 13px; font-size: 14px;
  font-family: inherit; background: var(--surface); color: var(--ink); resize: vertical;
}
.rn-read { display: flex; flex-direction: column; }
.rn-timer {
  text-align: center; font-weight: 900; font-size: 14px; color: var(--brand-press);
  background: var(--surface); border: 2px solid var(--ink); border-radius: 999px;
  padding: 6px 0; margin-bottom: 10px; width: 120px; margin-left: auto; margin-right: auto;
}
.rn-timer-toggle { display: flex; align-items: center; gap: 8px; font-weight: 750; font-size: 13.5px; cursor: pointer; }
.rn-timer-toggle input { width: 18px; height: 18px; }

/* ══════════ 결과 화면 ══════════ */
.rs-wrap { max-width: 460px; margin: 20px auto 0; text-align: center; }
.rs-char { width: 120px; height: 120px; object-fit: contain; }
.rs-stars { font-size: 40px; color: var(--gold); letter-spacing: 6px; margin: 4px 0; }
.rs-title { font-size: 22px; font-weight: 950; }
.rs-line { font-size: 14px; color: var(--ink-soft); font-weight: 700; margin: 6px 0; }
.rs-classavg {
  display: inline-block; font-size: 12.5px; font-weight: 800; color: var(--brand-press);
  background: var(--tone); border-radius: 999px; padding: 6px 14px; margin: 0 0 16px;
}
.rs-reflect { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.rs-reflect span { font-size: 13px; font-weight: 800; color: var(--ink-soft); }

/* ══════════ 공통 문제 컴포넌트 ══════════ */
.ep-card {
  border: 3px solid var(--ink); border-radius: var(--radius); background: var(--surface);
  padding: 16px; margin: 12px 0; box-shadow: 6px 6px 0 var(--ink);
}
.ep-card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 950; }
.ep-hint { color: var(--ink-soft); font-size: 13px; margin: 4px 0 10px; }
.ep-q { border-top: 2px dashed var(--line); padding: 12px 0; }
.ep-q:first-child { border-top: 0; }
.ep-q .stem { font-weight: 800; white-space: pre-wrap; margin-bottom: 10px; }

.ep-vocab { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ep-word { border: 2px solid var(--ink); border-radius: 12px; padding: 12px; background: var(--surface); box-shadow: 3px 3px 0 var(--ink); }
.ep-word .w { font-weight: 950; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.ep-word .w button { margin-left: auto; border: 2px solid var(--ink); background: var(--gold); border-radius: 8px; width: 26px; height: 26px; cursor: pointer; font-size: 12px; }
.ep-word .pos { font-size: 11px; color: var(--brand); font-weight: 800; }
.ep-word .mean { font-weight: 700; margin: 3px 0; }
.ep-word .ex { font-size: 12px; color: var(--ink-soft); }

.ep-opts { display: grid; gap: 8px; }
.ep-opt {
  text-align: left; border: 2px solid var(--ink); background: var(--surface); color: var(--ink);
  border-radius: 12px; padding: 12px 14px; font-weight: 750; font-size: 14.5px; cursor: pointer;
  box-shadow: var(--shadow-btn) var(--ink);
}
.ep-opt:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.ep-opt.correct { background: var(--good); color: #fff; }
.ep-opt.wrong { background: var(--bad); color: #fff; animation: shake .3s; }
.ep-opt.eliminated { opacity: .4; text-decoration: line-through; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.ep-exp { margin-top: 10px; font-size: 13px; color: var(--ink-soft); background: var(--tone);
  border-radius: 10px; padding: 9px 11px; display: none; }
.ep-exp.on { display: block; }

.ep-modes { display: flex; gap: 6px; margin-bottom: 10px; }
.ep-mode {
  border: 2px solid var(--ink); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; font-weight: 800; cursor: pointer;
}
.ep-mode[aria-selected="true"] { background: var(--brand); color: #fff; }
.ep-tiles { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; min-height: 44px;
  border: 2px dashed var(--line); border-radius: 10px; padding: 8px; }
.ep-tile {
  border: 2px solid var(--ink); background: var(--gold); border-radius: 8px; padding: 7px 11px;
  font-weight: 800; font-size: 14px; cursor: pointer; box-shadow: 2px 2px 0 var(--ink);
}
.ep-slot { border-color: var(--brand); background: var(--tone); }
.ep-fill { display: flex; gap: 6px; }
.ep-fill input {
  flex: 1; border: 2px solid var(--ink); border-radius: 10px; padding: 11px 13px; font-size: 15px;
  font-family: inherit; background: var(--surface); color: var(--ink);
}
.ep-check {
  border: 2px solid var(--good-press); background: var(--good); color: #fff; border-radius: 12px;
  padding: 12px 20px; font-weight: 900; font-size: 15px; cursor: pointer;
  box-shadow: var(--shadow-btn) var(--good-press);
}
.ep-check:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--good-press); }
.ep-check.reveal { background: var(--brand); border-color: var(--brand-press); box-shadow: var(--shadow-btn) var(--brand-press); }

.ep-sent { border: 2px solid var(--ink); border-radius: 12px; padding: 10px 12px; margin: 8px 0; box-shadow: 3px 3px 0 var(--ink); }
.ep-sent .ko { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.chunk { display: inline-block; padding: 2px 6px; border-radius: 6px; font-weight: 800; margin: 2px; }
.chunk.S { background: #dbeafe; color: #1e40af; } .chunk.V { background: #dcfce7; color: #166534; }
.chunk.O { background: #fee2e2; color: #991b1b; } .chunk.C { background: #fef9c3; color: #854d0e; }
.chunk.M { background: #ede9fe; color: #5b21b6; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chunk { filter: brightness(.85); } }
.ep-line { display: flex; gap: 8px; padding: 6px 0; }
.ep-line .who { font-weight: 900; color: var(--brand); min-width: 74px; font-size: 13px; }
.ep-line .en { font-weight: 700; } .ep-line .ko { color: var(--ink-soft); font-size: 12px; }
.ep-empty { color: var(--ink-soft); font-size: 13px; padding: 20px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; }

/* ── 떠다니는 코치 ── */
.ep-coach {
  position: fixed; right: 16px; bottom: 16px; max-width: 260px; z-index: 60;
  background: var(--surface); border: 3px solid var(--ink); border-radius: 14px;
  padding: 10px 12px 10px 44px; font-weight: 800; font-size: 13px; box-shadow: 5px 5px 0 var(--ink);
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(24px); transition: transform .28s cubic-bezier(.2,1.4,.4,1), opacity .2s, visibility .2s;
}
.ep-coach.on { transform: translateY(0); opacity: 1; visibility: visible; }
.ep-coach::before { content: "🐣"; position: absolute; left: 8px; top: 8px; font-size: 24px; }
.ep-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; display: none; }
.ep-confetti.on { display: block; }
.ep-confetti i { position: absolute; width: 9px; height: 14px; top: -20px; animation: fall 1.6s linear forwards; }
@keyframes fall { to { transform: translateY(102vh) rotate(540deg); } }
