:root {
  --bg: #fff8ec;
  --card: #ffffff;
  --ink: #2b2a33;
  --muted: #6b6875;
  --line: #e7dfd0;
  --brand: #2f6fde;
  --brand-ink: #ffffff;
  --brand-soft: #e6efff;
  --good: #1f9d55;
  --good-soft: #e3f6ea;
  --bad: #d64545;
  --bad-soft: #fde8e8;
  --warn-soft: #fff3c4;
  --radius: 16px;
  color-scheme: light;
}
* { box-sizing: border-box; }
/* 수학 세션과 같은 휴대폰 사용감: 탭 깜빡임 없음, 글자 확대 방지, 당겨서 새로고침 막기(읽는 중 진행이 사라지지 않게) */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 18px; line-height: 1.5; word-break: keep-all;
}
#app {
  max-width: 640px; margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(32px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}
button {
  font: inherit; color: inherit; touch-action: manipulation; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 120ms ease-out, background-color 120ms ease-out;
}
button:not([disabled]):active { transform: scale(0.96); }
button[disabled] { opacity: .45; cursor: default; }
h1 { font-size: 26px; margin: 4px 0; }
h2 { font-size: 21px; margin: 20px 0 8px; }
h3 { font-size: 18px; margin: 0 0 6px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 15px; }
.center { text-align: center; }
.noscript { padding: 16px; }
.foot { margin-top: 16px; text-align: center; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.chip {
  border: 2px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; min-height: 44px; font-size: 16px; white-space: nowrap;
}
.btn {
  border: 0; background: var(--brand); color: var(--brand-ink); border-radius: 14px;
  padding: 12px 18px; min-height: 52px; font-size: 19px; font-weight: 700;
}
.btn.ghost { background: var(--card); color: var(--brand); border: 2px solid var(--brand); }
.btn.small { min-height: 44px; font-size: 15px; padding: 8px 12px; }
.btn.wide { width: 100%; margin-top: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.row > .btn { flex: 1 1 140px; }
.row.big > .btn { min-height: 64px; font-size: 21px; }
.card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 12px 0; }
.card.small { margin-top: 24px; }

/* 길잡이 캐릭터 + 말풍선 */
.guide { display: flex; align-items: flex-end; gap: 10px; margin: 8px 0 12px; }
.guide-img { width: 78px; height: 92px; object-fit: contain; flex: none; }
.bubble { position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 10px 12px; flex: 1; font-size: 18px; }
.bubble::before { content: ""; position: absolute; left: -9px; bottom: 16px; width: 14px; height: 14px; background: var(--card); border-left: 2px solid var(--line); border-bottom: 2px solid var(--line); transform: rotate(45deg); }

/* 홈 이야기 카드 */
.story-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.story-card {
  display: flex; align-items: center; gap: 8px; text-align: left; background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 88px;
}
.story-card img { width: 52px; height: 60px; object-fit: contain; flex: none; }
.sc-body { display: flex; flex-direction: column; min-width: 0; }
.sc-body b { font-size: 17px; line-height: 1.3; }
.sc-stars { color: #f0a020; font-size: 16px; }
@media (max-width: 360px) { .story-list { grid-template-columns: minmax(0, 1fr); } }

/* 이야기 쪽 */
.story-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 8px; }
.story-head img { width: 56px; height: 64px; object-fit: contain; }
.st-title { font-size: 24px; }
.page {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 10px; font-size: 27px; line-height: 2.1;
}
.page.live { border-color: var(--brand); }
.page.small { font-size: 18px; line-height: 1.7; margin-top: 8px; padding: 10px; }
.sent { display: inline; border-radius: 10px; }
.sent::after { content: " "; }
.sent.reading { background: var(--warn-soft); }
/* 어절 하나 = 버튼 하나 (누르면 들려줌). 글자 크기 그대로, 테두리 없음 */
.w {
  border: 0; background: transparent; padding: 0 3px; margin: 0; border-radius: 8px;
  font-size: inherit; line-height: 1.5; display: inline; color: var(--ink);
  border-bottom: 3px solid transparent;
}
.w.ok { color: var(--good); }
.w.cur { background: var(--brand-soft); }
.w.next { background: var(--warn-soft); border-bottom-color: #f0a020; }
.w.tts { background: #ffe38a; }
.w.miss { background: var(--bad-soft); color: var(--bad); border-bottom: 3px solid var(--bad); }
.w.skip { color: var(--muted); border-bottom: 3px dashed var(--muted); }
.w.hard { background: var(--bad-soft); border-bottom: 3px solid var(--bad); }
.w.hint { animation: hint 1.2s ease-in-out 2; }
.w.hint::after { content: " 🔊"; font-size: 18px; }
@keyframes hint { 50% { background: #ffd34d; } }
@media (prefers-reduced-motion: reduce) { .w.hint { animation: none; } }

.listen-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  background: var(--card); border: 2px solid var(--brand); border-radius: var(--radius);
  padding: 10px; margin: 12px 0 6px; font-weight: 700;
}
.listen-bar .btn { flex: 0 0 auto; }
.dot-rec { width: 14px; height: 14px; border-radius: 50%; background: var(--bad); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .dot-rec { animation: none; } }
.bar { height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar span { display: block; height: 100%; background: var(--brand); transition: width .2s; }

.result .score { font-size: 20px; }
.good-note { color: var(--good); font-weight: 700; }
.miss-list { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip { font-size: 20px; border-color: var(--bad); }

/* 내용 확인 문제 */
.choices { display: grid; gap: 10px; }
.choice { background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 12px; min-height: 56px; font-size: 20px; text-align: left; }
.choice.right { border-color: var(--good); background: var(--good-soft); }
.choice.right[disabled] { opacity: 1; font-weight: 700; }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.speak { border: 0; background: transparent; font-size: 20px; min-width: 44px; min-height: 44px; padding: 0; vertical-align: middle; }
.fb { border-radius: 12px; padding: 10px 12px; margin-top: 10px; font-weight: 700; }
.fb.good { background: var(--good-soft); color: var(--good); }
.fb.bad { background: var(--bad-soft); color: var(--bad); }
.peek { margin-top: 14px; }
.peek summary { min-height: 44px; display: flex; align-items: center; color: var(--brand); font-weight: 700; cursor: pointer; }

.done-img { width: 120px; height: 140px; object-fit: contain; }
.big-stars { font-size: 40px; color: #f0a020; margin: 4px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

@media (hover: hover) and (pointer: fine) {
  .story-card:hover, .choice:not([disabled]):hover { border-color: var(--brand); }
  .w:hover { background: var(--brand-soft); }
}
@media (max-width: 360px) {
  .page { font-size: 24px; padding: 12px 6px; }
  .guide-img { width: 62px; height: 74px; }
  .btn { font-size: 17px; }
  .row.big > .btn { font-size: 19px; }
}
