/* ============================================================
   DDD in functional TypeScript — shared course stylesheet
   Linked by every lesson and reference doc in this course.
   Design language matches the workspace's other courses
   (warm paper, Merriweather/Source Sans 3/Fira Code).
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,300;0,400;0,700;1,300&family=Source+Sans+3:wght@400;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
  --bg: #fdfbf7;
  --text: #222;
  --muted: #666;
  --accent: #8B3A3A;
  --accent-soft: #B55A5A;
  --accent-wash: #f7efec;
  --code-bg: #f5f2eb;
  --border: #ddd6c8;
  --sidebar: #f7f5f0;
  --good: #3d6b45;
  --good-bg: #eef4ee;
  --bad: #8B3A3A;
  --bad-bg: #f7efec;
  --info-bg: #eef2f6;
  --info-border: #7a93ad;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Source Sans 3', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
}

/* ---------- headings ---------- */
h1 {
  font-family: 'Merriweather', serif;
  font-weight: 300;
  font-size: 2.4rem;
  margin: 0 0 0.3rem;
  letter-spacing: -0.01em;
}
.subtitle {
  color: var(--muted);
  font-size: 1rem;
  margin-bottom: 2.5rem;
}
h2 {
  font-family: 'Merriweather', serif;
  font-weight: 400;
  font-size: 1.5rem;
  margin-top: 2.5rem;
  margin-bottom: 0.8rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
h3 {
  font-weight: 600;
  font-size: 1.15rem;
  margin-top: 1.8rem;
  margin-bottom: 0.5rem;
}
p { margin: 0.8rem 0; }
.lead {
  font-size: 1.15rem;
  color: var(--muted);
  line-height: 1.8;
  margin-bottom: 2rem;
}
ul, ol { margin: 0.8rem 0; padding-left: 1.5rem; }
li { margin: 0.3rem 0; }

/* ---------- code ---------- */
code {
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
  background: var(--code-bg);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  color: var(--accent);
}
pre {
  background: var(--code-bg);
  padding: 1.2rem 1.5rem;
  border-radius: 6px;
  overflow-x: auto;
  border-left: 3px solid var(--accent);
  margin: 1rem 0;
  font-size: 0.92rem;
  line-height: 1.6;
}
pre code {
  background: transparent;
  padding: 0;
  color: var(--text);
}
.cmt { color: #8a8174; font-style: italic; }
.kw  { color: var(--accent); }
.ty  { color: #3d5a80; }
.str { color: #5a7a5a; }

/* ---------- tables ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.95rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
th { font-weight: 600; color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- defined terms & citations ---------- */
.term {
  border-bottom: 1px dotted var(--accent-soft);
  font-weight: 600;
  cursor: help;
}
.cite { font-size: 0.78em; vertical-align: super; }
.cite a { color: var(--accent-soft); text-decoration: none; }

/* ---------- callouts ---------- */
.callout {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  background: var(--sidebar);
  padding: 0.9rem 1.2rem;
  margin: 1.4rem 0;
  font-size: 0.97rem;
}
.callout .label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.callout.mission   { border-left-color: var(--accent); background: var(--accent-wash); }
.callout.principle { border-left-color: var(--good); }
.callout.principle .label { color: var(--good); }
.callout.gotcha    { border-left-color: #b07d2b; background: #faf4e8; }
.callout.gotcha .label { color: #b07d2b; }
.callout.teacher   { border-left-color: var(--info-border); background: var(--info-bg); }
.callout.teacher .label { color: var(--info-border); }

/* ---------- before/after comparison ---------- */
.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1.2rem 0;
}
@media (max-width: 720px) { .compare { grid-template-columns: 1fr; } }
.compare .pane {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.compare .pane > .pane-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.45rem 0.9rem;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
}
.compare .pane.bad  > .pane-title { color: var(--bad); }
.compare .pane.good > .pane-title { color: var(--good); }
.compare pre { margin: 0; border-left: none; border-radius: 0; }

/* ---------- quiz ---------- */
.quiz {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffdf9;
  padding: 1.1rem 1.3rem;
  margin: 1.2rem 0;
}
.quiz .qnum {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.quiz .qtext { font-weight: 600; margin: 0.3rem 0 0.8rem; }
.quiz .opt {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--sidebar);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 0.9rem;
  margin: 0.4rem 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.quiz .opt:hover { background: var(--accent-wash); }
.quiz .opt.correct { background: var(--good-bg); border-color: var(--good); color: var(--good); font-weight: 600; }
.quiz .opt.wrong   { background: var(--bad-bg);  border-color: var(--bad);  color: var(--bad); }
.quiz .explain {
  display: none;
  margin-top: 0.7rem;
  padding: 0.7rem 0.9rem;
  background: var(--code-bg);
  border-radius: 6px;
  font-size: 0.92rem;
  color: var(--muted);
}
.quiz .explain.show { display: block; }
.quiz .explain code { color: var(--accent); }
.quiz-score {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.5rem;
  padding: 0.8rem 1.1rem;
  border-radius: 6px;
  background: var(--sidebar);
  border: 1px solid var(--border);
}

/* ---------- code exercise ---------- */
.exercise {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fffdf9;
  padding: 1.2rem 1.4rem;
  margin: 1.4rem 0;
}
.exercise .ex-title {
  font-family: 'Merriweather', serif;
  font-weight: 400;
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}
.exercise textarea {
  width: 100%;
  min-height: 190px;
  font-family: 'Fira Code', monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem 1rem;
  resize: vertical;
  tab-size: 2;
}
.exercise textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent-soft); }
.exercise .ex-actions { margin-top: 0.7rem; display: flex; gap: 0.6rem; flex-wrap: wrap; }
.btn {
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 0.45rem 1.1rem;
  cursor: pointer;
}
.btn.secondary {
  background: transparent;
  color: var(--accent);
}
.btn:hover { filter: brightness(1.08); }
.ex-results { margin-top: 0.9rem; }
.ex-results .tcase {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-family: 'Fira Code', monospace;
  font-size: 0.86rem;
  padding: 0.35rem 0.6rem;
  border-radius: 4px;
}
.ex-results .tcase.pass { background: var(--good-bg); color: var(--good); }
.ex-results .tcase.fail { background: var(--bad-bg); color: var(--bad); }
.ex-results .tcase .icon { font-weight: 700; }
.ex-results .tcase .detail { color: var(--muted); font-size: 0.8rem; }
.ex-solution { display: none; margin-top: 0.9rem; }
.ex-solution.show { display: block; }
.ex-error {
  margin-top: 0.7rem;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  color: var(--bad);
  white-space: pre-wrap;
}

/* ---------- lesson navigation & roadmap ---------- */
.roadmap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 1.5rem 0 2.5rem;
  font-size: 0.82rem;
}
.roadmap .step {
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--sidebar);
  color: var(--muted);
  text-decoration: none;
}
.roadmap .step.here {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.lesson-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 2px solid var(--border);
  font-size: 0.95rem;
}
.lesson-nav a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.lesson-nav a:hover { text-decoration: underline; }
.lesson-nav .next { text-align: right; }

/* ---------- glossary / reference ---------- */
dl.glossary dt {
  font-family: 'Merriweather', serif;
  font-weight: 700;
  font-size: 1.05rem;
  margin-top: 1.6rem;
}
dl.glossary dt .tsig {
  font-family: 'Fira Code', monospace;
  font-weight: 400;
  font-size: 0.82rem;
  color: var(--muted);
  margin-left: 0.5rem;
}
dl.glossary dd {
  margin: 0.3rem 0 0 0;
  color: var(--text);
}
dl.glossary dd .see-also { font-size: 0.85rem; color: var(--muted); }

/* ---------- print ---------- */
@media print {
  body { background: #fff; font-size: 11pt; }
  .container { max-width: 100%; padding: 0; }
  .roadmap, .lesson-nav, .btn, .exercise .ex-actions { display: none; }
  .exercise textarea { border: 1px dashed var(--muted); background: #fff; }
  pre, .quiz, .callout, .exercise { break-inside: avoid; }
  a { color: inherit; }
}
