/* ============================================================
   Shared design system for the "Learn Software Design" site.
   Dark, calm, high-contrast. No build step — plain CSS.
   ============================================================ */

:root {
  --bg:        #0f1220;
  --bg-soft:   #171a2b;
  --panel:     #1d2136;
  --panel-2:   #252a44;
  --ink:       #e8ebf5;
  --ink-soft:  #a6adc8;
  --ink-dim:   #6b7194;
  --line:      #2e3352;

  --good:      #4ade80;
  --good-dim:  #14532d;
  --bad:       #f87171;
  --bad-dim:   #4c1d1d;
  --accent:    #7c9cff;
  --accent-2:  #c084fc;
  --warn:      #fbbf24;

  --radius:    14px;
  --shadow:    0 10px 40px rgba(0,0,0,.45);
  --mono:      'JetBrains Mono', 'Fira Code', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans:      system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --ease:      cubic-bezier(.22,.61,.36,1);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  background:
    radial-gradient(1200px 600px at 80% -10%, #1b1f3a 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 20%, #201a3a 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1040px; margin: 0 auto; padding: 32px 24px 96px; }
/* full-width variant (index) — cards use the whole screen; heading text still
   caps its measure via .lede/.eyebrow so long lines stay readable */
.wrap.wide { max-width: none; padding-left: 40px; padding-right: 40px; }

/* ---------- Header / nav ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(10px);
  background: rgba(15,18,32,.72);
}
.topbar .brand { font-weight: 700; letter-spacing: .3px; }
.topbar .brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 18px; font-size: 14px; color: var(--ink-soft); }

.eyebrow {
  text-transform: uppercase; letter-spacing: 2px; font-size: 12px;
  color: var(--accent-2); font-weight: 600;
}

h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1.1; margin: 10px 0 8px; }
h2 { font-size: 22px; margin: 40px 0 12px; }
.lede { color: var(--ink-soft); font-size: 18px; max-width: 70ch; }

/* ---------- Topic cards (index) ---------- */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-top: 28px; }
.card {
  display: block; padding: 20px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .25s var(--ease), border-color .25s var(--ease);
}
.card:hover { transform: translateY(-4px); border-color: var(--accent); text-decoration: none; }
.card .tag {
  display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--ink-soft); margin-bottom: 12px;
}
.card h3 { margin: 0 0 6px; color: var(--ink); }
.card p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.card.soon { opacity: .5; pointer-events: none; }
/* ⭐ marks patterns you reach for constantly */
.card .star { position: absolute; top: 14px; right: 16px; font-size: 15px; filter: drop-shadow(0 0 6px rgba(251,191,36,.5)); }
.card { position: relative; }
.legend { color: var(--ink-soft); font-size: 13px; margin: 6px 0 0; }
.legend .star { filter: drop-shadow(0 0 6px rgba(251,191,36,.5)); }

/* ---------- Search + group filter (index) ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 24px 0 6px; }
.search {
  flex: 1 1 260px; min-width: 200px; padding: 11px 15px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 15px; font-family: var(--sans);
}
.search::placeholder { color: var(--ink-dim); }
.search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.2); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink-soft); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.active { background: var(--accent); color: #0b0e1a; border-color: transparent; }
.topic-group[hidden] { display: none; }
#no-results { color: var(--ink-soft); font-size: 15px; margin: 36px 2px; }

/* ---------- career-path tabs + level filter (home) ---------- */
.paths { display: flex; flex-wrap: wrap; gap: 8px; margin: 24px 0 4px; }
.ctab {
  padding: 10px 16px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink-soft); font-size: 14.5px; font-weight: 700; cursor: pointer;
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}
.ctab:hover { border-color: var(--accent); color: var(--ink); }
.ctab.active { background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #0b0e1a; border-color: transparent; }
.path-hint { color: var(--ink-dim); font-size: 13px; margin: 2px 2px 12px; }

.toolbar2 { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; margin: 6px 0 2px; }
.pills { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill-label { color: var(--ink-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700; }
.lvl {
  padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink-soft); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .2s var(--ease);
}
.lvl:hover { border-color: var(--accent); color: var(--ink); }
.lvl.active { background: var(--accent); color: #0b0e1a; border-color: transparent; }

/* per-card difficulty badge (auto-added by topic-filter.js) */
.lvl-badge {
  position: absolute; bottom: 12px; right: 14px; font-size: 9.5px; font-weight: 800; letter-spacing: .6px;
  padding: 2px 7px; border-radius: 999px;
}
.lvl-badge.basic { background: var(--good-dim); color: #bbf7d0; }
.lvl-badge.advanced { background: rgba(251,191,36,.16); color: var(--warn); }
.card p { padding-right: 46px; }   /* keep description clear of the badge */
.subhead { font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-dim); font-weight: 700; margin: 26px 2px 4px; }
h2 .count { font-size: 14px; color: var(--ink-dim); font-weight: 500; letter-spacing: normal; }

/* ---------- Stepper ---------- */
.stage {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; margin-top: 24px;
}

/* Side-by-side layout so code + visuals fill the width instead of stacking
   with an empty right half. Collapses to one column on narrow screens. */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; align-items: center; margin: 16px 0; }
.split > * { margin: 0; min-width: 0; }
.split pre { align-self: stretch; }
@media (max-width: 760px) { .split { grid-template-columns: 1fr; } }

/* ============================================================
   REUSABLE FULL-VIEWPORT LESSON SHELL
   Opt in per topic page with:
     <body class="lesson-page">  +  <main class="lesson">
   Result: the page never scrolls; the stage fills the leftover
   height and the active slide expands to use all of it. Only an
   overly tall individual slide scrolls — inside its own area.
   ============================================================ */
.lesson-page { height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.lesson-page .topbar { flex: 0 0 auto; padding: 10px 24px; }

.lesson {
  flex: 1 1 auto; min-height: 0; width: 100%; max-width: 1180px; margin: 0 auto;
  display: flex; flex-direction: column; padding: 10px 24px 12px;
}
/* ultra-compact header — hand as much height as possible to the stage */
.lesson > .eyebrow, .lesson > h1, .lesson > .lede { flex: 0 0 auto; }
.lesson > .eyebrow { font-size: 11px; margin: 0; }
.lesson > h1   { margin: 2px 0; font-size: clamp(20px, 3vw, 28px); line-height: 1.15; }
.lesson > .lede { font-size: 14px; line-height: 1.45; margin: 2px 0 0; max-width: 95ch; }

/* stage grows to fill ALL remaining height */
.lesson .stage {
  flex: 1 1 auto; min-height: 0; margin-top: 10px; padding: 20px 22px;
  display: flex; flex-direction: column; overflow: hidden;
}
/* active slide fills the stage and spreads its content to use the space;
   `safe center` keeps the top reachable if a slide is ever taller than the box */
.lesson .stage > .step.active {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  display: flex; flex-direction: column; justify-content: safe center; gap: 6px;
}
/* the nav row is pinned to the bottom of the stage */
.lesson .stage > .controls { flex: 0 0 auto; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }

/* let the main visual of a slide grow to fill freed vertical space */
.lesson .step.active .split { flex: 1 1 auto; align-content: center; }

/* tighten headings / spacing inside slides so content fits without scrolling */
.lesson .step h2      { margin: 4px 0 2px; font-size: 20px; }
.lesson .step .note   { margin: 2px 0; }
.lesson .step pre     { margin: 8px 0; }
/* wrap long code lines instead of showing a horizontal scrollbar in the
   narrow split panels; `anywhere` also stops a long line from widening the grid */
.lesson .step pre { white-space: pre-wrap; overflow-wrap: anywhere; overflow-x: hidden; }
.lesson .step .callout { margin: 8px 0 0; }
.lesson .step .diagram { gap: 12px; padding: 8px 0; }
.lesson .step .node   { padding: 10px 16px; }

/* progressively drop the lede as viewport height shrinks */
@media (max-height: 820px) { .lesson > .lede { display: none; } }
.step { display: none; animation: fade 1.1s var(--ease); }
.step.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.step h2 { margin-top: 0; }
.step .note { color: var(--ink-soft); }

.controls {
  display: flex; align-items: center; gap: 14px; margin-top: 22px;
}
.btn {
  font-family: var(--sans); font-size: 15px; font-weight: 600;
  padding: 10px 20px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink); cursor: pointer;
  transition: background .2s var(--ease), transform .1s var(--ease);
}
.btn:hover:not(:disabled) { background: var(--accent); color: #0b0e1a; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #0b0e1a; border-color: transparent; }

.progress { display: flex; gap: 8px; margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background .3s var(--ease), transform .3s var(--ease); }
.dot.on { background: var(--accent); transform: scale(1.25); }
.stepcount { color: var(--ink-dim); font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Code blocks ---------- */
pre {
  font-family: var(--mono); font-size: 13.5px; line-height: 1.7;
  background: #0b0e1a; border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; overflow-x: auto; margin: 14px 0;
}
code { font-family: var(--mono); }
.tok-key { color: #c084fc; }
.tok-fn  { color: #7c9cff; }
.tok-str { color: #4ade80; }
.tok-com { color: var(--ink-dim); font-style: italic; }
.tok-cls { color: #fbbf24; }

/* line highlight for animated code walkthroughs */
pre .ln { display: block; padding: 0 6px; border-radius: 4px; transition: background .35s var(--ease); }
pre .ln[hidden] { display: none; }   /* beat `pre .ln`'s display:block so hidden lines stay hidden */
pre .ln.hl { background: rgba(124,156,255,.16); box-shadow: inset 3px 0 0 var(--accent); }
pre .ln.add { background: rgba(74,222,128,.12); box-shadow: inset 3px 0 0 var(--good); }
pre .ln.del { background: rgba(248,113,113,.12); box-shadow: inset 3px 0 0 var(--bad); opacity: .65; }

/* ---------- Verdict badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px;
  padding: 6px 12px; border-radius: 999px; }
.badge.bad  { background: var(--bad-dim);  color: #fecaca; }
.badge.good { background: var(--good-dim); color: #bbf7d0; }

/* ---------- Diagram primitives (animated boxes + arrows) ---------- */
.diagram { position: relative; display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: center; padding: 20px 0; }
.node {
  padding: 14px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); text-align: center; min-width: 120px;
  transition: all .5s var(--ease); position: relative;
}
.node .t { font-weight: 700; }
.node .s { font-size: 12px; color: var(--ink-soft); }
.node.hot    { border-color: var(--bad);  box-shadow: 0 0 0 3px var(--bad-dim); }
.node.calm   { border-color: var(--good); box-shadow: 0 0 0 3px var(--good-dim); }
.node.accent { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.25); }
.node.pop { animation: pop 1.4s var(--ease); }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.08); } 100% { transform: scale(1); opacity: 1; } }

.arrow { color: var(--ink-dim); font-size: 24px; align-self: center; transition: color .4s var(--ease); }
.arrow.live { color: var(--accent); }

.callout {
  border-left: 3px solid var(--accent); background: var(--panel);
  padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 16px 0; color: var(--ink-soft);
}
.callout.good { border-color: var(--good); }
.callout.bad  { border-color: var(--bad); }
/* "principle applied" callout — ties a pattern back to the principle it serves */
.callout.principle {
  border-color: var(--accent-2); color: var(--ink);
  background: linear-gradient(90deg, rgba(192,132,252,.12), transparent);
}
.callout.principle a { color: var(--accent-2); }

.kbd { font-family: var(--mono); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 1px 7px; font-size: 12px; }

.foot { margin-top: 60px; color: var(--ink-dim); font-size: 13px; text-align: center; }

/* ============================================================
   Animated sequence diagram (assets/sequence-diagram.js)
   Actor columns + dashed lifelines + numbered, labelled message
   arrows revealed one at a time to show request ORDER.
   ============================================================ */
.seq { display: block; }
.seq-actors { display: flex; gap: 8px; }
.seq-actor {
  flex: 1 1 0; min-width: 0; text-align: center; font-weight: 700; font-size: 12px;
  padding: 8px 4px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel-2); color: var(--ink); transition: all .3s var(--ease);
  overflow: hidden;
}
.seq-actor span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seq-actor.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.25); }

.seq-stage { position: relative; margin-top: 8px; max-height: 38vh; overflow-y: auto; overflow-x: hidden; }
.seq-lifelines, .seq-msgs { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }
.seq-line { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--line); transform: translateX(-1px); }

.seq-msg { position: absolute; height: 0; }
.seq-msg .seq-arrow {
  position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--accent);
  transform: scaleX(0); transition: transform .5s var(--ease);
}
.seq-msg[data-dir=r] .seq-arrow { transform-origin: left; }
.seq-msg[data-dir=l] .seq-arrow { transform-origin: right; }
.seq-msg.go .seq-arrow { transform: scaleX(1); }
.seq-msg .seq-arrow::after {
  content: ''; position: absolute; top: -3px; width: 0; height: 0;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent;
}
.seq-msg[data-dir=r] .seq-arrow::after { right: -1px; border-left: 7px solid var(--accent); }
.seq-msg[data-dir=l] .seq-arrow::after { left: -1px; border-right: 7px solid var(--accent); }

.seq-msg .seq-label {
  position: absolute; top: -15px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: var(--ink-soft); white-space: nowrap;
  background: var(--bg-soft); padding: 0 6px; opacity: 0; transition: opacity .4s var(--ease);
}
.seq-msg.go .seq-label { opacity: 1; }
.seq-num {
  position: absolute; top: -9px; left: -9px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #0b0e1a; font-size: 11px; font-weight: 700; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: scale(.4); transition: all .3s var(--ease);
}
.seq-msg[data-dir=l] .seq-num { left: auto; right: -9px; }
.seq-msg.go .seq-num { opacity: 1; transform: scale(1); }

/* message kinds */
.seq-msg.return .seq-arrow { background: var(--good); }
.seq-msg.return .seq-arrow::after { border-left-color: var(--good); border-right-color: var(--good); }
.seq-msg.return .seq-num { background: var(--good); }
.seq-msg.fail .seq-arrow { background: var(--bad); }
.seq-msg.fail .seq-arrow::after { border-left-color: var(--bad); border-right-color: var(--bad); }
.seq-msg.fail .seq-num { background: var(--bad); }
.seq-msg.fail .seq-label { color: #fecaca; }

.seq-controls { display: flex; gap: 10px; align-items: center; margin-top: 14px; flex-wrap: wrap; }

/* ---------- in-page lesson modal (assets/lesson-frame.js) ---------- */
.lf-overlay {
  position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center;
  padding: 22px; background: rgba(6,8,16,.74); backdrop-filter: blur(5px);
}
.lf-overlay.show { display: flex; animation: fade .22s var(--ease); }
.lf-modal {
  width: min(1120px, 96vw); height: min(90vh, 940px); display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.lf-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px 9px 16px; border-bottom: 1px solid var(--line); background: var(--bg-soft);
}
.lf-title { font-weight: 700; font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lf-actions { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.lf-hint { color: var(--ink-dim); font-size: 12px; }
.lf-open { color: var(--accent); font-size: 13px; text-decoration: none; }
.lf-open:hover { text-decoration: underline; }
.lf-close {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); border-radius: 8px;
  width: 30px; height: 30px; cursor: pointer; font-size: 14px; line-height: 1;
}
.lf-close:hover { background: var(--bad-dim); color: #fecaca; border-color: var(--bad); }
.lf-frame { flex: 1 1 auto; width: 100%; border: 0; background: var(--bg); }
@media (max-width: 600px) { .lf-hint { display: none; } }

/* ---------- high-level "big picture" flow map (assets/flow-map.js) ---------- */
.fmap { margin: 8px 0; }
.fm-row { display: flex; flex-wrap: wrap; align-items: stretch; justify-content: center; gap: 6px; }
.fm-box {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-width: 116px; max-width: 168px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--ink); text-decoration: none;
  opacity: 0; transform: translateY(8px); transition: opacity .4s var(--ease), transform .4s var(--ease);
}
.fm-box.in { opacity: 1; transform: none; }
a.fm-box:hover { border-color: var(--accent); }
.fm-ic { font-size: 20px; line-height: 1; }
.fm-lbl { font-weight: 700; font-size: 13.5px; margin-top: 3px; }
.fm-role { font-size: 11px; color: var(--ink-soft); margin-top: 2px; }
.fm-arrow { display: flex; align-items: center; gap: 4px; align-self: center; opacity: 0; transition: opacity .4s var(--ease); }
.fm-arrow.in { opacity: 1; }
.fm-line { position: relative; width: 22px; height: 2px; background: var(--accent); }
.fm-line::after { content: ''; position: absolute; right: -1px; top: -3px; width: 0; height: 0;
  border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 7px solid var(--accent); }
.fm-num { width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #0b0e1a;
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.fm-cap { text-align: center; color: var(--ink-soft); font-size: 13px; margin: 12px auto 0; max-width: 74ch; }
@media (max-width: 640px) { .fm-arrow { transform: rotate(90deg); } }
