/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs-body); line-height: 1.7; }
img { display: block; max-width: 100%; height: auto; }
figure { margin: 0; }
button { font: inherit; }

/* ---------- light mode tokens + phone sizes (under 600 px) ---------- */
:root {
  --bg: #FFFFFF; --text: #0E0F12; --muted: #565A61; --surface: #EEEEEC;
  --line: #E4E4E1; --accent: #0077B6; --sun: #FDC733; --mark: #FFF4CC;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --gutter: 20px; --col: 100%; --bar: 56px;
  --fs-body: 18px; --fs-title: 28px; --fs-hook: 20px;
  color-scheme: light;
}
/* tablet: 600 px to 1023 px */
@media (min-width: 600px) {
  :root { --gutter: 40px; --col: 720px; --fs-body: 19px; --fs-title: 34px; --fs-hook: 21px; }
}
/* laptop and projector: 1024 px and wider */
@media (min-width: 1024px) {
  :root { --gutter: 48px; --col: 800px; --fs-body: 20px; --fs-title: 40px; --fs-hook: 22px; }
}
/* dark mode: follows the device unless the child chose light */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E0F12; --text: #F2F2EF; --muted: #A3A7AE; --surface: #1A1C21;
    --line: #2A2D33; --accent: #5BB8EA; --mark: #2E2710; color-scheme: dark;
  }
}
/* dark mode chosen with the toggle button */
:root[data-theme="dark"] {
  --bg: #0E0F12; --text: #F2F2EF; --muted: #A3A7AE; --surface: #1A1C21;
  --line: #2A2D33; --accent: #5BB8EA; --mark: #2E2710; color-scheme: dark;
}

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; height: var(--bar); display: flex; align-items: center; gap: 8px; padding: 0 var(--gutter); background: var(--bg); border-bottom: 1px solid var(--line); }
.topbar-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 16px; font-weight: 700; }

/* ---------- buttons ---------- */
.btn { min-height: 48px; min-width: 48px; padding: 0 18px; border-radius: 999px; border: 2px solid var(--text); background: transparent; color: var(--text); font-size: 16px; font-weight: 700; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn-primary { background: var(--sun); border-color: var(--sun); color: #0E0F12; }
.btn-icon { padding: 0; width: 48px; }

/* ---------- page column ---------- */
.page { max-width: calc(var(--col) + 2 * var(--gutter)); margin: 0 auto; padding: 32px var(--gutter) 64px; }

/* ---------- chapter page ---------- */
.label { margin: 0 0 8px; font-size: 14px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.chapter-title { margin: 0 0 16px; font-size: var(--fs-title); line-height: 1.15; }
.hook { margin: 0 0 24px; font-size: var(--fs-hook); line-height: 1.5; color: var(--muted); }
.story { display: block; }
.story p { margin: 0 0 1.1em; }

/* a chapter has several parts: each part is one picture with its own paragraphs */
.story-part { display: flow-root; margin: 0 0 8px; }
/* the part's picture: on top for phones, text wraps around it on tablet and laptop (its shape is set by app.js) */
.story-pic { width: 100%; aspect-ratio: 4 / 3; margin: 0 0 24px; border-radius: 16px; overflow: hidden; background: var(--surface); }
.story-pic img { width: 100%; height: 100%; object-fit: cover; }
.story-pic .pic-missing { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; font-size: 15px; line-height: 1.4; color: var(--muted); }
@media (min-width: 600px) {
  .story-pic { float: right; width: 46%; max-width: 380px; margin: 6px 0 16px 28px; }
}
@media (min-width: 1024px) {
  .story-pic { width: 45%; margin: 6px 0 20px 32px; }
}

/* end of chapter */
.chapter-end { clear: both; margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- tap-to-see-meaning words ---------- */
.word { display: inline; padding: 0; margin: 0; border: 0; background: none; color: inherit; font: inherit; line-height: inherit; cursor: pointer; text-decoration-line: underline; text-decoration-style: dotted; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 5px; border-radius: 4px; }
.word[aria-expanded="true"] { background: var(--mark); }
.pop { position: absolute; z-index: 20; width: min(320px, calc(100vw - 32px)); padding: 16px; border-radius: 16px; background: var(--surface); color: var(--text); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); font-size: 17px; line-height: 1.5; }
.pop-word { margin: 0 0 4px; font-weight: 700; }
.pop-meaning { margin: 0 0 12px; }

/* ---------- read aloud highlight ---------- */
.reading { background: var(--mark); border-radius: 8px; box-shadow: 0 0 0 6px var(--mark); }

/* ---------- original text panel ---------- */
.original { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; }
.original-inner { max-width: calc(var(--col) + 2 * var(--gutter)); margin: 0 auto; padding: 24px var(--gutter) 64px; white-space: pre-wrap; }

/* ---------- focus and motion ---------- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* ---------- start screen ---------- */
.cover-pic { width: 100%; aspect-ratio: 4 / 3; border-radius: 20px; overflow: hidden; margin: 0 0 24px; background: var(--surface); }
.cover-pic img { width: 100%; height: 100%; object-fit: cover; }
.cover-pic .pic-missing { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; font-size: 15px; line-height: 1.4; color: var(--muted); }
.start-title { margin: 0 0 8px; font-size: var(--fs-title); line-height: 1.15; }
.credit { margin: 0 0 24px; font-size: 16px; color: var(--muted); }
.start-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.studio-link-wrap { margin: 32px 0 0; }
.studio-link { font-size: 14px; color: var(--muted); }

/* ---------- chapter menu ---------- */
.menu-progress { margin: 0 0 20px; font-size: 16px; color: var(--muted); }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-row { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 64px; padding: 12px 20px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--text); text-align: left; cursor: pointer; }
.menu-row:disabled { opacity: 0.5; cursor: not-allowed; }
.menu-num { width: 40px; height: 40px; flex-shrink: 0; border-radius: 999px; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; }
.menu-title { flex: 1; min-width: 0; font-weight: 700; }
.menu-status { font-size: 15px; font-weight: 700; white-space: nowrap; }
.menu-status.is-read { color: var(--accent); }
.menu-status.is-soon { color: var(--muted); }

/* ---------- original text panel details ---------- */
.original-note { margin: 16px 0 24px; font-size: 16px; color: var(--muted); white-space: normal; }
.original-title { margin: 0 0 16px; font-size: var(--fs-title); line-height: 1.15; white-space: normal; }
.original-text { margin: 0; }

/* ---------- status / error ---------- */
.status-msg { margin: 0 0 20px; color: var(--muted); }
