/* ==========================================================================
   TutorBox — shared styles
   Idea: a school exercise book. Pale ruled lines, a red margin rule that runs
   down every page, and the teacher's notes written in the margin.
   To change colours, edit the tokens in :root only.
   ========================================================================== */

:root {
  --paper: #FAFCFF;
  --paper-2: #EEF3FB;
  --ink: #1C2B45;
  --ink-soft: #4B5A76;
  --rule: #D3E0F2;
  --margin: #D8465C;
  --pen: #1E4FB5;
  --hl: #FFE45C;
  --on-hl: #1C2B45;

  --margin-w: 168px;
  --measure: 66ch;
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1B2622;
    --paper-2: #23312C;
    --ink: #EDF1EA;
    --ink-soft: #B3BFB5;
    --rule: #34463F;
    --margin: #F27D8E;
    --pen: #A3C6FF;
    --hl: #E9CF4B;
  }
}
:root[data-theme="dark"] {
  --paper: #1B2622;
  --paper-2: #23312C;
  --ink: #EDF1EA;
  --ink-soft: #B3BFB5;
  --rule: #34463F;
  --margin: #F27D8E;
  --pen: #A3C6FF;
  --hl: #E9CF4B;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 16px; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1.125rem;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; }

h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; text-wrap: balance; }
h1 { font-size: clamp(2.1rem, 4.6vw, 3.4rem); letter-spacing: -0.015em; font-weight: 700; }
h2 { font-size: clamp(1.45rem, 2.4vw, 1.75rem); font-weight: 700; letter-spacing: -0.005em; }
h3 { font-size: 1.2rem; font-weight: 700; }
p { margin: 0 0 1em; max-width: var(--measure); }

a { color: var(--pen); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 3px; border-radius: 2px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 10;
  background: var(--ink); color: var(--paper); padding: .6rem 1rem; border-radius: 6px;
}
.skip-link:focus { top: 12px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 24px; }

/* ---------- The notebook row: margin column + ruled column ---------- */
.row {
  display: grid;
  grid-template-columns: var(--margin-w) minmax(0, 1fr);
}
.row > .m {
  padding: 0 22px 0 0;
  text-align: right;
}
.row > .c {
  border-left: 2px solid var(--margin);
  padding-left: 32px;
  min-width: 0;
}
.pad-top { padding-top: 56px; }
.pad-bottom { padding-bottom: 56px; }

/* Handwritten margin notes */
.note {
  display: inline-block;
  font-family: var(--hand);
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.05;
  color: var(--margin);
  transform: rotate(-3deg);
  margin-top: .35rem;
}
.hl { background: linear-gradient(transparent 52%, var(--hl) 52% 90%, transparent 90%); color: inherit; }

/* ---------- Header ---------- */
.site-header { border-bottom: 1px solid var(--rule); min-height: 68px; }
.site-header .bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 68px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; font-weight: 700; font-size: 1.3rem;
}
.brand svg { width: 30px; height: 30px; flex: none; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 2px; }
.nav a {
  display: block; padding: .45rem .7rem; border-radius: 6px;
  color: var(--ink); text-decoration: none; font-size: 1rem;
}
.nav a:hover { background: var(--paper-2); }
.nav a[aria-current="page"] {
  background: linear-gradient(transparent 55%, var(--hl) 55% 92%, transparent 92%);
  color: var(--on-hl);
  font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .nav a[aria-current="page"] { color: var(--ink); background: var(--paper-2); }
}
.menu-btn {
  display: none;
  font: inherit; font-size: 1rem; font-weight: 700;
  color: var(--ink); background: transparent;
  border: 2px solid var(--ink); border-radius: 6px; padding: .4rem .85rem; cursor: pointer;
}

@media (max-width: 960px) {
  .menu-btn { display: inline-block; }
  .nav { display: none; width: 100%; padding: 0 0 14px; }
  .nav.open { display: block; }
  .nav ul { flex-direction: column; }
  .nav a { padding: .7rem .5rem; border-bottom: 1px solid var(--rule); border-radius: 0; }
  .site-header .bar { flex-wrap: wrap; }
}

/* ---------- Hero / page head (ruled paper band) ---------- */
.ruled {
  background-image: repeating-linear-gradient(to bottom, transparent 0 35px, var(--rule) 35px 36px);
  background-position: 0 18px;
}
.hero .c { padding-top: 64px; padding-bottom: 64px; }
.hero .m { padding-top: 76px; }
.page-head .m { padding-top: 56px; }
.hero h1 { max-width: 18ch; }
.lede { font-size: 1.25rem; color: var(--ink-soft); max-width: 56ch; }
.page-head .c { padding-top: 48px; padding-bottom: 40px; }
.page-head h1 { font-size: clamp(2rem, 4vw, 2.9rem); max-width: 22ch; }

.actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 1.6rem; }
.btn {
  display: inline-block; font-weight: 700; text-decoration: none;
  padding: .8rem 1.15rem; border-radius: 6px; border: 2px solid var(--ink);
  background: var(--ink); color: var(--paper);
}
.btn:hover { background: transparent; color: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--paper-2); }

/* On this page */
.toc { margin-top: 1.4rem; }
.toc p { margin: 0 0 .3rem; font-weight: 700; font-size: 1rem; }
.toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.toc a { font-size: 1rem; }

/* ---------- Home: pathways ---------- */
.path {
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
}
.path:first-of-type { border-top: 1px solid var(--rule); }
.path h3 { font-size: 1.35rem; margin-bottom: .3rem; }
.path h3 a { color: var(--ink); text-decoration: none; }
.path h3 a:hover { text-decoration: underline; }
.path .who { color: var(--ink-soft); margin-bottom: .45rem; font-size: 1.02rem; }
.path .first { margin: 0; font-size: 1.02rem; }

/* Home: section index */
.index { list-style: none; margin: 0; padding: 0; }
.index li {
  display: grid; grid-template-columns: minmax(180px, 250px) 1fr; gap: 4px 24px;
  padding: 16px 0; border-bottom: 1px solid var(--rule);
}
.index li:first-child { border-top: 1px solid var(--rule); }
.index a { font-weight: 700; font-size: 1.15rem; }
.index p { margin: 0; color: var(--ink-soft); }
.index .for { display: block; font-size: .95rem; color: var(--ink-soft); font-weight: 400; margin-top: 2px; }

/* Numbered steps (genuine sequences only) */
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps > li { counter-increment: step; }
.steps .num::before {
  content: counter(step);
  font-family: var(--hand); font-weight: 600; font-size: 2.3rem; line-height: 1;
  color: var(--margin);
}
.steps .c { padding-top: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.steps li:first-child .c { border-top: 1px solid var(--rule); }
.steps h3 { margin-bottom: .2rem; }
.steps p { margin: 0; }

/* Notice */
.notice {
  background: var(--paper-2);
  border-radius: 6px;
  padding: 20px 22px;
  max-width: 72ch;
}
.notice h2 { font-size: 1.3rem; margin-bottom: .35rem; }
.notice p:last-child { margin-bottom: 0; }

/* ---------- Section pages: resource lists ---------- */
.group-head .c { padding-top: 52px; padding-bottom: 12px; }
.group-head .m { padding-top: 58px; }
.group-head .intro { color: var(--ink-soft); margin-bottom: .4rem; }

.res { list-style: none; margin: 0; padding: 0; }
.res > li > .m {
  padding-top: 17px;
  font-size: .95rem;
  color: var(--ink-soft);
}
.res > li > .c { padding-top: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--rule); }
.res > li:first-child > .c { border-top: 1px solid var(--rule); }
.res .c > a { font-weight: 700; font-size: 1.1rem; }
.res .c p { margin: .15rem 0 0; color: var(--ink-soft); font-size: 1.02rem; }
.res .flag {
  display: inline-block; margin-left: 6px; font-size: .85rem; font-weight: 700;
  padding: 0 .45em; border-radius: 4px; background: var(--hl); color: var(--on-hl);
  vertical-align: 2px;
}

/* Prose blocks (AI guidance etc.) */
.prose h3 { margin-top: 1.4rem; }
.prose ul { padding-left: 1.2rem; max-width: var(--measure); }
.prose li { margin-bottom: .5rem; }

.checked { font-size: .95rem; color: var(--ink-soft); }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--rule); margin-top: 0; font-size: 1rem; color: var(--ink-soft); }
.site-footer .c { padding-top: 32px; padding-bottom: 40px; }
.site-footer ul { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.site-footer p { max-width: 80ch; margin-bottom: .6rem; }

/* ---------- Small screens: margin notes move inside the ruled column ---------- */
@media (max-width: 760px) {
  body { font-size: 1.0625rem; }
  .wrap { padding: 0 16px; }
  .row { grid-template-columns: minmax(0, 1fr); }
  .row > .m {
    text-align: left; padding: 0 0 0 18px;
    border-left: 2px solid var(--margin);
  }
  .row > .m:empty:not(.num) { display: none; }
  .m.pad-top + .c.pad-top { padding-top: 6px; }
  .m.pad-top:not(:empty) { padding-top: 44px; }
  .steps .num::before { font-size: 1.8rem; }
  .row > .c { padding-left: 18px; }
  .note { transform: none; font-size: 1.35rem; }
  .hero .m, .page-head .m { padding-top: 32px; }
  .hero .c { padding-top: 8px; padding-bottom: 44px; }
  .page-head .c { padding-top: 8px; }
  .group-head .m { padding-top: 36px; }
  .group-head .c { padding-top: 40px; }
  .group-head .m:not(:empty) + .c { padding-top: 4px; }
  .res > li > .m { padding-top: 12px; font-size: .9rem; }
  .res > li > .c { border-top: 0; padding-top: 2px; }
  .res > li:first-child > .c { border-top: 0; }
  .res > li > .m { border-top: 1px solid var(--rule); }
  .steps .m { padding-top: 12px; }
  .steps .c { border-top: 0 !important; padding-top: 0; }
  .steps .m { border-top: 1px solid var(--rule); }
  .index li { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  .site-header, .skip-link, .actions { display: none; }
  .ruled { background: none; }
  a::after { content: " (" attr(href) ")"; font-size: .85em; color: #555; }
}
.more-link { margin-top: 1.2rem; }
