:root {
  color-scheme: light;
  --ink: #26352f;
  --muted: #63716b;
  --paper: #fffefa;
  --cream: #f8f7f3;
  --orange: #d8763d;
  --orange-dark: #92502d;
  --gold: #edb45b;
  --green: #367463;
  --green-dark: #245548;
  --green-soft: #e7f1ed;
  --blue-soft: #edf3f5;
  --rose-soft: #f7ecea;
  --lavender: #f2f0f6;
  --line: #e5e3dc;
  --line-strong: #d7d4cc;
  --shadow: 0 8px 28px rgb(43 61 53 / 6%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: #f1f3ef; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgb(237 180 91 / 10%), transparent 28rem),
    radial-gradient(circle at 90% 100%, rgb(54 116 99 / 8%), transparent 30rem),
    #f1f3ef;
}

button, input, select { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100%, 960px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: 0 0 32px rgb(43 61 53 / 5%);
}

.topbar {
  min-height: 64px;
  padding: max(12px, env(safe-area-inset-top)) 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgb(231 226 216 / 80%);
  background: rgb(255 254 250 / 92%);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(10px);
}

.brand {
  border: 0;
  background: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  min-height: 48px;
  font-size: 1.08rem;
  font-weight: 740;
  cursor: pointer;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: var(--gold);
  color: #4a2a14;
  font-size: .86rem;
}

.text-button {
  border: 0;
  background: transparent;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--green);
  font-weight: 750;
  cursor: pointer;
}

main { padding: 30px 20px calc(38px + env(safe-area-inset-bottom)); }

.screen { width: min(100%, 700px); margin: 0 auto; animation: arrive .18s ease-out; }
@keyframes arrive { from { opacity: 0; transform: translateY(5px); } }
@media (prefers-reduced-motion: reduce) { .screen { animation: none; } }

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 7vw, 2.8rem); line-height: 1.1; letter-spacing: -.025em; font-weight: 760; }
h2 { font-size: clamp(1.45rem, 5vw, 1.95rem); line-height: 1.18; letter-spacing: -.018em; font-weight: 740; }
h3 { font-size: 1.05rem; }
.eyebrow { margin-bottom: 7px; color: var(--orange-dark); font-size: .75rem; font-weight: 760; letter-spacing: .12em; text-transform: uppercase; }
.lead { font-size: 1.14rem; color: var(--muted); line-height: 1.55; }
.muted { color: var(--muted); }
.tiny { font-size: .85rem; }
.center { text-align: center; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

.hero { padding: 24px 8px 26px; text-align: center; }
.fox-face {
  width: 94px;
  height: 82px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 44% 44% 54% 54%;
  background: var(--orange);
  color: white;
  font-size: 2.2rem;
  font-weight: 900;
  box-shadow: none;
}
.fox-face::before, .fox-face::after {
  content: "";
  position: absolute;
  top: -13px;
  width: 32px;
  height: 36px;
  background: var(--orange);
  border-radius: 6px 28px 4px 20px;
  z-index: -1;
}
.fox-face::before { left: 6px; transform: rotate(-17deg); }
.fox-face::after { right: 6px; transform: scaleX(-1) rotate(-17deg); }

.menu-grid, .stack { display: grid; gap: 12px; }
.menu-card, .primary-button, .secondary-button, .soft-button, .choice-button {
  width: 100%;
  min-height: 58px;
  border-radius: 15px;
  border: 1px solid transparent;
  padding: 15px 17px;
  cursor: pointer;
  text-align: left;
  font-weight: 720;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.menu-card:hover, .primary-button:hover, .secondary-button:hover, .soft-button:hover, .choice-button:hover { transform: translateY(-1px); }
.menu-card:focus-visible, button:focus-visible, select:focus-visible { outline: 4px solid rgb(47 125 98 / 30%); outline-offset: 2px; }
.menu-card { display: flex; align-items: center; gap: 15px; background: rgb(255 255 255 / 72%); border-color: var(--line); box-shadow: none; }
.menu-card.featured { background: var(--green); border-color: var(--green); color: white; box-shadow: none; }
.menu-icon { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; background: rgb(255 255 255 / 72%); color: var(--green-dark); }
.menu-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu-label { display: block; font-size: 1.06rem; }
.menu-note { display: block; margin-top: 3px; font-size: .82rem; font-weight: 600; opacity: .78; }
.parent-link { display: block; min-height: 48px; margin: 24px auto 0; border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 4px; cursor: pointer; }

.primary-button { background: var(--green); color: white; text-align: center; box-shadow: none; }
.primary-button:hover { background: var(--green-dark); }
.primary-button:active, .secondary-button:active, .menu-card:active { transform: translateY(1px); }
.secondary-button { background: var(--cream); border-color: var(--line-strong); text-align: center; }
.soft-button { background: var(--green-soft); color: #205b47; text-align: center; }
.danger-button { background: white; color: #9c332c; border: 2px solid #e6b2ad; box-shadow: none; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.recommend-card { padding: 22px; margin: 20px 0 28px; border-radius: 18px; background: linear-gradient(135deg, #faf0df, #f4eee5); border: 1px solid #eadcca; }
.recommend-card h2 { margin-bottom: 6px; }
.recommend-card .primary-button { margin-top: 5px; }

.practice-category-card { display: grid; border: 1px solid var(--line); border-radius: 17px; overflow: hidden; background: rgb(255 255 255 / 72%); }
.practice-category-card .menu-card { border: 0; border-radius: 0; background: transparent; }
.challenge-link { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 12px; border: 0; border-top: 1px solid var(--line); background: #f8f5ef; color: var(--orange-dark); font-size: .86rem; font-weight: 720; cursor: pointer; }
.challenge-link:hover { background: #f5ecdf; }
.challenge-link:active { background: #f0e5d5; }
.challenge-link span { display: grid; place-items: center; }
.challenge-link svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.practice-shell { min-height: calc(100dvh - 126px); display: flex; flex-direction: column; }
.practice-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 34px; color: var(--muted); font-size: .9rem; }
.progress-track { height: 6px; margin: 10px 0 18px; overflow: hidden; border-radius: 999px; background: #ebeae5; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--gold); transition: width .25s ease; }
.reading-stage { flex: 1; min-height: 260px; display: grid; place-items: center; padding: 30px 6px; text-align: center; }
.reading-unit { max-width: 100%; overflow-wrap: anywhere; line-height: 1.18; }
.reading-unit.syllable { font-size: clamp(4rem, 20vw, 5rem); font-weight: 720; }
.reading-unit.word { font-size: clamp(3rem, 15vw, 4.2rem); font-weight: 680; }
.reading-unit.sentence { font-size: clamp(2rem, 8.8vw, 3rem); font-weight: 620; }
.reading-unit.story-text { max-width: 620px; font-size: clamp(1.65rem, 7.5vw, 2.15rem); font-weight: 560; line-height: 1.58; text-align: left; overflow-wrap: normal; hyphens: auto; }
.segmented-word { color: var(--ink); letter-spacing: .01em; }
.syllable-part { white-space: nowrap; }
.syllable-part.tone-0 { color: #2f6758; }
.syllable-part.tone-1 { color: #a45831; }
.syllable-dot { color: var(--muted); white-space: pre; }
.inline-segmented { display: inline; white-space: nowrap; }
.help-button { width: auto; min-width: 160px; margin: 0 auto 16px; }

.assessment-panel { display: grid; gap: 14px; padding-top: 8px; }
.assessment-group { min-width: 0; margin: 0; padding: 0; border: 0; }
.assessment-group legend { width: 100%; margin-bottom: 7px; color: var(--muted); font-size: .86rem; font-weight: 700; text-align: center; }
.assessment-options { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.assessment-button { min-height: 56px; padding: 10px; border: 1px solid var(--line-strong); border-radius: 13px; background: var(--paper); font-weight: 720; cursor: pointer; }
.assessment-button.selected { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); box-shadow: inset 0 0 0 1px var(--green); }
.assessment-next { min-height: 58px; }
button:disabled { cursor: not-allowed; opacity: .42; transform: none !important; }

.toggle-control { width: 100%; min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--cream); font-weight: 680; cursor: pointer; }
.switch-track { width: 46px; height: 26px; padding: 3px; flex: none; border-radius: 999px; background: #c9c6bf; transition: background .16s ease; }
.switch-track span { display: block; width: 20px; height: 20px; border-radius: 50%; background: white; transition: transform .16s ease; }
.toggle-control[aria-checked="true"] .switch-track { background: var(--green); }
.toggle-control[aria-checked="true"] .switch-track span { transform: translateX(20px); }
.reading-help-control { display: grid; gap: 7px; }
.control-label, .field-label { color: var(--muted); font-size: .84rem; font-weight: 700; }
.segmented-control { display: grid; grid-template-columns: .7fr 1.5fr 1fr; padding: 3px; border-radius: 13px; background: #eeebe4; }
.segmented-control button { min-height: 44px; border: 0; border-radius: 10px; padding: 6px 7px; background: transparent; color: var(--muted); font-size: .76rem; font-weight: 700; cursor: pointer; }
.segmented-control button.selected { background: white; color: var(--green-dark); box-shadow: 0 1px 4px rgb(50 40 25 / 8%); }
.settings-stack { display: grid; gap: 12px; }

.feedback-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; }
.feedback-button { min-height: 64px; border: 0; border-radius: 17px; padding: 10px 8px; font-weight: 850; cursor: pointer; }
.feedback-button[data-result="easy"] { background: var(--green-soft); color: #195a44; }
.feedback-button[data-result="correct"] { background: var(--blue-soft); color: #25556a; }
.feedback-button[data-result="difficult"] { background: #fff2cf; color: #744f00; }
.feedback-button[data-result="wrong"] { background: var(--rose-soft); color: #8a3530; }
.undo-row { min-height: 45px; display: flex; align-items: center; justify-content: center; }

.story-lines { display: grid; gap: 4px; width: min(100%, 620px); margin: 0 auto; }
.story-line { margin: 0; padding: 12px 14px; border-radius: 11px; font-size: clamp(1.4rem, 6.5vw, 1.9rem); line-height: 1.5; text-align: left; }
.story-line:nth-child(odd) { background: var(--cream); }
.reader-label { display: block; margin-bottom: 4px; color: var(--orange-dark); font-size: .75rem; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.question-card { padding: 22px; border-radius: 16px; background: var(--lavender); border: 1px solid #e3deea; }
.choice-button { background: white; border-color: #dcd4ec; box-shadow: none; text-align: center; }
.choice-button.correct { background: var(--green-soft); border-color: #7fbea5; }
.answer-note { min-height: 28px; margin-top: 14px; font-weight: 750; }

.celebration { padding: 45px 14px; text-align: center; }
.star { font-size: 3.8rem; margin-bottom: 12px; }
.summary-number { font-size: 3.2rem; line-height: 1; font-weight: 900; color: var(--green); }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card { padding: 16px; border-radius: 14px; background: var(--cream); border: 1px solid var(--line); }
.stat-value { display: block; font-size: 1.65rem; font-weight: 760; }
.stat-label { color: var(--muted); font-size: .85rem; }
.dashboard-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.dashboard-section:last-child { border: 0; }
.metric-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.metric-pair > div { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--cream); }
.metric-pair h2 { margin-bottom: 8px; font-size: 1.05rem; }
.metric-pair p { margin: 0; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 8px 11px; border-radius: 999px; background: var(--cream); border: 1px solid var(--line); font-weight: 720; }
.meter-row { display: grid; grid-template-columns: 50px 1fr 34px; align-items: center; gap: 10px; margin: 10px 0; }
.meter { height: 10px; border-radius: 999px; overflow: hidden; background: #ede7df; }
.meter > span { display: block; height: 100%; background: var(--orange); border-radius: inherit; }
.select-field { width: 100%; min-height: 54px; border: 2px solid var(--line); border-radius: 14px; padding: 0 12px; background: white; }
.timer-note { font-variant-numeric: tabular-nums; font-weight: 750; }
.duration-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.duration-option.selected { background: var(--green); color: white; border-color: var(--green); }
.install-note { margin-top: 24px; padding: 14px 16px; border-radius: 14px; background: var(--blue-soft); color: #345462; font-size: .9rem; }

.challenge-intro, .challenge-result { width: min(100%, 540px); margin: 0 auto; padding: 38px 0 18px; text-align: center; }
.challenge-emblem { width: 66px; height: 66px; display: grid; place-items: center; margin: 0 auto 18px; border-radius: 20px; background: #f7ead6; color: var(--orange-dark); }
.challenge-emblem svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.challenge-intro .lead { margin-bottom: 22px; }
.challenge-intro .primary-button { margin-top: 22px; }
.challenge-help { margin: 22px 0 4px; text-align: left; }
.record-pill { display: inline-flex; gap: 5px; margin: 2px 0 8px; padding: 10px 15px; border: 1px solid #e6d5bc; border-radius: 999px; background: #fbf2e5; color: #735036; }
.challenge-meta { align-items: center; }
.challenge-timer { min-width: 64px; padding: 7px 10px; border-radius: 11px; background: var(--green-soft); color: var(--green-dark); font-size: 1.22rem; font-weight: 780; font-variant-numeric: tabular-nums; text-align: center; transition: background .2s ease, color .2s ease; }
.challenge-timer.ending { background: #f8ead9; color: var(--orange-dark); }
.challenge-scoreline { display: flex; justify-content: center; gap: 18px; color: var(--muted); font-size: .85rem; }
.challenge-reading { min-height: 310px; }
.challenge-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.challenge-answer { min-height: 66px; border: 1px solid var(--line-strong); border-radius: 15px; font-weight: 760; cursor: pointer; }
.challenge-answer.wrong { background: var(--rose-soft); color: #803e38; border-color: #ead2ce; }
.challenge-answer.correct { background: var(--green); color: white; border-color: var(--green); }
.challenge-answer:hover { filter: brightness(.98); }
.challenge-answer:active { transform: translateY(1px); }
.result-confetti { margin-bottom: 10px; font-size: 3.3rem; }
.challenge-points { margin: 20px 0; color: var(--green-dark); font-size: clamp(4rem, 16vw, 6.2rem); font-weight: 780; line-height: .95; letter-spacing: -.04em; }
.challenge-points span { display: block; margin-top: 12px; color: var(--muted); font-size: 1rem; font-weight: 650; letter-spacing: 0; }
.result-breakdown { width: min(100%, 340px); display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 auto 20px; }
.result-breakdown span { padding: 14px; border: 1px solid var(--line); border-radius: 13px; background: var(--cream); }
.result-breakdown strong { display: block; font-size: 1.4rem; }
.new-record { color: var(--orange-dark); }
.record-note { font-size: 1.05rem; }
.result-actions { margin-top: 28px; }
.challenge-record-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.record-card { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--cream); }
.record-card span { color: var(--muted); font-size: .85rem; }
.record-card strong { color: var(--green-dark); }
.recent-heading { margin: 22px 0 10px; }
.recent-challenges { display: grid; gap: 0; border-top: 1px solid var(--line); }
.recent-challenges > div { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); font-size: .9rem; }
.challenge-empty { margin-top: 14px; }

@media (min-width: 620px) {
  main { padding: 38px 42px 48px; }
  .menu-grid.two-col { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .assessment-panel { grid-template-columns: 1fr 1fr; align-items: end; }
  .assessment-next { grid-column: 1 / -1; width: min(100%, 330px); justify-self: center; }
  .segmented-control button { font-size: .85rem; }
  .recommend-card { display: grid; grid-template-columns: 1fr auto; column-gap: 24px; align-items: center; }
  .recommend-card .eyebrow, .recommend-card h2, .recommend-card p { grid-column: 1; }
  .recommend-card .primary-button { grid-column: 2; grid-row: 1 / 4; min-width: 170px; }
}

@media (min-width: 900px) {
  .screen { width: min(100%, 760px); }
  .practice-shell { min-height: calc(100dvh - 150px); }
  .reading-stage { min-height: 300px; }
  .challenge-shell { width: min(100%, 680px); margin: 0 auto; }
}

@media (max-width: 359px) {
  main { padding-inline: 12px; }
  .button-row { grid-template-columns: 1fr; }
  .reading-stage { min-height: 220px; }
}
