/* Reading App styles. Big, calm and tablet-friendly. */

:root {
  --bg: #FFF8EE;
  --surface: #FFFFFF;
  --ink: #23303B;
  --muted: #5C6873;
  --line: #E7DCCB;
  --primary: #1E6F86;
  --primary-dark: #155366;
  --primary-ink: #FFFFFF;
  --accent: #F3E3C3;
  --accent-ink: #6B4A12;
  --good: #217346;
  --good-bg: #E2F3E8;
  --try: #A3462F;
  --try-bg: #FBE9E3;
  --story: #7357B8;
  --article: #2B72B0;
  --poem: #2F8A5F;
  --highlight: #FFE89A;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(35, 48, 59, 0.08);
  --reader-scale: 1;
  --chunk0: #FFD6C9;
  --chunk1: #CDE7F7;
  --chunk2: #D7F0D4;
  --chunk3: #EADCF8;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 19px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.08rem; margin-top: 1em; }
p { margin: 0 0 0.75em; }

.screen {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.loading { text-align: center; padding: 40px; color: var(--muted); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.big { font-size: 1.25rem; }
.center { text-align: center; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.notice { text-align: center; }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > .btn { flex: 1 1 auto; }

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-weight: 600;
  min-height: 52px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.98); }
.btn:focus-visible, .option:focus-visible, .chunk:focus-visible, .input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:active { background: var(--primary-dark); }
.btn-accent { background: var(--accent); border-color: #E6CF9F; color: var(--accent-ink); }
.btn-danger { background: var(--try); border-color: var(--try); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-small { min-height: 44px; padding: 6px 14px; font-size: 0.95rem; }
.btn-big { min-height: 60px; font-size: 1.1rem; }
.btn-huge { min-height: 72px; font-size: 1.3rem; width: 100%; border-radius: 20px; }
.btn:disabled { opacity: 0.85; cursor: default; }

.pill {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  background: #EEF2F4;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}
.pill-good { background: var(--good-bg); color: var(--good); }

/* ---- Inputs ---- */
.input {
  font: inherit;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #FFFDF9;
  color: var(--ink);
}
textarea.input { resize: vertical; }
.input-short { max-width: 260px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; margin-bottom: 10px; }
.pin-input { font-size: 2rem; letter-spacing: 0.5em; text-align: center; max-width: 220px; margin: 0 auto; }

/* ---- Top bar ---- */
.topbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; }
.topbar-title { font-size: 1.25rem; margin: 0; text-align: center; overflow-wrap: anywhere; }
.back-btn { padding-left: 4px; }

/* ---- Home ---- */
.home-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.home-top h1 { margin: 0; font-size: 1.8rem; }
.parent-btn { font-size: 0.9rem; color: var(--muted); }
.streak-card { display: flex; align-items: center; gap: 16px; }
.streak-flame { font-size: 2.6rem; }
.streak-text { flex: 1; }
.streak-num { font-size: 1.35rem; font-weight: 700; }
.badge-strip { display: flex; align-items: center; gap: 8px; width: 100%; font: inherit; color: inherit; cursor: pointer; text-align: left; flex-wrap: wrap; }
.badge-mini { font-size: 1.8rem; }
.badge-strip-more { margin-left: auto; color: var(--primary); font-weight: 600; }
.home-nav { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.nav-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; font: inherit; font-weight: 600; color: inherit; cursor: pointer; min-height: 110px; justify-content: center; }
.nav-icon { font-size: 2.2rem; }

/* ---- Mood picker ---- */
.mood-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.mood-tile { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; font: inherit; color: inherit; text-align: left; cursor: pointer; border-width: 3px; min-height: 190px; }
.mood-emoji { font-size: 2.6rem; }
.mood-label { font-size: 1.15rem; font-weight: 700; }
.mood-cat { font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.mood-title { color: var(--muted); flex: 1; }
.cat-story { border-color: #D9CFF1; } .cat-story .mood-cat { color: var(--story); }
.cat-article { border-color: #C8DDF0; } .cat-article .mood-cat { color: var(--article); }
.cat-poem { border-color: #C9E6D6; } .cat-poem .mood-cat { color: var(--poem); }
.suggestion { width: 100%; min-height: 60px; }
.request-card { display: flex; flex-direction: column; gap: 10px; }
.request-card h2, .request-card p { margin: 0; }
.older summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.older-item { justify-content: flex-start; width: 100%; text-align: left; }

/* ---- Reader ---- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  position: sticky; top: 0; z-index: 5;
  background: var(--bg); padding: 8px 0;
}
.tool { min-height: 48px; padding: 6px 14px; font-size: 0.95rem; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }
.passage {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 22px 10px;
  font-size: calc(23px * var(--reader-scale));
  line-height: 1.75;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.passage .para { margin: 0 0 1em; }
.passage.poem { font-style: normal; }
.passage.poem .para { margin-bottom: 1.3em; }
.w { border-radius: 6px; padding: 1px 1px; cursor: pointer; transition: background 0.15s; }
.w.target { border-bottom: 2px dotted var(--primary); }
.w.speaking { background: var(--highlight); }
.w.tapped { background: #CDE7F7; }

/* ---- Pop-up sheet ---- */
.backdrop {
  position: fixed; inset: 0; background: rgba(20, 28, 35, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
  animation: fade 0.15s ease-out;
}
.sheet {
  position: relative; width: 100%; max-width: 680px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 26px 20px calc(24px + env(safe-area-inset-bottom));
  animation: slideup 0.2s ease-out;
}
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { border-radius: 24px; }
}
.sheet-close { position: absolute; top: 10px; right: 10px; width: 48px; height: 48px; border-radius: 50%; border: none; background: #F1ECE3; font-size: 1.2rem; cursor: pointer; }
@keyframes slideup { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.word-popup { display: flex; flex-direction: column; gap: 12px; }
.wp-word { font-size: 2.2rem; font-weight: 700; padding-right: 50px; overflow-wrap: anywhere; }
.wp-def { font-size: 1.2rem; margin: 0; }
.wp-example { font-style: italic; color: var(--muted); margin: 0; }
.wp-save { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; flex-wrap: wrap; }
.save-note { color: var(--good); font-weight: 600; }
.break-apart { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.break-apart h3 { margin: 0; }
.chunks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chunk-dot { font-size: 1.6rem; color: var(--muted); }
.chunk {
  font: inherit; font-size: 1.6rem; font-weight: 700;
  min-width: 56px; min-height: 56px; padding: 6px 14px;
  border-radius: 12px; border: 2px solid rgba(0, 0, 0, 0.08); cursor: pointer; color: var(--ink);
}
.c0 { background: var(--chunk0); } .c1 { background: var(--chunk1); } .c2 { background: var(--chunk2); } .c3 { background: var(--chunk3); }
.chunk-bank { background: #F4F1EA; }
.word-parts h3 { margin: 0 0 6px; }
.parts-list { list-style: none; padding: 0; margin: 0 0 6px; display: flex; flex-direction: column; gap: 6px; }
.part { font-weight: 700; padding: 2px 10px; border-radius: 8px; background: #EEF2F4; }
.part-prefix { background: var(--chunk0); } .part-root { background: var(--chunk1); } .part-suffix { background: var(--chunk2); }
.part-type { font-size: 0.8rem; color: var(--muted); margin-left: 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.confirm { display: flex; flex-direction: column; gap: 16px; padding-top: 20px; }
.confirm-msg { font-size: 1.1rem; }

/* ---- Questions ---- */
.q-body, .review-body, .spell-body, .wc-body { display: flex; flex-direction: column; gap: 14px; }
.progress-label { color: var(--muted); font-weight: 600; margin: 0; }
.q-prompt-row { display: flex; gap: 10px; align-items: flex-start; }
.q-prompt { flex: 1; font-size: 1.35rem; margin: 0; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  font: inherit; text-align: left; display: flex; gap: 14px; align-items: center;
  min-height: 64px; padding: 12px 16px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer;
}
.option-letter { flex: none; width: 38px; height: 38px; border-radius: 50%; background: #EEF2F4; display: grid; place-items: center; font-weight: 700; }
.option.right { border-color: var(--good); background: var(--good-bg); }
.option.right .option-letter { background: var(--good); color: #fff; }
.option.wrong { border-color: var(--try); background: var(--try-bg); }
.option.wrong .option-letter { background: var(--try); color: #fff; }
.option:disabled { cursor: default; color: var(--ink); }
.feedback:empty { display: none; }
.feedback p { margin: 0 0 6px; }
.fb-good { color: var(--good); font-weight: 700; font-size: 1.2rem; }
.fb-try { color: var(--try); font-weight: 700; }
.written-box { min-height: 160px; font-size: 1.15rem; }

/* ---- Review and Word Builder ---- */
.flashcard { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 30px 18px; }
.flash-word { font-size: 2.6rem; font-weight: 700; overflow-wrap: anywhere; }
.flash-back { display: flex; flex-direction: column; gap: 8px; }
.builder { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.builder h2, .builder p { margin: 0; }
.builder-slots { display: flex; flex-wrap: wrap; gap: 8px; min-height: 72px; width: 100%; padding: 8px; border: 2px dashed var(--line); border-radius: 14px; align-items: center; }
.builder-bank { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---- Spelling ---- */
.spell-card { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.spell-card .pill { align-self: flex-start; }
.spell-input { font-size: 1.8rem; text-align: center; letter-spacing: 0.04em; }
.spell-answer { font-size: 2rem; font-weight: 700; letter-spacing: 0.12em; color: var(--good); }

/* ---- Complete ---- */
.celebrate { font-size: 4rem; text-align: center; }
.summary-table { width: 100%; border-collapse: collapse; }
.summary-table th, .summary-table td { padding: 10px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.summary-table td { text-align: right; font-weight: 700; }
.summary-table tr:last-child th, .summary-table tr:last-child td { border-bottom: none; }
.new-badges { display: flex; flex-direction: column; gap: 10px; }
.badge-big { display: flex; gap: 14px; align-items: center; }
.badge-icon { font-size: 2.6rem; }

/* ---- My words ---- */
.word-list { display: flex; flex-direction: column; gap: 10px; }
.word-row { padding: 14px 16px; }
.word-row-main { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.word-row-word { font: inherit; font-size: 1.25rem; font-weight: 700; background: none; border: none; color: var(--ink); cursor: pointer; padding: 6px 0; min-height: 44px; }
.word-row-def { margin: 4px 0 0; }
.word-row.learned { border-color: #CDE8D6; }

/* ---- Badges ---- */
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.badge-tile { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.badge-tile p { margin: 0; }
.badge-tile.locked .badge-icon { filter: grayscale(1); opacity: 0.35; }
.badge-tile.earned { border-color: #EBCB7E; background: #FFFBEF; }

/* ---- Books ---- */
.books section { display: flex; flex-direction: column; gap: 12px; }
.book-card { display: flex; flex-direction: column; gap: 10px; }
.book-card p { margin: 0; }
.book-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.book-title { margin: 0; font-size: 1.2rem; }
.stars { display: flex; gap: 4px; }
.star { font-size: 2rem; background: none; border: none; cursor: pointer; color: #C9A43A; min-width: 48px; min-height: 48px; }
.books .card h2 { margin-bottom: 4px; }
.books section.card { gap: 10px; }

/* ---- Grown-up screen ---- */
.parent section.card > h2 { margin-bottom: 10px; }
.parent section.card { display: flex; flex-direction: column; gap: 10px; }
.parent section.card h3 { margin: 6px 0 0; }
.parent section.card p { margin: 0; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat { background: #F7F3EC; border-radius: 14px; padding: 12px; text-align: center; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }
.summary-text { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85rem; margin-top: 10px; }
.plain-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.written-answer { border-left: 4px solid var(--line); padding-left: 12px; }
.error-box { background: var(--try-bg); border: 2px solid #EDC2B5; border-radius: 14px; padding: 14px; color: var(--ink); }
.error-box ul { margin: 6px 0; padding-left: 20px; }
.danger-zone { border-color: #EDC2B5; }
.tips ul { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
details summary { cursor: pointer; }

/* ---- Word check ---- */
.wc-word { font-size: clamp(2.4rem, 8vw, 4rem); font-weight: 700; text-align: center; padding: 50px 16px; overflow-wrap: anywhere; }
.wc-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.wc-got { border-color: var(--good); }
.wc-guess { border-color: #D9A441; }
.wc-results { columns: 2; padding-left: 20px; font-size: 0.95rem; }

/* ---- Toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 14px;
  max-width: calc(100% - 32px); text-align: center; z-index: 100;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- Small screens ---- */
@media (max-width: 520px) {
  body { font-size: 18px; }
  .home-nav { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .nav-tile { min-height: 96px; padding: 10px; font-size: 0.95rem; }
  .passage { padding: 16px 14px 6px; }
  .wc-buttons { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
