/* =====================================================================
   EDA Study Lab — one stylesheet for the whole web app.
   1. Design tokens (light + dark)   4. Lesson content helpers
   2. App shell (top bar, sidebar)   5. Animations
   3. Chart classes (SVG)            6. Responsive + print
   Lesson markup keeps its inline styles; it only relies on the tokens
   and classes defined here, so a new lesson needs no new CSS.
   ===================================================================== */

/* ---------- 1. tokens ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: #F4F6F9; }
body.is-dark { background: #0A101B; }
a { color: #1D4ED8; } a:hover { color: #C2410C; }

.app {
  --bg:#F4F6F9; --surface:#FFFFFF; --surface2:#EEF2F7; --ink:#0E1726; --ink2:#334155; --muted:#556173;
  --line:#D9E0EA; --grid:#E6EBF2; --axis:#9AA6B8; --accent:#1D4ED8; --accent2:#C2410C; --ok:#047857;
  --k1:#2563EB; --k2:#EA580C; --k3:#0D9488; --k4:#7C3AED; --k5:#64748B; --k6:#DB2777; --k7:#F2B33D;
  --codebg:#0F172A; --codeink:#E2E8F0; --tint1:#E7EEFE; --tint2:#FDEEE4; --tint3:#E2F4F1; --tint4:#F0EAFE;
  --shadow: 0 14px 34px -16px rgba(14,23,38,.35);
  --top-h: 64px; --side-w: 284px;
  background: var(--bg); color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  min-height: 100vh; color-scheme: light;
  transition: background .35s, color .35s;
}
.app[data-theme="dark"] {
  --bg:#0A101B; --surface:#111A2A; --surface2:#172238; --ink:#E8EDF5; --ink2:#C6CFDD; --muted:#97A3B6;
  --line:#253149; --grid:#1C2740; --axis:#4B5A76; --accent:#82A8FF; --accent2:#FDA46A; --ok:#34D399;
  --k1:#60A5FA; --k2:#FB923C; --k3:#2DD4BF; --k4:#A78BFA; --k5:#94A3B8; --k6:#F472B6; --k7:#FBBF24;
  --codebg:#060A12; --tint1:#16264A; --tint2:#3A2212; --tint3:#0F3330; --tint4:#261C45;
  --shadow: 0 14px 34px -16px rgba(0,0,0,.7);
  color-scheme: dark;
}
.app a { color: var(--accent); } .app a:hover { color: var(--accent2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 2. shell ---------- */
.skip { position: absolute; left: 12px; top: -60px; z-index: 100; padding: 10px 14px; border-radius: 10px; background: var(--accent); color: var(--bg) !important; font-weight: 600; text-decoration: none; }
.skip:focus { top: 10px; }

.topbar {
  position: sticky; top: 0; z-index: 40; height: var(--top-h);
  display: flex; align-items: center; gap: 12px; padding: 0 clamp(12px, 2.4vw, 28px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink) !important; flex: 0 0 auto; }
.brand b { font: 700 18px 'Space Grotesk', sans-serif; letter-spacing: -.01em; }
.brand small { display: block; font: 500 11px 'IBM Plex Mono', monospace; color: var(--muted); letter-spacing: .02em; }
.logo-bar { transform-box: fill-box; transform-origin: 50% 100%; animation: rise 1s cubic-bezier(.2,.8,.2,1) both; }

.searchbox { position: relative; flex: 1 1 420px; max-width: 520px; margin-left: auto; }
.searchbox input {
  width: 100%; height: 42px; padding: 0 44px 0 40px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--ink); font: 15px 'IBM Plex Sans', sans-serif;
}
.searchbox input:focus { outline: none; border-color: var(--accent); background: var(--surface); }
.searchbox svg { position: absolute; left: 13px; top: 13px; color: var(--muted); pointer-events: none; }
.searchbox kbd { position: absolute; right: 10px; top: 10px; padding: 2px 7px; border-radius: 6px; border: 1px solid var(--line); font: 600 11px 'IBM Plex Mono', monospace; color: var(--muted); background: var(--surface); }
.results {
  position: absolute; left: 0; right: 0; top: 48px; max-height: min(70vh, 520px); overflow: auto;
  margin: 0; padding: 6px; list-style: none; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow);
}
.results a { display: grid; grid-template-columns: 58px 1fr; gap: 2px 10px; padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--ink) !important; }
.results a:hover, .results a[aria-selected="true"] { background: var(--tint1); }
.results .r-id { grid-row: span 2; align-self: center; text-align: center; padding: 4px 0; border-radius: 7px; background: var(--surface2); font: 700 11px 'IBM Plex Mono', monospace; color: var(--accent); }
.results .r-t { font-weight: 600; font-size: 14.5px; }
.results .r-s { font-size: 12.5px; color: var(--muted); }
.results .r-empty { padding: 14px; color: var(--ink2); font-size: 14px; }

.tb-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-width: 42px; height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface2); color: var(--ink); font: 500 14px 'IBM Plex Sans', sans-serif; cursor: pointer;
  transition: background .2s, border-color .2s;
}
.icon-btn:hover { border-color: var(--accent); }
.badge { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 999px; background: var(--accent2); color: #fff; font: 700 11px/20px 'IBM Plex Mono', monospace; text-align: center; }
.menu-btn { display: none; }

.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: var(--top-h); height: calc(100vh - var(--top-h)); overflow-y: auto;
  padding: 18px 14px 24px; border-right: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; gap: 18px;
}
.side-group h3 { margin: 0 0 6px 10px; font: 600 11px 'IBM Plex Mono', monospace; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.side-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; text-decoration: none; color: var(--ink2) !important; font-size: 14px; line-height: 1.3;
  transition: background .2s, color .2s;
}
.side-link:hover { background: var(--surface2); color: var(--ink) !important; }
.side-link[aria-current="page"] { background: var(--tint1); color: var(--ink) !important; font-weight: 600; }
.side-id { text-align: center; padding: 3px 0; border-radius: 6px; background: var(--surface2); font: 700 11px 'IBM Plex Mono', monospace; color: var(--accent); }
.side-link[aria-current="page"] .side-id { background: var(--accent); color: var(--bg); }
.side-link.is-tp { margin-left: 14px; grid-template-columns: 46px 1fr auto; }
.side-flag { font: 700 10px 'IBM Plex Mono', monospace; padding: 2px 6px; border-radius: 999px; background: var(--tint2); color: var(--accent2); }
.side-done { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: transparent; }
.side-done.on { background: var(--ok); border-color: var(--ok); color: var(--bg); }
.side-toc { list-style: none; margin: 4px 0 6px 64px; padding: 0 0 0 10px; border-left: 2px solid var(--line); display: flex; flex-direction: column; }
.side-toc a { display: block; padding: 4px 8px; border-radius: 6px; font-size: 13px; color: var(--muted) !important; text-decoration: none; }
.side-toc a:hover { color: var(--ink) !important; background: var(--surface2); }
.side-toc a.on { color: var(--accent) !important; font-weight: 600; }
.side-progress { margin-top: auto; padding: 14px; border-radius: 14px; background: var(--surface2); }
.side-progress .row { display: flex; justify-content: space-between; align-items: baseline; font: 600 11px 'IBM Plex Mono', monospace; color: var(--muted); }
.side-progress strong { font: 700 22px 'Space Grotesk', sans-serif; color: var(--ink); }
.bar { height: 8px; margin-top: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .6s cubic-bezier(.2,.8,.2,1); }

#view { min-width: 0; outline: none; }
/* the sidebar already lists this page's sections on wide screens */
@media (min-width: 1081px) { #view nav[aria-label="On this page"] { display: none; } }
#view [id] { scroll-margin-top: calc(var(--top-h) + 16px); }
.lesson-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; max-width: 1180px; margin: 0 auto;
  padding: 14px clamp(16px, 4vw, 48px) 0;
}
.lesson-bar .crumb { margin-right: auto; font: 500 13px 'IBM Plex Mono', monospace; color: var(--muted); }
.pill-btn {
  min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: 600 13.5px 'IBM Plex Sans', sans-serif; cursor: pointer; transition: background .2s, color .2s, border-color .2s;
}
.pill-btn:hover { border-color: var(--accent); }
.pill-btn[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: var(--bg); }

/* What's new drawer */
.scrim { position: fixed; inset: 0; z-index: 70; background: rgba(6,10,18,.45); }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 80; width: min(460px, 100vw); overflow-y: auto;
  padding: 22px 22px 32px; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  animation: slideL .3s cubic-bezier(.2,.8,.2,1) both;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.drawer-head h2 { margin: 0; font: 700 24px 'Space Grotesk', sans-serif; }
.drawer p.sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.upd { position: relative; padding: 0 0 20px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.upd::before { content: ''; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.upd.is-new::before { background: var(--accent2); border-color: var(--accent2); }
.upd time { font: 600 12px 'IBM Plex Mono', monospace; color: var(--muted); }
.upd h4 { margin: 2px 0 6px; font: 600 16px 'Space Grotesk', sans-serif; }
.upd ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.55; color: var(--ink2); }
.upd .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.upd .tags a { padding: 3px 8px; border-radius: 999px; background: var(--tint1); font: 700 11px 'IBM Plex Mono', monospace; text-decoration: none; }
.new-chip { margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--accent2); color: #fff; font: 700 10px 'IBM Plex Mono', monospace; vertical-align: 2px; }

/* home: what's new strip + contents cards rendered from js/lessons.js */
.home-updates { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.home-upd { padding: 16px 18px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.home-upd time { font: 600 12px 'IBM Plex Mono', monospace; color: var(--muted); }
.home-upd h4 { margin: 4px 0 6px; font: 600 16px 'Space Grotesk', sans-serif; }
.home-upd p { margin: 0; font-size: 14px; color: var(--ink2); line-height: 1.5; }
.toc-item { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; padding: 18px 20px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.toc-item.is-tp { margin-left: clamp(0px, 3vw, 36px); }
.toc-item .t-id { flex: 0 0 auto; width: 64px; padding: 8px 0; text-align: center; border-radius: 10px; background: var(--tint1); color: var(--accent); font: 700 13px 'IBM Plex Mono', monospace; }
.toc-item.is-tp .t-id { background: var(--tint3); color: var(--k3); }
.toc-item.is-ref .t-id { background: var(--tint4); color: var(--k4); }
.toc-item .t-body { flex: 999 1 360px; min-width: 0; }
.toc-item .t-title { font: 600 20px 'Space Grotesk', sans-serif; text-decoration: none; color: var(--ink) !important; }
.toc-item .t-meta { margin-left: 8px; font: 500 12px 'IBM Plex Mono', monospace; color: var(--muted); }
.toc-item p { margin: 6px 0 0; font-size: 14px; color: var(--ink2); line-height: 1.5; }
.toc-item .pill-btn { min-width: 120px; min-height: 44px; }

/* ---------- 3. charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.f1{fill:var(--k1)}.f2{fill:var(--k2)}.f3{fill:var(--k3)}.f4{fill:var(--k4)}.f5{fill:var(--k5)}.f6{fill:var(--k6)}.f7{fill:var(--k7)}
.s1{stroke:var(--k1);fill:none}.s2{stroke:var(--k2);fill:none}.s3{stroke:var(--k3);fill:none}.s4{stroke:var(--k4);fill:none}.s5{stroke:var(--k5);fill:none}.s6{stroke:var(--k6);fill:none}
.dot { stroke-linecap: round; fill: none; }
.g-grid { stroke: var(--grid); } .g-ax { stroke: var(--axis); }
.g-t { fill: var(--muted); font: 11px 'IBM Plex Mono', monospace; }
.g-l { fill: var(--ink2); font: 12px 'IBM Plex Sans', sans-serif; }
.g-v { fill: var(--ink); font: 600 12px 'IBM Plex Mono', monospace; }
.g-in { fill: #fff; stroke: rgba(14,23,38,.6); stroke-width: 3px; paint-order: stroke; font: 600 11px 'IBM Plex Mono', monospace; }
#view[data-id="C01"] .g-in { stroke: none; }            /* C01 labels sit on solid bars */
.g-ann { fill: var(--ink); font: 600 11.5px 'IBM Plex Sans', sans-serif; }
.g-big { fill: var(--ink); font: 700 26px 'Space Grotesk', sans-serif; }
.g-cell { font: 600 13px 'IBM Plex Mono', monospace; }
.g-frame { fill: var(--surface2); stroke: var(--line); }
.g-violin { opacity: .55; } .g-ridge { opacity: .7; stroke: var(--surface); stroke-width: 1.5; }
.z1{fill:var(--k3);opacity:.10}.z2{fill:var(--k7);opacity:.14}.z3{fill:var(--k7);opacity:.26}.z4{fill:var(--k2);opacity:.14}.z5{fill:var(--k2);opacity:.22}

/* ---------- 4. content helpers ---------- */
.card { transition: transform .25s, box-shadow .25s, border-color .25s; }
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--accent); }
.navlink { transition: background .2s, color .2s; } .navlink:hover { background: var(--surface2); }
.chip { transition: background .2s, color .2s, border-color .2s; }
.frac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; margin: 0 4px; line-height: 1.25; }
.frac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 4px 1px; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '+'; display: inline-block; width: 22px; font-weight: 700; color: var(--accent); transition: transform .2s; }
details[open] > summary::before { transform: rotate(45deg); }
.cm{color:#8B9BB4}.kw{color:#93C5FD}.st{color:#FCD34D}
.fx { transition: filter .3s; }
.quiz .fx { filter: blur(7px); } .quiz .fx:hover, .quiz .fx:focus-within { filter: none; }

/* ---------- 5. animations ---------- */
@keyframes rise   { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes growx  { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes draw   { from { stroke-dashoffset: 1800; } to { stroke-dashoffset: 0; } }
@keyframes pop    { from { transform: scale(.4); } to { transform: scale(1); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes slideIn{ from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: none; } }
@keyframes slideL { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.g-bar { transform-box: fill-box; transform-origin: 50% 100%; animation: rise .9s cubic-bezier(.2,.8,.2,1) both; }
.g-barh { transform-box: fill-box; transform-origin: 0 50%; animation: growx .9s cubic-bezier(.2,.8,.2,1) both; }
.g-area { transform-box: fill-box; transform-origin: 50% 100%; animation: rise 1s cubic-bezier(.2,.8,.2,1) both; }
.g-line:not([stroke-dasharray]) { stroke-dasharray: 1800; animation: draw 1.8s ease-out both; }
.g-dot, .g-seg, .g-bub, .g-box { transform-box: fill-box; transform-origin: center; animation: pop .7s ease-out both; transition: opacity .2s; }
.chart:hover .g-dot, .chart:hover .g-bub { opacity: .28; }
.chart .g-dot:hover, .chart .g-bub:hover { opacity: .9; }
.reveal { animation: fadeUp .7s ease-out both; }
.group { animation: slideIn .45s ease-out both; }
.view-enter { animation: fadeUp .35s ease-out both; }

/* ---------- 6. responsive + print ---------- */
@media (max-width: 1080px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-btn { display: inline-flex; }
  .sidebar {
    position: fixed; z-index: 80; top: 0; left: 0; bottom: 0; height: auto; width: min(320px, 88vw);
    transform: translateX(-102%); transition: transform .28s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
}
@media (max-width: 720px) {
  .brand small, .tb-label, .searchbox kbd { display: none; }
  .searchbox { flex: 1 1 0; min-width: 0; }
  .topbar { gap: 8px; }
  .icon-btn { padding: 0 10px; }
}
@media (max-width: 480px) {
  .brand b { display: none; }
}
@media (prefers-reduced-motion: reduce) { .app *, .app *::before { animation: none !important; transition: none !important; } html { scroll-behavior: auto; } }
@media print {
  .no-print, .topbar, .sidebar, .lesson-bar, .scrim, .drawer { display: none !important; }
  .shell { display: block; }
  .app, body { background: #fff !important; }
  .quiz .fx { filter: none; }
  .app * { animation: none !important; transition: none !important; }
  figure, svg, pre, table { break-inside: avoid; }
}
