/* Math Detours — shared styles (screen + print) */
:root {
  --ink: #1d1f3a;
  --muted: #5d6079;
  --paper: #fffdf8;
  --bg: #f4f1ea;
  --accent: #3f44c9;
  --accent-soft: #e6e7fb;
  --warm: #f5a524;
  --warm-soft: #fff1d6;
  --rule: #d9d6cc;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 17px; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .4em; font-weight: 800; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.35rem; margin-top: 1.4em; }
h3 { font-size: 1.1rem; margin-top: 1.2em; }
p, li { margin: 0 0 .7em; }
code, .mono { font-family: var(--mono); font-size: .92em; background: #eeece6; padding: .05em .3em; border-radius: 4px; }
table { border-collapse: collapse; margin: .6em 0 1em; }
td, th { border: 1px solid var(--rule); padding: .25em .55em; text-align: center; }
th { background: var(--accent-soft); }

/* Top nav */
nav.top {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: .8rem 1.2rem; background: var(--paper); border-bottom: 1px solid var(--rule);
}
nav.top .brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--ink); display: flex; align-items: center; gap: .45rem; }
/* The logo mark: the span keeps its text for screen readers and old caches; the picture is drawn over it. */
.inf { display: inline-block; width: 1em; height: 1em; background: url(logo.svg) center / contain no-repeat; color: transparent; overflow: hidden; user-select: none; }
nav.top .brand .inf { font-size: 2rem; line-height: 1; }
nav.top a:not(.brand) { text-decoration: none; color: var(--muted); font-weight: 700; }
nav.top a:not(.brand):hover { color: var(--accent); }
nav.top .spacer { flex: 1; }
nav.top button { font: inherit; font-weight: 700; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .45rem .9rem; cursor: pointer; }
nav.top button.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }

/* Page shells */
main.wrap { max-width: 980px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
main.paper {
  max-width: 760px; margin: 1.5rem auto 3rem; padding: 2rem 2.2rem 2.5rem;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 12px;
  box-shadow: 0 2px 10px rgba(29,31,58,.06);
}
@media (max-width: 600px) { main.paper { padding: 1.3rem 1rem; margin: .8rem .5rem 2rem; } html { font-size: 16px; } }
footer { text-align: center; color: var(--muted); font-size: .9rem; padding: 2rem 1rem 3rem; }

/* Home */
.hero { padding: 2.5rem 1rem 1.5rem; text-align: center; }
.hero h1 { font-size: 2.8rem; }
.hero .inf { font-size: 3.6rem; vertical-align: -0.2em; }
.hero p.tagline { font-size: 1.45rem; font-weight: 800; color: var(--accent); margin: .2rem auto .9rem; }
.hero p.lead { font-size: 1.2rem; color: var(--muted); max-width: 620px; margin: 0 auto 1rem; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin: 1.5rem 0 2rem; }
.steps div { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.1rem; }
.steps b { display: block; font-size: 1.05rem; margin-bottom: .2rem; }
.steps .n { display: inline-block; width: 1.7em; height: 1.7em; line-height: 1.7em; text-align: center; border-radius: 50%; background: var(--warm); color: #fff; font-weight: 800; margin-right: .4em; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin: 1rem 0 2rem; }
.card { display: block; text-decoration: none; color: inherit; background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 1rem 1.1rem; transition: transform .12s, box-shadow .12s; }
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(29,31,58,.10); }
.card .num { font-size: .8rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.card h3 { margin: .15em 0 .3em; }
.card p { color: var(--muted); margin: 0; font-size: .95rem; }
.card.demo .num { color: var(--warm); }
.cards.grades { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.card.grade.live { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.card.grade.soon { opacity: .55; }
.card.grade.soon:hover { transform: none; box-shadow: none; }
.tag { display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: .1em .6em; margin-left: .4em; vertical-align: middle; }

/* Sheets */
.sheet-head .kicker { font-size: .82rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.sheet-head .namebar { display: none; }
.sheet-head .teaser { color: var(--muted); font-size: 1.05rem; margin-top: .2em; }
section.idea { }
section.example { background: var(--warm-soft); border-radius: 10px; padding: .9rem 1.1rem .5rem; margin-top: 1.2rem; }
section.example h2 { margin-top: 0; }
section.exercises ol { padding-left: 1.4em; }
section.exercises li { margin-bottom: .8em; }
.space { display: none; }
section.stretch { border: 2px dashed var(--accent); border-radius: 10px; padding: .8rem 1.1rem .3rem; margin-top: 1.4rem; }
section.stretch h2 { margin-top: 0; }
section.stretch h2::before { content: "★ "; color: var(--warm); }
section.answers { margin-top: 2rem; border-top: 2px solid var(--rule); padding-top: .5rem; }
section.answers.is-hidden { display: none; }
.answers-toggle { margin-top: 2rem; font: inherit; font-weight: 700; background: var(--accent-soft); color: var(--accent); border: 0; border-radius: 8px; padding: .5rem 1rem; cursor: pointer; }
.callout { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: .6rem .9rem; border-radius: 6px; margin: .8em 0; }
.grid100 { display: grid; grid-template-columns: repeat(10, 1fr); gap: 0; max-width: 420px; border: 1px solid var(--ink); margin: .6em 0 1em; }
.grid100 span { border: 1px solid var(--rule); text-align: center; padding: .25em 0; font-size: .92rem; }
figure { margin: 1em 0; text-align: center; }
figure svg { max-width: 100%; height: auto; }
figcaption { font-size: .88rem; color: var(--muted); margin-top: .3em; }
.sheet-nav { display: flex; justify-content: space-between; gap: 1rem; margin: 2rem 0 0; font-weight: 700; }
.small { font-size: .9rem; color: var(--muted); }

/* Demos */
.demo-wrap { max-width: 980px; margin: 1.5rem auto 3rem; padding: 0 1rem; }
.demo-panel { background: var(--paper); border: 1px solid var(--rule); border-radius: 12px; padding: 1.2rem 1.4rem; margin: 1rem 0; }
.controls { display: flex; flex-wrap: wrap; gap: .8rem 1.4rem; align-items: center; margin: .6rem 0 1rem; }
.controls label { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.controls input[type=number] { font: inherit; width: 6em; padding: .25em .4em; border: 1px solid var(--rule); border-radius: 6px; }
.controls input[type=range] { width: 180px; }
.controls button { font: inherit; font-weight: 700; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .45rem .9rem; cursor: pointer; }
.controls button.alt { background: var(--warm); }
.controls button.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
canvas { max-width: 100%; display: block; background: #fff; border: 1px solid var(--rule); border-radius: 8px; }
.readout { font-family: var(--mono); font-size: 1rem; background: #eeece6; border-radius: 8px; padding: .5rem .8rem; margin: .6rem 0; white-space: pre-wrap; }
.explain { max-width: 70ch; }

/* Print */
/* narrow screens: wide tables scroll sideways instead of stretching the page */
@media screen and (max-width: 520px) {
  main.paper table, main.demo-wrap table { display: block; width: max-content; max-width: 100%; overflow-x: auto; }
  .katex-display { overflow-x: auto; overflow-y: hidden; padding: .2em 0; }
  main.paper p, main.paper li, main.paper .callout, main.demo-wrap p { overflow-x: auto; }
}

@media print {
  @page { margin: 1.6cm; }
  html { font-size: 11pt; }
  body { background: #fff; color: #000; }
  nav.top, footer, .answers-toggle, .sheet-nav, .noprint { display: none !important; }
  main.paper { max-width: none; margin: 0; padding: 0; border: 0; box-shadow: none; background: #fff; }
  .sheet-head .namebar { display: flex; justify-content: space-between; margin: .6em 0 1em; padding-bottom: .4em; border-bottom: 1px solid #000; font-size: .95rem; }
  section.example { background: #f3f3f3; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  section.stretch { border-color: #000; margin-top: .9rem; padding: .5rem .9rem .2rem; }
  .callout { background: #f3f3f3; border-left-color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  section.exercises li { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }
  section.example h2 { break-after: auto; } /* otherwise Chrome drags the whole example box to the next page */
  section.exercises li:first-child { break-before: avoid; }
  .space { display: block; height: 2.4cm; margin: .3em 0 .6em; background: repeating-linear-gradient(to bottom, transparent 0, transparent calc(0.8cm - 1px), #cfcfcf calc(0.8cm - 1px), #cfcfcf 0.8cm); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .space.tall { height: 3.2cm; }
  .space.short { height: 1.6cm; }
  section.answers { display: block !important; break-before: page; border-top: 0; }
  section.answers h2::after { content: "  (for whoever is checking)"; font-weight: 400; font-size: .8em; color: #555; }
  a { color: #000; text-decoration: none; }
  figure { break-inside: avoid; }
  section.stretch { break-inside: avoid; }
  section.stretch .space { display: none; }
}

/* Research page */
.study { border-left: 3px solid var(--rule); padding: .1rem 0 .1rem 1rem; margin: 1.1rem 0; }
.study h3 { margin: 0 0 .25rem; font-size: 1.05rem; }
.study .cite { font-size: .92rem; color: var(--muted); margin: 0 0 .4rem; }
.study p { margin: .3rem 0; }
.tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: .1em .55em; border-radius: 999px; background: var(--accent-soft); color: var(--accent); margin-right: .4rem; vertical-align: middle; }
.tag.synth { background: #efe7d6; color: #7a5a1c; }
.tag.quasi { background: #e4efe6; color: #2f6b3a; }
.tag.corr { background: #eeece6; color: #555; }
.research-toc { columns: 2; column-gap: 2rem; font-size: .95rem; }
@media screen and (max-width: 520px) { .research-toc { columns: 1; } }

/* research page folds */
details.fold { margin: .2rem 0 1.4rem; }
details.fold > summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: .35rem 0; list-style-position: inside; }
details.fold > summary:hover { text-decoration: underline; }
details.fold[open] > summary { margin-bottom: .4rem; }
details.fold.howto { border: 1px solid var(--rule); border-radius: 10px; padding: .3rem .9rem; margin: 1rem 0 1.6rem; }
details.fold.howto > summary { color: var(--ink); }

/* research page: one fold per study */
details.study { border-left: 3px solid var(--rule); padding: .05rem 0 .05rem .8rem; margin: .35rem 0; }
details.study > summary { cursor: pointer; list-style-position: inside; padding: .15rem 0; line-height: 1.35; }
details.study > summary .st { font-weight: 700; }
details.study > summary:hover .st { text-decoration: underline; }
details.study > summary .tag { margin-right: .35em; }
details.study[open] { margin: .7rem 0 1.1rem; border-left-color: var(--accent); }
details.study[open] > summary { margin-bottom: .3rem; }
.foldhint { margin: 0 0 .5rem; color: var(--muted); }
