:root {
  --bg: #fff6ea;
  --bg-2: #ffe3bf;
  --ink: #1c2430;
  --muted: #5b6573;
  --card: #ffffff;
  --line: #ead9c0;
  --shadow: #e2ccad;
  --maths: #2b6fff;
  --maths-soft: #e8f0ff;
  --english: #188a5c;
  --english-soft: #e3f7ee;
  --science: #d67d00;
  --science-soft: #fff1d6;
  --chinese: #c83333;
  --chinese-soft: #ffe8e6;
  --good: #0f8a57;
  --good-soft: #d9f6e8;
  --bad: #c23b3b;
  --bad-soft: #ffe3e0;
  --star: #f0b429;
  --y4: #0f8a8a;
  --y5: #5b4fd6;
  --tap: 52px;
  --radius: 24px;
  --max: 760px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 400px at 50% -80px, var(--bg-2), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  font-size: 19px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; }
button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}
button:disabled { cursor: default; opacity: 0.6; }

:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--maths);
  outline-offset: 3px;
}

#app {
  max-width: var(--max);
  margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(32px + var(--safe-bottom));
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 2rem; line-height: 1.15; letter-spacing: -0.02em; }
h2 { font-size: 1.45rem; line-height: 1.2; }
h3 { font-size: 1.15rem; line-height: 1.25; }

.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 12px 20px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 5px 0 var(--shadow);
  text-decoration: none;
  user-select: none;
  width: 100%;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--shadow); }
.btn-primary { background: var(--ink); color: #fff; box-shadow: 0 5px 0 #0b1016; }
.btn-primary:active { box-shadow: 0 2px 0 #0b1016; }
.btn-good { background: var(--good); color: #fff; border-color: #0a5e3b; box-shadow: 0 5px 0 #0a5e3b; }
.btn-good:active { box-shadow: 0 2px 0 #0a5e3b; }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--muted);
  min-height: 44px;
  width: auto;
  padding: 8px 12px;
}
.btn-ghost:active { transform: none; background: rgba(0,0,0,0.05); }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { flex: 1 1 140px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: none;
}

/* Home */
.hero { text-align: center; padding: 12px 8px 8px; }
.hero .sun { font-size: 2.6rem; line-height: 1; margin-bottom: 8px; }
.hero p { margin-top: 10px; color: var(--muted); font-size: 1.05rem; }
.eyebrow {
  display: inline-block;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 10px;
}

.year-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 24px 0 8px; }
.year-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 140px;
  padding: 18px 12px;
  border: 3px solid var(--line);
  border-radius: 24px;
  background: #fff;
  box-shadow: 0 8px 0 var(--shadow);
  font-weight: 900;
  color: var(--ink);
  text-align: center;
}
.year-card:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--shadow); }
.year-card.y4 { border-color: var(--y4); background: #e8fafa; }
.year-card.y5 { border-color: var(--y5); background: #efedff; }
.year-card .label { font-size: 1.5rem; }
.year-card .sub { font-weight: 650; color: var(--muted); font-size: 0.95rem; }
.year-card.selected { box-shadow: 0 8px 0 var(--ink); border-color: var(--ink); }

.note {
  margin: 18px 0 0;
  padding: 14px 16px;
  background: #fff;
  border-radius: 16px;
  border: 2px dashed var(--line);
  color: var(--muted);
  font-size: 0.95rem;
}

/* Day cards */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.topbar h1, .topbar h2 { flex: 1; }
.progress-chip {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.9rem;
  white-space: nowrap;
}

.day-list { display: flex; flex-direction: column; gap: 14px; }
.day-card {
  display: block;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 3px solid var(--line);
  border-radius: 24px;
  padding: 18px 18px 16px;
  box-shadow: 0 7px 0 var(--shadow);
  color: inherit;
}
.day-card:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--shadow); }
.day-card.done { border-color: var(--good); background: var(--good-soft); }
.day-card .day-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.day-card .theme { color: var(--muted); font-weight: 650; margin-top: 4px; }
.pips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; }
.pip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border-radius: 14px;
  padding: 8px 4px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--muted);
  min-height: 64px;
  justify-content: center;
}
.pip .mark { font-size: 1.15rem; line-height: 1; }
.pip.done { background: var(--good-soft); color: var(--good); }
.pip.maths.done { background: var(--maths-soft); color: var(--maths); }
.pip.english.done { background: var(--english-soft); color: var(--english); }
.pip.science.done { background: var(--science-soft); color: var(--science); }
.pip.chinese.done { background: var(--chinese-soft); color: var(--chinese); }

/* Subject grid */
.subject-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subject-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-height: 150px;
  padding: 16px;
  border: 3px solid var(--line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 7px 0 var(--shadow);
  text-align: left;
  color: inherit;
}
.subject-card:active { transform: translateY(4px); box-shadow: 0 3px 0 var(--shadow); }
.subject-card.maths { background: var(--maths-soft); border-color: #b9d0ff; }
.subject-card.english { background: var(--english-soft); border-color: #b5e6cd; }
.subject-card.science { background: var(--science-soft); border-color: #f3d7a0; }
.subject-card.chinese { background: var(--chinese-soft); border-color: #f5c2be; }
.subject-card.done { box-shadow: 0 7px 0 #8fd4b3; }
.subject-card .emoji { font-size: 1.8rem; }
.subject-card .title { font-weight: 900; font-size: 1.1rem; }
.subject-card .topic { color: var(--muted); font-weight: 650; font-size: 0.92rem; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  color: var(--good);
}

/* Lesson */
.lesson-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}
.lesson-meta { flex: 1; }
.lesson-meta .kicker { font-weight: 800; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; }
.kicker.maths { color: var(--maths); }
.kicker.english { color: var(--english); }
.kicker.science { color: var(--science); }
.kicker.chinese { color: var(--chinese); }

.card {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: 0 6px 0 var(--shadow);
}

.explain p { margin: 0 0 12px; }
.explain p:last-child { margin-bottom: 0; }
.example {
  margin-top: 12px;
  padding: 14px;
  background: var(--bg);
  border-radius: 16px;
  border: 2px dashed var(--line);
}
.example strong { display: block; margin-bottom: 4px; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 16px 0 4px; }
.dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--line);
}
.dot.on { background: var(--ink); }

/* Practice */
.stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.stat {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 800;
  font-size: 0.9rem;
}
.bar {
  height: 12px;
  background: #f0e2cd;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 14px;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #45c08a, #20a56a);
  border-radius: inherit;
  transition: width 0.3s ease;
}

.prompt { font-size: 1.2rem; font-weight: 800; margin-bottom: 14px; }
.prompt p { font-weight: 650; margin: 0 0 8px; }
.passage {
  background: #fffaf2;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 14px;
  font-weight: 550;
  font-size: 1.05rem;
}
.passage p { margin: 0 0 10px; }
.passage p:last-child { margin-bottom: 0; }

.hanzi {
  text-align: center;
  font-size: 4.2rem;
  line-height: 1.1;
  font-weight: 500;
  margin: 4px 0 8px;
}
.pinyin-line { text-align: center; font-size: 1.3rem; font-weight: 800; color: var(--chinese); margin-bottom: 6px; }

.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  padding: 12px 14px;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: #fff;
  font-weight: 750;
  box-shadow: none;
  color: inherit;
}
.choice:active { background: var(--bg); }
.choice.selected { border-color: var(--ink); background: #fff3d4; }
.choice.correct { border-color: var(--good); background: var(--good-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }
.choice .key {
  flex: 0 0 32px;
  height: 32px;
  border-radius: 10px;
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
}

.answer-box { margin-top: 4px; }
.answer-input {
  width: 100%;
  min-height: 60px;
  padding: 12px 16px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: #fff;
  font-size: 1.35rem;
  font-weight: 800;
  text-align: center;
}
.answer-input:disabled { background: #f6f1e8; }
.pair-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pair-inputs label { display: block; font-size: 0.85rem; font-weight: 800; color: var(--muted); margin-bottom: 6px; text-align: center; }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.key {
  min-height: 56px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: 0 3px 0 var(--shadow);
}
.key:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
.key.wide { grid-column: span 2; }
.key.danger { color: var(--bad); }

.feedback {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  border: 2px solid;
  font-weight: 650;
}
.feedback.ok { background: var(--good-soft); border-color: #8fd4b3; }
.feedback.no { background: var(--bad-soft); border-color: #f0b3ad; }
.feedback strong { display: block; font-size: 1.1rem; margin-bottom: 4px; }

.rect-viz {
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}
.rect-viz .shape {
  border: 4px solid var(--ink);
  background: var(--maths-soft);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--muted);
  position: relative;
}
.rect-viz .dim {
  position: absolute;
  font-size: 0.85rem;
  font-weight: 900;
  color: var(--ink);
}

/* Complete */
.celebrate { text-align: center; padding: 12px 0 8px; }
.celebrate .big { font-size: 3rem; margin-bottom: 8px; }
.stars { font-size: 2.2rem; letter-spacing: 0.1em; margin: 8px 0 12px; }
.subject-summary { display: grid; gap: 10px; margin: 18px 0; }
.subject-summary .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 800;
}

.footer-tools {
  margin-top: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}
.footer-tools button { font-size: 0.95rem; }

.confetti {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 20;
}
.confetti i {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 16px;
  border-radius: 2px;
  animation: fall 1.6s linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.8; }
}

@media (max-width: 420px) {
  body { font-size: 18px; }
  h1 { font-size: 1.7rem; }
  .year-pick { grid-template-columns: 1fr; }
  .hanzi { font-size: 3.4rem; }
}
@media (min-width: 700px) {
  #app { padding-top: calc(24px + var(--safe-top)); }
  .subject-grid { gap: 16px; }
}
