/* biglearn — layout, typography, chrome. briggen.dev brand: paper + ink,
   one amber accent, hard pixel shadows, graph-paper grid, terminal voice. */

* { box-sizing: border-box; }

html { height: 100%; }

/* absolutely-positioned bits (glossary tips) must never pan the page sideways */
html, body { overflow-x: clip; }

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-ink) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-ink) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--t-body-m);
  line-height: var(--lh-body);
}

.mono { font-family: var(--font-mono); font-size: var(--t-mono-s); }
.muted { color: var(--text-muted); }

a { color: var(--text-link); text-decoration: none; transition: color var(--dur-fast) var(--ease); }
a:hover { color: var(--accent-lo); text-decoration: underline; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- chrome ---------- */

.site-header, .site-footer, main {
  width: 100%;
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

.site-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: var(--space-14);
  padding-bottom: var(--space-8);
}

.wordmark {
  font-family: var(--font-display);
  font-size: var(--t-display-m);
  color: var(--text-strong);
  letter-spacing: var(--tracking-label);
}
.wordmark:hover { text-decoration: none; color: var(--text-strong); }
.wordmark .bracket { color: var(--accent); }

.site-nav { display: flex; gap: var(--space-8); }
.site-nav a { color: var(--text-secondary); }
.site-nav a:hover { color: var(--accent); text-decoration: none; }

.linklike {
  background: none; border: none; padding: 0; cursor: pointer;
  font: inherit; color: var(--text-secondary);
  transition: color var(--dur-fast) var(--ease);
}
.linklike:hover { color: var(--accent); }

main { flex: 1; padding-top: var(--space-8); padding-bottom: var(--space-28); }

.site-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  padding-top: var(--space-8);
  padding-bottom: var(--space-14);
  border-top: var(--border-line);
  color: var(--text-muted);
  font-size: var(--t-mono-xs);
}

.dot { color: var(--dark-dot); transition: color var(--dur) var(--ease); }
.dot.on { color: var(--accent); }

/* ---------- shared bits ---------- */

.kicker {
  color: var(--text-muted);
  font-size: var(--t-mono-xs);
  letter-spacing: var(--tracking-kicker);
  margin: 0 0 var(--space-4);
}
.kicker a { color: var(--text-muted); }
.kicker a:hover { color: var(--accent); text-decoration: none; }

.meta { color: var(--text-secondary); margin: var(--space-3) 0; }

.prompt-line {
  font-family: var(--font-mono);
  font-size: var(--t-mono-l);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  margin: 0 0 var(--space-14);
}
.prompt { color: var(--accent); margin-right: var(--space-3); }

.cursor::after {
  content: "";
  display: inline-block;
  width: 0.55em; height: 1.1em;
  margin-left: var(--space-2);
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.card {
  display: block;
  background: var(--surface-card);
  border: var(--border-line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-4);
  padding: var(--space-10);
}

.btn {
  display: inline-block;
  background: var(--surface-card);
  border: var(--border-line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: var(--space-3) var(--space-8);
  font-family: var(--font-mono);
  font-size: var(--t-mono-s);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn:active { transform: translate(1px, 1px); box-shadow: none; }

/* ---------- home ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-10);
}

.course-card { color: var(--text); position: relative; }
.course-card:hover { border-color: var(--accent); text-decoration: none; }
.course-card:hover .course-title { color: var(--accent); }

/* the title link stretches over the whole card; secondary links sit above it */
.course-card .card-link { color: inherit; }
.course-card .card-link:hover { color: inherit; text-decoration: none; }
.course-card .card-link::after { content: ""; position: absolute; inset: 0; }
.course-card .card-alt-link { position: relative; z-index: 1; color: var(--text-muted); }
.course-card .card-alt-link:hover { color: var(--accent); }

.course-cover {
  margin: calc(-1 * var(--space-10)) calc(-1 * var(--space-10)) var(--space-8);
  border-bottom: var(--border-line);
}
.course-cover img { display: block; width: 100%; height: 140px; object-fit: cover; border-radius: var(--radius-sm) var(--radius-sm) 0 0; }

.course-title {
  font-family: var(--font-display);
  font-size: var(--t-display-s);
  font-weight: var(--fw-regular);
  letter-spacing: var(--tracking-label);
  color: var(--text-strong);
  margin: 0 0 var(--space-4);
  transition: color var(--dur-fast) var(--ease);
}
.course-desc { margin: 0 0 var(--space-6); font-size: var(--t-body-s); color: var(--text-secondary); }
.progress { margin: 0; color: var(--accent); }
.progress.muted { color: var(--text-muted); }
.complete { color: var(--green); margin: var(--space-3) 0; }

/* ---------- course overview ---------- */

.course-heading, .chapter h1 {
  font-family: var(--font-display);
  font-size: var(--t-display-l);
  font-weight: var(--fw-regular);
  line-height: var(--lh-tight);
  color: var(--text-strong);
  margin: var(--space-4) 0 var(--space-6);
}

.lede { font-size: var(--t-body-l); max-width: 62ch; }

.course-cover-lg img { max-height: 260px; object-fit: cover; }

.chapter-list { padding: 0; margin: var(--space-14) 0; overflow: hidden; }

.chapter-row {
  display: flex;
  align-items: baseline;
  gap: var(--space-6);
  padding: var(--space-6) var(--space-10);
  color: var(--text);
  border-bottom: 1px solid var(--border-soft);
  transition: border-color var(--dur-fast) var(--ease);
}
.chapter-row:last-child { border-bottom: none; }
.chapter-row:hover { text-decoration: none; }
.chapter-row:hover .chapter-row-title { color: var(--accent); }
.chapter-row .check { color: var(--text-muted); }
.chapter-row.done .check { color: var(--accent); }
.chapter-row.current .num::after { content: " ●"; color: var(--accent); }
.chapter-row .num { color: var(--text-muted); }
.chapter-row-title { flex: 1; transition: color var(--dur-fast) var(--ease); }
.chapter-row-summary { display: block; font-size: var(--t-body-xs); color: var(--text-muted); }
.chapter-row .arrow { color: var(--text-muted); }
.chapter-row:hover .arrow { color: var(--accent); }

.resume { margin: var(--space-14) 0; }

.sources summary { cursor: pointer; color: var(--text-secondary); }
.sources summary:hover { color: var(--accent); }
.sources ul { font-size: var(--t-body-s); padding-left: var(--space-14); }
.sources li { margin: var(--space-3) 0; }

/* ---------- chapter ---------- */

.chapter-content {
  max-width: 68ch;
}
.chapter-content h2, .chapter-content h3 {
  font-family: var(--font-display);
  font-weight: var(--fw-regular);
  letter-spacing: var(--tracking-label);
  color: var(--text-strong);
  line-height: var(--lh-snug);
  margin: var(--space-18) 0 var(--space-6);
}
.chapter-content h2 { font-size: var(--t-display-m); }
.chapter-content h3 { font-size: var(--t-display-s); }
.chapter-content h2::before, .chapter-content h3::before { content: "# "; color: var(--accent); }

.chapter-content code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--surface-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xs);
  padding: 0 var(--space-2);
}
.chapter-content pre {
  background: var(--dark);
  color: var(--dark-text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-5);
  padding: var(--space-10);
  overflow-x: auto;
  line-height: var(--lh-loose);
}
.chapter-content pre code { background: none; border: none; padding: 0; color: inherit; font-size: var(--t-mono-s); }

.chapter-content blockquote {
  margin: var(--space-10) 0;
  padding: var(--space-2) var(--space-10);
  border-left: 2px solid var(--accent);
  color: var(--text-secondary);
}

.chapter-content table { border-collapse: collapse; width: 100%; font-size: var(--t-body-s); }
.chapter-content th, .chapter-content td { border: var(--border-line); padding: var(--space-4) var(--space-6); text-align: left; }
.chapter-content th { font-family: var(--font-mono); font-size: var(--t-mono-xs); letter-spacing: var(--tracking-kicker); color: var(--text-secondary); }

.fig { margin: var(--space-14) 0; }
.fig img {
  display: block;
  max-width: 100%;
  border: var(--border-line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-3);
}
.fig figcaption { font-family: var(--font-mono); font-size: var(--t-mono-xs); color: var(--text-muted); margin-top: var(--space-4); }
.fig figcaption::before { content: "// "; }

.mermaid-slot { margin: var(--space-14) 0; overflow-x: auto; }
.mermaid-slot svg { max-width: 100%; }
.mermaid-error { color: var(--accent-lo); font-size: var(--t-mono-xs); }

/* glossary tooltips */
.gloss {
  border-bottom: 1px dashed var(--accent);
  cursor: help;
  position: relative;
}
.gloss-tip {
  position: absolute;
  left: 50%; bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: max-content; max-width: min(280px, calc(100vw - 32px));
  background: var(--dark);
  color: var(--dark-text);
  font-size: var(--t-body-xs);
  line-height: var(--lh-snug);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  padding: var(--space-4) var(--space-6);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease);
  z-index: 10;
}
.gloss-term { display: block; font-family: var(--font-mono); color: var(--accent-hi); font-size: var(--t-mono-xs); margin-bottom: var(--space-1); }
.gloss:hover .gloss-tip, .gloss:focus .gloss-tip { opacity: 1; }

.chapter-footer {
  max-width: 68ch;
  margin-top: var(--space-20);
  padding-top: var(--space-10);
  border-top: var(--border-line);
  display: flex;
  flex-direction: column;
  gap: var(--space-10);
}
.chapter-footer .btn { align-self: flex-start; }
.chapter-nav { display: flex; justify-content: space-between; gap: var(--space-8); }

.loading { padding: var(--space-14) 0; }

@media (max-width: 600px) {
  :root { --gutter: 16px; }
  .course-heading, .chapter h1 { font-size: var(--t-display-m); }
  /* diagrams render at natural size on phones (useMaxWidth off) — scroll, don't shrink */
  .mermaid-slot svg { max-width: none; }
}

/* ---------- print — paper voice, minus the chrome ---------- */

@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-card: #fff;
    --text: #000; --text-strong: #000; --text-secondary: #333; --text-muted: #555;
    --border: #999; --border-soft: #ccc; --border-line: 1px solid #999;
    --shadow-1: none; --shadow-2: none; --shadow-3: none;
    --shadow-4: none; --shadow-5: none; --shadow-tile: none;
  }
  body { background-image: none; display: block; }
  .site-header .site-nav, .site-footer, .chapter-footer, .btn,
  .flashcard-actions, .tree-crumbs, .quiz-reset, .quiz-retry, .quiz-check,
  .resume, .gloss-tip, .cursor::after { display: none !important; }
  .chapter-content pre, .outcome {
    background: #fff; color: #000; border: 1px solid #999; box-shadow: none;
  }
  .chapter-content pre code { color: #000; }
  .outcome-title, .outcome-body a, .outcome-links a { color: #000; }
  .outcome .block-kicker { color: #555; }
  .gloss { border-bottom: none; }
  a { color: inherit; }
  .sources details, .sources summary { display: block; }
  .sources ul { display: block; }
}
