:root {
  color-scheme: light;
  --ink: #183a46;
  --muted: #62747b;
  --paper: #fffdf7;
  --purple: #5d4bd8;
  --purple-dark: #4534b9;
  --purple-pale: #eeeafd;
  --coral: #ef6f66;
  --coral-pale: #ffebe8;
  --mint: #4fbda8;
  --mint-pale: #e4f7f2;
  --yellow: #ffd452;
  --line: #e9e5da;
  --shadow: 0 14px 34px rgba(43, 54, 64, .10);
  --radius: 26px;
  font-family: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 212, 82, .14), transparent 23rem),
    linear-gradient(180deg, #fffdf8, #fffaf1);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(93, 75, 216, .28);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  z-index: 99;
  top: -100px;
  left: 1rem;
  padding: .8rem 1rem;
  border-radius: 12px;
  background: var(--ink);
  color: white;
}

.skip-link:focus {
  top: 1rem;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: .6rem max(1rem, calc((100vw - 1060px) / 2));
  border-bottom: 1px solid rgba(24, 58, 70, .08);
  background: rgba(255, 253, 247, .92);
  backdrop-filter: blur(12px);
}

.brand,
.icon-button {
  border: 0;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .45rem;
  font-size: clamp(1.05rem, 3vw, 1.35rem);
  font-weight: 900;
}

.brand-mark {
  position: relative;
  width: 38px;
  height: 38px;
  transform: rotate(-8deg);
}

.brand-mark i {
  position: absolute;
  width: 8px;
  height: 30px;
  border-radius: 8px;
  background: var(--purple);
  transform: rotate(42deg);
}

.brand-mark i:nth-child(1) { left: 6px; top: 1px; }
.brand-mark i:nth-child(2) { left: 18px; top: 1px; }
.brand-mark i:nth-child(3) { left: 12px; top: 8px; background: var(--coral); transform: rotate(-42deg); }
.brand-mark i:nth-child(4) { left: 24px; top: 8px; background: var(--coral); transform: rotate(-42deg); }

.top-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
}

.icon-button,
.star-pill {
  min-width: 44px;
  min-height: 44px;
  border-radius: 16px;
}

.icon-button {
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.icon-button:hover {
  background: var(--purple-pale);
}

.star-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  padding: 0 .75rem;
  background: #fff3bd;
}

#app {
  min-height: calc(100vh - 155px);
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(280px, .88fr);
  align-items: center;
  min-height: 430px;
  max-width: 1100px;
  margin: 0 auto;
  padding: clamp(2.3rem, 7vw, 6rem) clamp(1.2rem, 5vw, 3.5rem);
  overflow: hidden;
}

.hero-copy {
  position: relative;
  z-index: 2;
}

.eyebrow,
.kicker {
  margin: 0 0 .55rem;
  color: var(--purple);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .14em;
}

.hero h1,
.page-title-row h1 {
  margin: 0;
  line-height: 1.04;
  letter-spacing: -.045em;
}

.hero h1 {
  max-width: 700px;
  font-size: clamp(2.5rem, 7.6vw, 5.5rem);
}

.hero h1 em {
  color: var(--coral);
  font-style: normal;
}

.hero-copy > p:not(.eyebrow) {
  max-width: 510px;
  margin: 1.25rem 0 1.6rem;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: clamp(1rem, 2.5vw, 1.25rem);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 54px;
  border-radius: 18px;
  padding: .85rem 1.35rem;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  border: 0;
  background: var(--purple);
  box-shadow: 0 10px 22px rgba(93, 75, 216, .25);
  color: white;
}

.primary-button:hover {
  background: var(--purple-dark);
  transform: translateY(-1px);
}

.secondary-button {
  border: 2px solid var(--line);
  background: white;
  color: var(--ink);
}

.danger-button {
  border: 2px solid #ffc8c3;
  background: #fff5f4;
  color: #a7312b;
}

.line-friend {
  position: relative;
  width: min(330px, 42vw);
  aspect-ratio: 1;
  margin: auto;
  border-radius: 45% 55% 48% 52%;
  background: linear-gradient(145deg, var(--purple-pale), #fff);
  box-shadow: var(--shadow);
  transform: rotate(4deg);
}

.friend-lines {
  position: absolute;
  inset: 18%;
}

.friend-lines::before,
.friend-lines::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 78%;
  border-radius: 12px;
  background: var(--purple);
  transform: rotate(42deg);
}

.friend-lines::before { left: 25%; }
.friend-lines::after { left: 57%; }
.friend-lines.two::before,
.friend-lines.two::after {
  background: var(--coral);
  transform: rotate(-42deg);
}
.friend-lines.two::before { left: 30%; top: 5%; }
.friend-lines.two::after { left: 62%; top: 5%; }

.friend-face {
  position: absolute;
  inset: 0;
}

.friend-face i {
  position: absolute;
  top: 45%;
  width: 16px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
}
.friend-face i:first-child { left: 42%; }
.friend-face i:nth-child(2) { left: 59%; }
.friend-face b {
  position: absolute;
  top: 56%;
  left: 47%;
  width: 54px;
  height: 25px;
  border-bottom: 7px solid var(--ink);
  border-radius: 50%;
  transform: translateX(-20%);
}

.section-wrap,
.page-shell {
  width: min(100% - 2rem, 980px);
  margin: 0 auto;
}

.section-wrap {
  padding: 1.3rem 0 3rem;
}

.section-heading,
.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading h2 {
  margin: .15rem 0 0;
  font-size: clamp(1.4rem, 3vw, 2rem);
}

.mini-progress {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 78px;
  padding: .55rem .8rem;
  border-radius: 18px;
  background: white;
  box-shadow: var(--shadow);
}

.mini-progress span {
  color: var(--coral);
  font-size: 1.4rem;
  font-weight: 900;
}

.mini-progress small {
  color: var(--muted);
  font-family: system-ui, sans-serif;
}

.journey-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1.3rem;
}

.journey-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .8rem;
  min-height: 112px;
  padding: 1rem;
  border: 2px solid transparent;
  border-radius: var(--radius);
  background: white;
  box-shadow: var(--shadow);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.journey-card:hover {
  transform: translateY(-3px);
}

.journey-card.purple { border-color: #dcd5ff; }
.journey-card.coral { border-color: #ffd1cd; }
.journey-card.mint { border-color: #c5eee5; }

.journey-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 18px;
  background: var(--purple-pale);
  font-size: 1.7rem;
}
.coral .journey-icon { background: var(--coral-pale); }
.mint .journey-icon { background: var(--mint-pale); }

.journey-card strong,
.journey-card small {
  display: block;
}
.journey-card strong { margin-bottom: .25rem; font-size: 1.05rem; }
.journey-card small { color: var(--muted); font-family: system-ui, sans-serif; line-height: 1.35; }
.journey-card .arrow { font-size: 2rem; color: var(--muted); }

.encouragement {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-top: 1.2rem;
  padding: 1rem 1.2rem;
  border-radius: 22px;
  background: #fff3bd;
}
.encouragement > span { font-size: 2rem; }
.encouragement strong,
.encouragement small { display: block; }
.encouragement small { margin-top: .2rem; color: #695d36; font-family: system-ui, sans-serif; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  align-items: stretch;
  justify-content: space-around;
  height: calc(70px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid rgba(24, 58, 70, .12);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px);
}

.bottom-nav button {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.bottom-nav span,
.bottom-nav small {
  display: block;
}
.bottom-nav span { font-size: 1.25rem; }
.bottom-nav small { margin-top: .2rem; font-size: .68rem; font-weight: 800; }
.bottom-nav button.active { color: var(--purple); }

.page-shell {
  padding: clamp(1.4rem, 4vw, 3rem) 0 3rem;
}

.page-title-row {
  min-height: 66px;
}

.page-title-row h1 {
  font-size: clamp(1.65rem, 5vw, 2.8rem);
}

.back-button,
.speak-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 50px;
  height: 50px;
  border: 0;
  border-radius: 18px;
  background: white;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 2rem;
  cursor: pointer;
}

.speak-button {
  font-size: 1.2rem;
}

.step-dots {
  display: flex;
  justify-content: center;
  gap: .5rem;
  margin: 1.2rem 0;
}
.step-dots i {
  width: 28px;
  height: 7px;
  border-radius: 5px;
  background: #ddd8cd;
}
.step-dots i.done { background: var(--purple); }

.math-stage {
  position: relative;
  max-width: 760px;
  margin: 1rem auto;
  padding: clamp(1rem, 3vw, 1.7rem);
  border: 2px solid #ece8dd;
  border-radius: 30px;
  background: white;
  box-shadow: var(--shadow);
}

.equation,
.big-equation {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(.5rem, 3vw, 1.3rem);
}

.equation strong {
  display: grid;
  place-items: center;
  min-width: 48px;
  min-height: 48px;
  border-radius: 15px;
  background: var(--purple-pale);
  font-size: 1.6rem;
}
.equation strong:nth-of-type(2) { background: var(--coral-pale); }
.equation strong:last-child { background: #fff2b8; }
.equation span { font-size: 1.5rem; font-weight: 900; }

#line-canvas {
  display: block;
  width: 100%;
  height: clamp(255px, 44vw, 360px);
  margin: .6rem auto 0;
  border-radius: 22px;
  touch-action: manipulation;
}

.stage-help,
.gentle-note {
  color: var(--muted);
  font-family: system-ui, sans-serif;
  line-height: 1.55;
  text-align: center;
}

.tap-counter {
  width: fit-content;
  margin: .8rem auto 0;
  padding: .55rem .9rem;
  border-radius: 14px;
  background: var(--mint-pale);
  color: #176c5c;
  font-weight: 900;
}

.hidden {
  display: none !important;
}

.lesson-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 760px;
  margin: 1rem auto 0;
}

.level-list {
  display: grid;
  gap: .85rem;
  max-width: 720px;
  margin: 1.7rem auto;
}

.level-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  min-height: 104px;
  padding: 1rem 1.2rem;
  border: 2px solid #e7e2d7;
  border-radius: 25px;
  background: white;
  box-shadow: 0 8px 18px rgba(43, 54, 64, .06);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.level-card:not(.locked):hover {
  border-color: var(--purple);
  transform: translateY(-2px);
}

.level-card.locked {
  opacity: .58;
  filter: grayscale(.65);
}

.level-number {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 19px;
  background: var(--purple-pale);
  font-size: 1.8rem;
}

.level-card small,
.level-card strong,
.level-card em {
  display: block;
}
.level-card small { margin-bottom: .2rem; color: var(--purple); font-size: .7rem; letter-spacing: .1em; }
.level-card strong { font-size: 1.15rem; }
.level-card em { margin-top: .25rem; color: var(--muted); font-family: system-ui, sans-serif; font-size: .9rem; font-style: normal; }
.level-state { font-size: 1.7rem; }

.compact {
  justify-content: space-between;
}

.level-chip,
.streak-chip {
  padding: .6rem .85rem;
  border-radius: 14px;
  background: var(--purple-pale);
  color: var(--purple-dark);
  font-weight: 900;
}
.streak-chip { background: #fff0c9; color: #8d5918; }

.question {
  margin: 1.4rem 0 .5rem;
  text-align: center;
}
.question p {
  margin: 0 0 .35rem;
  color: var(--muted);
  font-family: system-ui, sans-serif;
}

.big-equation strong,
.big-equation b {
  font-size: clamp(2.5rem, 9vw, 4rem);
}
.big-equation span {
  color: var(--muted);
  font-size: 2rem;
}
.big-equation b { color: var(--coral); }

.practice-stage {
  margin-top: 1rem;
  padding-bottom: 1rem;
}

.hint-button {
  display: block;
  min-height: 44px;
  margin: -.3rem auto .4rem;
  padding: .55rem .9rem;
  border: 0;
  border-radius: 14px;
  background: #fff3bd;
  color: #6e591c;
  font-weight: 900;
  cursor: pointer;
}

.zone-help {
  margin-top: .8rem;
  padding: .9rem;
  border-radius: 18px;
  background: #f3f7f7;
  text-align: center;
}
.zone-help > strong { display: block; margin-bottom: .6rem; }
.zone-help > div { display: flex; justify-content: center; gap: .7rem; flex-wrap: wrap; }
.zone-help span { min-width: 74px; padding: .5rem; border-radius: 13px; background: white; }
.zone-help b,
.zone-help small { display: block; }
.zone-help b { font-size: 1.3rem; }
.zone-help small { color: var(--muted); font-family: system-ui, sans-serif; }
.zone-help p { margin: .7rem 0 0; color: var(--muted); font-family: system-ui, sans-serif; }

.answer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .7rem;
  max-width: 760px;
  margin: 1rem auto 0;
}

.answer-grid button {
  min-height: 68px;
  border: 3px solid #e5e0d4;
  border-radius: 20px;
  background: white;
  color: var(--ink);
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  cursor: pointer;
}

.answer-grid button:hover:not(:disabled) {
  border-color: var(--purple);
  transform: translateY(-2px);
}
.answer-grid button.correct {
  border-color: #35a88e;
  background: var(--mint-pale);
  color: #176c5c;
}
.answer-grid button.wrong {
  border-color: var(--coral);
  background: var(--coral-pale);
}

.answer-feedback {
  display: grid;
  gap: .25rem;
  max-width: 760px;
  margin: .9rem auto 0;
  text-align: center;
}
.answer-feedback strong { font-size: 1.25rem; }
.answer-feedback span { color: var(--muted); font-family: system-ui, sans-serif; }
.next-task { margin: .7rem auto 0; }

.number-pickers {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: clamp(.55rem, 3vw, 1.3rem);
  margin: 1.8rem 0 1rem;
}
.number-pickers label span {
  display: block;
  margin-bottom: .4rem;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: .85rem;
  text-align: center;
}
.number-pickers input {
  width: clamp(90px, 25vw, 140px);
  min-height: 68px;
  border: 3px solid #ddd7ca;
  border-radius: 20px;
  background: white;
  color: var(--ink);
  font-size: 2rem;
  font-weight: 900;
  text-align: center;
}
.number-pickers .times { padding-bottom: .8rem; font-size: 2rem; font-weight: 900; }
.draw-button { display: block; margin: 0 auto; }
.reveal-button { display: block; margin: .6rem auto 0; }

.privacy-note,
.parent-tip {
  display: flex;
  gap: .8rem;
  max-width: 760px;
  margin: 1.3rem auto;
  padding: 1rem 1.1rem;
  border-radius: 20px;
  background: var(--mint-pale);
}
.privacy-note > span { font-size: 1.8rem; }
.privacy-note p,
.parent-tip p { margin: 0; color: #315f57; font-family: system-ui, sans-serif; line-height: 1.5; }
.privacy-note strong { display: block; color: #176c5c; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .8rem;
  max-width: 760px;
  margin: 1.2rem auto;
}
.stats-grid div {
  padding: 1rem .5rem;
  border-radius: 20px;
  background: white;
  box-shadow: var(--shadow);
  text-align: center;
}
.stats-grid strong,
.stats-grid span { display: block; }
.stats-grid strong { color: var(--purple); font-size: 1.7rem; }
.stats-grid span { margin-top: .3rem; color: var(--muted); font-family: system-ui, sans-serif; font-size: .82rem; }

.parent-settings {
  max-width: 760px;
  margin: 1.2rem auto;
  padding: 1.3rem;
  border-radius: 24px;
  background: white;
  box-shadow: var(--shadow);
}
.parent-settings h2 { margin-top: 0; }
.toggle-row,
.today-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.toggle-row strong,
.toggle-row small { display: block; }
.toggle-row small { margin-top: .2rem; color: var(--muted); font-family: system-ui, sans-serif; }
.toggle-row input { width: 28px; height: 28px; accent-color: var(--purple); }
.today-row { font-family: system-ui, sans-serif; }
.danger-button { margin-top: 1rem; }
.parent-tip { display: block; background: #fff3bd; }
.parent-tip p { margin-top: .35rem; color: #64582d; }

.toast {
  position: fixed;
  z-index: 80;
  right: 1rem;
  bottom: calc(85px + env(safe-area-inset-bottom));
  left: 1rem;
  max-width: 420px;
  margin: auto;
  padding: .9rem 1rem;
  border-radius: 18px;
  background: var(--ink);
  box-shadow: var(--shadow);
  color: white;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  transform: translateY(18px);
  pointer-events: none;
  transition: .25s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

.celebration {
  position: fixed;
  z-index: 70;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.celebration span {
  position: absolute;
  top: -40px;
  left: 50%;
  color: var(--yellow);
  font-size: 1.4rem;
  opacity: 0;
}
.celebration span:nth-child(1) { left: 7%; --delay: .05s; --turn: 310deg; }
.celebration span:nth-child(2) { left: 14%; --delay: .22s; --turn: -180deg; }
.celebration span:nth-child(3) { left: 20%; --delay: .12s; --turn: 420deg; }
.celebration span:nth-child(4) { left: 27%; --delay: .31s; --turn: -250deg; }
.celebration span:nth-child(5) { left: 34%; --delay: .02s; --turn: 370deg; }
.celebration span:nth-child(6) { left: 40%; --delay: .19s; --turn: -330deg; }
.celebration span:nth-child(7) { left: 46%; --delay: .08s; --turn: 240deg; }
.celebration span:nth-child(8) { left: 52%; --delay: .29s; --turn: -410deg; }
.celebration span:nth-child(9) { left: 58%; --delay: .15s; --turn: 290deg; }
.celebration span:nth-child(10) { left: 64%; --delay: .25s; --turn: -230deg; }
.celebration span:nth-child(11) { left: 70%; --delay: .04s; --turn: 460deg; }
.celebration span:nth-child(12) { left: 76%; --delay: .33s; --turn: -360deg; }
.celebration span:nth-child(13) { left: 82%; --delay: .11s; --turn: 210deg; }
.celebration span:nth-child(14) { left: 88%; --delay: .27s; --turn: -290deg; }
.celebration span:nth-child(15) { left: 93%; --delay: .17s; --turn: 390deg; }
.celebration span:nth-child(16) { left: 24%; --delay: .24s; --turn: -440deg; }
.celebration span:nth-child(17) { left: 55%; --delay: .07s; --turn: 350deg; }
.celebration span:nth-child(18) { left: 79%; --delay: .20s; --turn: -200deg; }
.celebration.go span {
  animation: confetti 1.5s var(--delay) ease-in forwards;
}

@keyframes confetti {
  0% { opacity: 0; transform: translateY(-20px) rotate(0); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translateY(88vh) rotate(var(--turn)); }
}

@media (max-width: 760px) {
  body { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
  .topbar { min-height: 60px; }
  .grownups-button { display: grid; }
  .bottom-nav { display: flex; }
  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    padding-top: 2.5rem;
    text-align: center;
  }
  .hero-copy > p:not(.eyebrow) { margin-right: auto; margin-left: auto; }
  .line-friend {
    order: -1;
    width: min(210px, 58vw);
    margin-bottom: 1.7rem;
  }
  .journey-grid { grid-template-columns: 1fr; }
  .journey-card { min-height: 92px; }
  .page-shell { width: min(100% - 1.2rem, 980px); padding-top: 1rem; }
  .page-title-row { gap: .65rem; }
  .back-button,
  .speak-button { width: 46px; height: 46px; border-radius: 15px; }
  .answer-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .math-stage { border-radius: 24px; }
  #line-canvas { height: clamp(250px, 75vw, 330px); }
}

@media (max-width: 390px) {
  .brand { font-size: 1rem; }
  .brand-mark { width: 32px; height: 32px; transform: scale(.86) rotate(-8deg); }
  .star-pill { min-width: 54px; }
  .icon-button { min-width: 40px; }
  .hero h1 { font-size: 2.35rem; }
  .section-heading { align-items: flex-start; }
  .page-title-row h1 { font-size: 1.45rem; }
  .level-card { padding: .8rem; gap: .7rem; }
  .level-number { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
