/* ============================================================
   Course — shared lesson stylesheet
   Tufte-inspired: quiet typography, generous margins, prints well.
   Linked by every lesson and reference doc for a consistent look.
   ============================================================ */

:root {
  --ink:        #1a1a1a;
  --ink-soft:   #44464b;
  --muted:      #6b6e76;
  --rule:       #e2e2dd;
  --bg:         #fdfdfb;
  --paper:      #ffffff;
  /* The accent (--accent, --accent-dk, --accent-bg) is the course's brand
     colour, used sparingly. BaseLayout sets it from src/course.config.mjs. */
  --code-bg:    #f6f6f4;
  --code-ink:   #2b2b2b;
  --warn-bg:    #fdf6e3;
  --warn-ink:   #8a6d1a;
  --maxw:       46rem;
}

* { box-sizing: border-box; }

html { font-size: 18px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 4rem 1.5rem 6rem;
}

/* ---- Course chrome ---------------------------------------- */
.eyebrow {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-dk);
  font-weight: 600;
  margin: 0 0 0.6rem;
}

h1 {
  font-size: 2.1rem;
  line-height: 1.15;
  margin: 0 0 0.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
/* Smaller on a phone, so a title's no-break group ("POST, PUT, DELETE")
   still fits the screen */
@media (max-width: 40rem) {
  h1 { font-size: 1.7rem; }
}

.dek {
  font-size: 1.12rem;
  color: var(--ink-soft);
  font-style: italic;
  margin: 0 0 2rem;
}

/* The course's code repo under the home page's dek: a link and a stars badge */
.code-repo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.8rem;
  margin: -1rem 0 2rem;
}
.code-repo a.stars { border-bottom: none; line-height: 0; }
.code-repo img { height: 20px; }

h2 {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1.0rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-dk);
  margin: 2.8rem 0 0.4rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--rule);
}

h3 {
  font-size: 1.18rem;
  margin: 1.8rem 0 0.3rem;
  font-weight: 600;
}

p { margin: 0.7rem 0; }

a { color: var(--accent-dk); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent-dk) 35%, transparent); }
a:hover { border-bottom-color: var(--accent-dk); }

strong { font-weight: 600; }

ul, ol { padding-left: 1.3rem; }
li { margin: 0.35rem 0; }

/* ---- Code ------------------------------------------------- */
code {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 0.84em;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: 0.12em 0.36em;
  border-radius: 4px;
}
/* A long path or class name in prose breaks at the edge of a phone screen
   instead of widening the page */
:not(pre) > code { overflow-wrap: anywhere; }

/* Code blocks are drawn by Expressive Code (colours, frames, tabs: see
   astro.config.mjs); only the space around each block is set here. */
.expressive-code { margin: 1.2rem 0; }
/* A long path in a tab wraps on a phone instead of being cut off */
.expressive-code .frame .title { overflow-wrap: anywhere; }

/* ---- Code blocks: full-screen view (assets/code-fullscreen.js) ----
   The button copies the look and the show-on-hover behaviour of
   Expressive Code's copy button and sits just to its left. */
.expressive-code .code-expand {
  position: absolute;
  inset-block-start: calc(var(--ec-brdWd) + var(--button-spacing));
  inset-inline-end: calc(var(--ec-brdWd) + var(--ec-uiPadInl) / 2 + 2.5rem + 0.25rem);
}
.expressive-code .code-expand button {
  position: relative;
  display: block;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0.2rem;
  z-index: 1;
  cursor: pointer;
  transition: opacity 0.2s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  width: 2.5rem;
  height: 2.5rem;
  background: var(--code-background);
  opacity: 0.75;
}
.expressive-code .code-expand button div {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--ec-frm-inlBtnBg);
  opacity: var(--ec-frm-inlBtnBgIdleOpa);
}
.expressive-code .code-expand button::before {
  content: '';
  position: absolute;
  pointer-events: none;
  inset: 0;
  border-radius: inherit;
  border: var(--ec-brdWd) solid var(--ec-frm-inlBtnBrd);
  opacity: var(--ec-frm-inlBtnBrdOpa);
}
.expressive-code .code-expand button::after {
  content: '';
  position: absolute;
  pointer-events: none;
  inset: 0;
  margin: 0.55rem;
  background-color: var(--ec-frm-inlBtnFg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7'/%3E%3C/svg%3E") center / contain no-repeat;
}
.expressive-code .code-expand button:hover,
.expressive-code .code-expand button:focus-visible { opacity: 1; }
.expressive-code .code-expand button:hover div,
.expressive-code .code-expand button:focus-visible div { opacity: var(--ec-frm-inlBtnBgHoverOrFocusOpa); }
@media (hover: hover) {
  .expressive-code .code-expand { inset-inline-end: calc(var(--ec-brdWd) + var(--ec-uiPadInl) / 2 + 2rem + 0.25rem); }
  .expressive-code .code-expand button { opacity: 0; width: 2rem; height: 2rem; }
  .expressive-code .code-expand button::after { margin: 0.45rem; }
  .expressive-code .frame:hover .code-expand button:not(:hover),
  .expressive-code .frame:focus-within :focus-visible ~ .code-expand button:not(:hover) { opacity: 0.75; }
  /* In the full-screen view both buttons stay visible: the exit
     button is the way back, and a short block may not be under the
     mouse. */
  .code-dialog .expressive-code .copy button:not(:hover),
  .code-dialog .expressive-code .code-expand button:not(:hover) { opacity: 0.75; }
}
/* In the full-screen view the same place holds "full screen off" */
.expressive-code .code-expand.is-exit button::after {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7'/%3E%3C/svg%3E");
}
/* "Open full screen in a new tab" sits left of the full-screen button */
.expressive-code .code-expand.is-new-tab {
  inset-inline-end: calc(var(--ec-brdWd) + var(--ec-uiPadInl) / 2 + 2 * (2.5rem + 0.25rem));
}
@media (hover: hover) {
  .expressive-code .code-expand.is-new-tab {
    inset-inline-end: calc(var(--ec-brdWd) + var(--ec-uiPadInl) / 2 + 2 * (2rem + 0.25rem));
  }
}
/* In a header (tab strip or terminal title bar) it sits at the right
   end, always visible: the header is otherwise empty there. */
.expressive-code .header:has(.code-expand) { padding-inline-end: 2.75rem; }
.expressive-code .header .code-expand.is-new-tab {
  inset-block-start: 50%;
  inset-inline-end: 0.4rem;
  transform: translateY(-50%);
}
/* A bare icon there, without the copy button's border and background */
.expressive-code .header .code-expand button { width: 1.75rem; height: 1.75rem; background: none; }
.expressive-code .header .code-expand button:not(:hover) { opacity: 0.75; }
.expressive-code .header .code-expand button div,
.expressive-code .header .code-expand button::before { display: none; }
.expressive-code .header .code-expand button::after { margin: 0.45rem; }
.expressive-code .code-expand.is-new-tab button::after {
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 3h7v7M21 3l-9 9M19 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 3h7v7M21 3l-9 9M19 14v5a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h5'/%3E%3C/svg%3E");
}

/* The dialog fills the window; the block inside keeps its own height,
   up to the window's, and scrolls on its own beyond it. */
.code-dialog {
  box-sizing: border-box;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 1rem;
  border: 0;
  background: var(--bg);
}
.code-dialog[open] { display: flex; flex-direction: column; }
.code-dialog::backdrop { background: var(--bg); }
html:has(.code-dialog[open]) { overflow: hidden; }
.code-dialog .code-dialog-body { flex: 1; min-height: 0; margin: 0; }
.code-dialog .code-dialog-body .frame { display: flex; flex-direction: column; max-height: 100%; }
.code-dialog .code-dialog-body pre { min-height: 0; overflow: auto; }

/* ---- Tabs (<Tabs>/<Tab>; behaviour in assets/tabs.js) ------ */
.tabs { margin: 1.2rem 0; }
.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  border-bottom: 1px solid var(--rule);
}
.tab {
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  padding: 0.45rem 0.8rem;
  margin-bottom: -1px;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] {
  color: var(--accent-dk);
  font-weight: 600;
  border-bottom-color: var(--accent);
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tab-panel > :first-child { margin-top: 0.9rem; }
.tab-panel > :last-child { margin-bottom: 0; }
/* The label heads each panel only when the script hasn't built a tab bar */
.tab-label {
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.tabs-ready .tab-label { display: none; }
.tabs-ready .tab-label + * { margin-top: 0.9rem; }

/* ---- Callouts --------------------------------------------- */
.callout {
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  margin: 1.4rem 0;
  font-size: 0.96rem;
}
.callout.warn { background: var(--warn-bg); }
.callout .label {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--accent-dk);
  display: block;
  margin-bottom: 0.3rem;
}
.callout.warn .label { color: var(--warn-ink); }

/* Blocks inside a callout: tighter than in the page, flush at the edges */
.callout > p { margin: 0.6rem 0 0; }
.callout > ul { margin: 0.5rem 0 0; }
.callout .expressive-code { margin: 0.6rem 0 0; }
.callout > .label + p { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }

/* Troubleshooting list inside a callout — one item per line.
   Hand-written lessons put the class on the <ul>; MDX's <QaList> wraps one. */
.callout .qa-list, .callout .qa-list > ul { list-style: none; padding-left: 0; margin: 0.5rem 0 0; }
.callout .qa-list > ul { margin: 0; }
.callout .qa-list li { margin: 0.7rem 0; padding-left: 1.1rem; text-indent: -1.1rem; }
.callout .qa-list li::before { content: "›"; color: var(--accent-dk); font-weight: 700; margin-right: 0.5rem; }
.callout.warn .qa-list li::before { color: var(--warn-ink); }
.callout .qa-list strong { color: inherit; }

/* Margin note, Tufte style */
.note {
  font-size: 0.86rem;
  color: var(--muted);
  font-style: italic;
}

/* ---- Key term / definition -------------------------------- */
.term {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  color: var(--accent-dk);
  font-style: normal;
}

/* ---- "Win" banner ----------------------------------------- */
.win {
  border: 1px solid var(--accent);
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin: 2rem 0;
}
.win .label { color: var(--accent-dk); }
/* The label runs into the sentence: "The win  By the end you'll have …" */
.win > .label + p { display: inline; }

/* ---- Quiz widget (paired with assets/quiz.js) ------------- */
.quiz {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1.2rem 1.3rem;
  margin: 1.4rem 0;
  background: var(--paper);
}
.quiz .q {
  font-weight: 600;
  margin-bottom: 0.8rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.98rem;
}
.quiz .opt {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.92rem;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  margin: 0.4rem 0;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.quiz .opt:hover { border-color: var(--accent); background: var(--accent-bg); }
.quiz .opt.correct { border-color: var(--accent); background: var(--accent-bg); }
.quiz .opt.wrong   { border-color: #d98b8b; background: #fbeded; }
.quiz .opt:disabled { cursor: default; }
.quiz .feedback {
  font-size: 0.9rem;
  margin-top: 0.7rem;
  min-height: 1.2em;
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.quiz .feedback.ok  { color: var(--accent-dk); }
.quiz .feedback.no  { color: #b4504f; }

/* ---- Footer / nav ----------------------------------------- */
/* Discuss button under a lesson: opens the course's GitHub Discussions category */
.discuss { margin-top: 1.6rem; }
a.discuss-button {
  display: inline-block;
  padding: 0.45rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--paper);
  color: var(--accent-dk);
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  transition: background 0.15s;
}
a.discuss-button:hover { background: var(--accent-bg); border-bottom-color: var(--accent); }

/* Previous / next cards at the end of a lesson (LessonCard.astro) */
.lesson-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--rule);
}
.lesson-card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}
a.lesson-card { border-bottom: 1px solid var(--rule); transition: border-color 0.15s, background 0.15s; }
a.lesson-card:hover { border-color: var(--accent); background: var(--accent-bg); }
.lesson-card.next, .lesson-card.upcoming { grid-column: 2; text-align: right; }
.lesson-card .dir, .lesson-card .num, .lesson-card .soon {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.lesson-card .dir { font-weight: 700; color: var(--accent-dk); }
.lesson-card .title { font-weight: 600; font-size: 1.05rem; line-height: 1.3; }
.lesson-card .desc { font-size: 0.86rem; color: var(--ink-soft); line-height: 1.45; }
.lesson-card.upcoming { border-style: dashed; background: none; color: var(--muted); }
.lesson-card.upcoming .dir { color: var(--muted); }
.lesson-card.upcoming .desc { color: var(--muted); }
@media (max-width: 40rem) {
  .lesson-nav { grid-template-columns: 1fr; }
  .lesson-card.next, .lesson-card.upcoming { grid-column: 1; grid-row: 1; text-align: left; }
}

/* ---- Course home (index.astro) ---------------------------- */
.hero { margin-bottom: 1rem; }
.mission-card {
  background: var(--accent-bg);
  border-radius: 8px;
  padding: 1.1rem 1.3rem;
  margin: 1.6rem 0 2.4rem;
  font-size: 0.98rem;
}
.mission-card .label {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase;
  font-weight: 700; color: var(--accent-dk); display: block; margin-bottom: 0.3rem;
}
ol.toc { list-style: none; padding-left: 0; counter-reset: lesson; }
ol.toc li {
  counter-increment: lesson;
  display: flex; align-items: baseline; gap: 0.9rem;
  padding: 0.85rem 0; border-bottom: 1px solid var(--rule);
}
ol.toc li::before {
  content: counter(lesson, decimal-leading-zero);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.82rem; color: var(--muted);
  flex: 0 0 auto; min-width: 1.6rem;
}
ol.toc .body { flex: 1; }
ol.toc .body .title { font-weight: 600; font-size: 1.05rem; }
ol.toc .body .desc { font-size: 0.9rem; color: var(--muted); margin-top: 0.1rem; }
ol.toc li.upcoming { opacity: 0.55; }
.status {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase;
  font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; flex: 0 0 auto;
}
.status.ready { background: var(--accent); color: white; }
.status.soon  { background: var(--rule); color: var(--muted); }
.ref-list { list-style: none; padding-left: 0; }
.ref-list li { padding: 0.4rem 0; }

/* ---- Glossary page ---------------------------------------- */
.glossary-section { scroll-margin-top: 1rem; }
dl.glossary { margin: 0.5rem 0 1.5rem; }
dl.glossary dt {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-weight: 600;
  color: var(--accent-dk);
  margin-top: 1.4rem;
  font-size: 1.02rem;
}
dl.glossary dd { margin: 0.3rem 0 0; }
dl.glossary dd code { font-size: 0.8em; }

/* ---- Architecture decisions ------------------------------- */
/* The coin a lesson puts where it introduces a decision (Decision.astro),
   linking to its entry on /architecture-decisions. */
a.decision {
  display: inline-block; line-height: 0; margin: 0 0.1rem;
  border: none; border-radius: 50%; vertical-align: -0.15em;
  scroll-margin-top: 4rem;
  transition: transform 0.15s;
}
a.decision:hover { transform: scale(1.15); }
.coin { width: 1.05em; height: 1.05em; }
/* The words that state the decision (DecisionText.astro) light up while the
   coin with the same id is hovered or focused; Decision.astro writes that
   rule per id, in this colour. */
:root { --decision-hl: rgba(251, 191, 36, 0.35); }
.decision-text {
  border-radius: 3px;
  transition: background-color 0.15s, box-shadow 0.15s;
}
.decisions h2,
.decisions h3 { scroll-margin-top: 1rem; }
.decisions h3:target { color: var(--accent-dk); }
.decisions h3 a.decision { vertical-align: -0.05em; }

/* ---- Comparison table ------------------------------------- */
.cmp-wrap { overflow-x: auto; margin: 1.3rem 0; }
table.cmp { width: 100%; border-collapse: collapse; font-size: 0.9rem; min-width: 34rem; }
table.cmp th, table.cmp td {
  text-align: left; padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--rule); vertical-align: top;
}
table.cmp thead th {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem; letter-spacing: 0.02em; color: var(--muted);
  border-bottom: 2px solid var(--rule);
}
table.cmp tbody th {
  font-weight: 600; color: var(--ink); font-size: 0.86rem;
  font-family: ui-sans-serif, system-ui, sans-serif;
  background: var(--accent-bg);
}

/* ---- Print ------------------------------------------------ */
@media print {
  html { font-size: 12pt; }
  body { background: white; }
  .wrap { padding: 0; max-width: 100%; }
  .expressive-code, .quiz, .callout, .win { break-inside: avoid; }
  a { color: var(--ink); border: none; }
  .quiz .opt { break-inside: avoid; }
  .expressive-code .copy, .expressive-code .code-expand { display: none; }
}
