/* ============================================================
   Coding Interviews — the pattern map
   Shared stylesheet for the hub (index.html) and ch01–ch24.
   Written ONCE by the scaffold. Chapter agents: do NOT edit this
   file — use the generic classes below; truly chapter-specific
   rules go in cssfrag-chNN.css (merged later).
   Palette: forest green (#3B7A5C, "Accepted ✓") + ochre
   (#C28E2C, whiteboard marker) on the family paper base.
   Every code surface uses the LIGHT --code-* theme. No dark panes.
   ============================================================ */

/* === TOKENS === */
:root {
  --bg: #FAFAF8;
  --bg-card: #FFFFFF;
  --bg-sunken: #F4F3F9;
  --text: #1A1A2E;
  --text-muted: #5C5C7A;
  --accent:                 #3B7A5C;   /* forest green — "Accepted ✓" */
  --accent-dark:            #2D5C45;
  --accent-light:           #DEEEE6;
  --accent-secondary:       #C28E2C;   /* ochre — whiteboard marker */
  --accent-secondary-light: #F5E9D0;
  --warn: #D97706;
  --warn-light: #FDF1E0;
  --ok: #2D7D46;
  --ok-light: #E8F5EC;
  --err: #DC2626;
  --err-light: #FEE8E8;
  --grid-line: rgba(59, 122, 92, 0.07);
  --border: #E5E3EC;
  --shadow: rgba(40, 30, 90, 0.07);
  --radius: 0.75rem;
  --mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', ui-monospace, Menlo, Consolas, monospace;

  /* code theme — ONE light scheme for every code surface */
  --code-bg: #EEF2F5;          /* light cool surface */
  --code-bg-soft: #E1E7EC;     /* tab bar / chips */
  --code-border: #D3DAE0;
  --code-fg: #1F2533;          /* near-black code text */
  --code-cm: #7A8590;          /* comment (grey, italic) */
  --code-kw: #9C2D6E;          /* keyword (magenta) */
  --code-ty: #2D6E78;          /* type (teal) */
  --code-fn: #2F5FA3;          /* function / value name (blue) */
  --code-op: #B5552A;          /* operator (rust) */
  --code-st: #3B7A4B;          /* string / literal (green) */
}

/* === RESET === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === LAYOUT === */
.container { max-width: 1040px; margin: 0 auto; padding: 0 1.5rem; }
.wide { max-width: 1040px; }

/* === HEADER === */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(250, 250, 248, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s, box-shadow 0.3s;
}
header.scrolled {
  border-bottom-color: var(--border);
  box-shadow: 0 1px 8px var(--shadow);
}
header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; max-width: 1040px;
}
.wordmark {
  display: flex; align-items: center; gap: 0.5rem;
  font-weight: 600; font-size: 0.95rem; color: var(--text);
}
.wordmark:hover { text-decoration: none; }
.wordmark .mk {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: 0.85rem;
}
.wordmark .mk svg { width: 16px; height: 16px; }
.wordmark span { opacity: 0.5; font-weight: 400; }
header nav { display: flex; gap: 1.2rem; align-items: center; }
header nav a {
  font-size: 0.85rem; color: var(--text-muted);
  transition: color 0.2s;
}
header nav a:hover { color: var(--accent); text-decoration: none; }
.back-link {
  font-size: 0.85rem; color: var(--text-muted);
  transition: color 0.2s;
}
.back-link:hover { color: var(--accent); text-decoration: none; }
/* scroll progress — ochre marker line */
.progress {
  position: absolute; left: 0; bottom: -1px; height: 2px;
  background: var(--accent-secondary); width: 0%;
  transition: width 0.1s linear;
}

/* === HERO === */
.hero {
  padding: 4.5rem 0 3rem;
  text-align: center;
  position: relative;
  overflow: hidden;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 28px 28px;
}
.hero::after {
  content: '';
  position: absolute; bottom: 0; left: 0; right: 0; height: 80px;
  background: linear-gradient(transparent, var(--bg));
  pointer-events: none;
}
.eyebrow {
  display: inline-flex; align-items: center; gap: 0.5rem;
  font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--accent-dark);
  background: var(--accent-light);
  padding: 0.35rem 0.8rem; border-radius: 999px;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.6s ease-out both;
}
.hero-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 3rem; font-weight: 600;
  letter-spacing: -0.02em; line-height: 1.1;
  margin-bottom: 0.85rem;
  animation: fadeUp 0.6s ease-out 0.08s both;
}
.hero-title em { font-style: italic; color: var(--accent-secondary); }
.hero-subtitle {
  font-size: 1.15rem; color: var(--text-muted);
  max-width: 620px; margin: 0 auto 2rem;
  animation: fadeUp 0.6s ease-out 0.16s both;
}
.hero-motif, .hero-arrows { animation: fadeUp 0.6s ease-out 0.28s both; }
/* subtle drift on hub-motif dots (killed under reduced motion) */
.hero-motif .mdot { animation: motifFloat 4s ease-in-out infinite alternate; }
.hero-motif .mdot.m2 { animation-duration: 5.2s; animation-delay: -1.7s; }
.hero-motif .mdot.m3 { animation-duration: 6.1s; animation-delay: -2.9s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes motifFloat {
  from { transform: translateY(0); }
  to   { transform: translateY(-4px); }
}

/* === SECTIONS === */
section.lesson { padding: 1rem 0; }
.block { margin: 2.75rem 0; }
h2.sec {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.7rem; font-weight: 600; letter-spacing: -0.01em;
  margin-bottom: 0.4rem;
  scroll-margin-top: 72px;
}
h2.sec .num {
  font-family: var(--mono); font-size: 0.95rem; font-weight: 500;
  color: var(--accent-secondary); margin-right: 0.5rem;
  vertical-align: 0.12em;
}
h3.sub { font-size: 1.1rem; font-weight: 600; margin: 1.5rem 0 0.5rem; }
p.lead { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 1rem; }
.prose p { margin-bottom: 0.9rem; }
.prose ul, .prose ol:not(.checklist) { margin: 0.4rem 0 1rem 1.3rem; }
.prose li { margin-bottom: 0.35rem; }

/* inline code-ish chip */
.m {
  font-family: var(--mono); font-size: 0.92em;
  background: var(--bg-sunken);
  padding: 0.08em 0.38em; border-radius: 4px;
  white-space: nowrap;
}
.m.obj { color: var(--accent-secondary); background: var(--accent-secondary-light); }
.m.mor { color: var(--accent-dark); background: var(--accent-light); }

/* === DIFFICULTY CHIPS (canonical problem names) === */
.diff {
  display: inline-block;
  font-family: var(--mono); font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.06rem 0.5rem; border-radius: 999px;
  vertical-align: 0.12em; white-space: nowrap;
}
.diff.easy { background: var(--ok-light);   color: var(--ok); }
.diff.med  { background: var(--warn-light); color: var(--warn); }
.diff.hard { background: var(--err-light);  color: var(--err); }

/* === CALLOUTS === */
.callout {
  display: flex; gap: 0.85rem;
  background: var(--accent-light);
  border: 1px solid #c5ded1;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin: 1.5rem 0;
  font-size: 0.95rem;
}
.callout .ic { font-size: 1.2rem; flex-shrink: 0; line-height: 1.5; }
.callout strong { color: var(--accent-dark); }
.callout.warn { background: var(--warn-light); border-color: #f3dcb6; border-left-color: var(--warn); }
.callout.warn strong { color: var(--warn); }
/* the book's signature: 🎯 "The tell:" — cues in the problem statement */
.callout.tell { background: var(--accent-secondary-light); border-color: #ecd8ae; border-left: 3px solid var(--accent-secondary); }
.callout.tell strong { color: #8F681C; }

/* === CHECKLIST RECAP (whiteboard skeleton) === */
.checklist { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.checklist li {
  display: flex; gap: 0.7rem; align-items: flex-start;
  padding: 0.55rem 0; border-bottom: 1px dashed var(--border);
  font-size: 0.95rem;
}
.checklist li:last-child { border-bottom: none; }
.checklist .step { font-family: var(--mono); font-weight: 700; color: var(--accent-secondary); flex-shrink: 0; }

/* === WIDGET FRAME === */
.widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
  box-shadow: 0 1px 3px var(--shadow);
}
.widget-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.6rem;
  margin-bottom: 0.5rem;
}
.widget-title {
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 0.45rem;
}
.widget-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-secondary); }
.hint { font-size: 0.8rem; color: var(--text-muted); }

svg.diagram { width: 100%; height: auto; display: block; touch-action: none; user-select: none; }
.diagram-wrap { background: var(--bg-sunken); border-radius: 0.5rem; padding: 0.5rem; }

/* === BUTTONS / CONTROLS === */
.controls { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.85rem; align-items: center; }
.btn {
  font: inherit; font-size: 0.85rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 8px;
  padding: 0.45rem 0.85rem; cursor: pointer;
  transition: all 0.15s ease-out;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.readout {
  font-family: var(--mono); font-size: 0.85rem;
  color: var(--text-muted); margin-left: auto;
}
select.pick {
  font: inherit; font-family: var(--mono); font-size: 0.85rem;
  padding: 0.3rem 0.5rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  cursor: pointer;
}
/* range sliders */
.slider-row { display: flex; align-items: center; gap: 0.7rem; margin-top: 0.7rem; flex-wrap: wrap; }
.slider-row label { font-size: 0.82rem; color: var(--text-muted); min-width: 8.5rem; }
.slider-row input[type=range] { flex: 1; min-width: 140px; accent-color: var(--accent-secondary); cursor: pointer; }
.slider-row .val { font-family: var(--mono); font-size: 0.82rem; color: var(--accent-dark); min-width: 4.5rem; text-align: right; }
/* +/- stepper */
.stepper { display: inline-flex; align-items: center; gap: 0.25rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-card); padding: 0.1rem; }
.stepper button { font: inherit; font-family: var(--mono); font-weight: 700; width: 26px; height: 26px; border: none; background: transparent; color: var(--accent); cursor: pointer; border-radius: 6px; }
.stepper button:hover { background: var(--accent-light); }
.stepper .val { font-family: var(--mono); font-size: 0.9rem; min-width: 1.6rem; text-align: center; }
/* toggle pills */
.toggle-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
label.toggle {
  display: inline-flex; align-items: center; gap: 0.45rem;
  font-size: 0.85rem; font-weight: 500;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); border-radius: 999px;
  padding: 0.35rem 0.8rem; cursor: pointer;
  transition: all 0.15s ease-out;
  user-select: none;
}
label.toggle:hover { border-color: var(--accent); }
label.toggle.on { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); }
label.toggle input { accent-color: var(--accent); cursor: pointer; }

/* stat grid (live readouts) */
.statgrid { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.85rem; }
.stat {
  flex: 1; min-width: 130px;
  background: var(--bg-sunken); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.6rem 0.75rem;
}
.stat .k { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-muted); font-weight: 600; }
.stat .v { font-family: var(--mono); font-size: 1.15rem; font-weight: 600; color: var(--accent-dark); }
.stat .v.warnv { color: var(--err); }
.stat .v.okv { color: var(--ok); }

/* === CODE CARD — light theme everywhere === */
.code-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin: 1.5rem 0; }
.code-tabs { display: flex; background: var(--code-bg-soft); border-bottom: 1px solid var(--code-border); }
.code-tab {
  font: inherit; font-size: 0.82rem; font-weight: 500;
  font-family: var(--mono);
  color: var(--text-muted); background: transparent; border: none;
  padding: 0.6rem 1.05rem; cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.code-tab:hover { color: var(--text); }
.code-tab.active { color: var(--accent-dark); border-bottom-color: var(--accent-secondary); }
.code-tab .lang-ic { opacity: 0.9; margin-right: 0.4rem; }
pre.code, pre.live {
  margin: 0; padding: 1.1rem 1.2rem;
  background: var(--code-bg); color: var(--code-fg);
  font-family: var(--mono); font-size: 0.84rem; line-height: 1.7;
  overflow-x: auto;
}
pre.live { padding: 0.9rem 1.1rem; line-height: 1.75; border-radius: 0.5rem; white-space: pre-wrap; }
pre.code .cm, pre.live .cm { color: var(--code-cm); font-style: italic; }
pre.code .kw, pre.live .kw { color: var(--code-kw); }
pre.code .ty, pre.live .ty { color: var(--code-ty); }
pre.code .fn, pre.live .fn { color: var(--code-fn); }
pre.code .op, pre.live .op { color: var(--code-op); }
pre.code .st, pre.live .st { color: var(--code-st); }
pre.live .hl { background: rgba(194, 142, 44, 0.22); border-radius: 3px; box-shadow: 0 0 0 2px rgba(194, 142, 44, 0.22); }
pre.live .dim { opacity: 0.38; }
.trace-line { transition: opacity 0.2s, background 0.2s; }
.code-pane { display: none; }
.code-pane.active { display: block; }

/* === QUIZ === */
.quiz-q { margin-bottom: 1.4rem; }
.quiz-q:last-child { margin-bottom: 0; }
.quiz-q .q { font-weight: 600; margin-bottom: 0.6rem; }
.quiz-q .q .qn {
  font-family: var(--mono); color: var(--accent-secondary); font-size: 0.85rem; margin-right: 0.4rem;
}
.opt {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: 0.92rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.6rem 0.85rem; margin-bottom: 0.5rem;
  cursor: pointer; transition: all 0.12s ease-out;
  display: flex; align-items: center; gap: 0.6rem;
}
.opt:hover:not(.locked) { border-color: var(--accent); background: var(--accent-light); }
.opt .mark { width: 18px; flex-shrink: 0; font-weight: 700; }
.opt.correct { border-color: var(--ok); background: var(--ok-light); color: #1b5e2e; }
.opt.wrong { border-color: var(--err); background: var(--err-light); color: #b91c1c; }
.opt.locked { cursor: default; }
.quiz-fb { font-size: 0.88rem; margin-top: 0.4rem; min-height: 1.2em; color: var(--text-muted); }
.quiz-fb.show.ok { color: var(--ok); }
.quiz-fb.show.no { color: var(--err); }

/* === NEXT CARD === */
.next-card {
  display: flex; align-items: center; gap: 1rem;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-secondary-light));
  border: 1px solid #d9cba3; border-radius: var(--radius);
  padding: 1.25rem 1.4rem; margin: 2.5rem 0 1rem;
}
.next-card .big { font-size: 1.6rem; }
.next-card .t1 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); font-weight: 600; }
.next-card .t2 { font-weight: 600; font-size: 1.05rem; }
.next-card .t3 { font-size: 0.88rem; color: var(--text-muted); }
.next-card .lock { margin-left: auto; font-size: 0.8rem; color: var(--text-muted); }
a.next-card { color: inherit; text-decoration: none; transition: transform 0.2s ease-out, box-shadow 0.2s ease-out; }
a.next-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px var(--shadow); text-decoration: none; }
.next-card .arrow { margin-left: auto; font-size: 1.4rem; color: var(--accent-dark); transition: transform 0.2s ease-out; }
a.next-card:hover .arrow { transform: translateX(4px); }
/* series-complete finale (ch24 → index.html) */
.next-card.finale { background: linear-gradient(135deg, var(--accent-light), var(--accent-secondary-light)); }
.next-card.finale .big { font-size: 2.2rem; }
.next-card.finale .t2 { font-family: 'Fraunces', Georgia, serif; font-size: 1.35rem; }

/* === HUB: PART SECTIONS === */
.part { padding: 2rem 0; }
.part + .part { border-top: 1px solid var(--border); }
.part .part-label {
  display: inline-block;
  font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: #8F681C;
  background: var(--accent-secondary-light);
  padding: 0.25rem 0.6rem; border-radius: 999px;
  margin-bottom: 0.7rem;
}
.part .part-intro { color: var(--text-muted); margin-bottom: 1.5rem; max-width: 640px; }

/* === HUB: FIELD GRID + CARDS === */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}
.field-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-secondary);
  border-radius: var(--radius);
  padding: 1.25rem 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  position: relative;
  color: inherit;
  text-decoration: none;
  transition: box-shadow 0.25s ease-out, transform 0.25s ease-out;
}
.field-card:hover {
  text-decoration: none;
  transform: translateY(-3px);
  box-shadow: 0 8px 22px var(--shadow);
}
/* card reveal on scroll (generic: any element can carry .reveal) */
.reveal { opacity: 0; transform: translateY(18px); }
.reveal.in { opacity: 1; transform: translateY(0); transition: opacity 0.5s ease-out, transform 0.5s ease-out; }

.field-head { display: flex; align-items: flex-start; gap: 0.7rem; }
.ch-badge {
  flex-shrink: 0;
  font-family: var(--mono); font-weight: 700; font-size: 0.82rem;
  color: var(--accent-dark);
  background: var(--accent-light);
  border-radius: 7px;
  width: 2.1rem; height: 2.1rem;
  display: grid; place-items: center;
}
.field-name {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.15rem; font-weight: 600;
  letter-spacing: -0.01em; line-height: 1.25;
}
.field-meta { font-size: 0.74rem; color: var(--text-muted); font-family: var(--mono); margin-top: 0.15rem; }
.field-what { font-size: 0.93rem; line-height: 1.55; }
.field-what strong { font-weight: 600; color: var(--text); }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.1rem; }
.tag {
  font-size: 0.72rem; font-family: var(--mono);
  color: var(--text-muted);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
}
.field-foot {
  margin-top: auto; padding-top: 0.6rem;
  display: flex; align-items: center; justify-content: flex-end;
}
.field-foot .open {
  font-size: 0.82rem; font-weight: 600;
  color: var(--accent);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.field-foot .open .arrow { transition: transform 0.2s ease-out; }
.field-card:hover .field-foot .open .arrow { transform: translateX(4px); }

/* === FOOTER === */
footer {
  padding: 2.5rem 0; text-align: center;
  font-size: 0.8rem; color: var(--text-muted);
  border-top: 1px solid var(--border); margin-top: 1rem;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .hero-motif .mdot { animation: none; }
  .reveal { opacity: 1; transform: none; }
}

/* === RESPONSIVE === */
@media (max-width: 1023px) {
  .hero-title { font-size: 2.5rem; }
}
@media (max-width: 767px) {
  /* long formula chips must wrap on narrow screens */
  .m { white-space: normal; overflow-wrap: anywhere; }
  .hero { padding: 3rem 0 2rem; }
  .hero-title { font-size: 2.1rem; }
  .hero-subtitle { font-size: 1rem; }
  h2.sec { font-size: 1.4rem; }
  header nav a:not(.nav-keep) { display: none; }
  .readout { margin-left: 0; width: 100%; }
  .field-grid { grid-template-columns: 1fr; }
}
