/* ==========================================================================
   Software Design Reference — shared course stylesheet
   Linked by every lesson, the index, and all reference documents.

   Design: a modern editorial system. Space Grotesk for display, Inter for
   body, JetBrains Mono for code; one indigo→violet gradient accent; hairline
   borders, generous radii, quiet shadows; automatic dark theme.

   Fonts load from Google Fonts and fall back to high-quality system stacks,
   so the course still reads well offline.
   ========================================================================== */

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-2: #f4f4f2;
  --field: #ffffff;
  --ink: #18181b;
  --ink-soft: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e7e7e2;
  --line-strong: #d4d4ce;

  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: #eef0ff;
  --violet: #8b5cf6;
  --grad: linear-gradient(120deg, var(--accent), var(--violet));

  --ok: #15803d;
  --ok-bg: #e8f6ee;
  --bad: #b91c1c;
  --bad-bg: #fdeeee;

  --code-bg: #f4f4f1;
  --mast-bg: rgba(250, 250, 249, 0.85);
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, 0.04);
  --shadow-md: 0 4px 16px -4px rgba(24, 24, 27, 0.08);
  --shadow-lg: 0 12px 32px -8px rgba(24, 24, 27, 0.14);

  --display: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --serif: var(--sans);
  --mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e11;
    --surface: #17171b;
    --surface-2: #1f1f24;
    --field: #1c1c21;
    --ink: #f4f4f5;
    --ink-soft: #d4d4d8;
    --muted: #a1a1aa;
    --faint: #6f6f77;
    --line: #2a2a30;
    --line-strong: #3f3f46;

    --accent: #818cf8;
    --accent-strong: #a5b4fc;
    --accent-soft: rgba(99, 102, 241, 0.16);
    --violet: #a78bfa;

    --ok: #4ade80;
    --ok-bg: rgba(74, 222, 128, 0.12);
    --bad: #f87171;
    --bad-bg: rgba(248, 113, 113, 0.12);

    --code-bg: #16161a;
    --mast-bg: rgba(14, 14, 17, 0.82);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px -4px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 12px 32px -8px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  font-size: 17px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.65;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent-soft); }

/* ---------- Layout ---------- */

.container {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.container.home { max-width: 68rem; }

main { padding: 2.2rem 0 3.5rem; }

/* ---------- Masthead ---------- */

.masthead {
  position: sticky;
  top: 0;
  z-index: 80;
  background: var(--mast-bg);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.masthead .inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0.6rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 2.9rem;
}
.masthead a.title,
.masthead .inner > a {
  font-family: var(--display);
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.masthead a:hover { color: var(--accent); }
.masthead .phase {
  font-family: var(--sans);
  font-size: 0.66rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28em 0.9em;
  white-space: nowrap;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: none;
}

footer.nav {
  border-top: 1px solid var(--line);
  background: var(--surface);
}
footer.nav .inner {
  max-width: 46rem;
  margin: 0 auto;
  padding: 1.2rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}
footer.nav a {
  color: var(--ink);
  text-decoration: none;
  font-family: var(--display);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.45em 0.9em;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
footer.nav a:hover {
  color: var(--accent);
  border-color: var(--line-strong);
  transform: translateY(-1px);
}
footer.nav .up { color: var(--muted); background: none; border: none; cursor: default; }
footer.nav .up:hover { color: var(--muted); transform: none; }

/* ---------- Typography ---------- */

h1 {
  font-family: var(--display);
  font-size: 2.25rem;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.025em;
  margin: 0.5rem 0 1rem;
}

h2 {
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin: 2.6rem 0 0.8rem;
}

h3 {
  font-family: var(--display);
  font-size: 1.02rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 1.7rem 0 0.45rem;
}

p { margin: 0.75rem 0; }
ul, ol { margin: 0.75rem 0; padding-left: 1.4rem; }
li { margin: 0.35rem 0; }
li::marker { color: var(--faint); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
a:focus-visible, summary:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

strong { font-weight: 650; }
em { font-style: italic; }

.kicker {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: 999px;
  padding: 0.4em 1em;
  margin: 0 0 0.9rem;
  line-height: 1.5;
}
.kicker a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }

.lede {
  font-size: 1.12rem;
  line-height: 1.55;
  color: var(--ink-soft);
  margin: 0 0 1.4rem;
  max-width: 42rem;
}

.mission-note {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin: 1.4rem 0;
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2.6rem 0;
}

/* ---------- Code ---------- */

code {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.08em 0.4em;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.05em 1.15em;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.6;
  margin: 1.1rem 0;
}
pre code { background: none; border: none; padding: 0; font-size: 1em; }

/* ---------- Sidenotes ---------- */

.sidenote {
  display: block;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.9rem;
  margin: 0.8rem 0 1.2rem;
}
.sidenote .marker {
  color: var(--accent);
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 600;
}

@media (min-width: 1320px) {
  .sidenote {
    float: right;
    width: 250px;
    margin: 0.25rem -280px 0 0;
    border-left: none;
  }
}

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.1rem 0;
  font-size: 0.93rem;
}
th {
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  text-align: left;
  color: var(--muted);
  border-bottom: 1.5px solid var(--ink);
  padding: 0.5rem 0.7rem;
}
td {
  border-bottom: 1px solid var(--line);
  padding: 0.55rem 0.7rem;
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface-2); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-family: var(--display);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.72em 1.3em;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  color: #fff;
  background: linear-gradient(120deg, var(--accent), var(--violet));
  box-shadow: 0 2px 10px -2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px -4px color-mix(in srgb, var(--accent) 65%, transparent);
}

.btn-ghost {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
}
.btn-ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.btn-small {
  font-size: 0.8rem;
  padding: 0.55em 1em;
}

/* ---------- Index: hero ---------- */

.hero {
  position: relative;
  text-align: center;
  padding: 3.4rem 0 2.8rem;
}
.hero::before {
  content: "";
  position: absolute;
  inset: -6rem -20% auto;
  height: 26rem;
  background:
    radial-gradient(42% 55% at 30% 40%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(42% 55% at 70% 55%, color-mix(in srgb, var(--violet) 12%, transparent), transparent 70%);
  pointer-events: none;
}
.hero-inner { position: relative; max-width: 52rem; margin: 0 auto; }

.hero h1 {
  font-size: clamp(2.5rem, 5.5vw, 3.7rem);
  margin: 0.3rem 0 1.1rem;
}
.hero h1 .grad {
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero .subtitle {
  font-size: 1.18rem;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: 44rem;
  margin: 0 auto 1.8rem;
}

.hero-cta {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.8rem;
  margin-bottom: 2.6rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--line);
  box-shadow: var(--shadow-md);
  margin: 0;
}
.stat {
  background: var(--surface);
  padding: 1.15rem 0.5rem 1rem;
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.stat span {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* ---------- Index: sections and cards ---------- */

.prose { max-width: 46rem; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1.1rem;
  margin: 1.4rem 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem 1.5rem;
}
.card h3 { margin-top: 0; }
.card p { color: var(--ink-soft); }

.card ul, .card ol {
  list-style: none;
  padding-left: 0;
  margin: 0.4rem 0 0;
}
.card li {
  position: relative;
  padding-left: 1.35rem;
  margin: 0.55rem 0;
  color: var(--ink-soft);
}
.card li::before {
  content: "";
  position: absolute;
  left: 0.2rem;
  top: 0.62em;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--grad);
  opacity: 0.85;
}
.card li a { font-weight: 550; }

.card .card-note {
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 0.9rem;
}

.section-title {
  margin: 3.2rem 0 0.4rem;
}
.section-sub {
  color: var(--muted);
  max-width: 46rem;
  margin: 0 0 1.4rem;
}

/* Pillars: Knowledge / Skills / Wisdom */
.pillars {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13.5rem, 1fr));
  gap: 1.1rem;
  margin: 1.5rem 0;
}
.pillar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.3rem 1.4rem;
}
.pillar .chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-family: var(--display);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}
.pillar h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.pillar p { margin: 0; color: var(--ink-soft); font-size: 0.93rem; }

/* ---------- Index: resume ---------- */

.resume {
  background:
    radial-gradient(60% 120% at 100% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.5rem 1.6rem;
  margin: 1.6rem 0 2.2rem;
}
.resume .count {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.resume .progress-bar { margin: 0.8rem 0 1rem; }
.resume a.continue {
  display: inline-flex;
  font-family: var(--display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  border-radius: var(--radius-sm);
  padding: 0.6em 1em;
}
.resume a.continue:hover {
  text-decoration: none;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.resume .hint { font-size: 0.85rem; color: var(--muted); margin: 0.5rem 0 0; }

/* ---------- Index: phase cards ---------- */

.phase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr));
  gap: 1.2rem;
  margin: 1.5rem 0 0.5rem;
}

.phase-card {
  --phase-a: var(--accent);
  --phase-b: var(--violet);
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.6rem 1.7rem;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.phase-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

#core { --phase-a: #6366f1; --phase-b: #8b5cf6; }
#system { --phase-a: #0891b2; --phase-b: #22d3ee; }
#master { --phase-a: #d97706; --phase-b: #fbbf24; }
#initiative { --phase-a: #e11d48; --phase-b: #fb7185; }

.phase-head {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 0.8rem;
}
.phase-badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.8rem;
  background: linear-gradient(135deg, var(--phase-a), var(--phase-b));
  color: #fff;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 700;
  box-shadow: 0 4px 12px -2px color-mix(in srgb, var(--phase-a) 50%, transparent);
}
.phase-card h2 {
  font-size: 1.18rem;
  margin: 0;
  line-height: 1.2;
}
.phase-card .phase-note {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.phase-card .progress-bar { margin: 0.9rem 0 0.2rem; }
.phase-card .progress-bar .fill { background: linear-gradient(90deg, var(--phase-a), var(--phase-b)); }

.phase-card .tagline {
  color: var(--ink-soft);
  margin: 0.6rem 0 0;
}
.phase-card .note { color: var(--muted); font-size: 0.85rem; }

.phase-card h3.module-title {
  font-family: var(--sans);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--phase-a);
  margin: 1.5rem 0 0.4rem;
}

.phase-card ol { padding-left: 0; list-style: none; margin: 0.3rem 0 0.4rem; }
.phase-card li {
  position: relative;
  margin: 0;
  border-top: 1px solid var(--line);
}
.phase-card li:first-child { border-top: none; }
.phase-card ol a {
  display: flex;
  gap: 0.65rem;
  align-items: baseline;
  padding: 0.5rem 0.15rem;
  color: var(--ink);
  text-decoration: none;
  border-radius: 6px;
  transition: color 0.12s ease;
}
.phase-card ol a:hover { color: var(--phase-a); text-decoration: none; }
.phase-card ol a::before {
  content: attr(data-num);
  flex: none;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  min-width: 2.6em;
  padding-top: 0.15em;
}
.phase-card ol a:hover::before { color: var(--phase-a); }
.phase-card ol a.is-done { color: var(--faint); }
.phase-card ol a.is-done::after { content: " ✓"; color: var(--ok); flex: none; }
.phase-card ol li .note {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin: -0.15rem 0 0.55rem 3.3rem;
}

/* ---------- Index: reference grid ---------- */

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 1.1rem;
  margin: 1.5rem 0;
}
.ref-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1.35rem;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.ref-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.ref-card h3 { margin: 0 0 0.4rem; font-size: 1rem; }
.ref-card h3 a { color: var(--ink); }
.ref-card h3 a:hover { color: var(--accent); }
.ref-card p { margin: 0; font-size: 0.9rem; color: var(--ink-soft); flex: 1; }
.ref-card .ref-meta {
  margin-top: 0.8rem;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- Progress bars ---------- */

.progress-bar {
  height: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  margin: 0.8rem 0 0;
  overflow: hidden;
}
.progress-bar .fill {
  height: 100%;
  background: var(--grad);
  width: 0%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ---------- Callouts ---------- */

.win {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.1rem 1.3rem;
  margin: 1.6rem 0;
}
.win h3 { margin-top: 0; }

.tip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.95rem 1.2rem;
  margin: 1.3rem 0;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.note { color: var(--muted); font-size: 0.92em; }
li .note { display: inline; }

/* ---------- Field notes ---------- */

.field-guide {
  margin: 1.8rem 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.3rem 0.5rem;
  overflow-x: auto;
}
.field-guide .fg-label {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.35em 0.9em;
  margin: 0 0 0.8rem;
}
.field-guide table { margin: 0.3rem 0 0.9rem; font-size: 0.88rem; }
.field-guide th { border-bottom: 1px solid var(--line-strong); }
.field-guide td:first-child {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--ink);
  white-space: nowrap;
}
.field-guide td code { font-size: 0.92em; }

/* ---------- Ledgers and artifacts ---------- */

.ledger, .artifact {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.93rem;
}
.ledger h4, .artifact .artifact-label {
  margin: 0 0 0.5rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.ledger p { margin: 0.4rem 0; }
.ledger ul { margin: 0.4rem 0; }

.artifact {
  border-left-color: var(--accent);
  overflow-x: auto;
}
.artifact .artifact-label { color: var(--accent); }
.artifact p, .artifact ul, .artifact ol, .artifact table { margin: 0.45rem 0; }
.artifact dl {
  display: grid;
  grid-template-columns: minmax(7rem, 0.35fr) 1fr;
  gap: 0.35rem 0.9rem;
  margin: 0;
}
.artifact dt {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--ink-soft);
}
.artifact dd { margin: 0; }
.artifact.template { border-left-color: var(--muted); }
.artifact.template .artifact-label { color: var(--muted); }

@media (max-width: 620px) {
  .artifact dl { grid-template-columns: 1fr; gap: 0.1rem; }
  .artifact dd { margin: 0 0 0.45rem; }
}

/* ---------- Details / practice reveals ---------- */

details {
  margin: 1.2rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
details summary {
  cursor: pointer;
  padding: 0.85rem 1.2rem;
  font-family: var(--sans);
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  list-style: none;
}
details summary::-webkit-details-marker { display: none; }
details summary::after {
  content: "";
  flex: none;
  width: 0.55em;
  height: 0.55em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
}
details[open] summary::after { transform: rotate(-135deg); }
details summary:hover { color: var(--accent); }
details summary:hover::after { border-color: var(--accent); }
details .reveal-body { padding: 0 1.2rem 1.1rem; }

/* ---------- Quiz widget ---------- */

.quiz {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 1.3rem 1.4rem 1.4rem;
  margin: 1.4rem 0;
}
.quiz .q {
  font-family: var(--display);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
}
.quiz .opt {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--sans);
  font-size: 0.93rem;
  line-height: 1.5;
  padding: 0.62rem 0.95rem;
  margin: 0.45rem 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--field);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease;
}
.quiz .opt:hover:not([aria-disabled="true"]) {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.quiz .opt.correct {
  border-color: var(--ok);
  background: var(--ok-bg);
}
.quiz .opt.wrong {
  border-color: var(--bad);
  background: var(--bad-bg);
}
.quiz .opt.correct::after {
  content: " \2713";
  color: var(--ok);
  font-weight: 700;
}
.quiz .opt.wrong::after {
  content: " \2717";
  color: var(--bad);
  font-weight: 700;
}
.quiz .opt[aria-disabled="true"] { cursor: default; }
.quiz .opt[aria-disabled="true"]:not(.correct):not(.wrong) { opacity: 0.55; }

.quiz-feedback {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.75rem 0 0;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--line-strong);
}
.quiz-feedback strong { color: var(--ink); }

/* ---------- Lesson-complete toggle ---------- */

.lesson-done {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--muted);
  margin: 1.6rem 0 0;
  cursor: pointer;
  user-select: none;
}
.lesson-done input { accent-color: var(--accent); width: 1.05em; height: 1.05em; cursor: pointer; }

/* ---------- Reference documents ---------- */

.ref-term { margin: 1.6rem 0; }
.ref-term h3 { margin-bottom: 0.2rem; }
.ref-term .where {
  margin-top: 0.35rem;
  font-family: var(--sans);
  font-size: 0.76rem;
  letter-spacing: 0.02em;
  color: var(--faint);
}
.ref-term .where a { color: var(--faint); border-bottom: 1px dotted var(--line-strong); }
.ref-term .where a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.ref-term .avoid {
  font-size: 0.85rem;
  color: var(--faint);
  font-family: var(--sans);
  margin-top: 0.2rem;
}
.ref-term p { margin-top: 0.3rem; }
.ref-term pre { margin: 0.7rem 0 0.5rem; font-size: 0.78rem; }

.term-index {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 1rem 1.2rem 1.1rem;
  margin: 1.5rem 0 2.2rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 2;
}
.term-index .idx-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.term-index a {
  color: var(--ink);
  border-radius: 6px;
  padding: 0.1em 0.45em;
  border: 1px solid transparent;
}
.term-index a:hover {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
  text-decoration: none;
}
.term-index .sep { display: none; }

h2[id], h3[id], .ref-term h3[id] { scroll-margin-top: 4.5rem; }

.bib { font-size: 0.88rem; color: var(--muted); }

/* ---------- TOC drawer (hamburger menu) ---------- */

.toc-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.1rem;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  flex: none;
  transition: border-color 0.12s ease;
}
.toc-toggle:hover { border-color: var(--accent); }
.toc-toggle .bars { display: block; width: 1rem; }
.toc-toggle .bars span {
  display: block;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  margin: 0.2rem 0;
  transition: background 0.12s ease;
}
.toc-toggle[aria-expanded="true"] .bars span { background: var(--accent); }

body.toc-open { overflow: hidden; }

.toc-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 13, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  z-index: 90;
}
body.toc-open .toc-backdrop { opacity: 1; visibility: visible; }

.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(21rem, 88vw);
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0.22s;
  z-index: 100;
  overflow-y: auto;
  font-family: var(--sans);
}
body.toc-open .toc-drawer { transform: translateX(0); visibility: visible; }

.toc-drawer .toc-head {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.9rem 1.3rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent);
}
.toc-close {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink);
  font-size: 1.1rem;
  line-height: 1;
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  cursor: pointer;
}
.toc-close:hover { border-color: var(--accent); color: var(--accent); }

.toc-body { padding: 0.9rem 1.3rem 2.5rem; }

.toc-body > a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.55rem 0.4rem;
  font-size: 0.9rem;
  font-weight: 650;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.toc-body > a:hover { color: var(--accent); text-decoration: none; }

.toc-phase { margin-top: 1.3rem; }
.toc-phase-name {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.35rem;
  padding: 0 0.4rem;
}
.toc-body ol { list-style: none; margin: 0; padding: 0; }
.toc-body li { margin: 0; border-top: 1px solid var(--line); }
.toc-body li:first-child { border-top: none; }
.toc-body a {
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
  padding: 0.5rem 0.4rem;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.toc-body a:hover { color: var(--accent); text-decoration: none; background: var(--surface-2); }
.toc-body a.current {
  color: var(--accent-strong);
  font-weight: 600;
  background: var(--accent-soft);
}
.toc-body a.is-done { color: var(--faint); }
.toc-body a.is-done::after { content: " \2713"; color: var(--ok); flex: none; }
.toc-body .num {
  flex: none;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
}
.toc-body a.current .num { color: var(--accent); }
.toc-body .t { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .toc-drawer, .toc-backdrop, details summary::after, .phase-card, .ref-card, .btn, .btn-primary, .btn-ghost, footer.nav a {
    transition: none;
  }
}

/* ---------- Print ----------
   Paper is not the screen theme; the greys here are chosen for toner. */

@media print {
  body { background: #fff; font-size: 11pt; }
  .masthead, footer.nav, .lesson-done, .quiz .opt, .toc-toggle, .toc-drawer, .toc-backdrop {
    display: none !important;
  }
  main { padding: 0; }
  pre { border-color: #ccc; box-shadow: none; }
  a { color: #000; }
  .quiz { border: 1px solid #999; background: #fff; }
  .field-guide, .ledger, .artifact, .win, .tip, .resume, .phase-card, .card, .ref-card, .pillar, .term-index, details {
    border-color: #999;
    background: #fff;
    box-shadow: none;
  }
  .quiz-feedback { color: #000; }
  .sidenote { float: none; width: auto; margin: 0.5em 0; border-left: 2px solid #ccc; padding-left: 0.7em; }
  .hero::before { display: none; }
  .phase-card:hover, .ref-card:hover { transform: none; box-shadow: none; }
}