/* iprep — explainer design system.
   Used by every explainer page. Loaded as <link rel="stylesheet" href="/assets/explainer.css">.
   Requires /assets/base.css first (palette, fonts, body, theme toggle, reveal).
   Pair with /assets/explainer.js for behavior (TOC, tabs, mermaid, etc.).
*/

/* Body override — explainer prefers slightly looser line-height for long reading */
body { line-height: 1.7; }

/* --- Layout: TOC sidebar + main column --- */
.layout { display: grid; grid-template-columns: 320px 1fr; gap: 0; max-width: 1540px; margin: 0 auto; }
.toc {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding: 56px 28px 40px 40px; background: var(--bg-sunken); border-right: 1px solid var(--border);
}
.toc h4 { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin: 0 0 12px 0; font-weight: 600; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc li { margin: 2px 0; }
.toc li.toc-h3 { padding-left: 20px; }
.toc a {
  color: var(--text); text-decoration: none; font-size: 14px; font-weight: 500;
  display: block; padding: 4px 8px; border-radius: 4px; border-left: 2px solid transparent;
  transition: color .15s, border-color .15s, background .15s; line-height: 1.35;
}
.toc li.toc-h3 a { color: var(--text-muted); font-size: 12.5px; font-weight: 400; }
.toc a:hover { color: var(--text); background: var(--bg-elevated); }
.toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.toc li.toc-h3 a.active { color: var(--accent); font-weight: 500; }

main { padding: 56px 72px 96px; max-width: 1180px; }

.toc-toggle { display: none; }
.toc-backdrop { display: none; }

@media (max-width: 1100px) {
  .toc-toggle {
    display: flex;
    position: fixed; top: 16px; left: 16px;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    align-items: center; justify-content: center;
    z-index: 101;
    transition: border-color .15s;
  }
  .toc-toggle:hover { border-color: var(--accent); }

  .layout { grid-template-columns: 1fr; }
  .toc {
    position: fixed; top: 0; left: 0;
    height: 100vh; width: 300px; max-width: 82vw;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    padding: 60px 28px 40px 28px;
    border-right: 1px solid var(--border);
    border-bottom: none;
    background: var(--bg-sunken);
    box-shadow: 4px 0 16px rgba(0,0,0,.12);
    overflow-y: auto;
  }
  .toc.open { transform: translateX(0); }

  .toc-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .toc-backdrop.open { opacity: 1; pointer-events: auto; }

  main { padding: 64px 24px 64px; max-width: 100%; }
}

/* --- Typography --- */
h1, h2, h3, h4 { font-family: var(--font-sans); color: var(--text); line-height: 1.25; margin-top: 2.2em; margin-bottom: .6em; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 40px; margin-top: 0; letter-spacing: -0.02em; }
h2 { font-size: 28px; padding-top: 8px; }
h3 { font-size: 20px; font-weight: 600; }
h4 { font-size: 16px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }

p { margin: 0 0 1.1em 0; }
a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
a:hover { border-bottom-color: var(--accent); }
strong { font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2.4em 0; }
ul, ol { padding-left: 1.4em; margin: 0 0 1.1em 0; }
li { margin: .3em 0; }

/* --- Code --- */
code { font-family: var(--font-mono); font-size: .92em; background: var(--bg-elevated); padding: .12em .4em; border-radius: 4px; color: var(--text); }
pre { position: relative; margin: 1.4em 0; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; overflow-x: auto; }
pre code { background: transparent; padding: 0; font-size: 14px; line-height: 1.55; display: block; }
.copy-btn { position: absolute; top: 8px; right: 8px; padding: 4px 10px; font-size: 11px; font-family: var(--font-sans); color: var(--text-muted); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; cursor: pointer; opacity: 0; transition: opacity .15s, color .15s; }
pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--accent); }
.copy-btn.copied { color: var(--signal); }

/* --- Callouts --- */
.callout { border-left: 3px solid var(--border); background: var(--bg-elevated); padding: 16px 20px; margin: 1.6em 0; border-radius: 6px; }
.callout-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; color: var(--text-muted); }
.callout > *:last-child { margin-bottom: 0; }
.callout-insight { border-left-color: var(--accent); background: var(--insight-soft); }
.callout-insight .callout-title { color: var(--accent); }
.callout-signal  { border-left-color: var(--signal);  background: var(--signal-soft); }
.callout-signal .callout-title { color: var(--signal); }
.callout-trap    { border-left-color: var(--trap);    background: var(--trap-soft); }
.callout-trap .callout-title { color: var(--trap); }
.callout-aside   { border-left-color: var(--border); background: var(--bg-elevated); }

/* --- Compare cards --- */
.compare { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 1.6em 0; }
.compare-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; }
.compare-card h4 { margin: 0 0 8px 0; font-size: 14px; color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 600; }
.compare-card p:last-child { margin-bottom: 0; }
.compare-card svg { width: 100%; height: auto; display: block; margin: 6px 0 10px 0; }

/* --- Tables (auto-wrapped in .table-scroll by JS) --- */
table { width: 100%; border-collapse: collapse; margin: 1.6em 0; font-size: 15px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; background: var(--bg-elevated); color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--bg-elevated); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 1.6em 0; }
.table-scroll table { margin: 0; min-width: max-content; }

/* --- Tabs --- */
.tabs { margin: 1.6em 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg-elevated); }
.tab-bar { display: flex; gap: 0; background: var(--bg-sunken); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab-btn { font-family: var(--font-sans); font-size: 14px; font-weight: 500; padding: 10px 18px; background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--text-muted); cursor: pointer; transition: color .15s, border-color .15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--bg-elevated); }
.tab-panel { padding: 20px 22px; display: none; }
.tab-panel.active { display: block; }
.tab-panel > *:first-child { margin-top: 0; }
.tab-panel > *:last-child { margin-bottom: 0; }

/* --- Quiz / flashcard --- */
.quiz { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 18px 20px; margin: 1.6em 0; cursor: pointer; transition: box-shadow .15s; user-select: none; }
.quiz:hover { box-shadow: var(--shadow); }
.quiz-q { font-weight: 500; margin-bottom: 0; }
.quiz-q::before { content: "Q."; color: var(--accent); font-weight: 700; margin-right: 8px; }
.quiz-a { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); color: var(--text); }
.quiz-a::before { content: "A."; color: var(--signal); font-weight: 700; margin-right: 8px; }
.quiz.revealed .quiz-a { display: block; }
.quiz-hint { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.quiz.revealed .quiz-hint { display: none; }

/* --- Mermaid --- */
.mermaid { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin: 1.6em 0; text-align: center; overflow-x: auto; }
.mermaid-compact svg { max-height: 240px !important; height: auto !important; }

/* --- KaTeX (math) --- */
.katex { font-size: 1.05em; }

/* --- Reveal animation override (explainer uses slightly larger offset) --- */
.reveal { transform: translateY(24px); }

/* --- Hero block --- */
.hero { margin: 0 0 3em 0; padding: 8px 0 24px 0; border-bottom: 1px solid var(--border); }
.hero-quote { font-size: 32px; font-weight: 600; line-height: 1.25; letter-spacing: -0.015em; color: var(--text); margin: 0; }
.hero-quote .accent { color: var(--accent); }
.hero-sub { margin-top: 16px; color: var(--text-muted); font-size: 17px; }

/* --- Stats showcase --- */
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin: 1.6em 0; }
.stat { background: var(--bg-elevated); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 18px 20px; }
.stat-num { font-size: 30px; font-weight: 700; color: var(--accent); letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.stat-org   { font-size: 14px; font-weight: 600; margin-top: 10px; }

/* --- Versus panel (before/after) --- */
.versus { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; margin: 1.6em 0; }
.versus-card { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 28px 22px 22px 22px; position: relative; }
.versus-card.bad  { border-top: 3px solid var(--trap); }
.versus-card.good { border-top: 3px solid var(--signal); }
.versus-tag { position: absolute; top: -11px; left: 16px; background: var(--bg); padding: 2px 10px; border-radius: 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; border: 1px solid var(--border); }
.versus-card.bad  .versus-tag { color: var(--trap);   border-color: var(--trap); }
.versus-card.good .versus-tag { color: var(--signal); border-color: var(--signal); }
.versus-card h4 { margin: 0 0 10px 0; color: var(--text); font-size: 16px; text-transform: none; letter-spacing: 0; }
.versus-card p:last-child { margin-bottom: 0; }
.versus-card svg { width: 100%; height: auto; display: block; margin: 6px 0; }
@media (max-width: 760px) { .versus { grid-template-columns: 1fr; } }

/* --- Flow steps (sequential pills) --- */
.flow { display: flex; align-items: stretch; gap: 22px; margin: 1.6em 0; flex-wrap: wrap; }
.flow-step { flex: 1 1 160px; min-width: 160px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; position: relative; transition: border-color .2s, box-shadow .2s, transform .2s; }
.flow-step::after { content: ""; position: absolute; right: -18px; top: 50%; width: 14px; height: 2px; background: var(--accent); transform: translateY(-50%); }
.flow-step::before { content: ""; position: absolute; right: -19px; top: 50%; width: 0; height: 0; border: 5px solid transparent; border-left-color: var(--accent); transform: translateY(-50%); }
.flow-step:last-child::after, .flow-step:last-child::before { display: none; }
.flow-step.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); transform: translateY(-2px); }
.flow-num { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; width: 22px; height: 22px; border-radius: 50%; margin-bottom: 10px; }
.flow-title { font-size: 14px; font-weight: 600; margin: 0 0 4px 0; }
.flow-desc  { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.5; }

/* --- Equation line (visually emphasized one-liner) --- */
.equation { margin: 1.4em 0; padding: 18px 20px; text-align: center; font-size: 20px; font-weight: 600; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; letter-spacing: -0.005em; }
.equation .plus { color: var(--text-muted); margin: 0 14px; }
.equation .eq   { color: var(--accent);     margin: 0 14px; }

/* --- Hand-rolled SVG helpers --- */
.draw-path { stroke-dasharray: var(--len, 400); stroke-dashoffset: var(--len, 400); }
.reveal.in-view .draw-path { animation: draw 1.4s ease forwards; }
.reveal.in-view .draw-path.delay-1 { animation-delay: .2s; }
.reveal.in-view .draw-path.delay-2 { animation-delay: .6s; }
.reveal.in-view .draw-path.delay-3 { animation-delay: 1.0s; }
.reveal.in-view .draw-path.delay-4 { animation-delay: 1.4s; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }
.svg-node { fill: var(--bg-elevated); stroke: var(--accent); stroke-width: 2; }
.svg-node-bad { stroke: var(--trap); fill: var(--trap-soft); }
.svg-node-cold { fill: var(--bg-elevated); stroke: var(--text-muted); stroke-width: 1.5; }
.svg-label { font-family: var(--font-sans); font-size: 13px; fill: var(--text); font-weight: 500; }
.svg-sub   { font-family: var(--font-sans); font-size: 11px; fill: var(--text-muted); }
.svg-arrow { stroke: var(--accent); stroke-width: 2; fill: none; }
.svg-arrow-bad { stroke: var(--trap); stroke-width: 2; fill: none; stroke-dasharray: 6 5; }
.svg-arrow-cold { stroke: var(--text-muted); stroke-width: 1.5; fill: none; }
.pulse-bad { animation: pulse 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) {
  .draw-path { stroke-dashoffset: 0; }
  .reveal.in-view .draw-path { animation: none; }
  .pulse-bad { animation: none; }
}

/* --- Followups (visible Q+A pairs — interview phrasings to memorize) --- */
.followups { margin: 1.6em 0; display: flex; flex-direction: column; gap: 12px; }
.followup { background: var(--bg-elevated); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 14px 18px; }
.followup-q { font-weight: 600; margin: 0 0 8px 0; color: var(--text); font-size: 15.5px; line-height: 1.45; }
.followup-q::before { content: "Q."; color: var(--accent); font-weight: 700; margin-right: 8px; font-size: 14px; letter-spacing: 0.04em; }
.followup-a { margin: 0; color: var(--text); font-size: 15px; line-height: 1.6; }
.followup-a::before { content: "→ "; color: var(--signal); font-weight: 700; margin-right: 4px; }

/* --- Failure mode cards --- */
.failures { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 1.6em 0; }
.failure { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; border-left: 3px solid var(--trap); }
.failure h4 { margin: 0 0 8px 0; font-size: 15px; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: 0; }
.failure-impact { color: var(--trap); font-size: 14px; margin: 0 0 8px 0; }
.failure-fix { font-size: 14px; color: var(--text); margin: 0 0 6px 0; }
.failure-fix strong { color: var(--signal); font-weight: 600; }
.failure-line { font-size: 13.5px; color: var(--text-muted); font-style: italic; margin: 0; }

/* --- Algorithm/concept figure with caption --- */
.algo-fig { margin: 0 0 1.2em 0; }
.algo-fig svg { width: 100%; height: auto; display: block; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.algo-fig figcaption { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; text-align: center; font-style: italic; }

/* --- Lessons (signal-flavored, like failures but green-bordered) --- */
.lessons { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin: 1.6em 0; }
.lesson { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; border-left: 3px solid var(--signal); }
.lesson h4 { margin: 0 0 8px 0; font-size: 15px; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: 0; }
.lesson-problem { color: var(--text-muted); font-size: 14px; margin: 0 0 8px 0; }
.lesson-takeaway { font-size: 14px; color: var(--text); margin: 0; }
.lesson-takeaway strong { color: var(--signal); font-weight: 600; }

/* --- Scenarios (workload reference catalog) --- */
.scenarios { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); margin: 1.6em 0; }
.scenario { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.scenario h4 { margin: 0 0 4px 0; font-size: 14.5px; font-weight: 600; color: var(--text); text-transform: none; letter-spacing: 0; }
.scenario .key { font-family: var(--font-mono); font-size: 13px; color: var(--accent); margin: 0 0 8px 0; background: var(--bg); padding: 4px 8px; border-radius: 4px; display: inline-block; }
.scenario .why { font-size: 13.5px; color: var(--text); margin: 0 0 6px 0; line-height: 1.55; }
.scenario .gotcha { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.5; }
.scenario .gotcha strong { color: var(--trap); font-weight: 600; }

/* --- Worked example block --- */
.worked { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 18px 22px; margin: 1.6em 0; border-left: 3px solid var(--accent); }
.worked h4 { margin: 0 0 10px 0; font-size: 14px; color: var(--accent); text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.worked .premise { font-style: italic; color: var(--text-muted); margin: 0 0 12px 0; }
.worked .step { font-family: var(--font-mono); font-size: 14px; margin: 4px 0; color: var(--text); }
.worked .step .label { color: var(--text-muted); display: inline-block; min-width: 90px; }
.worked .conclusion { margin: 12px 0 0 0; padding-top: 12px; border-top: 1px solid var(--border); font-weight: 500; }

/* --- Mobile pass --- */
@media (max-width: 760px) {
  body { font-size: 18px; }
  pre code { font-size: 15px; }
  .tab-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex: 0 0 auto; white-space: nowrap; }
  .svg-label { font-size: 15px; }
  .svg-sub   { font-size: 13px; }
}
@media (max-width: 640px) {
  .hero-quote { font-size: 22px; line-height: 1.3; }
  .hero-sub   { font-size: 15px; }
  h1 { font-size: 30px; }
  h2 { font-size: 23px; }
}
