/* anvil course: shared stylesheet for lessons and reference docs */
:root {
  --bg: #fbf9f4;
  --bg-2: #f3efe5;
  --panel: #ffffff;
  --ink: #1d1b16;
  --ink-2: #4a463d;
  --ink-3: #7b7566;
  --rule: #e2dccd;
  --accent: #b4451f;        /* forge orange */
  --accent-soft: #f6e3d6;
  --ok: #2f7a4a;
  --ok-soft: #dcefe2;
  --bad: #a8322d;
  --bad-soft: #f6dcda;
  --code-bg: #f2eee4;
  --code-ink: #2a2620;
  --kw: #8a3b8f; --str: #2f7a4a; --com: #8b8473; --num: #b4451f; --ty: #1f5f99;
  --serif: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --measure: 42rem;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16140f; --bg-2: #1d1a14; --panel: #201d17;
    --ink: #ece6d8; --ink-2: #c4bcab; --ink-3: #8f8879; --rule: #353026;
    --accent: #ec7a4f; --accent-soft: #3a2519;
    --ok: #6cc28c; --ok-soft: #1c3325; --bad: #ef7b74; --bad-soft: #3a1d1b;
    --code-bg: #1c1914; --code-ink: #e6dfcf;
    --kw: #d39be0; --str: #8fd3a5; --com: #8a8372; --num: #f0a07c; --ty: #8ec1f0;
  }
}
:root[data-theme="dark"] {
  --bg: #16140f; --bg-2: #1d1a14; --panel: #201d17;
  --ink: #ece6d8; --ink-2: #c4bcab; --ink-3: #8f8879; --rule: #353026;
  --accent: #ec7a4f; --accent-soft: #3a2519;
  --ok: #6cc28c; --ok-soft: #1c3325; --bad: #ef7b74; --bad-soft: #3a1d1b;
  --code-bg: #1c1914; --code-ink: #e6dfcf;
  --kw: #d39be0; --str: #8fd3a5; --com: #8a8372; --num: #f0a07c; --ty: #8ec1f0;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--serif); font-size: 18px; line-height: 1.6;
  font-feature-settings: "kern", "liga", "onum";
}
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3, h4 { font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 2.3rem; margin: 0.2em 0 0.3em; }
h2 { font-size: 1.45rem; margin: 2.2em 0 0.6em; padding-top: 0.6em; border-top: 1px solid var(--rule); }
h3 { font-size: 1.12rem; margin: 1.8em 0 0.4em; }
h4 { font-family: var(--sans); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-3); margin: 1.6em 0 0.4em; }
p, li { max-width: var(--measure); }
ul, ol { padding-left: 1.3em; }
li { margin: 0.25em 0; }
hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5em 0; }
code { font-family: var(--mono); font-size: 0.84em; background: var(--code-bg); color: var(--code-ink); padding: 0.08em 0.32em; border-radius: 3px; }
pre { font-family: var(--mono); font-size: 0.8rem; line-height: 1.55; background: var(--code-bg); color: var(--code-ink); padding: 1em 1.1em; border-radius: 6px; overflow-x: auto; margin: 0.8em 0; max-width: 100%; position: relative; border: 1px solid var(--rule); }
pre code { background: none; padding: 0; font-size: inherit; }
pre .copy { position: absolute; top: 6px; right: 6px; font-family: var(--sans); font-size: 0.7rem; padding: 2px 8px; border: 1px solid var(--rule); background: var(--panel); color: var(--ink-3); border-radius: 4px; cursor: pointer; opacity: 0; transition: opacity .15s; }
pre:hover .copy { opacity: 1; }
.tok-kw { color: var(--kw); } .tok-str { color: var(--str); } .tok-com { color: var(--com); font-style: italic; } .tok-num { color: var(--num); } .tok-ty { color: var(--ty); }
table { border-collapse: collapse; width: 100%; font-size: 0.86rem; margin: 1em 0; font-family: var(--sans); }
th, td { text-align: left; padding: 0.45em 0.7em; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; color: var(--ink-2); border-bottom: 2px solid var(--rule); }
td code { font-size: 0.8rem; }
.table-wrap { overflow-x: auto; max-width: 100%; }
kbd { font-family: var(--mono); font-size: 0.8em; border: 1px solid var(--rule); border-bottom-width: 2px; border-radius: 3px; padding: 0 0.3em; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--bg-2); border-right: 1px solid var(--rule); padding: 1.4rem 1.1rem 3rem; font-family: var(--sans); font-size: 0.86rem; }
.brand { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.2rem; }
.brand b { font-family: var(--serif); font-size: 1.35rem; letter-spacing: -0.01em; }
.brand span { color: var(--accent); font-family: var(--mono); font-size: 0.75rem; }
.sub { color: var(--ink-3); font-size: 0.78rem; margin: 0 0 1rem; }
.progress { height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; margin: 0.6rem 0 0.3rem; }
.progress > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .3s; }
.progress-label { font-size: 0.72rem; color: var(--ink-3); }
.nav-part { margin: 1.2rem 0 0.3rem; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-3); font-weight: 600; }
.nav a { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.3rem 0.5rem; margin: 0 -0.5rem; border-radius: 5px; color: var(--ink-2); text-decoration: none; line-height: 1.35; }
.nav a:hover { background: var(--panel); color: var(--ink); }
.nav a.active { background: var(--panel); color: var(--ink); box-shadow: inset 2px 0 0 var(--accent); }
.nav a .n { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-3); min-width: 1.4rem; }
.nav a .done { margin-left: auto; color: var(--ok); font-size: 0.8rem; visibility: hidden; }
.nav a.is-done .done { visibility: visible; }
.side-links { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.side-links a { display: block; color: var(--ink-2); text-decoration: none; padding: 0.2rem 0; }
.side-links a:hover { color: var(--accent); }
.theme-toggle, .menu-toggle { font-family: var(--sans); font-size: 0.75rem; border: 1px solid var(--rule); background: var(--panel); color: var(--ink-2); border-radius: 4px; padding: 3px 8px; cursor: pointer; }
.menu-toggle { display: none; }

main { padding: 2.5rem clamp(16px, 5vw, 4.5rem) 6rem; min-width: 0; }
.chapter { display: none; max-width: 50rem; }
.chapter.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.eyebrow { font-family: var(--sans); font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.lede { font-size: 1.2rem; color: var(--ink-2); max-width: var(--measure); margin-top: 0; }
.meta-row { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; font-family: var(--sans); font-size: 0.8rem; color: var(--ink-3); margin: 0.8rem 0 1.5rem; }
.meta-row b { color: var(--ink-2); font-weight: 600; }

/* ---------- Callouts ---------- */
.win, .note, .warn, .source, .ask { border-left: 3px solid var(--rule); padding: 0.7rem 1rem; margin: 1.2rem 0; background: var(--panel); border-radius: 0 6px 6px 0; max-width: var(--measure); font-size: 0.95rem; }
.win { border-color: var(--accent); background: var(--accent-soft); }
.win::before { content: "Tangible win"; display: block; font-family: var(--sans); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin-bottom: 0.2rem; }
.note::before, .warn::before, .source::before, .ask::before { display: block; font-family: var(--sans); font-size: 0.7rem; letter-spacing: 0.1em; text-transform: uppercase; font-weight: 700; margin-bottom: 0.2rem; }
.note::before { content: "Design note"; color: var(--ty); }
.note { border-color: var(--ty); }
.warn { border-color: var(--bad); }
.warn::before { content: "Gotcha"; color: var(--bad); }
.source { border-color: var(--ok); }
.source::before { content: "Primary source: read this"; color: var(--ok); }
.ask { border-color: var(--ink-3); background: transparent; font-style: italic; color: var(--ink-2); }
.ask::before { content: "Stuck or curious?"; color: var(--ink-3); font-style: normal; }
.win p, .note p, .warn p, .source p, .ask p { margin: 0.3em 0; }

/* ---------- Build steps ---------- */
.step { border: 1px solid var(--rule); background: var(--panel); border-radius: 8px; padding: 0.4rem 1.2rem 1rem; margin: 1.4rem 0; }
.step > h3 { margin-top: 0.8em; display: flex; gap: 0.6rem; align-items: baseline; }
.step > h3 .sn { font-family: var(--mono); font-size: 0.78rem; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 0 0.35em; }
.step .file { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-3); margin: -0.3rem 0 0.6rem; }
.accept { list-style: none; padding-left: 0; font-size: 0.93rem; }
.accept li { padding-left: 1.5em; position: relative; }
.accept li::before { content: "☐"; position: absolute; left: 0; color: var(--ink-3); }
.accept li.checked::before { content: "☑"; color: var(--ok); }
.accept li { cursor: pointer; }

details { border: 1px dashed var(--rule); border-radius: 6px; margin: 0.7rem 0; background: var(--bg); }
details > summary { cursor: pointer; padding: 0.5rem 0.9rem; font-family: var(--sans); font-size: 0.82rem; font-weight: 600; color: var(--ink-2); list-style: none; user-select: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; width: 1em; color: var(--ink-3); transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
details > .inner { padding: 0 0.9rem 0.6rem; }
details.hint > summary { color: var(--ty); }
details.solution > summary { color: var(--bad); }
details.solution > summary::after { content: " · try it yourself first"; font-weight: 400; color: var(--ink-3); }
details.recall > summary { color: var(--ink); font-family: var(--serif); font-size: 0.98rem; font-weight: 400; }
details.recall .inner { font-size: 0.93rem; color: var(--ink-2); }

/* ---------- Quiz ---------- */
.quiz { border: 1px solid var(--rule); border-radius: 8px; padding: 0.9rem 1.1rem; margin: 1.1rem 0; background: var(--panel); max-width: var(--measure); }
.quiz .q { margin: 0 0 0.6rem; font-weight: 600; }
.quiz ol { list-style: none; padding: 0; margin: 0; }
.quiz li { max-width: none; }
.quiz button.opt { display: block; width: 100%; text-align: left; font: inherit; font-size: 0.93rem; color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: 6px; padding: 0.5rem 0.8rem; margin: 0.35rem 0; cursor: pointer; }
.quiz button.opt:hover:not([disabled]) { border-color: var(--ink-3); }
.quiz button.opt.right { background: var(--ok-soft); border-color: var(--ok); }
.quiz button.opt.wrong { background: var(--bad-soft); border-color: var(--bad); }
.quiz button.opt[disabled] { cursor: default; }
.quiz .why { display: none; font-size: 0.9rem; color: var(--ink-2); margin-top: 0.6rem; border-top: 1px solid var(--rule); padding-top: 0.6rem; }
.quiz.answered .why { display: block; }
.quiz .retry { display: none; font-family: var(--sans); font-size: 0.75rem; margin-top: 0.4rem; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.quiz.answered .retry { display: inline-block; }

/* ---------- Chapter footer ---------- */
.chapter-foot { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 3rem; padding-top: 1.2rem; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: 0.85rem; flex-wrap: wrap; }
.btn { font-family: var(--sans); font-size: 0.85rem; padding: 0.5rem 1rem; border-radius: 6px; border: 1px solid var(--rule); background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.done-state { background: var(--ok); border-color: var(--ok); color: #fff; }

/* ---------- Home ---------- */
.roadmap { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.8rem; margin: 1.2rem 0; }
.roadmap a { display: block; border: 1px solid var(--rule); background: var(--panel); border-radius: 8px; padding: 0.7rem 0.9rem; text-decoration: none; color: var(--ink); font-size: 0.92rem; line-height: 1.35; }
.roadmap a:hover { border-color: var(--accent); }
.roadmap a small { display: block; font-family: var(--mono); font-size: 0.7rem; color: var(--accent); margin-bottom: 0.15rem; }
.roadmap a span { display: block; color: var(--ink-3); font-size: 0.8rem; margin-top: 0.25rem; font-family: var(--sans); }
.diagram { margin: 1.2rem 0; max-width: 100%; overflow-x: auto; }
.diagram svg { display: block; max-width: 100%; height: auto; }
.diagram svg text { font-family: var(--sans); fill: var(--ink); }
.diagram svg .muted { fill: var(--ink-3); }
.diagram svg .box { fill: var(--panel); stroke: var(--rule); stroke-width: 1.5; }
.diagram svg .box.hl { stroke: var(--accent); fill: var(--accent-soft); }
.diagram svg .line { stroke: var(--ink-3); stroke-width: 1.4; fill: none; }
.diagram svg .arrowhead { fill: var(--ink-3); }

/* ---------- Reference documents ---------- */
.ref { max-width: 60rem; margin: 0 auto; padding: 2.5rem clamp(16px, 5vw, 3rem) 4rem; }
.ref header { border-bottom: 2px solid var(--ink); padding-bottom: 0.8rem; margin-bottom: 1.5rem; }
.ref header p { margin: 0; color: var(--ink-3); font-family: var(--sans); font-size: 0.85rem; }
.ref dl { display: grid; grid-template-columns: minmax(10rem, 14rem) 1fr; gap: 0.5rem 1.4rem; margin: 0.8rem 0; }
.ref dt { font-weight: 600; }
.ref dd { margin: 0; color: var(--ink-2); font-size: 0.95rem; }
.ref dd .avoid { display: block; font-family: var(--sans); font-size: 0.75rem; color: var(--ink-3); }
.cols-2 { columns: 2 22rem; column-gap: 2.5rem; }
.cols-2 > * { break-inside: avoid; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 88vw); z-index: 20; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-block; position: fixed; top: 10px; right: 12px; z-index: 30; }
  main { padding-top: 3rem; }
  body { font-size: 17px; }
  h1 { font-size: 1.8rem; }
  .ref dl { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .menu-toggle, .chapter-foot, pre .copy, .theme-toggle { display: none !important; }
  .shell { display: block; }
  .chapter { display: block !important; page-break-after: always; }
  details { border: 0; } details > .inner { display: block; }
  body { background: #fff; color: #000; font-size: 11pt; }
  pre { white-space: pre-wrap; border: 1px solid #ccc; }
}
