/* Math Drill Pages — one stylesheet for the whole site.
   Look: a clean teacher's resource. Graph-paper blue for links and actions,
   pencil yellow only for the answer highlight, plenty of white for print. */
:root {
  --paper: #fbfcfe;
  --surface: #ffffff;
  --ink: #1b2a41;
  --muted: #5b6b82;
  --line: #dbe2ec;
  --grid: #e9eef6;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0fc;
  --pencil: #f3b531;
  --answer: #b23a2c;
  --f-display: "Lexend", "Segoe UI", system-ui, sans-serif;
  --f-body: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111824; --surface: #182233; --ink: #e6ecf5; --muted: #9daabd; --line: #2b384d; --grid: #1f2a3c;
    --accent: #7aa7ff; --accent-ink: #0d1626; --accent-soft: #1d2b45; --pencil: #e8b23e; --answer: #ff8a7a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 18px; line-height: 1.6; }
img { max-width: 100%; }
a { color: var(--accent); }
a:focus-visible, .btn:focus-visible, summary:focus-visible, input:focus-visible { outline: 3px solid var(--pencil); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--f-display); line-height: 1.2; text-wrap: balance; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin: 0 0 .5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.4rem; margin: 2.2rem 0 .8rem; }
h3 { font-size: 1.1rem; margin: 0 0 .4rem; }
p { margin: 0 0 1rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding-left: max(18px, env(safe-area-inset-left)); padding-right: max(18px, env(safe-area-inset-right)); }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.nowrap { white-space: nowrap; user-select: all; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 68ch; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* Header and footer */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-block: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; }
.site-header nav { display: flex; gap: 20px; flex-wrap: wrap; }
.site-header nav a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: .98rem; }
.site-header nav a:hover { color: var(--accent); }
.crumbs ol { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 14px 0 0; margin: 0; font-size: .92rem; color: var(--muted); }
.crumbs li + li::before { content: "›"; margin-right: 6px; }
.crumbs a { color: var(--muted); }
main { padding-bottom: 56px; }
.site-footer { border-top: 1px solid var(--line); background: var(--surface); padding-block: 32px 24px; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 24px; margin-bottom: 16px; }
.footer-grid ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.footer-brand { font-family: var(--f-display); font-weight: 700; margin-bottom: .3rem; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px; border-radius: var(--radius); border: 2px solid var(--accent); color: var(--accent); background: var(--surface); text-decoration: none; font-weight: 600; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn:hover { filter: brightness(1.06); }

/* Page head */
.page-head { padding-top: 22px; }
.facts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 1rem 0 0; }
.facts div { min-width: 0; }
.facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

/* Download */
.download { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 1.6rem 0; padding: 18px; background: var(--accent-soft); border-radius: var(--radius); }
.download p { flex-basis: 100%; margin: 0; }

/* Worksheet preview: a sheet of paper on a faint grid */
.sheet { margin: 2rem 0; }
.sheet-bar { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.sheet-bar h2 { margin: 0 0 .6rem; }
.toggle { font-weight: 600; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }
.paper { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 26px 28px; box-shadow: 0 1px 0 var(--line), 0 10px 24px -18px rgba(27,42,65,.35);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
.paper h3 { font-size: 1rem; margin: 1.2rem 0 .6rem; }
.paper h3:first-child { margin-top: 0; }
.paper h3 span { font-family: var(--f-body); font-weight: 400; color: var(--muted); font-size: .92rem; margin-left: 6px; }
.problems { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 24px; padding-left: 2.2em; margin: 0; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.problems li { padding-left: 4px; white-space: nowrap; }
.problems li::marker { color: var(--muted); font-size: .8rem; }
.problems.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.problems.stacked { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 22px 24px; }
.stack { display: inline-grid; justify-items: end; font-size: 1.25rem; line-height: 1.35; vertical-align: top; }
.stack > span:nth-child(2) { border-bottom: 2px solid var(--ink); padding-left: .4em; width: 100%; text-align: right; }
.stack .op { float: left; margin-right: .5em; }
.stack .ans { min-height: 1.35em; }
.blank.short { min-width: 1.8em; }
.blank { display: inline-block; min-width: 2.6em; border-bottom: 1.5px solid var(--ink); text-align: center; vertical-align: baseline; }
.ans { visibility: hidden; color: var(--answer); font-weight: 700; }
.sheet:has(#show-answers:checked) .ans, .ans.show { visibility: visible; }

/* Body copy */
.columns { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 40px; }
.prose { max-width: 70ch; }
.prose.narrow { padding-top: 22px; }
.tips { padding-left: 1.2em; display: grid; gap: .6rem; }
.related { align-self: start; border-left: 3px solid var(--accent-soft); padding-left: 20px; }
.related ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.faq details { border-bottom: 1px solid var(--line); padding: 14px 0; max-width: 70ch; }
.faq summary { font-weight: 600; cursor: pointer; }
.faq details p { margin: .6rem 0 0; }
.contact-list { display: grid; gap: 14px; }
.contact-list dt { font-weight: 600; }
.contact-list dd { margin: 0; }

/* Cards */
.cards { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.cards-compact { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.card a { display: flex; flex-direction: column; gap: 4px; height: 100%; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.card a:hover { border-color: var(--accent); }
.card strong { font-family: var(--f-display); font-weight: 600; }
.card span { color: var(--muted); font-size: .92rem; }

/* Guide */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 24px; }
.guide-grid p { color: var(--muted); }

/* Home hero */
.hero { background: var(--surface); border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.hero-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 40px; align-items: center; padding-block: 48px; }
.hero-sheet { background: var(--paper); border: 1px solid var(--line); border-radius: 4px; padding: 22px 26px; transform: rotate(-1.5deg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 24px 24px; }
.hero-sheet-title { font-family: var(--f-display); font-weight: 600; margin-bottom: .6rem; }
.hero-sheet ol { margin: 0; padding-left: 1.6em; display: grid; gap: 12px; font-size: 1.25rem; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  body { font-size: 17px; }
  .columns, .hero-grid, .footer-grid { grid-template-columns: 1fr; }
  .problems, .problems.stacked { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .problems.wide { grid-template-columns: 1fr; }
  .paper { padding: 18px 16px; }
  .hero-sheet { transform: none; }
  .related { border-left: 0; padding-left: 0; }
}
@media (max-width: 400px) {
  .problems:not(.stacked) { grid-template-columns: 1fr; }
}
@media print {
  .site-header, .site-footer, .crumbs, .download, .toggle { display: none; }
}
