/* ==========================================================================
   House style: "hybrid with hand-drawn cards"
   Loaded after each page's own CSS, so it sets the shared look everywhere:
   tokens, header, footer, buttons, and hand-drawn outlines on boxes.
   Buttons and form controls stay crisp; cards and boxes wobble.
   The worksheets themselves (.sheet) are never restyled.
   ========================================================================== */

:root {
  --bg: #FBF7EE; --panel: #FFFFFF; --fg: #1F2340; --muted: #555A73; --line: #E6DECC; --chip: #F1EADB;
  --die: #E2483D; --pop: #C9372C; --on-pop: #FFFFFF; --pen: #35577A; --hl: #F4B63F;
  --accent: #1F2340; --on-accent: #FBF7EE;
  --sun: #FDEBC0; --sun-ink: #6B4A00; --teal: #D9EFEB; --teal-ink: #1E5E59; --ochre: #F3E2CF; --ochre-ink: #8A3B12;
  --navy-band: #1F2340; --on-navy: #FBF7EE; --on-navy-muted: #C6C8D8;
  --draft: #FFF1C2; --draft-ink: #6B4A00;
  --tape: rgba(244,182,63,.65); --mini-paper: #FFFFFF; --mini-ink: #1F2340;
  --display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
  --ui: 'Nunito', system-ui, sans-serif;
  --hand: 'Kalam', 'Segoe Print', 'Comic Sans MS', cursive;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161A2E; --panel: #1F2440; --fg: #F3EEE2; --muted: #B4B7CC; --line: #343A5E; --chip: #2A3052;
    --pop: #F06A5E; --on-pop: #161A2E; --pen: #9DC0E6; --hl: #C98F1E;
    --accent: #F3EEE2; --on-accent: #161A2E;
    --sun: #3B3216; --sun-ink: #F5D77A; --teal: #183634; --teal-ink: #9DDCD2; --ochre: #3A2A22; --ochre-ink: #F2B48C;
    --navy-band: #0F1222; --on-navy: #F3EEE2; --on-navy-muted: #B4B7CC;
    --draft: #3B3216; --draft-ink: #F5D77A; --tape: rgba(201,143,30,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #161A2E; --panel: #1F2440; --fg: #F3EEE2; --muted: #B4B7CC; --line: #343A5E; --chip: #2A3052;
  --pop: #F06A5E; --on-pop: #161A2E; --pen: #9DC0E6; --hl: #C98F1E;
  --accent: #F3EEE2; --on-accent: #161A2E;
  --sun: #3B3216; --sun-ink: #F5D77A; --teal: #183634; --teal-ink: #9DDCD2; --ochre: #3A2A22; --ochre-ink: #F2B48C;
  --navy-band: #0F1222; --on-navy: #F3EEE2; --on-navy-muted: #B4B7CC;
  --draft: #3B3216; --draft-ink: #F5D77A; --tape: rgba(201,143,30,.6);
  color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--ui); font-size: 17px; line-height: 1.55; }
a { color: var(--pop); }
a:hover { color: var(--fg); }
.band { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.inner { max-width: 1160px; margin: 0 auto; }
h1, h2, h3 { margin: 0; font-family: var(--display); line-height: 1.1; text-wrap: balance; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 50; background: var(--panel); color: var(--fg); padding: 10px 14px; border: 2px solid var(--fg); border-radius: 10px; font-weight: 800; }
.skip:focus { left: 16px; }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; }

/* ---------- Header, with a hand-drawn rule under it ---------- */
.site { border-bottom: 0 !important; padding-block: 14px; position: relative; background: transparent; }
.site .inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; }
.site::after { content: ""; position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); bottom: -3px; height: 8px; background: var(--fg); opacity: .55; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='8' viewBox='0 0 400 8'%3E%3Cpath d='M0 4.2 C40 3.1 70 5.2 110 4 S190 2.9 230 4.6 S320 5.4 360 3.8 S390 3.9 400 4.2' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 400px 8px; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='8' viewBox='0 0 400 8'%3E%3Cpath d='M0 4.2 C40 3.1 70 5.2 110 4 S190 2.9 230 4.6 S320 5.4 360 3.8 S390 3.9 400 4.2' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 400px 8px; }
.logo { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--fg); text-decoration: none; letter-spacing: -.02em; }
.logo:hover { color: var(--fg); }
.logo .amp { color: var(--die); }
.site nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 22px; font-weight: 700; }
.site nav a { color: var(--fg); text-decoration: none; padding: 8px 0; display: inline-block; font-family: var(--ui); font-size: 17px; }
.site nav a:hover, .site nav a[aria-current] { box-shadow: inset 0 -3px 0 var(--die); }

/* ---------- Footer ---------- */
.site-foot { border-top: 0; padding-block: 34px 40px; margin-top: 56px; color: var(--muted); font-size: 15px; position: relative; }
.site-foot::before { content: ""; position: absolute; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); top: 0; height: 8px; background: var(--fg); opacity: .3; -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='8' viewBox='0 0 400 8'%3E%3Cpath d='M0 4.2 C40 3.1 70 5.2 110 4 S190 2.9 230 4.6 S320 5.4 360 3.8 S390 3.9 400 4.2' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 400px 8px; mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='8' viewBox='0 0 400 8'%3E%3Cpath d='M0 4.2 C40 3.1 70 5.2 110 4 S190 2.9 230 4.6 S320 5.4 360 3.8 S390 3.9 400 4.2' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 400px 8px; }
.site-foot .inner { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px 32px; }
.site-foot b { display: block; font-family: var(--display); font-size: 18px; color: var(--fg); margin-bottom: 4px; }
.site-foot ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.site-foot a { color: var(--fg); font-weight: 700; text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }
.site-foot .small { grid-column: 1 / -1; font-size: 13px; margin: 0; }

/* ---------- Shared pieces ---------- */
.hl { position: relative; z-index: 0; padding: 0 .1em; white-space: nowrap; }
.hl::before { content: ""; position: absolute; z-index: -1; left: 0; right: 0; bottom: .08em; height: .42em; background: var(--hl); clip-path: polygon(1% 18%, 30% 8%, 70% 6%, 99% 14%, 98% 92%, 66% 84%, 30% 88%, 2% 98%); }
.pen { font-family: var(--hand); color: var(--pen); }
.stamp-line { display: inline-block; border: 2px solid var(--pen); color: var(--pen); padding: 3px 12px; font-weight: 800; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; border-radius: 4px; transform: rotate(-1.5deg); }
.inked, .subject { position: relative; isolation: isolate; border-radius: 16px; --fill: var(--panel); }
.inked::before, .inked::after, .subject::before, .subject::after { content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none; }
.inked::before, .subject::before { background: var(--fill); border: 2px solid var(--fg); z-index: 0; }
.inked::after, .subject::after { background: var(--fg); transform: translate(4px, 4px); z-index: -1; }
.inked > *, .subject > * { position: relative; z-index: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px; border-radius: 12px; font: 800 17px/1 var(--ui); text-decoration: none; cursor: pointer; border: 2px solid var(--fg); }
.btn.red { background: var(--pop); color: var(--on-pop); border-color: var(--pop); box-shadow: 3px 3px 0 var(--fg); }
.btn.ink { background: var(--fg); color: var(--bg); }
.btn.plain { background: var(--panel); color: var(--fg); box-shadow: 3px 3px 0 var(--fg); }
.btn:hover { transform: translate(-1px, -1px); }
.open { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 10px; background: var(--sun); color: var(--sun-ink); font-weight: 800; font-size: 14px; text-decoration: none; border: 1.5px solid var(--fg); align-self: flex-start; }
.open:hover { color: var(--sun-ink); background: var(--hl); }
.icon { flex: none; color: var(--fg); }

/* ---------- Section pages (Maths, English, Topics, For parents, All printables) ---------- */
.hub-hero { padding-block: 40px 8px; }
.hub-hero h1 { font-weight: 800; font-size: clamp(36px, 5vw, 54px); letter-spacing: -.02em; margin-top: 12px; }
.hub-hero p { font-size: 19px; max-width: 60ch; margin: 12px 0 0; }
.crumb { font-size: 14px; font-weight: 700; color: var(--muted); margin: 0; }
.crumb a { color: inherit; }
.hub-sec { padding-block: 26px; }
.hub-sec h2 { font-size: clamp(26px, 3.4vw, 32px); font-weight: 800; display: flex; align-items: center; gap: 10px; }
.hub-sec h2 a { color: inherit; text-decoration: none; }
.mcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 20px; margin-top: 18px; }
.mcard { display: flex; gap: 14px; padding: 18px; min-height: 150px; text-decoration: none; color: var(--fg); }
.mcard > div { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.mcard h3 { font-size: 20px; font-weight: 800; }
.mcard p { margin: 0; font-size: 15px; color: var(--muted); }
.mcard .open { margin-top: auto; }
.mcard:hover::before { border-width: 3px; }
.mcard.s-maths { --fill: var(--sun); } .mcard.s-english { --fill: var(--teal); } .mcard.s-topics { --fill: var(--ochre); }
.prose { max-width: 70ch; }
.prose h2 { font-size: 28px; font-weight: 800; margin: 30px 0 8px; }
.prose p, .prose li { font-size: 18px; }
.todo { background: var(--draft); color: var(--draft-ink); padding: 0 .3em; border-radius: 4px; font-weight: 700; }

/* ==========================================================================
   Skin for the maker and topic pages (body.pg): the same hand-drawn
   outlines on their boxes, crisp buttons with an ink shadow.
   ========================================================================== */
.pg .gen-box, .pg .card, .pg .quick, .pg details, .pg .fs-cta, .pg .family, .pg .pk, .pg .step, .pg .way, .pg .callout, .pg .tcard {
  position: relative; isolation: isolate; border-color: transparent !important; background: transparent !important; box-shadow: none !important;
  --fill: var(--panel); --sh: 4px;
}
.pg .gen-box::before, .pg .card::before, .pg .quick::before, .pg details::before, .pg .fs-cta::before, .pg .family::before, .pg .pk::before, .pg .step::before, .pg .way::before, .pg .callout::before, .pg .tcard::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--fill); border: 2px solid var(--fg); z-index: -1; pointer-events: none;
}
.pg .gen-box::after, .pg .card::after, .pg .quick::after, .pg details::after, .pg .fs-cta::after, .pg .family::after, .pg .pk::after, .pg .step::after, .pg .way::after, .pg .callout::after, .pg .tcard::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--fg); transform: translate(var(--sh), var(--sh)); z-index: -2; pointer-events: none;
}
.pg .step, .pg .callout, .pg details { --sh: 3px; }
.pg .callout { --sh: 0px; }
.pg .callout::before { border-width: 1.5px; }
.pg .fs-cta { --fill: var(--sun); color: var(--sun-ink); }
.pg .family, .pg .callout { --fill: var(--ochre); }
.pg details[open] { --fill: var(--panel); }
/* the topic page's sections share some class names: keep those plain */
.pg section.gen, .pg section.pack { isolation: auto; }
.pg section.gen::before, .pg section.gen::after, .pg section.pack::before, .pg section.pack::after { display: none !important; }

/* Highlighter on the red word in page titles, pen colour for side notes */
.pg .hero h1 .red, .pg .hero h1 em { color: inherit !important; font-style: normal; position: relative; z-index: 0; padding: 0 .08em; }
.pg .hero h1 .red::before, .pg .hero h1 em::before { content: ""; position: absolute; z-index: -1; left: 0; right: 0; bottom: .06em; height: .42em; background: var(--hl); clip-path: polygon(1% 18%, 30% 8%, 70% 6%, 99% 14%, 98% 92%, 66% 84%, 30% 88%, 2% 98%); }
.pg .tag { background: var(--panel); color: var(--fg); border: 1.5px solid var(--fg); }
.pg .step .n { border: 2px solid var(--fg); }

/* Buttons stay crisp, with a small ink shadow */
.pg main button:not(:disabled), .pg .jump a { box-shadow: 3px 3px 0 var(--fg); border: 2px solid var(--fg) !important; }
.pg main button { border-color: var(--fg); }
.pg main button.ghost, .pg .jump a:not(.main) { background: var(--panel) !important; color: var(--fg) !important; }
.pg .family button.ghost { color: var(--fg) !important; }
.pg main button:not(:disabled):hover, .pg .jump a:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--fg); }
.pg main button:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; border: 2px dashed var(--fg) !important; background: transparent !important; color: var(--fg) !important; }
.pg .chips label { border: 1.5px solid var(--fg); background: var(--panel); box-shadow: 2px 2px 0 var(--fg); }
.pg .chips input:checked + label { background: var(--sun); color: var(--sun-ink); }
.pg .chips input:focus-visible + label { outline: 3px solid var(--pen); outline-offset: 2px; }
.pg .fs-btns button[aria-pressed="true"] { background: var(--fg) !important; color: var(--bg) !important; }
.print-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }

/* The worksheets keep their own look */
.sheet button { box-shadow: none !important; }

/* ==========================================================================
   Printing: house.js copies the chosen sheets into #print-root
   ========================================================================== */
#print-root { display: none; }
@media print {
  @page { size: A4 portrait; margin: 0; }
  html, body { background: #FFFFFF !important; margin: 0 !important; padding: 0 !important; }
  body.printing > :not(#print-root) { display: none !important; }
  body.printing #print-root { display: block; }
  #print-root .sheet { position: relative !important; transform: none !important; box-shadow: none !important; margin: 0 !important; break-after: page; page-break-after: always; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* A4 is 1122.5 x 793.7 CSS px: clip half a pixel so a sheet never spills onto a blank page */
  #print-root .sheet { width: 793px !important; height: 1122px !important; overflow: hidden !important; }
  #print-root.wide .sheet { width: 1122px !important; height: 793px !important; }
  #print-root .sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ==========================================================================
   Phone menu: a Menu button opens the links in a hand-drawn panel.
   Without JavaScript the links simply stay visible.
   ========================================================================== */
.site .menu-btn { display: none; }
@media (max-width: 760px) {
  .js .site .inner { flex-wrap: nowrap; position: relative; }
  .js .site .menu-btn {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; margin: 0;
    border: 2px solid var(--fg); border-radius: 12px; background: var(--panel); color: var(--fg);
    box-shadow: 3px 3px 0 var(--fg); font: 800 16px/1 var(--ui); cursor: pointer; flex: none;
  }
  .js .site .menu-btn:hover { background: var(--panel); color: var(--fg); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--fg); }
  .js .site .menu-btn[aria-expanded="true"] { background: var(--sun); color: var(--sun-ink); }
  .site .bars { display: inline-flex; flex-direction: column; gap: 4px; width: 18px; }
  .site .bars i { display: block; height: 2.5px; border-radius: 2px; background: currentColor !important; transition: transform .2s, opacity .2s; }
  .menu-btn[aria-expanded="true"] .bars i:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
  .menu-btn[aria-expanded="true"] .bars i:nth-child(2) { opacity: 0; }
  .menu-btn[aria-expanded="true"] .bars i:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }
  .js .site nav { display: none; position: absolute; z-index: 40; top: calc(100% + 12px); left: 0; right: 0; isolation: isolate; padding: 8px 6px; border-radius: 16px; }
  .js .site nav.open { display: block; }
  .js .site nav::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--panel); border: 2px solid var(--fg); z-index: -1; }
  .js .site nav::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--fg); transform: translate(4px, 4px); z-index: -2; }
  .js .site nav ul { flex-direction: column; gap: 0; }
  .js .site nav a { display: block; padding: 13px 16px; font-size: 19px; border-radius: 10px; }
  .js .site nav a:hover, .js .site nav a[aria-current] { box-shadow: none; background: var(--sun); color: var(--sun-ink); }
  .js .site nav li + li { border-top: 1.5px dashed var(--line); }
}
@media (prefers-reduced-motion: reduce) { .site .bars i { transition: none; } }
@media print { .site .menu-btn { display: none !important; } }

/* ---------- Cookie choice (scripts/consent.js): Accept and Reject look the same ---------- */
.consent { position: fixed; z-index: 60; left: max(16px, env(safe-area-inset-left, 0px)); right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); max-width: 560px; margin: 0 auto; padding: 14px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; isolation: isolate; border-radius: 16px; color: var(--fg); font-family: var(--ui); }
.consent::before { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--panel); border: 2px solid var(--fg); z-index: -1; }
.consent::after { content: ""; position: absolute; inset: 0; border-radius: inherit; background: var(--fg); transform: translate(4px, 4px); z-index: -2; }
.consent p { flex: 1 1 260px; margin: 0; font-size: 15px; line-height: 1.45; }
.consent-btns { display: flex; gap: 10px; }
.consent-btn { min-height: 44px; padding: 0 18px; border: 2px solid var(--fg) !important; border-radius: 12px; background: var(--panel) !important; color: var(--fg) !important; box-shadow: 3px 3px 0 var(--fg); font: 800 15px/1 var(--ui); cursor: pointer; }
.consent-btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--fg); }
@media print { .consent { display: none !important; } }

/* A sheet-shaped placeholder for the moment before a maker page builds its first sheet */
.pg .preview:empty:not([hidden]) { display: flex; align-items: center; justify-content: center; aspect-ratio: 210 / 297; width: 100%; max-width: 794px; border: 2px dashed var(--line); border-radius: 8px; background: var(--panel); }
.pg .preview:empty:not([hidden])::after { content: "Making your sheet…"; font-family: var(--hand); font-size: 22px; color: var(--pen); }

/* ==========================================================================
   Maker (house.js): an example image until an option is picked
   ========================================================================== */
.maker-sample { position: relative; margin: 0; width: 100%; max-width: 794px; }
.maker-sample img { display: block; width: 100%; height: auto; aspect-ratio: 794 / 1123; background: #FFFFFF; border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 6px 24px rgba(0,0,0,.10); opacity: .9; }
.maker-sample figcaption { position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%) rotate(-1.5deg); width: min(88%, 440px); background: var(--panel); color: var(--fg); border: 2px solid var(--fg); border-radius: 12px; box-shadow: 3px 3px 0 var(--fg); padding: 10px 14px 12px; font-size: 15px; line-height: 1.4; text-align: center; }
.maker-sample figcaption .pen { display: block; font-size: 21px; line-height: 1.1; margin-bottom: 2px; }
@media print { .maker-sample { display: none !important; } }

/* Drawn outlines (house.js): once a box is drawn, its plain border and shadow
   are swapped for the hand-drawn pictures in --hd-o and --hd-s */
.drawn::before, .drawn::after { inset: -3px !important; border: 0 !important; border-radius: 0 !important; background-color: transparent !important; background-repeat: no-repeat !important; background-position: 0 0 !important; background-size: 100% 100% !important; }
.drawn::before { background-image: var(--hd-o) !important; }
.drawn::after { background-image: var(--hd-s) !important; }
