:root {
  --bg: #f7f7f2;
  --surface: #ffffff;
  --ink: #17342c;
  --muted: #64736d;
  --line: #dfe5e1;
  --brand: #153d33;
  --brand-soft: #dcece5;
  --yellow: #f2c94c;
  --yellow-soft: #fff4c9;
  --blue: #5a8dee;
  --blue-soft: #e7eefc;
  --coral: #ef7a68;
  --coral-soft: #fce8e4;
  --green: #5f9b76;
  --shadow: 0 8px 24px rgba(23, 52, 44, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }

html {
  background: #e9eeeb;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: #e9eeeb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

button,
input { font: inherit; }

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

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(90, 141, 238, .35);
  outline-offset: 2px;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
}

.app-shell {
  position: relative;
  width: 100%;
  min-height: 100svh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 18px calc(92px + env(safe-area-inset-bottom));
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand img { flex: 0 0 auto; }

.brand span { display: grid; gap: 1px; }

.brand strong {
  font-size: 18px;
  line-height: 1.2;
  font-weight: 700;
}

.brand small {
  color: var(--muted);
  font-size: 11px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.streak {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 10px;
  color: #7a5a00;
  background: var(--yellow-soft);
  border-radius: 8px;
  font-size: 13px;
}

.streak svg { width: 17px; height: 17px; }
.streak b { font-weight: 700; }

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.grade-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 22px;
  overflow: hidden;
}

.grade-switch > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.grade-switch > div {
  display: grid;
  grid-template-columns: repeat(6, minmax(36px, 1fr));
  width: 100%;
  gap: 6px;
}

.grade-switch button {
  min-width: 0;
  height: 38px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.grade-switch button[aria-pressed="true"] {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
  font-weight: 700;
}

.greeting {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

.greeting h1,
.page-heading h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.25;
}

.greeting p:not(.eyebrow),
.page-heading > p:last-child {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.time-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  padding: 8px 10px;
  color: #365f9f;
  background: var(--blue-soft);
  border-radius: 8px;
  font-size: 12px;
}

.time-badge svg { width: 16px; height: 16px; }

.quick-stats,
.report-summary,
.parent-stats {
  display: grid;
  gap: 8px;
}

.quick-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.report-summary,
.parent-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.quick-stats article,
.report-summary article,
.parent-stats article {
  display: grid;
  min-width: 0;
  padding: 13px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.quick-stats span,
.report-summary span,
.parent-stats span {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.quick-stats strong,
.report-summary strong,
.parent-stats strong {
  margin: 4px 0 2px;
  font-size: 22px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.quick-stats strong b,
.parent-stats strong b { font: inherit; }

.quick-stats small,
.report-summary small,
.parent-stats small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.daily-steps {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 22px 0 28px;
  padding: 0;
  list-style: none;
}

.daily-steps::before {
  content: "";
  position: absolute;
  top: 17px;
  left: 16.6%;
  right: 16.6%;
  height: 2px;
  background: var(--line);
}

.daily-steps li {
  position: relative;
  z-index: 1;
  display: grid;
  justify-items: center;
  gap: 7px;
  color: var(--muted);
}

.daily-steps li > span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: #ebefec;
  border: 2px solid var(--bg);
  border-radius: 50%;
}

.daily-steps li.is-done > span,
.daily-steps li.is-current > span {
  color: #fff;
  background: var(--brand);
}

.daily-steps li.is-current small {
  color: var(--ink);
  font-weight: 700;
}

.daily-steps small { font-size: 11px; }

.lesson { padding-bottom: 8px; }

.lesson-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.subject-tag,
.difficulty {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.subject-tag { color: #365f9f; background: var(--blue-soft); }
.difficulty { color: #6d5000; background: var(--yellow-soft); white-space: nowrap; }

.lesson-head h2 {
  margin: 7px 0 3px;
  font-size: 21px;
  line-height: 1.35;
}

.lesson-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.scene {
  margin: 0 0 22px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.scene img {
  display: block;
  width: 100%;
  aspect-ratio: 760 / 460;
  object-fit: cover;
}

.scene figcaption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.scene figcaption small {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.question-block h3 {
  margin: 0;
  font-size: 19px;
  line-height: 1.55;
}

.question-block > p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.answers {
  display: grid;
  gap: 9px;
  margin-top: 17px;
}

.answer-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.answer-button::after {
  content: "";
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(45deg);
  opacity: .45;
}

.answer-button[aria-pressed="true"] {
  color: var(--brand);
  background: var(--brand-soft);
  border-color: var(--green);
  font-weight: 700;
}

.answer-button:disabled { cursor: default; opacity: .72; }
.answer-button.is-correct { color: #245e3b; background: #e0f1e6; border-color: #6aa982; opacity: 1; }
.answer-button.is-wrong { color: #8b3c31; background: var(--coral-soft); border-color: var(--coral); opacity: 1; }

.feedback {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
  padding: 13px;
  color: #245e3b;
  background: #e0f1e6;
  border-radius: 8px;
}

.feedback.is-wrong { color: #8b3c31; background: var(--coral-soft); }

.feedback-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.feedback strong { display: block; font-size: 14px; line-height: 1.4; }
.feedback p { margin: 4px 0 0; font-size: 12px; line-height: 1.55; }

.primary-button,
.secondary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 11px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  color: #fff;
  background: var(--brand);
  border: 1px solid var(--brand);
}

.secondary-button {
  color: var(--brand);
  background: transparent;
  border: 1px solid var(--brand);
}

.next-button { margin-top: 12px; }

.screen { display: none; animation: screen-in .2s ease-out; }
.screen.is-active { display: block; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .screen { animation: none; }
}

.page-heading { margin: 18px 0 22px; }

.path-list { margin: 4px 0 22px; }

.path-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: 11px;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.path-item > span {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--muted);
  background: #ebefec;
  border-radius: 50%;
}

.path-item.is-done > span,
.path-item.is-current > span { color: #fff; background: var(--brand); }

.path-item h2 { margin: 0; font-size: 15px; line-height: 1.4; }
.path-item p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.path-item > small { color: var(--muted); font-size: 10px; white-space: nowrap; }
.path-item.is-current > small { color: var(--brand); font-weight: 700; }

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 { margin: 0; font-size: 17px; }
.section-title span { color: var(--muted); font-size: 11px; }

.mastery-section,
.focus-section { margin-top: 27px; }

.mastery-list { display: grid; gap: 17px; }

.mastery-row {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 38px;
  gap: 10px;
  align-items: center;
}

.mastery-row span { font-size: 13px; }
.mastery-row strong { font-size: 12px; text-align: right; }

.mastery-track {
  height: 10px;
  overflow: hidden;
  background: #e5eae7;
  border-radius: 5px;
}

.mastery-track i {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: inherit;
  transition: width .3s ease;
}

.mastery-row:nth-child(2) .mastery-track i { background: var(--blue); }
.mastery-row:nth-child(3) .mastery-track i { background: var(--coral); }
.mastery-row:nth-child(4) .mastery-track i { background: var(--yellow); }

.achievement {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 13px;
  margin-top: 28px;
  padding: 15px;
  background: var(--yellow-soft);
  border-radius: 8px;
}

.achievement > span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  color: #fff;
  background: var(--brand);
  border-radius: 8px;
}

.achievement h2 { margin: 1px 0 4px; font-size: 15px; }
.achievement p { margin: 0; color: #66510d; font-size: 12px; line-height: 1.55; }

.focus-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 11px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}

.focus-item > svg { color: var(--green); }
.focus-item h3 { margin: 0; font-size: 14px; line-height: 1.45; }
.focus-item p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.focus-section + .secondary-button { margin-top: 20px; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .96);
  border-top: 1px solid var(--line);
}

.bottom-nav a {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 0;
  padding: 6px 2px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
}

.bottom-nav a span { font-size: 10px; }
.bottom-nav a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); font-weight: 700; }

.settings-dialog {
  width: min(440px, calc(100% - 28px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(23, 52, 44, .24);
}

.settings-dialog::backdrop { background: rgba(14, 31, 26, .48); }
.settings-dialog form { display: grid; gap: 20px; padding: 20px; }

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head h2 { margin: 0; font-size: 21px; }

.settings-dialog label {
  display: grid;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.settings-dialog input[type="text"] {
  width: 100%;
  min-height: 46px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settings-dialog output { justify-self: end; color: var(--muted); font-size: 12px; font-weight: 400; }
.settings-dialog input[type="range"] { width: 100%; accent-color: var(--brand); }

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 11px;
  color: var(--muted);
  background: var(--brand-soft);
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
}

.student-code {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 12px;
  margin: 0;
  padding: 11px;
  background: var(--blue-soft);
  border-radius: 8px;
}

.student-code span { color: var(--muted); font-size: 12px; }
.student-code strong { color: #365f9f; font-size: 14px; }
.student-code small { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }

.privacy-note svg { flex: 0 0 auto; color: var(--brand); }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 13px;
  color: #fff;
  text-align: center;
  background: var(--brand);
  border-radius: 8px;
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  font-size: 13px;
}

.loading {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
  background: var(--bg);
}

.loading span {
  width: 36px;
  height: 36px;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.loading p { margin: 0; font-size: 13px; }

@keyframes spin { to { transform: rotate(360deg); } }

[hidden] { display: none !important; }

@media (min-width: 560px) {
  body { padding: 24px 0; }
  .app-shell {
    max-width: 520px;
    min-height: calc(100svh - 48px);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
  }
  .bottom-nav {
    left: 50%;
    right: auto;
    max-width: 520px;
    transform: translateX(-50%);
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

@media (max-width: 360px) {
  .app-shell { padding-left: 14px; padding-right: 14px; }
  .brand small { display: none; }
  .greeting { align-items: flex-start; flex-direction: column; }
  .quick-stats strong { font-size: 19px; }
  .path-item { grid-template-columns: 38px minmax(0, 1fr); }
  .path-item > small { grid-column: 2; }
}
