:root {
  --ink: #252525;
  --muted: #5d6470;
  --line: #dce1e8;
  --paper: #ffffff;
  --wash: #f5f8fb;
  --blue: #2477d4;
  --blue-dark: #17518f;
  --yellow: #ffc900;
  --yellow-dark: #b88f00;
  --green: #168347;
  --coral: #df624a;
  --max: 1120px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Nunito Sans", sans-serif;
  font-size: 17px;
  line-height: 1.65;
  letter-spacing: 0;
}
a { color: inherit; }
img { display: block; max-width: 100%; height: auto; }
button, summary, a { -webkit-tap-highlight-color: transparent; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  height: 4px;
  z-index: 100;
  background: transparent;
}
.reading-progress span {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--yellow);
  transform: scaleX(0);
  transform-origin: left;
}

.site-header {
  width: min(calc(100% - 40px), var(--max));
  min-height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 32px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}
.brand img { border-radius: 8px; }
.brand span { display: grid; line-height: 1.05; }
.brand strong { font: 700 1.15rem/1 "Fredoka", sans-serif; }
.brand small { margin-top: 5px; color: var(--muted); font-size: 0.7rem; text-transform: uppercase; }
.site-header nav { margin-left: auto; display: flex; gap: 24px; font-size: 0.9rem; font-weight: 700; }
.site-header nav a, .site-footer a { text-decoration: none; }
.site-header nav a:hover, .site-footer a:hover { color: var(--blue); }
.header-cta, .mobile-app-cta a, .chapter-cta a {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid var(--yellow-dark);
  border-radius: 6px;
  color: var(--ink);
  background: var(--yellow);
  font-weight: 800;
  text-decoration: none;
}
.header-cta:hover, .mobile-app-cta a:hover, .chapter-cta a:hover { background: #ffd83d; }

main { min-height: 70vh; }
.breadcrumbs {
  width: min(calc(100% - 40px), var(--max));
  margin: 22px auto 0;
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-x: auto;
  white-space: nowrap;
}
.breadcrumbs a { text-decoration: none; }
.breadcrumbs a:hover { color: var(--blue); }

.hub-hero {
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(420px, 1.08fr);
  align-items: center;
  gap: 56px;
  padding: 56px max(20px, calc((100vw - var(--max)) / 2));
  background: var(--wash);
  border-bottom: 1px solid var(--line);
}
.hub-hero img { width: 100%; }
.hub-copy { max-width: 580px; }
.eyebrow, .section-label {
  margin: 0 0 12px;
  color: var(--blue-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}
h1, h2, h3 { margin-top: 0; font-family: "Fredoka", sans-serif; line-height: 1.12; letter-spacing: 0; }
h1 { margin-bottom: 22px; font-size: clamp(2.45rem, 5vw, 4.7rem); }
h2 { margin-bottom: 22px; font-size: clamp(1.8rem, 3vw, 2.65rem); }
h3 { font-size: 1.3rem; }
.hub-copy > p:last-child, .grade-hero > p:last-child { max-width: 700px; color: var(--muted); font-size: 1.08rem; }
.hub-section, .chapter-index {
  width: min(calc(100% - 40px), 900px);
  margin: 0 auto;
  padding: 76px 0 96px;
}
.grade-list { border-top: 1px solid var(--line); }
.grade-band {
  display: grid;
  grid-template-columns: 120px 1fr auto auto;
  align-items: center;
  gap: 18px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.grade-band > span { color: var(--blue-dark); font: 700 1.25rem/1 "Fredoka", sans-serif; }
.grade-band small { color: var(--muted); }
.grade-band b { color: var(--blue); font-size: 1.4rem; }
.grade-band:hover strong { color: var(--blue); }
.review-note { margin-top: 26px; color: var(--muted); font-size: 0.92rem; }

.grade-hero {
  width: min(calc(100% - 40px), var(--max));
  margin: 0 auto;
  padding: 72px 0 58px;
  border-bottom: 1px solid var(--line);
}
.grade-hero h1 { max-width: 820px; }
.index-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; }
.index-heading > span { color: var(--muted); font-weight: 800; }
.chapter-rows { border-top: 1px solid var(--line); }
.chapter-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 22px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.chapter-number {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  font-weight: 800;
}
.chapter-row > span:nth-child(2) { display: grid; }
.chapter-row small { color: var(--muted); }
.chapter-row strong { font: 600 1.15rem/1.3 "Fredoka", sans-serif; }
.row-action { color: var(--blue-dark); font-size: 0.88rem; font-weight: 800; }
.chapter-row:hover strong, .chapter-row:hover .row-action { color: var(--blue); }

.chapter-hero {
  width: min(calc(100% - 40px), var(--max));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.68fr);
  gap: 56px;
  align-items: center;
  padding: 50px 0 62px;
  border-bottom: 1px solid var(--line);
}
.chapter-hero h1 { max-width: 760px; font-size: clamp(2.3rem, 5vw, 4.15rem); }
.chapter-hero .lede { max-width: 720px; color: var(--muted); font-size: 1.08rem; }
.chapter-facts { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 24px; font-size: 0.85rem; font-weight: 800; }
.chapter-facts span { padding-left: 13px; border-left: 3px solid var(--yellow); }
.chapter-hero img { width: 100%; }

.chapter-layout {
  width: min(calc(100% - 40px), var(--max));
  margin: 0 auto;
  display: grid;
  grid-template-columns: 245px minmax(0, 720px);
  gap: 62px;
  align-items: start;
  padding: 56px 0 100px;
}
.contents-nav { position: sticky; top: 20px; }
.contents-nav h2 { margin-bottom: 16px; font-size: 1rem; }
.contents-nav ol { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.contents-nav a { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 0.84rem; text-decoration: none; }
.contents-nav a:hover { color: var(--blue); }
.chapter-content { min-width: 0; }
.chapter-intro { margin-bottom: 56px; }
.chapter-intro h2 { margin-bottom: 15px; }
.chapter-intro p { color: var(--muted); }
.sequence-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0; }
.sequence-strip span { padding: 7px 11px; border: 1px solid var(--line); border-radius: 4px; background: var(--wash); font-weight: 800; }
.solution-section { margin: 70px 0 0; scroll-margin-top: 20px; }
.solution-section-header { margin-bottom: 24px; padding-bottom: 16px; border-bottom: 3px solid var(--ink); }
.solution-section-header p { margin: 0 0 4px; color: var(--coral); font-size: 0.77rem; font-weight: 800; text-transform: uppercase; }
.solution-section-header h2 { margin: 0; font-size: 1.8rem; }
.solution-block { padding: 26px 0; border-bottom: 1px solid var(--line); scroll-margin-top: 20px; }
.question-label { margin: 0 0 7px; color: var(--blue-dark); font-size: 0.78rem; font-weight: 800; text-transform: uppercase; }
.solution-block h3 { margin-bottom: 14px; font: 700 1.13rem/1.45 "Nunito Sans", sans-serif; }
.solution-block details { border-left: 4px solid var(--yellow); padding: 0 0 0 18px; }
.solution-block summary { color: var(--blue-dark); cursor: pointer; font-weight: 800; }
.solution-block details[open] summary { margin-bottom: 12px; }
.solution-block p { margin: 10px 0; }
.solution-block ul, .solution-block ol { padding-left: 24px; }
.math-line { overflow-x: auto; padding: 12px 14px; background: var(--wash); font-weight: 800; white-space: nowrap; }
.answer-note { color: var(--muted); font-size: 0.92rem; }
.diagram { margin: 22px 0; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--wash); }
.diagram img { margin: 0 auto; }
.diagram figcaption { margin-top: 12px; color: var(--muted); font-size: 0.82rem; text-align: center; }
.mini-table { width: 100%; margin: 18px 0; border-collapse: collapse; font-size: 0.92rem; }
.mini-table th, .mini-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; }
.mini-table th { background: var(--wash); }

.concept-recap, .practice-set { margin-top: 72px; padding-top: 36px; border-top: 5px solid var(--yellow); }
.mistake-list { display: grid; gap: 0; border-top: 1px solid var(--line); }
.mistake-list div { display: grid; grid-template-columns: 170px 1fr; gap: 22px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.mistake-list strong { color: var(--coral); }
.practice-item { padding: 18px 0; border-bottom: 1px solid var(--line); }
.practice-item summary { cursor: pointer; color: var(--blue-dark); font-weight: 800; }
.chapter-cta {
  margin-top: 76px;
  padding: 34px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--yellow);
}
.chapter-cta h2 { margin-bottom: 10px; font-size: 2rem; }
.chapter-cta p { max-width: 560px; }
.chapter-cta a { margin-top: 8px; background: var(--ink); color: white; border-color: var(--ink); }
.chapter-cta a:hover { background: var(--blue-dark); }

.site-footer {
  width: min(calc(100% - 40px), var(--max));
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 40px;
  padding: 42px 0 60px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
}
.site-footer p { max-width: 520px; }
.site-footer nav { display: flex; gap: 18px; align-items: start; }
.mobile-app-cta { display: none; }

@media (max-width: 850px) {
  body { padding-bottom: 74px; }
  .site-header { min-height: 68px; gap: 14px; }
  .site-header nav { display: none; }
  .header-cta { margin-left: auto; min-height: 40px; padding: 0 13px; font-size: 0.8rem; }
  .hub-hero, .chapter-hero { grid-template-columns: 1fr; }
  .hub-hero { min-height: auto; padding-top: 44px; gap: 28px; }
  .hub-hero img { max-height: 340px; }
  .chapter-hero { gap: 28px; }
  .chapter-hero img { max-width: 520px; }
  .chapter-layout { grid-template-columns: 1fr; gap: 34px; }
  .contents-nav { position: static; }
  .contents-nav ol { columns: 2; column-gap: 24px; }
  .grade-band { grid-template-columns: 88px 1fr auto; }
  .grade-band small { display: none; }
  .mobile-app-cta {
    position: fixed;
    inset: auto 0 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 66px;
    padding: 8px 16px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,0.97);
    font-size: 0.84rem;
    font-weight: 800;
  }
  .mobile-app-cta a { min-height: 42px; padding: 0 14px; }
}

@media (max-width: 560px) {
  body { font-size: 16px; }
  .site-header, .breadcrumbs, .grade-hero, .chapter-hero, .chapter-layout, .site-footer { width: min(calc(100% - 28px), var(--max)); }
  .brand small { display: none; }
  .hub-hero { padding-left: 14px; padding-right: 14px; }
  h1 { font-size: 2.45rem; }
  .chapter-hero h1 { font-size: 2.35rem; }
  .chapter-hero { padding-top: 35px; }
  .chapter-facts { display: grid; }
  .contents-nav ol { columns: 1; }
  .chapter-layout { padding-top: 36px; }
  .solution-section { margin-top: 52px; }
  .solution-section-header h2 { font-size: 1.55rem; }
  .solution-block { padding: 22px 0; }
  .grade-band { grid-template-columns: 60px 1fr auto; gap: 10px; }
  .grade-band > span { font-size: 1rem; }
  .row-action { font-size: 0; }
  .row-action b { font-size: 1.2rem; }
  .mistake-list div { grid-template-columns: 1fr; gap: 4px; }
  .chapter-cta { padding: 24px; }
  .site-footer { display: grid; }
  .site-footer nav { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reading-progress { display: none; }
}

@media print {
  .site-header, .reading-progress, .contents-nav, .chapter-cta, .mobile-app-cta, .site-footer { display: none !important; }
  .chapter-layout { display: block; width: 100%; padding: 0; }
  .chapter-hero { width: 100%; grid-template-columns: 1fr; }
  .chapter-hero img { max-width: 320px; }
  .solution-block details > * { display: block; }
}
