/* The Algebra of Code — companion site.
   Minimal, responsive. Fonts + spacing + status colors only; no framework. */

:root {
  --text: #444;
  --muted: #888;
  --link: #4793ff;
  --rule: #e5e5e5;
  --bg: #fff;
  --code-bg: #f6f6f6;

  /* status colors */
  --submitted: #9acd32;      /* yellow-green: work submitted (ungraded) */
  --not-attempted: #e5e5e5;  /* gray */
  --pending: #b8c6d6;        /* blue-gray: attempted, awaiting feedback */
  --needs-correction: #e6a23c; /* amber */
  --correct: #6ab04c;        /* green */

  --measure: 42rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: "Source Serif Pro", "Source Serif 4", Georgia, serif;
  font-size: clamp(1rem, 0.95rem + 0.4vw, 1.125rem);
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  margin: 0 auto;
  max-width: var(--measure);
  padding: 2rem 1.25rem 6rem;
}

h1, h2, h3, h4 {
  font-family: "Manrope", system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.2;
  color: #222;
}
h1 { font-size: clamp(1.6rem, 1.3rem + 1.6vw, 2.25rem); margin: 0.2em 0 0.6em; }
h2 { font-size: clamp(1.3rem, 1.15rem + 0.8vw, 1.6rem); margin: 2em 0 0.5em; }
h3 { font-size: 1.15rem; margin: 1.6em 0 0.4em; }

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 1em; }

.site-header { margin-bottom: 1.5rem; }
.site-nav { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem 1.5rem; font-family: "Manrope", system-ui, sans-serif; }
.site-brand { margin: 0; font-size: clamp(1.2rem, 1rem + 1vw, 1.75rem); font-weight: 800; line-height: 1.2; }
.site-brand, .site-brand a { color: #222; }
body:not(.home) .site-brand { font-size: 1em; }
.site-nav-links { display: flex; gap: 1.5rem; font-size: 0.95rem; }

/* Series homepage and future book covers. */
body.home { max-width: 72rem; padding-top: 3rem; }
.home .lead { max-width: 58rem; }
.books { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(1rem, 4vw, 3rem); margin-top: 3rem; }
.book-cover {
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 8 / 10; border: 2px dashed #aaa;
  color: var(--text); font-family: "Manrope", system-ui, sans-serif;
  font-weight: 800;
}
.book-cover:hover { border-color: var(--link); color: var(--link); background: var(--code-bg); text-decoration: none; }
.book-cover:focus-visible { outline: 3px solid var(--link); outline-offset: 5px; }
.book-buy { margin: 0.75rem 0 0; text-align: center; }
@media (max-width: 40rem) {
  .books { grid-template-columns: 1fr; max-width: 20rem; margin-inline: auto; gap: 2rem; }
}

/* Code + REPL blocks: never break the mobile layout. */
code, pre, .repl {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
code { background: var(--code-bg); padding: 0.1em 0.35em; border-radius: 3px; font-size: 0.9em; }
pre, .repl {
  background: var(--code-bg);
  padding: 0.8rem 1rem;
  border-radius: 6px;
  overflow-x: auto;
  max-width: 100%;
  font-size: 0.9rem;
  line-height: 1.45;
}
pre code, .repl code { background: none; padding: 0; }
.repl .in { font-weight: 700; }   /* bold F# interactive input (from ***...***) */

img, table { max-width: 100%; }
.katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 0.2rem 0; }

/* Navigation / breadcrumbs */
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.6rem; font-family: "Manrope", system-ui, sans-serif; font-weight: 400; font-size: clamp(1.2rem, 3vw, 1.6rem); line-height: 1.3; margin-block: 3rem; }
.breadcrumbs h1 { margin: 0; font: inherit; }
.breadcrumbs .separator { color: var(--muted); }

/* Table of contents */
.toc { list-style: none; padding: 0; }
.toc .part { margin-top: 1.5rem; }
.toc .part p { margin: 0 0 0.5em; font-size: 1em; }
.toc .chapter { margin: 0.35rem 0 0.35rem 0; }
.toc .chapter .num { color: var(--muted); font-family: "Manrope", system-ui, sans-serif; font-size: 0.85rem; }

.exlist { list-style: none; padding: 0; }
.exlist li { display: flex; align-items: baseline; gap: 0.6rem; padding: 0.25rem 0; }
.exlist .num { color: var(--muted); font-family: "Manrope", system-ui, sans-serif; font-size: 0.85rem; min-width: 2.4rem; }

/* Per-exercise status dot (filled by auth-status.js when logged in) */
.status-dot {
  display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%;
  background: var(--not-attempted); flex: 0 0 auto; align-self: center;
}
.status-dot[data-status="submitted"] { background: var(--submitted); }
.status-dot[data-status="pending"] { background: var(--pending); }
.status-dot[data-status="needs_correction"] { background: var(--needs-correction); }
.status-dot[data-status="correct"] { background: var(--correct); }

/* Progress bar (chapter + volume). Hidden until auth-status.js reveals it. */
.progress { margin: 1.5rem 0; }
.progress[hidden] { display: none; }
.progress .bar {
  display: flex; height: 0.8rem; border-radius: 999px; overflow: hidden;
  background: var(--not-attempted);
}
.progress .bar span { display: block; height: 100%; }
.progress .bar .submitted { background: var(--submitted); }
.progress .bar .pending { background: var(--pending); }
.progress .bar .needs_correction { background: var(--needs-correction); }
.progress .bar .correct { background: var(--correct); }
.progress .label { font-family: "Manrope", system-ui, sans-serif; font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }

/* Exercise page */
.exercise-number { font-family: "Manrope", system-ui, sans-serif; color: var(--muted); font-size: 0.9rem; letter-spacing: 0.03em; text-transform: uppercase; }
.statement { font-size: 1.05em; }
.section-label { font-family: "Manrope", system-ui, sans-serif; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 2.5rem 0 0.5rem; border-top: 1px solid var(--rule); padding-top: 1.2rem; }

.work-part { margin: 1rem 0 1.5rem; }
.work-part .prompt { display: block; margin-bottom: 0.4rem; }
.work-part textarea {
  width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.95rem; line-height: 1.5; padding: 0.7rem; border: 1px solid var(--rule);
  border-radius: 6px; resize: vertical; background: var(--bg); color: var(--text);
}
.work-part textarea.math { font-family: "Source Serif Pro", serif; }
.math-preview { min-height: 1.5rem; margin-top: 0.4rem; color: var(--text); overflow-x: auto; }
.math-preview:empty { display: none; }

button {
  font-family: "Manrope", system-ui, sans-serif; font-weight: 800; font-size: 1rem;
  background: var(--link); color: #fff; border: 0; border-radius: 8px;
  padding: 0.7rem 1.4rem; cursor: pointer; min-height: 44px;
}
button:hover { background: #7ba5f0; }
button:disabled { background: var(--muted); cursor: default; }

/* Auth-gated bits. "in" blocks are hidden until the auth island reveals them
   for logged-in users; "out" blocks (e.g. the login hint) show by default and
   are hidden once logged in. This keeps anonymous pages fully static. */
[data-authgate="in"] { display: none; }

.lead { font-size: 1.2em; color: var(--muted); }
.muted { color: var(--muted); }
.ref-unresolved { color: var(--muted); }
.login-hint { color: var(--muted); font-size: 0.95rem; }

.ex-nav { display: flex; justify-content: space-between; gap: 1rem; margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); font-family: "Manrope", system-ui, sans-serif; font-size: 0.9rem; }
.ex-nav a { white-space: nowrap; }

.feedback { margin: 1rem 0; padding: 0.8rem 1rem; border-radius: 6px; border-left: 4px solid var(--rule); background: var(--code-bg); }
.feedback[data-status="correct"] { border-left-color: var(--correct); }
.feedback[data-status="needs_correction"] { border-left-color: var(--needs-correction); }

details.solution { margin-top: 2.5rem; border-top: 1px solid var(--rule); padding-top: 1.2rem; }
details.solution summary { font-family: "Manrope", system-ui, sans-serif; font-weight: 800; cursor: pointer; color: var(--link); }

.note { border-left: 4px solid var(--rule); padding: 0.4rem 0 0.4rem 1rem; color: var(--muted); margin: 1em 0; }

/* Forms (login/register) */
form.auth { display: flex; flex-direction: column; gap: 0.8rem; max-width: 22rem; }
form.auth input { font: inherit; padding: 0.6rem; border: 1px solid var(--rule); border-radius: 6px; min-height: 44px; }
form.auth .error { color: #e05252; font-size: 0.9rem; }

footer { margin-top: 5rem; padding-top: 1.5rem; border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.85rem; }
