:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #17181c;
  --muted: #6f7380;
  --line: #e6e8ef;
  --accent: #3b6cff;
  --accent-2: #6d8dff;
  --accent-soft: #eaf0ff;
  --bubble: #ffffff;
  --bubble-line: #e3e8f6;
  --shadow: 0 6px 20px rgba(24, 36, 80, 0.08);
  --shadow-sm: 0 2px 8px rgba(24, 36, 80, 0.06);
  --r: 18px;
  --r-sm: 12px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --card: #1a1d25;
    --text: #eef0f5;
    --muted: #8f95a3;
    --line: #262a35;
    --accent: #6f8fff;
    --accent-2: #8aa4ff;
    --accent-soft: #1f2740;
    --bubble: #1e2331;
    --bubble-line: #2a3145;
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}
.topbar h1 { font-size: 1.05rem; font-weight: 700; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.01em; }
.topbar .back {
  width: 36px; height: 36px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); box-shadow: var(--shadow-sm); font-size: 1.4rem; line-height: 1; padding-bottom: 3px;
}
.topbar .spacer { flex: 1; }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: transparent; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width 0.15s; }

/* ---------- 억양 배지 ---------- */
.accent-badge {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: var(--card); box-shadow: var(--shadow-sm);
  border-radius: 999px; padding: 5px 11px 5px 6px; cursor: pointer;
  font-size: 0.78rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em;
}
.accent-badge:active { transform: scale(0.96); }
.accent-badge .flag { display: inline-flex; line-height: 1; }
.flag-svg { width: 22px; height: 15px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(0,0,0,0.12); }
.choices .flag .flag-svg, .accent-choices .flag .flag-svg { width: 54px; height: 36px; border-radius: 6px; }

/* ---------- 공통 ---------- */
.wrap { max-width: 640px; margin: 0 auto; padding: 8px 16px calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)); }
.wrap.no-nav { padding-bottom: 120px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; background: var(--card); box-shadow: var(--shadow-sm); border-radius: 999px;
  padding: 9px 16px; cursor: pointer; font-size: 0.88rem; font-weight: 600;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 6px 16px rgba(59, 108, 255, 0.35); }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.btn.small { padding: 6px 12px; font-size: 0.8rem; }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; }
.section-title { font-size: 0.8rem; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin: 22px 4px 10px; }

/* ---------- 홈 ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 22px 20px 20px; margin: 6px 0 6px;
  color: #fff; background: linear-gradient(135deg, #2f5bff 0%, #6a4cff 55%, #9b5cff 100%);
  box-shadow: 0 14px 32px rgba(70, 80, 255, 0.35);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; background: rgba(255,255,255,0.12);
}
.hero::before { width: 220px; height: 220px; right: -70px; top: -90px; }
.hero::after { width: 140px; height: 140px; left: -50px; bottom: -70px; }
.hero .eyebrow { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; opacity: 0.85; margin: 0 0 4px; }
.hero h2 { font-size: 1.55rem; font-weight: 800; margin: 0 0 6px; letter-spacing: -0.02em; line-height: 1.2; }
.hero p { margin: 0; font-size: 0.88rem; opacity: 0.9; }
.hero .stats { display: flex; gap: 14px; margin-top: 16px; font-size: 0.8rem; opacity: 0.95; }
.hero .stats b { display: block; font-size: 1.25rem; font-weight: 800; line-height: 1.1; }
.hero .cta { position: relative; margin-top: 16px; display: inline-flex; align-items: center; gap: 8px; background: #fff; color: #2f4fff; border-radius: 999px; padding: 10px 18px; font-weight: 700; font-size: 0.9rem; box-shadow: 0 6px 14px rgba(0,0,0,0.15); }

.day-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 8px; margin: 14px -16px 4px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.day-strip::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; background: var(--card); box-shadow: var(--shadow-sm); border-radius: 999px;
  padding: 7px 14px; font-size: 0.82rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--text); color: var(--bg); }
@media (prefers-color-scheme: dark) { .chip.on { background: #fff; color: #111; } }

.ep {
  display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: var(--r);
  padding: 14px 14px 14px 14px; margin-bottom: 10px; box-shadow: var(--shadow-sm);
}
.ep .num {
  flex: none; width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.05rem; background: var(--accent-soft); color: var(--accent);
}
.ep.todo .num { background: var(--bg); color: var(--muted); }
.ep .body { flex: 1; min-width: 0; }
.ep h3 { margin: 0; font-size: 0.98rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep p { margin: 2px 0 0; color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ep .go { flex: none; display: flex; gap: 6px; }
.ep .go a { width: 38px; height: 38px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--bg); font-size: 1rem; }
.ep .go a.read { background: var(--accent); color: #fff; }
.ep.todo { opacity: 0.55; }
.ep.todo .go { display: none; }
.ep .soon { flex: none; font-size: 0.72rem; font-weight: 700; color: var(--muted); background: var(--bg); padding: 4px 8px; border-radius: 999px; }

/* ---------- 하단 탭 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 0.68rem; font-weight: 600; color: var(--muted); }
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }

/* ---------- 읽기 ---------- */
.ep-head { padding: 10px 4px 4px; }
.ep-head .eyebrow { font-size: 0.75rem; font-weight: 700; color: var(--accent); letter-spacing: 0.06em; margin: 0 0 2px; }
.ep-head h2 { margin: 0 0 8px; font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.ep-head .meta { display: flex; flex-direction: column; gap: 3px; margin: 0 0 12px; font-size: 0.82rem; color: var(--muted); }
.ep-head .meta b { color: var(--text); font-weight: 600; margin-right: 4px; }
.story { padding-top: 6px; }
.story .line { margin-bottom: 14px; cursor: pointer; border-radius: 14px; transition: background 0.15s; }
.story .line.narration { padding: 2px 6px; }
.story .line.narration .en { margin: 0; font-size: 1.02rem; line-height: 1.7; }
.story .line.narration .ko { margin: 4px 0 0; color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.story .line.dialogue {
  background: var(--bubble); border: 1px solid var(--bubble-line); box-shadow: var(--shadow-sm);
  padding: 12px 14px; border-radius: 18px 18px 18px 6px; max-width: 92%;
}
.story .line.dialogue .en { margin: 0; font-size: 1.02rem; font-weight: 500; line-height: 1.55; }
.story .line.dialogue .ko { margin: 5px 0 0; color: var(--muted); font-size: 0.86rem; }
.story .line.dialogue.ko-only { background: var(--accent-soft); border-color: transparent; border-radius: 18px 18px 6px 18px; margin-left: auto; }
.story .line.dialogue.ko-only .en { font-size: 0.95rem; }
.story .line.speaking { background: var(--accent-soft); border-color: var(--accent); }
.story .line.narration.speaking { box-shadow: inset 3px 0 0 var(--accent); padding-left: 10px; }
body.hide-ko .story .ko { display: none; }
.story .end { text-align: center; color: var(--muted); font-size: 0.8rem; margin: 30px 0 10px; letter-spacing: 0.1em; }

.floatbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; align-items: center; gap: 6px; background: var(--card); border-radius: 999px; padding: 6px;
  box-shadow: var(--shadow); max-width: calc(100% - 32px);
}
.floatbar .btn { box-shadow: none; white-space: nowrap; }
.floatbar .btn.icon { background: var(--bg); }
.floatbar .btn.icon.on { background: var(--accent); color: #fff; }
.floatbar .sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }

/* ---------- 공부 ---------- */
.grade-strip { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 10; background: var(--bg); display: flex; gap: 8px; overflow-x: auto; padding: 6px 16px 10px; margin: 0 -16px 6px; scrollbar-width: none; }
.grade-strip::-webkit-scrollbar { display: none; }
.grade-strip .chip { padding: 7px 12px; }
.grade-strip .chip b { display: inline-block; width: 18px; height: 18px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-size: 0.72rem; text-align: center; line-height: 18px; margin-right: 6px; }
.grade-strip .chip.on b { background: rgba(255,255,255,0.25); color: inherit; }
.grade { margin-bottom: 26px; }
.grade > h2 { font-size: 1rem; font-weight: 800; margin: 6px 4px 10px; display: flex; align-items: baseline; gap: 8px; }
.grade > h2 .tag { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: 8px; background: var(--accent); color: #fff; font-size: 0.8rem; }
.grade > h2 .note { font-weight: 500; color: var(--muted); font-size: 0.78rem; }
.item {
  background: var(--card); border-radius: var(--r); box-shadow: var(--shadow-sm);
  padding: 14px 14px 14px 16px; margin-bottom: 10px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center;
}
.item.speaking { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.item .en { margin: 0; font-weight: 600; font-size: 1rem; line-height: 1.45; }
.item .ko { margin: 3px 0 0; color: var(--muted); font-size: 0.86rem; }
.item .extra { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }
.item .extra b { display: inline-block; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 0 6px; margin-right: 6px; font-size: 0.72rem; }
.item .play {
  border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 50%;
  width: 42px; height: 42px; cursor: pointer; font-size: 0.95rem; flex: none; display: inline-flex; align-items: center; justify-content: center;
}
.item .play:active { transform: scale(0.94); }
.item .answer-play { grid-column: 1 / -1; justify-self: start; background: var(--bg); box-shadow: none; }
.grade-memo { white-space: pre-wrap; color: var(--muted); font-size: 0.85rem; background: var(--card); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow-sm); }

/* ---------- 설정 ---------- */
.group { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 6px 16px; margin-bottom: 14px; }
.group .row { padding: 14px 0; border-bottom: 1px solid var(--line); }
.group .row:last-child { border-bottom: 0; }
.group h2 { font-size: 0.95rem; font-weight: 700; margin: 0 0 4px; }
.group p { margin: 0 0 10px; color: var(--muted); font-size: 0.82rem; }
.group p:last-child { margin-bottom: 0; }
.choices { display: flex; gap: 10px; }
.choices button {
  flex: 1; border: 2px solid transparent; background: var(--bg); border-radius: 14px;
  padding: 12px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700;
}
.choices button.on { border-color: var(--accent); background: var(--accent-soft); }
.choices .flag { display: inline-flex; line-height: 1; }
.choices small { color: var(--muted); font-weight: 500; font-size: 0.72rem; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 0.95rem; font-weight: 600; }
.switch input { appearance: none; -webkit-appearance: none; width: 48px; height: 28px; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: left 0.2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 23px; }
input[type=range] { width: 100%; accent-color: var(--accent); }

/* ---------- 첫 실행 모달 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 20, 0.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center; padding: 0;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.modal { background: var(--card); border-radius: 26px 26px 0 0; padding: 26px 22px calc(26px + env(safe-area-inset-bottom)); width: 100%; max-width: 640px; animation: up 0.28s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h2 { margin: 0 0 6px; font-size: 1.25rem; font-weight: 800; letter-spacing: -0.01em; }
.modal p { margin: 0 0 18px; color: var(--muted); font-size: 0.88rem; }
.accent-choices { display: flex; gap: 12px; }
.accent-choices button {
  flex: 1; border: 2px solid transparent; background: var(--bg); border-radius: 18px;
  padding: 18px 8px 14px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700; font-size: 1rem;
}
.accent-choices button:active { border-color: var(--accent); background: var(--accent-soft); }
.accent-choices .flag { display: inline-flex; line-height: 1; margin-bottom: 2px; }
.accent-choices small { color: var(--muted); font-weight: 500; font-size: 0.74rem; }

/* ---------- 본문 안 공부 표시 ---------- */
.hint { margin: 0 0 6px; font-size: 0.8rem; color: var(--muted); }
.story mark, mark.demo {
  background: linear-gradient(transparent 55%, rgba(59, 108, 255, 0.22) 55%);
  color: inherit; border-radius: 2px; padding: 0 1px; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.story .vocab, .vocab.demo {
  text-decoration: underline dotted; text-decoration-color: var(--muted); text-underline-offset: 3px; cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .story mark, mark.demo { background: linear-gradient(transparent 55%, rgba(111, 143, 255, 0.28) 55%); }
}

/* ---------- 아래에서 올라오는 시트 ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(10, 12, 20, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 640px; background: var(--card); border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom)); box-shadow: 0 -10px 30px rgba(0,0,0,0.2);
  animation: up 0.22s ease-out;
}
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.sheet-tag { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.sheet-tag .tag { display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center; border-radius: 7px; background: var(--accent); color: #fff; font-size: 0.75rem; }
.sheet-en { margin: 0; font-size: 1.25rem; font-weight: 700; line-height: 1.4; letter-spacing: -0.01em; }
.sheet-ko { margin: 6px 0 12px; color: var(--muted); font-size: 0.95rem; }
.sheet-extra { margin: 0 0 6px; font-size: 0.9rem; }
.sheet-extra b { display: inline-block; font-weight: 700; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 7px; margin-right: 8px; font-size: 0.74rem; vertical-align: 1px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.sheet-actions .btn.ghost { margin-left: auto; }

/* ---------- 홈: 오늘 카드 ---------- */
.intro { margin: 14px 4px 4px; color: var(--muted); font-size: 0.88rem; }
.ep .dots { display: flex; gap: 4px; margin-top: 6px; }
.ep .dots i { width: 14px; height: 5px; border-radius: 3px; background: var(--line); }
.ep .dots i.done { background: var(--accent); }

/* ---------- 읽기: 장면, 모드, 한 줄씩 ---------- */
.scene-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 2px 0 8px; }
.scene-dot {
  width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); box-shadow: var(--shadow-sm); font-size: 0.75rem; font-weight: 700; color: var(--muted);
}
.scene-dot.done { background: var(--accent-soft); color: var(--accent); }
.scene-dot.on { background: var(--accent); color: #fff; }
.scene-label { margin-left: 4px; font-size: 0.85rem; font-weight: 600; color: var(--text); }
.mode-strip { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 4px 0 16px; }
.mode-hint { flex-basis: 100%; font-size: 0.76rem; color: var(--muted); margin: 2px 4px 0; }

.more {
  display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%;
  border: 1.5px dashed var(--line); background: transparent; color: var(--muted); border-radius: 16px;
  padding: 16px; font-weight: 600; cursor: pointer; margin: 8px 0 20px;
}
.more:active { background: var(--accent-soft); }
.more span { font-size: 1.1rem; line-height: 1; }
.story .line { animation: fade 0.25s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.scene-end {
  background: var(--card); border-radius: 22px; padding: 20px; margin: 14px 0 20px; box-shadow: var(--shadow); text-align: center;
}
.scene-end .eyebrow { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; color: var(--accent); margin: 0 0 4px; }
.scene-end h3 { margin: 0 0 4px; font-size: 1.15rem; font-weight: 800; }
.scene-end .sub { margin: 0; color: var(--muted); font-size: 0.85rem; }
.scene-end .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.floatbar .btn.icon.on { background: var(--accent); color: #fff; }

/* 편하게: 한국어가 본문, 공부 문장이 있는 대사만 영어를 작게 */
body.mode-easy .story .narration .en { display: none; }
body.mode-easy .story .narration .ko { margin: 0; color: var(--text); font-size: 1.02rem; line-height: 1.7; }
body.mode-easy .story .dialogue .en { display: none; }
body.mode-easy .story .dialogue .ko { margin: 0; color: var(--text); font-size: 1.02rem; font-weight: 500; }
body.mode-easy .story .dialogue.has-mark .en { display: block; order: 2; margin: 6px 0 0; font-size: 0.92rem; font-weight: 500; color: var(--muted); }
body.mode-easy .story .dialogue.has-mark { display: flex; flex-direction: column; }
body.mode-easy .story .dialogue.has-mark .ko { order: 1; }
body.mode-easy .story .dialogue.has-mark mark { color: var(--text); }
body.mode-easy .story .ko-only .en { display: block; }

/* 집중: 영어만, 누르면 한국어 */
body.mode-focus .story .ko { display: none; }
body.mode-focus .story .line.reveal .ko { display: block; }
