/* ==========================================================================
   FDE 101 — Design system
   Palette validated with dataviz/scripts/validate_palette.js against
   surfaces #ffffff (light) and #161a20 (dark). Do not edit series hues
   without re-running the validator.
   ========================================================================== */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, h2, h3, h4, p, figure, blockquote, dl, dd, ul, ol { margin: 0; }
ul[class], ol[class] { list-style: none; padding: 0; }
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  /* Surfaces & ink */
  --plane:            #f4f6f9;
  --surface:          #ffffff;
  --surface-2:        #f8fafc;
  --surface-sunk:     #eef2f7;
  --ink:              #0b0f14;
  --ink-2:            #47535f;
  --ink-muted:        #6b7784;
  --hairline:         #e2e8f0;
  --hairline-strong:  #cbd5e1;
  --ring:             rgba(11,15,20,.10);

  /* Brand */
  --brand:            #0070f2;
  --brand-ink:        #0057be;
  --brand-deep:       #052a4e;
  --brand-wash:       #e8f2fe;
  --accent:           #f0ab00;

  /* Categorical series (validated) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Sequential blue ramp */
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-400: #3987e5;
  --seq-450: #2a78d6; --seq-550: #1c5cab; --seq-650: #104281;

  /* Status (fixed, never themed) */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;

  /* Chart chrome */
  --grid:     #e1e0d9;
  --baseline: #c3c2b7;

  /* Shape & motion */
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-xl: 24px;
  --shadow-1: 0 1px 2px rgba(11,15,20,.06), 0 1px 3px rgba(11,15,20,.04);
  --shadow-2: 0 4px 12px rgba(11,15,20,.08), 0 1px 3px rgba(11,15,20,.05);
  --shadow-3: 0 12px 32px rgba(11,15,20,.12), 0 2px 8px rgba(11,15,20,.06);
  --ease: cubic-bezier(.22,.61,.36,1);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  --wrap: 1140px;
  --wrap-narrow: 760px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:           #0d1013;
    --surface:         #161a20;
    --surface-2:       #1c222a;
    --surface-sunk:    #11151a;
    --ink:             #f2f5f8;
    --ink-2:           #b3bfcc;
    --ink-muted:       #8794a3;
    --hairline:        #262e38;
    --hairline-strong: #38434f;
    --ring:            rgba(255,255,255,.10);

    --brand:      #4c9dff;
    --brand-ink:  #7cb8ff;
    --brand-deep: #cfe4ff;
    --brand-wash: #14243a;
    --accent:     #ffc233;

    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;

    --seq-100: #104281; --seq-250: #1c5cab; --seq-400: #2a78d6;
    --seq-450: #3987e5; --seq-550: #86b6ef; --seq-650: #cde2fb;

    --good-text: #0ca30c;
    --grid:     #2c2c2a;
    --baseline: #383835;

    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 4px 12px rgba(0,0,0,.45);
    --shadow-3: 0 12px 32px rgba(0,0,0,.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:           #0d1013;
  --surface:         #161a20;
  --surface-2:       #1c222a;
  --surface-sunk:    #11151a;
  --ink:             #f2f5f8;
  --ink-2:           #b3bfcc;
  --ink-muted:       #8794a3;
  --hairline:        #262e38;
  --hairline-strong: #38434f;
  --ring:            rgba(255,255,255,.10);

  --brand:      #4c9dff;
  --brand-ink:  #7cb8ff;
  --brand-deep: #cfe4ff;
  --brand-wash: #14243a;
  --accent:     #ffc233;

  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;

  --seq-100: #104281; --seq-250: #1c5cab; --seq-400: #2a78d6;
  --seq-450: #3987e5; --seq-550: #86b6ef; --seq-650: #cde2fb;

  --good-text: #0ca30c;
  --grid:     #2c2c2a;
  --baseline: #383835;

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 12px rgba(0,0,0,.45);
  --shadow-3: 0 12px 32px rgba(0,0,0,.55);
}

/* ---------- Base ---------- */
body {
  font-family: var(--sans);
  background: var(--plane);
  color: var(--ink);
  line-height: 1.6;
  font-size: 16px;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: 1.2; font-weight: 700; letter-spacing: -.02em; }
h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: clamp(1.5rem, 3.4vw, 2.1rem); letter-spacing: -.025em; }
h3 { font-size: clamp(1.15rem, 2.2vw, 1.4rem); }
h4 { font-size: 1.02rem; }
p  { max-width: 72ch; }
strong { font-weight: 650; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 3px;
}

.wrap { width: 100%; max-width: var(--wrap); margin-inline: auto; padding-inline: 20px; }
.wrap-narrow { max-width: var(--wrap-narrow); }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 200;
  background: var(--brand); color: #fff; padding: 10px 16px;
  border-radius: 0 0 var(--r-sm) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

.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;
}

/* ==========================================================================
   Site header
   ========================================================================== */
.site-header {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--hairline);
}
.site-header__bar {
  display: flex; align-items: center; gap: 16px;
  height: 60px; max-width: var(--wrap); margin-inline: auto; padding-inline: 20px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 750; letter-spacing: -.03em; font-size: 1.06rem;
  text-decoration: none; color: var(--ink); white-space: nowrap;
}
.brand__mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand) 0%, #6a4df5 100%);
  color: #fff; display: grid; place-items: center;
  font-size: .68rem; font-weight: 800; letter-spacing: -.02em;
}
.brand__sub { color: var(--ink-muted); font-weight: 500; font-size: .8rem; letter-spacing: 0; }

.header-spacer { flex: 1 1 auto; }

.header-actions { display: flex; align-items: center; gap: 8px; }

.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--hairline); background: var(--surface);
  border-radius: var(--r-sm); cursor: pointer; color: var(--ink-2);
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-sunk); color: var(--ink); border-color: var(--hairline-strong); }
.icon-btn svg { width: 17px; height: 17px; }

/* XP pill + progress ring in header */
.xp-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--brand-wash); color: var(--brand-ink);
  border: 1px solid color-mix(in srgb, var(--brand) 24%, transparent);
  padding: 5px 12px 5px 8px; border-radius: 999px;
  font-size: .82rem; font-weight: 650; text-decoration: none;
  white-space: nowrap; transition: transform .15s var(--ease);
}
.xp-pill:hover { transform: translateY(-1px); }
.xp-pill__ring { width: 22px; height: 22px; flex: none; }
.xp-pill__ring circle { fill: none; stroke-width: 3.5; }
.xp-pill__ring .track { stroke: color-mix(in srgb, var(--brand) 22%, transparent); }
.xp-pill__ring .fill {
  stroke: var(--brand); stroke-linecap: round;
  transform: rotate(-90deg); transform-origin: 50% 50%;
  transition: stroke-dashoffset .6s var(--ease);
}
.xp-pill.is-bump { animation: xpBump .5s var(--ease); }
@keyframes xpBump {
  0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); }
}

/* Module dropdown nav */
.navmenu { position: relative; }
.navmenu__panel {
  position: absolute; right: 0; top: calc(100% + 10px); width: min(340px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-md); box-shadow: var(--shadow-3);
  padding: 8px; max-height: min(70vh, 560px); overflow-y: auto;
  display: none;
}
.navmenu__panel[data-open="true"] { display: block; }
.navmenu__group {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-muted); font-weight: 700; padding: 12px 10px 6px;
}
.navmenu__link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm); text-decoration: none;
  color: var(--ink-2); font-size: .89rem; font-weight: 500;
}
.navmenu__link:hover { background: var(--surface-sunk); color: var(--ink); }
.navmenu__link[aria-current="page"] { background: var(--brand-wash); color: var(--brand-ink); font-weight: 650; }
.navmenu__num {
  width: 22px; height: 22px; flex: none; border-radius: 5px;
  background: var(--surface-sunk); color: var(--ink-muted);
  display: grid; place-items: center; font-size: .7rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.navmenu__link[aria-current="page"] .navmenu__num { background: var(--brand); color: #fff; }
.navmenu__link.is-done .navmenu__num { background: var(--good); color: #fff; }

/* ==========================================================================
   Layout primitives
   ========================================================================== */
main { display: block; padding-bottom: 80px; }

.section { padding-block: clamp(40px, 7vw, 72px); }
.section--tight { padding-block: clamp(28px, 4vw, 44px); }

.stack > * + * { margin-top: 20px; }
.stack-lg > * + * { margin-top: 36px; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: var(--r-lg); padding: 22px;
  box-shadow: var(--shadow-1);
}
.card--flush { padding: 0; overflow: hidden; }
.card--sunk { background: var(--surface-sunk); box-shadow: none; }

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: .72rem; font-weight: 700; letter-spacing: .11em;
  text-transform: uppercase; color: var(--brand-ink);
  margin-bottom: 12px;
}
.eyebrow::before {
  content: ""; width: 18px; height: 2px; border-radius: 2px;
  background: var(--brand); flex: none;
}
.lede { font-size: clamp(1.02rem, 1.6vw, 1.16rem); color: var(--ink-2); line-height: 1.65; }

/* ==========================================================================
   Prose
   ========================================================================== */
.prose > * + * { margin-top: 1.1em; }
.prose h2 { margin-top: 2em; scroll-margin-top: 80px; }
.prose h3 { margin-top: 1.7em; scroll-margin-top: 80px; }
.prose h2 + p, .prose h3 + p { margin-top: .7em; }
.prose ul, .prose ol { padding-left: 1.3em; }
.prose li + li { margin-top: .45em; }
.prose li::marker { color: var(--brand); }
.prose a { color: var(--brand-ink); text-underline-offset: 3px; }
.prose code {
  font-family: var(--mono); font-size: .88em;
  background: var(--surface-sunk); padding: .12em .4em;
  border-radius: 4px; border: 1px solid var(--hairline);
}

/* ==========================================================================
   Tables — always inside .table-scroll
   ========================================================================== */
.table-scroll {
  overflow-x: auto; border: 1px solid var(--hairline);
  border-radius: var(--r-md); background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
thead th {
  text-align: left; font-weight: 650; font-size: .76rem;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted);
  padding: 11px 14px; border-bottom: 1px solid var(--hairline);
  background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; z-index: 1;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ==========================================================================
   Badges, chips, callouts
   ========================================================================== */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 650;
  background: var(--surface-sunk); color: var(--ink-2);
  border: 1px solid var(--hairline); white-space: nowrap;
}
/* Long-form chip (checklist verdicts) — must wrap, unlike the compact table chips */
.chip--wrap { white-space: normal; text-align: left; line-height: 1.4; max-width: 100%; }
.chip--brand { background: var(--brand-wash); color: var(--brand-ink); border-color: color-mix(in srgb, var(--brand) 22%, transparent); }
.chip--good    { background: color-mix(in srgb, var(--good) 12%, transparent);    color: var(--good-text); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.chip--warning { background: color-mix(in srgb, var(--warning) 18%, transparent); color: #7a5200; border-color: color-mix(in srgb, var(--warning) 40%, transparent); }
.chip--critical{ background: color-mix(in srgb, var(--critical) 12%, transparent);color: #a02a2a; border-color: color-mix(in srgb, var(--critical) 30%, transparent); }
:root[data-theme="dark"] .chip--warning { color: #ffc233; }
:root[data-theme="dark"] .chip--critical { color: #ff8f8f; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .chip--warning { color: #ffc233; }
  :root:where(:not([data-theme="light"])) .chip--critical { color: #ff8f8f; }
}

/* Confidence badge — always paired with a label, never colour alone */
.conf {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .69rem; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 2px 7px; border-radius: 4px;
  border: 1px solid currentColor; white-space: nowrap;
}
.conf::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.conf--high     { color: var(--good-text); }
.conf--moderate { color: #9a6a00; }
.conf--low      { color: #a02a2a; }
:root[data-theme="dark"] .conf--moderate { color: #ffc233; }
:root[data-theme="dark"] .conf--low { color: #ff8f8f; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .conf--moderate { color: #ffc233; }
  :root:where(:not([data-theme="light"])) .conf--low { color: #ff8f8f; }
}

.callout {
  border-left: 3px solid var(--brand); background: var(--brand-wash);
  padding: 16px 18px; border-radius: 0 var(--r-md) var(--r-md) 0;
}
.callout__title { font-weight: 700; margin-bottom: 5px; display: flex; align-items: center; gap: 8px; }
.callout p { max-width: none; }
.callout--warn     { border-color: var(--warning);  background: color-mix(in srgb, var(--warning) 11%, transparent); }
.callout--critical { border-color: var(--critical); background: color-mix(in srgb, var(--critical) 9%, transparent); }
.callout--good     { border-color: var(--good);     background: color-mix(in srgb, var(--good) 10%, transparent); }
.callout--feature  { border-color: var(--accent);   background: color-mix(in srgb, var(--accent) 13%, transparent); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--r-sm); font-weight: 650; font-size: .92rem;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: transform .14s var(--ease), background .14s var(--ease), box-shadow .14s var(--ease);
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn--primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-1); }
.btn--primary:hover { background: var(--brand-ink); box-shadow: var(--shadow-2); }
:root[data-theme="dark"] .btn--primary { color: #06121f; }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .btn--primary { color: #06121f; }
}
.btn--ghost { background: var(--surface); color: var(--ink); border-color: var(--hairline-strong); }
.btn--ghost:hover { background: var(--surface-sunk); }
.btn--quiet { background: transparent; color: var(--ink-2); }
.btn--quiet:hover { background: var(--surface-sunk); color: var(--ink); }
.btn--sm { padding: 6px 12px; font-size: .82rem; }
.btn--lg { padding: 13px 26px; font-size: 1rem; }

/* ==========================================================================
   Module footer nav
   ========================================================================== */
.modnav {
  display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  margin-top: 48px; padding-top: 28px; border-top: 1px solid var(--hairline);
}
.modnav__link {
  display: flex; flex-direction: column; gap: 3px;
  padding: 16px 18px; border: 1px solid var(--hairline); border-radius: var(--r-md);
  text-decoration: none; background: var(--surface);
  transition: border-color .15s var(--ease), transform .15s var(--ease), box-shadow .15s var(--ease);
}
.modnav__link:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.modnav__dir { font-size: .72rem; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-muted); font-weight: 700; }
.modnav__title { font-weight: 650; color: var(--ink); }
.modnav__link--next { text-align: right; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--hairline); background: var(--surface);
  padding-block: 36px; margin-top: 40px;
}
.site-footer__inner {
  max-width: var(--wrap); margin-inline: auto; padding-inline: 20px;
  display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: space-between;
  font-size: .85rem; color: var(--ink-muted);
}
.site-footer a { color: var(--ink-2); text-decoration: none; }
.site-footer a:hover { color: var(--brand-ink); text-decoration: underline; }
.site-footer__links { display: flex; flex-wrap: wrap; gap: 18px; }

/* ==========================================================================
   Motion preferences
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}

@media print {
  .site-header, .modnav, .site-footer, .icon-btn, .xp-pill { display: none !important; }
  body { background: #fff; }
}
