/* ============================================================
   Sprilo — shared design system
   Used by: index.html (landing), portal.html, library.html, lesson.html
   Palette: Ink + Ember (rebrand 2026-07-24) — deep ink-navy anchor, warm
   ember accent, cream paper. Deliberately clear of green-leaf territory.
   ============================================================ */

/* ---------- 1. Tokens ---------- */
:root {
  /* Brand palette — Sprilo (from the spark logo, 2026-07-24) */
  --spark:      #f5b43c;   /* the spark — wordmark "i", eyebrow dots, small accents */
  --spark-soft: #ffd977;   /* spark core / highlights */
  --ember:      #e2643f;   /* warm ember — CTAs, the trailing spark */
  --ember-deep: #c24a28;   /* ember for text on light / hover */
  --ink-deep:   #2c2540;   /* the anchor — primary ink, primary buttons (= logo face) */
  --terra:      #e39a55;   /* the warmth — taglines, secondary CTAs, honey */
  /* Terra as TEXT (2026-09-25, WCAG 2.2 AA): #e39a55 is 2.1:1 on paper, so text
     uses one of these. Fills and borders keep --terra. */
  --terra-display: #c4692a; /* large display accents (Caveat in headings, ≥24px): 3.4:1 on paper */
  --terra-ink:     #a8531a; /* small terra text (kickers, labels, links): 4.7:1 on paper */
  --paper:      #f6f1e4;   /* the page — warm cream */

  /* Ink ramp — drives buttons & pills. Names kept from the old "oak" scale so
     every existing var(--oak-*) reference re-skins to navy with no edits. */
  --oak-900: #171327;
  --oak-800: #201b33;        /* dark surfaces */
  --oak-700: #3d3557;        /* hover state for primary CTA */
  --oak-600: #2c2540;        /* = ink-deep, primary CTA bg */
  --oak-500: #4a4266;
  --oak-400: #6b6288;
  --oak-300: #a49dba;
  --oak-200: #cdc8dc;
  --oak-100: #ece9f2;

  /* Sandstone backgrounds */
  --sand-50:  #fbf7ec;
  --sand-100: #f6f1e4;       /* = paper */
  --sand-200: #efe7d2;
  --sand-300: #e3d6b8;

  /* Ink (navy text family) */
  --ink:       #2c2540;       /* primary text = anchor (= logo face) */
  --ink-soft:  #4a4266;
  --ink-mute:  #544d68;       /* 2026-10-15: 7:1 on paper, the AAA bar for small text (was #655d7b, 5.4:1; before that #6f6885) */
  --ink-faint: #a9a3ba;

  /* Card / surfaces */
  --surface:        #ffffff;
  --surface-warm:   #fdfaf1;
  --surface-sunken: #f1ead4;

  /* Subject accents — used as pill backgrounds & accents per subject */
  --sub-maths:     #3a7a45;     /* forest green */
  --sub-english:   #c25438;     /* terracotta  */
  --sub-reading:   #5b3fa0;     /* ink violet  */
  --sub-science:   #2f7a86;     /* teal        */
  --sub-history:   #8a5a32;     /* sepia       */
  --sub-geography: #c08a2a;     /* ochre       */
  --sub-re:        #7a4380;     /* plum        */
  --sub-pshe:      #c25a8a;     /* rose        */
  --sub-pe:        #d96a44;     /* coral       */
  --sub-mfl:       #4a6ec0;     /* cornflower  */
  --sub-computing: #4a4a52;     /* graphite    */
  --sub-art:       #b8743c;     /* amber       */
  --sub-dt:        #7a5a3a;     /* walnut      */
  --sub-music:     #5a8a6a;     /* sage        */

  /* Semantic */
  --ok:    #3a7a45;
  --warn:  #c08a2a;
  --alert: #c25438;

  /* Type */
  --font-ui:   "Fredoka", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-hand: "Caveat", "Fredoka", cursive;
  --font-read: "Source Serif 4", "Source Serif Pro", Georgia, serif;

  /* Spacing scale */
  --s-1:  4px;
  --s-2:  8px;
  --s-3:  12px;
  --s-4:  16px;
  --s-5:  24px;
  --s-6:  32px;
  --s-7:  48px;
  --s-8:  64px;
  --s-9:  80px;
  --s-10: 120px;

  /* Radius */
  --r-1: 4px;
  --r-2: 8px;
  --r-3: 12px;
  --r-4: 16px;
  --r-5: 22px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-1: 0 1px 2px rgba(40,30,10,0.04), 0 4px 10px -4px rgba(40,30,10,0.10);
  --shadow-2: 0 1px 2px rgba(40,30,10,0.05), 0 18px 30px -16px rgba(40,30,10,0.18);
  --shadow-3: 0 1px 2px rgba(40,30,10,0.06), 0 32px 56px -24px rgba(40,30,10,0.28);

  /* Layout */
  --max-w:      1240px;
  --max-w-read: 720px;
  --header-h:   72px;

  /* Themeable (paper default) */
  --bg:   var(--paper);
  --card: var(--surface);
  --grid: rgba(27, 37, 64, 0.07);
  --show-grid: 1;
}

/* Slate theme (dark) */
[data-theme="blackboard"] {
  --bg:        #1b2436;
  --card:      #26314c;
  --ink:       #f1ead0;
  --ink-soft:  #d8d0b4;
  --ink-mute:  #aab3c4;
  --ink-faint: #7a8296;
  --grid:      rgba(241, 234, 208, 0.08);
  --surface-warm:   #2c3956;
  --surface-sunken: #161e2e;
}

/* English theme — light blue page (matches Jack's existing English deck convention BDD7EE) */
[data-theme="english"] {
  --ink-mute:     #4f4866;      /* 5.8:1 on the blue page (the paper shade is 4.1:1 here) */
  --terra-display: #a8531a;
  --bg:           #bdd7ee;
  --card:         #ffffff;
  --grid:         rgba(35, 77, 43, 0.05);
  --surface-warm:   #d6e5f2;
  --surface-sunken: #a8c2dc;
}

/* Notebook theme */
[data-theme="notebook"] {
  --bg:   #eaeaf2;
  --card: #ffffff;
  --grid: rgba(60, 80, 160, 0.10);
  --surface-warm:   #f3f3fb;
  --surface-sunken: #dfdfee;
}

/* ---------- 2. Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 16px); }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }   /* 2026-11-07: no smooth scrolling for people who ask for less motion */
[hidden] { display: none !important; }
body {
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .35s ease, color .35s ease;
  line-height: 1.5;
}

/* Subtle paper grid background, controllable via --show-grid */
body::before {
  content: "";
  position: fixed; inset: 0;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
  z-index: 0;
  opacity: var(--show-grid);
  transition: opacity .35s ease;
}

img, svg { display: block; max-width: 100%; }
a { color: inherit; }

/* ---------- 3. Typography ---------- */
.sp-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--ink-mute);
}
.sp-eyebrow .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ember);
}

.sp-h1 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: clamp(44px, 6.4vw, 84px);
  line-height: 1.02;
  letter-spacing: -0.025em;
  margin: 0;
  text-wrap: balance;
}
.sp-h1 em {
  font-family: var(--font-hand);
  font-style: normal;
  font-weight: 700;
  color: var(--terra-display);
  font-size: 1.05em;
  letter-spacing: 0;
  padding: 0 4px;
}

.sp-h2 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 1.1;
  letter-spacing: -0.018em;
  margin: 0 0 var(--s-4);
  text-wrap: balance;
}
.sp-h2 em {
  font-family: var(--font-hand);
  font-style: normal;
  font-weight: 700;
  color: var(--terra-display);
  font-size: 1.08em;
}

.sp-h3 {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
}

.sp-lede {
  font-size: clamp(17px, 1.6vw, 20px);
  line-height: 1.55;
  color: var(--ink-soft);
  max-width: 56ch;
  text-wrap: pretty;
  margin: 0;
}

.sp-quote {
  font-family: var(--font-hand);
  font-weight: 500;
  font-size: 22px;
  line-height: 1.25;
  color: var(--ink);
}

/* Long-form reading (lesson plans, knowledge organisers) */
.sp-read {
  font-family: var(--font-read);
  font-size: 17px;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: var(--max-w-read);
}

/* ---------- 4. Layout ---------- */
.sp-container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--s-6);
  position: relative;
  z-index: 1;
}
@media (max-width: 720px) {
  .sp-container { padding: 0 var(--s-4); }
}

.sp-section {
  padding: var(--s-9) 0;
}
.sp-section--tight { padding: var(--s-7) 0; }
.sp-section--hero  { padding: var(--s-9) 0 var(--s-8); }

/* ---------- 5. Top nav ---------- */
.sp-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink-deep);
  border-bottom: 1px solid rgba(245, 180, 60, 0.28);
}
.sp-nav-inner {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-5);
}
.sp-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--paper);
  text-decoration: none;
}
.sp-brand svg { width: 36px; height: 36px; }
/* The logo never gives way to a crowded bar (Jack, 2026-11-01: it vanished on the admin bar, which has one more link). */
.sp-brand { flex: none; }
.sp-brand-mark { display: inline-block; flex: none; width: 36px; height: 36px; }
.sp-brand-name { display: inline-block; }
.sp-brand-o {
  color: var(--spark);
}
/* The home page's light footer: the wordmark was paper on paper (only the "i" showed). */
.sp-footer .sp-brand { color: var(--ink-deep); }
.sp-footer .sp-brand-o { color: var(--terra-display); }
.sp-brand-tagline {
  font-family: var(--font-hand);
  font-weight: 600;
  font-size: 18px;
  color: var(--terra-ink);        /* was --spark: 1.6:1 on paper (it sits on the light footer) */
  line-height: 1;
  letter-spacing: 0.01em;
  margin-top: 2px;
  display: block;
}

.sp-nav-links {
  display: flex;
  align-items: center;
  gap: var(--s-5);
}
.sp-nav-link {
  font-size: 15px;
  font-weight: 500;
  color: rgba(246, 241, 228, 0.78);
  text-decoration: none;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-1);
  transition: background .15s ease, color .15s ease;
}
.sp-nav-link:hover { color: var(--paper); background: rgba(246, 241, 228, 0.10); }
.sp-nav-link.is-active { color: var(--spark); }
@media (max-width: 720px) {
  .sp-nav-links .sp-nav-link:not(.sp-btn) { display: none; }
}

/* ---------- 6. Buttons ---------- */
.sp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.005em;
  padding: 11px 18px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.sp-btn:active { transform: translateY(1px); }
.sp-btn--primary {
  background: var(--oak-600);
  color: var(--surface);
  box-shadow: var(--shadow-1);
}
.sp-btn--primary:hover {
  background: var(--oak-700);
  box-shadow: var(--shadow-2);
}
.sp-btn--ghost {
  background: transparent;
  color: var(--ink);
  border-color: color-mix(in srgb, var(--ink) 15%, transparent);
}
.sp-btn--ghost:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border-color: color-mix(in srgb, var(--ink) 25%, transparent);
}
.sp-btn--lg { padding: 14px 22px; font-size: 16px; }
.sp-btn--sm { padding: 7px 13px; font-size: 13px; }

/* ---------- 7. Cards ---------- */
.sp-card {
  background: var(--card);
  color: var(--ink);
  border-radius: var(--r-4);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sp-card--soft { box-shadow: var(--shadow-1); }
.sp-card-body { padding: var(--s-5); }
.sp-card-pad-lg .sp-card-body { padding: var(--s-6); }

/* ---------- 8. Badges & pills ---------- */
.sp-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  color: var(--ink-soft);
}
.sp-pill--subject {
  color: var(--surface);
  /* 2026-09-26: deepened toward ink so white text passes 4.5:1 on every subject (Geography,
     PSHE, PE, Art and Music were 3.0-4.1:1 at full colour). */
  background: color-mix(in srgb, var(--_subject, var(--oak-600)) 70%, var(--ink-deep));
}
.sp-pill--year {
  background: var(--oak-100);
  color: var(--oak-800);
  text-transform: uppercase;
}
.sp-pill--code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--surface-sunken);
  color: var(--ink-soft);
  letter-spacing: 0;
}

/* Subject accent helpers — set --_subject inline to switch palette */
.is-maths     { --_subject: var(--sub-maths); }
.is-english   { --_subject: var(--sub-english); }
.is-reading   { --_subject: var(--sub-reading); }
.is-science   { --_subject: var(--sub-science); }
.is-history   { --_subject: var(--sub-history); }
.is-geography { --_subject: var(--sub-geography); }
.is-re        { --_subject: var(--sub-re); }
.is-pshe      { --_subject: var(--sub-pshe); }
.is-pe        { --_subject: var(--sub-pe); }
.is-mfl       { --_subject: var(--sub-mfl); }
.is-computing { --_subject: var(--sub-computing); }
.is-art       { --_subject: var(--sub-art); }
.is-dt        { --_subject: var(--sub-dt); }
.is-music     { --_subject: var(--sub-music); }

/* ---------- 9. Footer ---------- */
.sp-footer {
  padding: var(--s-8) 0 var(--s-7);
  border-top: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink-mute);
  font-size: 14px;
}
.sp-footer-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: var(--s-7);
  margin-bottom: var(--s-6);
}
.sp-footer h4 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 var(--s-3);
}
.sp-footer ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--s-2); }
.sp-footer a { text-decoration: none; }
.sp-footer a:hover { color: var(--ink); }
.sp-footer-base {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--s-3);
  padding-top: var(--s-5);
  border-top: 1px dashed color-mix(in srgb, var(--ink) 12%, transparent);
}
@media (max-width: 720px) {
  .sp-footer-grid { grid-template-columns: 1fr 1fr; gap: var(--s-5); }
}

/* ---------- 10. Utilities ---------- */
.sp-row { display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.sp-stack-1 { display: flex; flex-direction: column; gap: var(--s-1); }
.sp-stack-2 { display: flex; flex-direction: column; gap: var(--s-2); }
.sp-stack-3 { display: flex; flex-direction: column; gap: var(--s-3); }
.sp-stack-4 { display: flex; flex-direction: column; gap: var(--s-4); }
.sp-stack-5 { display: flex; flex-direction: column; gap: var(--s-5); }
.sp-stack-6 { display: flex; flex-direction: column; gap: var(--s-6); }
.sp-mute { color: var(--ink-mute); }
.sp-center { text-align: center; }

/* Sticky note / mini callout */
.sp-note {
  background: var(--surface-warm);
  border-radius: var(--r-3);
  padding: var(--s-4) var(--s-5);
  font-family: var(--font-hand);
  font-size: 20px;
  color: var(--ink);
  display: inline-block;
  box-shadow: var(--shadow-1);
}

/* ============================================================
   11. Finesse layer (added 2026-06-04)
   Softer elevations, refined interactions, Caveat moments.
   ============================================================ */

/* Refined shadow tokens — softer, more sophisticated */
:root {
  --shadow-soft-1: 0 1px 0 rgba(35,77,43,0.04), 0 6px 18px -12px rgba(35,77,43,0.15);
  --shadow-soft-2: 0 1px 0 rgba(35,77,43,0.05), 0 12px 28px -16px rgba(35,77,43,0.22);
  --shadow-soft-3: 0 1px 0 rgba(35,77,43,0.06), 0 24px 48px -24px rgba(35,77,43,0.30);
  --ease-out:      cubic-bezier(0.16, 1, 0.3, 1);
  --ease-bounce:   cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Inline handwritten accent — `<span class="hand">growing</span>` */
.hand {
  font-family: var(--font-hand);
  font-weight: 700;
  color: var(--terra-display);
  font-style: normal;
  letter-spacing: 0;
}

/* Soft elevation cards — replace heavy borders */
.sp-card--soft-finesse {
  background: var(--card);
  border-radius: var(--r-3);
  box-shadow: var(--shadow-soft-1);
  transition: transform .25s var(--ease-out), box-shadow .25s var(--ease-out);
}
.sp-card--soft-finesse:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft-2);
}

/* Refined button transitions — slower, more deliberate */
.sp-btn { transition: transform .2s var(--ease-out), box-shadow .2s var(--ease-out), background .2s var(--ease-out), color .2s var(--ease-out), border-color .2s var(--ease-out); }
.sp-btn--primary:hover { transform: translateY(-1px); }
.sp-btn--primary:active { transform: translateY(0); }

/* Accessible focus visible — sprout-green ring */
:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
  border-radius: 4px;
}

/* Refined section dividers — subtle gradient line */
.sp-divider {
  height: 1px;
  background: linear-gradient(to right, transparent, color-mix(in srgb, var(--ink) 15%, transparent), transparent);
  margin: var(--s-7) 0;
  border: 0;
}

/* Refined small caps eyebrow — adds a sprilo dot before text */
.sp-eyebrow .dot {
  transition: transform .3s var(--ease-bounce);
}
.sp-eyebrow:hover .dot {
  transform: scale(1.25);
}

/* Subtle Caveat hover on em accents in headlines (when interactive) */
.sp-h1 em,
.sp-h2 em {
  transition: color .2s var(--ease-out);
}

/* Refined image rendering for SVG characters */
.sp-crew-illu svg,
.sp-crew-illu img {
  image-rendering: -webkit-optimize-contrast;
  filter: drop-shadow(0 2px 4px rgba(35,77,43,0.06));
}

/* Print refinement — clean for any printable view */
@media print {
  body::before { display: none; }
  .sp-nav, .sp-footer { display: none; }
  .sp-card--soft-finesse { box-shadow: none; border: 1px solid #e0d8c4; }
}
