/* The look of mathslikeanengineer.com: Nunito, navy and orange, cream
   background, rounded cards. Self-hosted fonts, no inline styles (CSP). */

@font-face { font-family: Nunito; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/nunito-400.woff2) format('woff2'); }
@font-face { font-family: Nunito; font-style: normal; font-weight: 700; font-display: swap; src: url(fonts/nunito-700.woff2) format('woff2'); }
@font-face { font-family: Nunito; font-style: normal; font-weight: 800; font-display: swap; src: url(fonts/nunito-800.woff2) format('woff2'); }
@font-face { font-family: Nunito; font-style: normal; font-weight: 900; font-display: swap; src: url(fonts/nunito-900.woff2) format('woff2'); }

:root {
  --blue: #01B1FA; --green: #03B15A; --sun: #FFAA6E; --link: #C2410C; --navy: #16213E;
  --orange: #EA580C; --brandink: #16213E; --ok: #028A46;
  --ink: #2D3436; --muted: #636E72; --bg: #FAF7F0; --surface: #fff; --line: #F0E6D6; --soft: #FFF3DF;
  --shadow: 0 1px 2px rgba(60,40,10,.05), 0 8px 24px rgba(60,40,10,.08);
  --shadow-lg: 0 4px 10px rgba(60,40,10,.08), 0 22px 48px rgba(60,40,10,.16);
  --r: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ECECEC; --muted: #A3ADB5; --bg: #11151C; --surface: #1A212B; --line: #2A3340; --soft: #222B37;
    --link: #FFAA6E; --brandink: #FAF7F0; --ok: #3DD68C;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.28);
    --shadow-lg: 0 4px 10px rgba(0,0,0,.35), 0 22px 48px rgba(0,0,0,.45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } * { transition: none !important; } }
body {
  margin: 0; font-family: Nunito, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink); line-height: 1.6; background: var(--bg); font-size: 16.5px;
}
a { color: var(--link); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px; }
h1, h2 { line-height: 1.15; letter-spacing: -.01em; }
h1 { font-size: clamp(30px, 5vw, 50px); font-weight: 900; margin: 12px 0 14px; }
h2 { font-size: clamp(22px, 3vw, 28px); font-weight: 900; margin: 56px 0 18px; scroll-margin-top: 88px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(1.5) blur(12px); -webkit-backdrop-filter: saturate(1.5) blur(12px);
}
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 900; font-size: 21px; letter-spacing: -.02em; }
.brand svg { width: 38px; height: 38px; border-radius: 50%; flex: none; }
.brand .name { color: var(--brandink); }
.topnav { display: flex; gap: 4px; align-items: center; }
.topnav a { text-decoration: none; color: var(--muted); font-weight: 800; font-size: 15px; padding: 8px 14px; border-radius: 999px; }
.topnav a:hover { background: var(--soft); color: var(--ink); }
.topnav a.app { background: #C2410C; color: #fff; box-shadow: 0 4px 14px rgba(194,65,12,.3); }
.topnav a.app:hover { background: #9A3412; color: #fff; }

/* Layout: settings on the left, the worksheet on the right */
.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 32px; align-items: start; padding-top: 28px; }
#make { scroll-margin-top: 84px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 22px; }
aside h1 { font-size: 25px; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 0; font-size: 14.5px; line-height: 1.45; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
aside fieldset, aside .legend { margin-top: 20px; }
aside legend, aside .legend { display: block; padding: 0; margin-bottom: 8px; font-size: 13px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.legend .note { text-transform: none; letter-spacing: 0; font-weight: 700; margin-left: 4px; }

/* Topics: compact buttons, each a checkbox, filled with the topic colour when
   picked. The colours are dark enough for white 13.5px text (WCAG AA, 4.5:1). */
.topics { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.topics legend { grid-column: 1 / -1; }
.tile {
  --c: #16213E;
  position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 12px;
  background: var(--soft); color: var(--ink); border: 2px solid transparent;
  cursor: pointer; user-select: none; transition: background .15s, border-color .15s;
}
.tile:hover { border-color: var(--c); }
.tile input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tile:has(input:checked) { background: var(--c); color: #fff; }
.tile:has(input:focus-visible) { outline: 3px solid var(--orange); outline-offset: 2px; }
.tile .badge { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; line-height: 1; background: var(--surface); }
.tile .name { font-size: 13.5px; font-weight: 800; line-height: 1.2; }

.t-addition { --c: #A95A00; }
.t-subtraction { --c: #C8202A; }
.t-multiplication { --c: #1368DB; }
.t-division { --c: #986108; }
.t-times_tables { --c: #6C31F4; }
.t-fractions { --c: #D23400; }
.t-percentages { --c: #4536A3; }
.t-order_of_operations { --c: #B0106A; }
.t-linear_equations { --c: #007070; }
.t-word_problems { --c: #02753A; }

.segments { display: inline-flex; flex-wrap: wrap; gap: 4px; background: var(--soft); border-radius: 16px; padding: 4px; }
.segments label { position: relative; }
.segments input { position: absolute; opacity: 0; }
.segments span { display: block; padding: 9px 14px; border-radius: 12px; font-weight: 800; cursor: pointer; color: var(--muted); }
.segments input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segments input:focus-visible + span { outline: 3px solid var(--orange); outline-offset: 1px; }
input[type="number"], select {
  font: inherit; font-weight: 800; color: var(--ink); background: var(--surface);
  border: 2px solid var(--line); border-radius: 12px; padding: 8px 10px;
}
input[type="number"] { width: 5.2em; }
input[type="number"]:focus, select:focus { border-color: var(--orange); outline: none; }
.note { font-size: 13.5px; color: var(--muted); }
.switches { display: grid; gap: 9px; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 700; font-size: 14.5px; }
.switch input { appearance: none; -webkit-appearance: none; flex: none; width: 44px; height: 26px; margin: 0; border-radius: 999px; background: var(--line); position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { transform: translateX(18px); }
.choices-count { margin: -2px 0 2px 56px; font-size: 14.5px; color: var(--muted); font-weight: 700; }
.choices-count select { padding: 3px 6px; margin: 0 4px; }
select:disabled { opacity: .5; }

/* Buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 22px 0 0; }
.actions .primary { grid-column: 1 / -1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 14px; border-radius: 12px;
  font: inherit; font-weight: 900; font-size: 15.5px; border: 2px solid transparent; cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}
.btn:hover { transform: translateY(-2px); }
.btn.primary { background: linear-gradient(135deg, #C2410C, #9A3412); color: #fff; box-shadow: 0 8px 20px -6px rgba(194,65,12,.55); }
.btn.secondary { background: var(--surface); color: var(--link); border-color: color-mix(in srgb, var(--orange) 55%, var(--line)); }
.btn.secondary:hover { background: var(--soft); }
.btn svg { width: 18px; height: 18px; flex: none; }
.status { min-height: 1.6em; margin: 8px 0 0; font-size: 14.5px; font-weight: 800; color: var(--ok); }

.facts { list-style: none; margin: 8px 0 0; padding: 14px 0 0; border-top: 1px solid var(--line); display: grid; gap: 6px; font-size: 13.5px; font-weight: 700; color: var(--muted); }
.facts span { margin-right: 6px; }

/* The worksheet: a sheet of A4 paper on screen, always black on white */
.sheet {
  background: #fff; color: #000; max-width: 210mm; margin: 0; padding: 16mm 15mm;
  border-radius: 10px; box-shadow: var(--shadow-lg);
  font-size: 16px; line-height: 1.5;
}
.sheet h1 { margin: 0 0 8px; font-size: 1.55rem; font-weight: 900; color: #16213E; }
.sheet h2 { margin: 0 0 12px; font-size: 1.3rem; font-weight: 900; color: #16213E; }
.name-date { display: flex; gap: 24px; margin: 0 0 20px; color: #333; font-weight: 700; }
.name-date span { flex: 1; border-bottom: 1.5px solid #555; padding-bottom: 2px; }
.questions, .key { margin: 0; padding-left: 1.9em; }
.questions > li { margin-bottom: 16px; break-inside: avoid; }
.questions > li::marker, .key > li::marker { font-weight: 900; color: #16213E; }
.questions .prompt { margin: 0; }
.answer-line { display: block; width: 45%; min-width: 160px; height: 1.7em; border-bottom: 1px solid #777; }
.choices { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 28px; }
.choices b { margin-right: 6px; }
.answer-key { margin-top: 32px; padding-top: 20px; border-top: 2px dashed #ccc; }
.key > li { margin-bottom: 8px; break-inside: avoid; }
.key .steps { margin: 4px 0 0; padding-left: 1.2em; color: #333; font-size: .95em; }

/* App promotion, as on mathslikeanengineer.com */
.cta { margin: 32px 0 0; border-radius: var(--r); padding: 22px 24px; color: #fff; display: grid; grid-template-columns: auto 1fr auto; gap: 20px; align-items: center; background: linear-gradient(135deg, #0195D7, #03A251); box-shadow: var(--shadow); max-width: 210mm; }
.cta > svg { width: 56px; height: 56px; border-radius: 16px; box-shadow: 0 0 0 4px rgba(255,255,255,.35); }
.cta h2 { margin: 0 0 4px; font-size: 19px; color: #fff; }
.cta p { margin: 0; opacity: .95; font-size: 14.5px; line-height: 1.45; }
.stores { display: flex; flex-direction: column; gap: 10px; }
.store { display: inline-flex; align-items: center; gap: 8px; background: #0b1114; color: #fff; text-decoration: none; border-radius: 13px; padding: 7px 14px 7px 11px; border: 1px solid rgba(255,255,255,.2); line-height: 1.15; transition: transform .15s; }
.store:hover { transform: translateY(-2px); }
.store svg { width: 24px; height: 24px; flex: none; }
.store small { display: block; font-size: 11px; opacity: .85; font-weight: 700; }
.store b { font-size: 15px; font-weight: 900; }

footer { margin-top: 56px; background: var(--surface); border-top: 1px solid var(--line); }
footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 14px; padding-top: 26px; padding-bottom: 30px; font-size: 14.5px; color: var(--muted); }
footer .brand { font-size: 17px; }
footer .brand svg { width: 30px; height: 30px; }
footer nav a { color: var(--muted); margin-left: 18px; font-weight: 700; }
footer nav a:first-child { margin-left: 0; }

@media (max-width: 1100px) {
  .cta { grid-template-columns: auto 1fr; }
  .cta .stores { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; }
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; gap: 24px; padding-top: 20px; }
}
@media (max-width: 560px) {
  body { font-size: 16px; }
  .brand { font-size: 15px; white-space: nowrap; }
  .topnav a.hide-sm { display: none; }
  .topnav a.app { padding: 8px 12px; font-size: 14px; white-space: nowrap; }
  .panel { padding: 18px; }
  .actions { grid-template-columns: 1fr; }
  .sheet { padding: 22px 16px; }
  .cta { grid-template-columns: 1fr; }
  .answer-line { width: 80%; }
  footer nav a { margin-left: 12px; }
}

/* Printing: only the worksheet, on A4, with the answer key on its own page. */
@page { size: A4; margin: 15mm; }
@media print {
  body { background: #fff; color: #000; }
  .no-print, .topbar, footer, .cta { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  .sheet { box-shadow: none; padding: 0; max-width: none; border-radius: 0; }
  .answer-key { break-before: page; margin-top: 0; padding-top: 0; border-top: none; }
}
