:root {
  color-scheme: light;
  --ink: #17343b;
  --muted: #6f7d80;
  --paper: #f8f3e9;
  --cream: #fffdf8;
  --teal: #276a70;
  --teal-dark: #123f48;
  --coral: #db6b57;
  --gold: #e3b85f;
  --line: #ded9cd;
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(227,184,95,.18), transparent 26rem),
    linear-gradient(150deg, #e5eee9, #f4eadc);
}

button { font: inherit; }

.app {
  width: min(100%, 480px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 40px rgba(16,44,53,.14);
}

.topbar {
  height: 70px;
  padding: max(14px, env(safe-area-inset-top)) 18px 10px;
  display: grid;
  grid-template-columns: 42px 42px 1fr auto;
  gap: 14px;
  align-items: center;
  background: var(--teal-dark);
  color: white;
}

.icon-button {
  width: 38px; height: 38px; border: 1px solid rgba(255,255,255,.35);
  border-radius: 12px; color: white; background: transparent; font-weight: 900;
}
.icon-button[hidden] { display: none; }
.topbar:has(.back-button[hidden]) { grid-template-columns: 42px 1fr auto; }

.progress { height: 7px; overflow: hidden; border-radius: 10px; background: rgba(255,255,255,.18); }
.progress span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .35s ease; }
.clues { font-size: 14px; white-space: nowrap; }

.scene {
  height: calc(100vh - 70px);
  height: calc(100dvh - 70px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px max(32px, env(safe-area-inset-bottom));
}
.start-card {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.eyebrow { letter-spacing: .15em; font-size: 11px; font-weight: 800; color: var(--teal); }
.hospital-mark { margin-top: 30px; width: 82px; height: 82px; display: grid; place-items: center; border-radius: 24px; background: var(--coral); color: white; font-size: 44px; transform: rotate(-3deg); box-shadow: 0 12px 25px rgba(219,107,87,.25); }
h1 { margin: 18px 0 0; font-family: Georgia, serif; font-size: 52px; line-height: 1; }
.subtitle { margin: 8px 0 26px; color: var(--muted); }
.case-note { width: 100%; padding: 18px; border: 1px solid var(--line); border-radius: 18px; display: grid; gap: 4px; background: rgba(255,255,255,.55); text-align: left; }
.case-note span, .label { font-size: 11px; font-weight: 900; letter-spacing: .12em; color: var(--coral); }
.case-note strong { font-family: Georgia, serif; font-size: 24px; }
.case-note small { color: var(--muted); }
.name-field { width: 100%; margin: 18px 0 0; text-align: left; }
.name-field span { display: block; margin: 0 0 7px 3px; color: var(--muted); font-size: 12px; font-weight: 750; }
.name-field input { width: 100%; min-height: 52px; padding: 12px 15px; border: 1.5px solid var(--line); border-radius: 15px; outline: 0; color: var(--ink); background: var(--cream); font: inherit; font-size: 17px; font-weight: 750; }
.name-field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(39,106,112,.12); }
.primary { width: 100%; min-height: 56px; margin-top: auto; border: 0; border-radius: 16px; background: var(--teal); color: white; font-weight: 800; box-shadow: 0 8px 18px rgba(39,106,112,.22); }
.duration { margin: 14px 0 0; color: var(--muted); font-size: 12px; }

.chapter-tag { color: var(--coral); letter-spacing: .12em; font-size: 11px; font-weight: 900; }
.scene h2 { margin: 8px 0 14px; font-family: Georgia, serif; font-size: 32px; line-height: 1.15; }
.story { color: #43585d; line-height: 1.6; }
.illustration { margin: 22px 0; min-height: 190px; display: grid; place-items: center; border-radius: 24px; background: linear-gradient(145deg, #d7e7e2, #bed1cc); font-size: 76px; box-shadow: inset 0 0 0 1px rgba(23,52,59,.08); }
.speech { position: relative; padding: 18px; margin: 16px 0; border-radius: 18px 18px 18px 4px; background: white; box-shadow: 0 5px 18px rgba(23,52,59,.08); }
.speaker { display: block; margin-bottom: 7px; color: var(--coral); font-size: 12px; font-weight: 900; text-transform: uppercase; }
.english { font-size: 22px; font-weight: 800; }
.translation { margin-top: 5px; color: var(--muted); font-size: 14px; }
.prompt { margin: 22px 0 10px; font-weight: 800; }
.choices { display: grid; gap: 10px; }
.choice { min-height: 58px; padding: 12px 16px; border: 1.5px solid var(--line); border-radius: 15px; text-align: left; color: var(--ink); background: var(--cream); font-weight: 750; transition: .16s ease; }
.choice:active { transform: scale(.985); }
.choice.correct { border-color: #4b9874; background: #e6f4ea; }
.choice.wrong { border-color: var(--coral); background: #fae8e3; }
.feedback { min-height: 48px; margin-top: 14px; padding: 12px 14px; border-radius: 13px; background: #e9efeb; line-height: 1.45; font-size: 14px; }
.next { margin-top: 14px; }
.word-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.word-card { padding: 15px 12px; border-radius: 16px; background: white; box-shadow: 0 4px 14px rgba(23,52,59,.07); }
.word-card strong { display: block; font-size: 18px; }
.word-card span { color: var(--muted); font-size: 13px; }
.question-word { color: var(--coral); }
.clue-card { margin: 22px 0; padding: 20px; border: 2px dashed var(--gold); border-radius: 18px; background: #fff9e9; transform: rotate(-1deg); }
.finish { text-align: center; }
.finish .illustration { min-height: 150px; }
.stats { display: flex; justify-content: center; gap: 12px; margin: 18px 0; }
.stat { flex: 1; padding: 14px 8px; border-radius: 15px; background: white; }
.stat strong { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 12px; }
.lesson-summary { margin: 20px 0 4px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--cream); text-align: left; }
.summary-words { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 13px 0 17px; }
.summary-words div { padding: 10px 12px; border-radius: 12px; background: #eef4f0; }
.summary-words b { margin-right: 7px; color: var(--teal); }
.summary-words span { color: var(--muted); font-size: 13px; }
.summary-examples { border-top: 1px solid var(--line); padding-top: 8px; }
.summary-examples p { margin: 10px 0; }
.summary-examples b, .summary-examples span { display: block; }
.summary-examples span { margin-top: 2px; color: var(--muted); font-size: 13px; }
.can-do { margin: 15px 0 0; padding: 12px; border-radius: 12px; color: #286447; background: #e6f4ea; font-size: 13px; font-weight: 750; line-height: 1.4; }
.mistake-review { margin: 18px 0 12px; padding: 17px; border: 1px solid #e7b6aa; border-radius: 18px; background: #fff7f4; text-align: left; }
.mistake-item { display: grid; gap: 4px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #efd5cf; }
.mistake-item:first-of-type { margin-top: 10px; }
.mistake-item b { font-size: 14px; }
.mistake-item span { font-size: 12px; line-height: 1.4; }
.chosen-answer { color: var(--coral); }
.correct-answer { color: #286447; font-weight: 750; }
.chapter-list { display: grid; gap: 11px; margin-top: 20px; }
.story-chapter { margin-top: 18px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,.45); overflow: hidden; }
.chapter-header { width: 100%; min-height: 88px; padding: 14px; display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; border: 0; color: var(--ink); background: var(--cream); text-align: left; }
.chapter-header > span { font-size: 31px; }
.chapter-header div { display: grid; gap: 3px; }
.chapter-header small { color: var(--coral); font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.chapter-header b { font-family: Georgia, serif; font-size: 19px; }
.chapter-header em { color: var(--muted); font-size: 12px; font-style: normal; }
.chapter-header > strong { transition: transform .2s ease; }
.story-chapter.is-open .chapter-header > strong { transform: rotate(180deg); }
.chapter-parts { padding: 11px; display: grid; gap: 9px; border-top: 1px solid var(--line); }
.chapter-parts[hidden] { display: none; }
.locked-chapter { opacity: .52; }
.test-button { border-color: var(--gold); background: #fff9e9; }
.test-source { display: inline-block; margin: 10px 0 18px; padding: 7px 10px; border-radius: 9px; color: var(--teal); background: #e5efeb; font-size: 11px; font-weight: 850; letter-spacing: .04em; }
.test-question { margin: 5px 0 24px; padding: 24px 18px; border-radius: 18px; background: var(--cream); box-shadow: 0 5px 18px rgba(23,52,59,.08); font-family: Georgia, serif; font-size: 24px; font-weight: 700; line-height: 1.4; }
.test-context { margin: 0 0 13px; padding: 14px 16px; border-left: 4px solid var(--gold); border-radius: 0 13px 13px 0; color: #43585d; background: #fff9e9; font-family: Georgia, serif; font-size: 16px; line-height: 1.5; }
.test-context small { display: block; margin-bottom: 5px; color: var(--coral); font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif; font-size: 9px; font-weight: 900; letter-spacing: .1em; }
.chapter-button { width: 100%; min-height: 76px; padding: 12px 14px; display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 17px; color: var(--ink); background: var(--cream); text-align: left; }
.chapter-button > span { font-size: 30px; }
.chapter-button div { display: grid; gap: 2px; }
.chapter-button small { color: var(--coral); font-size: 10px; font-weight: 900; letter-spacing: .1em; }
.chapter-button b { font-size: 17px; }
.chapter-button em { color: var(--muted); font-size: 12px; font-style: normal; }
.chapter-button:disabled { opacity: .48; }
.word-help { display: inline; padding: 0 2px; border: 0; border-bottom: 2px dotted var(--gold); color: inherit; background: transparent; font: inherit; font-weight: inherit; cursor: help; }
.speech, .feedback, .summary-examples { position: relative; }
.word-popover { position: absolute; z-index: 5; left: 12px; right: 12px; top: calc(100% + 8px); padding: 13px 15px; border-radius: 13px; color: white; background: var(--teal-dark); box-shadow: 0 8px 24px rgba(16,44,53,.24); font-size: 13px; text-align: left; }
.word-popover::before { content: ''; position: absolute; left: 24px; bottom: 100%; border: 7px solid transparent; border-bottom-color: var(--teal-dark); }
.word-popover b, .word-popover span { display: block; }
.word-popover span { margin-top: 4px; color: #dce9e7; font-weight: 400; }
.story-illustration { min-height: 135px; margin-bottom: 16px; }
.story-excerpt { position: relative; padding: 19px; border: 1px solid var(--line); border-radius: 18px; background: var(--cream); text-align: left; }
.story-excerpt p { margin: 10px 0; font-family: Georgia, serif; font-size: 19px; line-height: 1.62; }
.story-excerpt small { display: block; color: var(--muted); font-family: ui-rounded, "SF Pro Rounded", system-ui, sans-serif; font-size: 11px; line-height: 1.4; }
.answer-overlay { position: fixed; z-index: 20; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding-top: 80px; background: rgba(16,44,53,.4); animation: overlay-in .18s ease-out; }
.answer-sheet { width: min(100%, 480px); padding: 10px 20px max(20px, env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--cream); box-shadow: 0 -12px 35px rgba(16,44,53,.2); text-align: left; animation: sheet-in .24s ease-out; }
.answer-sheet.is-correct { border-top: 5px solid #4b9874; }
.answer-sheet.is-wrong { border-top: 5px solid var(--coral); }
.answer-handle { width: 42px; height: 5px; margin: 0 auto 17px; border-radius: 5px; background: var(--line); }
.answer-result { display: block; margin-bottom: 11px; color: var(--teal); font-size: 18px; }
.answer-sheet.is-wrong .answer-result { color: var(--coral); }
.answer-sentence { font-size: 21px; font-weight: 850; line-height: 1.35; }
.answer-translation { margin-top: 5px; color: var(--muted); font-size: 14px; }
.answer-sheet .primary { margin-top: 18px; }
.answer-sheet .word-popover { top: auto; bottom: calc(100% + 8px); }
.answer-sheet .word-popover::before { top: 100%; bottom: auto; border-top-color: var(--teal-dark); border-bottom-color: transparent; }
@keyframes overlay-in { from { background: rgba(16,44,53,0); } }
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (min-width: 600px) {
  .answer-overlay { align-items: center; padding: 24px; }
  .answer-sheet { border-radius: 24px; }
}

@media (min-width: 481px) {
  body { padding: 24px 0; }
  .app { height: calc(100vh - 48px); height: calc(100dvh - 48px); border-radius: 28px; }
  .scene { height: calc(100vh - 118px); height: calc(100dvh - 118px); }
}
