/* Build It Yourself — a founder's guide to coding with AI */

:root {
  color-scheme: light;
  --bg: #f6f8fc;
  --panel: #ffffff;
  --sidebar: #edf1f7;
  --ink: #0b1220;
  --ink-soft: #26303f;
  --muted: #5a6678;
  --line: #dde3ed;
  --line-soft: #e9eef5;
  --accent: #1769ff;
  --accent-ink: #0d4fd1;
  --accent-wash: #e8f0ff;
  /* The logo blue itself. Deliberately not redefined in the dark blocks —
     --accent lifts to #4d8dff there for text contrast, but the mark must stay
     the brand colour. Large fills only, never text. */
  --brand: #1769ff;
  --accent-on: #ffffff;
  --teal: #3f6b27;
  --teal-wash: #edf6e8;
  --teal-on: #ffffff;
  --amber-wash: #fdf6e3;
  --amber-line: #e0c274;
  --red-wash: #fdeeec;
  --red-line: #e7a99f;
  --code-bg: #eff3f9;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #05070a;
    --panel: #0d1117;
    --sidebar: #080a0e;
    --ink: #e8ecf3;
    --ink-soft: #c9d2e0;
    --muted: #8b97ab;
    --line: #1e242e;
    --line-soft: #161b23;
    --accent: #4d8dff;
    --accent-ink: #7ba9ff;
    --accent-wash: #0e1a2e;
    --accent-on: #07101f;
    --teal: #8cc26c;
    --teal-wash: #131c10;
    --teal-on: #0d1a08;
    --amber-wash: #241d0c;
    --amber-line: #5c4a1c;
    --red-wash: #2a1411;
    --red-line: #6e3229;
    --code-bg: #0f141b;
  }
}

:root[data-theme="dark"] {
    --bg: #05070a;
    --panel: #0d1117;
    --sidebar: #080a0e;
    --ink: #e8ecf3;
    --ink-soft: #c9d2e0;
    --muted: #8b97ab;
    --line: #1e242e;
    --line-soft: #161b23;
    --accent: #4d8dff;
    --accent-ink: #7ba9ff;
    --accent-wash: #0e1a2e;
    --accent-on: #07101f;
    --teal: #8cc26c;
    --teal-wash: #131c10;
    --teal-on: #0d1a08;
    --amber-wash: #241d0c;
    --amber-line: #5c4a1c;
    --red-wash: #2a1411;
    --red-line: #6e3229;
    --code-bg: #0f141b;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 1.5rem; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 17px; line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 99; background: var(--panel); padding: .6rem 1rem; border-radius: 8px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--line);
  padding: 1.6rem 1.2rem 3rem; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: .7rem; align-items: flex-start; text-decoration: none; color: var(--ink); margin-bottom: 1.6rem; }
/* wfoster.dev mark. The monogram follows the theme; the arc keeps the true
   brand blue in both, so the logo stays the logo. */
.brand-mark { display: block; flex: none; width: 34px; height: auto; margin-top: .1rem; }
.brand-mark .mark-ink { fill: var(--ink); }
.brand-mark .mark-arc { fill: var(--brand); }
.brand strong { display: block; font-family: var(--serif); font-size: 1.12rem; letter-spacing: -.01em; }
.brand em { display: block; font-style: normal; font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.nav-part {
  font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  margin: 1.4rem 0 .45rem; font-weight: 600;
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: block; padding: .38rem .6rem; margin-left: -.6rem; border-radius: 7px;
  color: var(--ink-soft); text-decoration: none; font-size: .9rem; line-height: 1.35;
}
.sidebar li a:hover { background: rgba(0,0,0,.05); color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sidebar li a:hover { background: rgba(255,255,255,.06); } }
:root[data-theme="dark"] .sidebar li a:hover { background: rgba(255,255,255,.06); }
.sidebar li a.active { background: var(--accent-wash); color: var(--accent-ink); font-weight: 600; }
.nav-foot { margin-top: 2rem; font-size: .74rem; color: var(--muted); line-height: 1.5; }
/* Ways back to the parent site. Quiet until hovered — these are exits, not
   destinations, and must not compete with the chapter nav above them. */
.nav-links {
  display: flex; flex-wrap: wrap; gap: .4rem 1rem;
  margin: 1.1rem 0 0; font-size: .78rem;
}
.nav-links a { color: var(--muted); text-decoration: none; }
.nav-links a:hover, .nav-links a:focus-visible { color: var(--accent); }
#progress-pill { display: inline-block; margin-top: .4rem; padding: .2rem .55rem; border-radius: 999px; background: var(--teal-wash); color: var(--teal); font-weight: 600; }

.menu-btn {
  display: none; position: sticky; top: 0; z-index: 20; width: 100%;
  padding: .7rem 1rem; border: 0; border-bottom: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-size: .9rem; text-align: left; cursor: pointer;
}

main { padding: 3.2rem 3rem 4rem; max-width: 56rem; }
article > * { max-width: 44rem; }

/* ---------- typography ---------- */
.page-head { margin-bottom: 2.4rem; padding-bottom: 1.6rem; border-bottom: 1px solid var(--line); }
.kicker { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 700; margin: 0 0 .7rem; }
h1 { font-family: var(--serif); font-size: 2.5rem; line-height: 1.12; letter-spacing: -.02em; margin: 0 0 .8rem; }
.lede { font-size: 1.15rem; color: var(--muted); margin: 0; line-height: 1.5; }
h2 {
  font-family: var(--serif); font-size: 1.65rem; line-height: 1.2; letter-spacing: -.015em;
  margin: 3rem 0 .9rem; padding-top: .4rem;
}
h3 { font-size: 1.08rem; margin: 2rem 0 .6rem; letter-spacing: -.005em; }
h4 { font-size: .95rem; margin: 1.5rem 0 .4rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
p { margin: 0 0 1.1rem; }
a { color: var(--accent-ink); text-underline-offset: 2px; }
strong { font-weight: 650; }
ul, ol { margin: 0 0 1.2rem; padding-left: 1.3rem; }
li { margin-bottom: .5rem; }
li > ul, li > ol { margin-top: .5rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2.5rem 0; }
blockquote {
  margin: 1.5rem 0; padding: .2rem 0 .2rem 1.2rem; border-left: 3px solid var(--line);
  color: var(--muted); font-style: italic;
}
code { font-family: var(--mono); font-size: .875em; background: var(--code-bg); padding: .12em .38em; border-radius: 5px; }
pre { background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; overflow-x: auto; margin: 0 0 1.2rem; }
pre code { background: none; padding: 0; font-size: .85rem; line-height: 1.6; }
kbd {
  font-family: var(--mono); font-size: .78em; background: var(--panel); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 5px; padding: .1em .4em;
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 0 1.4rem; max-width: 44rem; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- callouts ---------- */
.callout {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--muted);
  border-radius: var(--radius); padding: 1rem 1.2rem .3rem; margin: 1.6rem 0;
}
.callout .co-title { font-weight: 650; margin-bottom: .5rem; }
.callout p:last-child, .callout ul:last-child, .callout ol:last-child { margin-bottom: 1rem; }
.co-tip { border-left-color: var(--teal); background: var(--teal-wash); }
.co-warn { border-left-color: var(--amber-line); background: var(--amber-wash); }
.co-trap { border-left-color: var(--red-line); background: var(--red-wash); }
.co-money { border-left-color: var(--teal); background: var(--teal-wash); }
.co-key { border-left-color: var(--accent); background: var(--accent-wash); }
.co-note { border-left-color: var(--line); }

/* ---------- prompts ---------- */
.prompt {
  margin: 1.6rem 0; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; background: var(--panel);
}
.prompt figcaption {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .55rem .8rem .55rem 1rem; background: var(--accent-wash); border-bottom: 1px solid var(--line);
}
.prompt .tag { font-size: .72rem; letter-spacing: .07em; text-transform: uppercase; font-weight: 700; color: var(--accent-ink); }
.prompt pre { border: 0; border-radius: 0; background: var(--panel); margin: 0; }
.prompt pre code { font-family: var(--mono); font-size: .82rem; white-space: pre-wrap; color: var(--ink-soft); }
.copy {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft);
  font: inherit; font-size: .75rem; padding: .2rem .6rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.copy:hover { border-color: var(--accent); color: var(--accent-ink); }
.copy.done { background: var(--teal); border-color: var(--teal); color: var(--teal-on); }

/* ---------- exercises ---------- */
.exercise {
  margin: 1.8rem 0; padding: 1.1rem 1.3rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); border-top: 3px solid var(--teal);
}
.exercise h3 { margin: 0 0 .6rem; font-size: 1.05rem; }
.exercise h3 label { display: flex; gap: .6rem; align-items: baseline; cursor: pointer; }
.ex-box { width: 1.05rem; height: 1.05rem; accent-color: var(--teal); flex: none; position: relative; top: .15rem; }
.ex-n { font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--teal); font-weight: 700; white-space: nowrap; }
.exercise.done { opacity: .62; }
.exercise.done h3 { text-decoration: line-through; text-decoration-color: var(--muted); }
.ex-body > :last-child { margin-bottom: 0; }
.ex-list { list-style: none; padding: 0; }
.ex-list li { display: flex; gap: .6rem; align-items: baseline; padding: .45rem 0; border-bottom: 1px solid var(--line-soft); }
.ex-list label { display: flex; gap: .6rem; align-items: baseline; flex: 1; cursor: pointer; }
.ex-list .jump { font-size: .78rem; text-decoration: none; color: var(--muted); }
.ex-list .jump:hover { color: var(--accent-ink); }

/* ---------- misc components ---------- */
details.why {
  margin: 1.4rem 0; padding: .3rem 1.1rem; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius);
}
details.why summary { cursor: pointer; font-weight: 600; padding: .7rem 0; font-size: .95rem; }
details.why[open] summary { border-bottom: 1px solid var(--line-soft); margin-bottom: .9rem; }

.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 1.6rem 0; max-width: 44rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.card h3 { margin: 0 0 .45rem; font-size: 1rem; }
.card p { font-size: .88rem; color: var(--muted); margin: 0; }
.card a { text-decoration: none; }

.lib-item { margin-bottom: 2rem; }
.lib-src { font-size: .78rem; color: var(--muted); margin: 0 0 .35rem; }

.steps { counter-reset: step; list-style: none; padding: 0; }
.steps > li { counter-increment: step; position: relative; padding-left: 2.4rem; margin-bottom: 1.1rem; }
.steps > li::before {
  content: counter(step); position: absolute; left: 0; top: .05rem;
  width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent-wash); color: var(--accent-ink);
  display: grid; place-items: center; font-size: .8rem; font-weight: 700;
}

.pill-row { display: flex; flex-wrap: wrap; gap: .4rem; margin: 0 0 1.4rem; padding: 0; list-style: none; }
.pill-row li {
  margin: 0; font-size: .78rem; padding: .25rem .65rem; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}

/* ---------- footer ---------- */
.page-foot { margin-top: 4rem; padding-top: 1.6rem; border-top: 1px solid var(--line); max-width: 44rem; }
.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.6rem; }
.pg { display: block; padding: .9rem 1.1rem; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; background: var(--panel); }
.pg span { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: .25rem; }
.pg strong { color: var(--ink); font-weight: 600; font-size: .95rem; }
.pg.next { text-align: right; }
.pg:hover { border-color: var(--accent); }
.foot-note { font-size: .78rem; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  body { font-size: 16px; }
  .shell { grid-template-columns: 1fr; }
  .menu-btn { display: block; }
  .sidebar { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  body.nav-open .sidebar { display: block; }
  main { padding: 2rem 1.25rem 3rem; }
  h1 { font-size: 2rem; }
  h2 { font-size: 1.4rem; }
  .pager { grid-template-columns: 1fr; }
  .pg.next { text-align: left; }
}

@media print {
  .sidebar, .menu-btn, .pager, .copy { display: none; }
  main { padding: 0; max-width: none; }
  body { font-size: 11pt; }
}

/* ---------- credit line ---------- */
.credit {
  margin: 1.4rem 0 0; padding-top: 1rem; border-top: 1px solid var(--line-soft);
  font-size: .8rem; color: var(--muted);
}
.credit a { color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.credit a:hover { text-decoration: underline; }
@media print { .credit { border-top: 1px solid #ccc; } }


/* ---------- theme handling ---------- */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
html { transition: none; }

.theme-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft);
  font: inherit; font-size: .82rem; border-radius: 999px; cursor: pointer;
  padding: .35rem .7rem; display: inline-flex; align-items: center; gap: .45rem; line-height: 1;
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.theme-btn .theme-ico { font-size: .95rem; }
.theme-btn.wide { width: 100%; justify-content: center; padding: .5rem .7rem; }
.side-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: .5rem; margin-bottom: 1.5rem;
}
.side-head .brand { margin-bottom: 0; }
.side-head .theme-btn { flex: none; padding: .3rem .5rem; margin-top: .15rem; }

/* ---------- top bar (mobile) ---------- */
.topbar {
  display: none; position: sticky; top: 0; z-index: 30; align-items: center; gap: .6rem;
  padding: .55rem .8rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .menu-btn {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit;
  font-size: .82rem; padding: .35rem .7rem; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.topbar-title {
  flex: 1; min-width: 0; font-size: .85rem; font-weight: 600; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center;
}
body.nav-open .topbar .menu-btn { background: var(--accent-wash); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- on-this-page rail ---------- */
.toc { display: none; }
@media (min-width: 1240px) {
  .shell { grid-template-columns: 290px minmax(0, 1fr) 232px; }
  .toc {
    display: block; position: sticky; top: 0; align-self: start; max-height: 100vh; overflow-y: auto;
    padding: 3.6rem 1.4rem 3rem 0;
  }
  .toc-head { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 0 0 .7rem; }
  .toc a {
    display: block; padding: .28rem 0 .28rem .7rem; border-left: 2px solid var(--line);
    color: var(--muted); text-decoration: none; font-size: .8rem; line-height: 1.4;
  }
  .toc a:hover { color: var(--ink); border-left-color: var(--muted); }
  .toc a.current { color: var(--accent-ink); border-left-color: var(--accent); font-weight: 600; }
  .toc-top { margin-top: 1rem; border-left: 0 !important; padding-left: 0 !important; font-size: .78rem !important; }
}

/* ---------- sidebar quick filter ---------- */
.nav-filter {
  width: 100%; padding: .45rem .7rem; margin-bottom: .4rem; font: inherit; font-size: .84rem;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
}
.nav-filter::placeholder { color: var(--muted); }
.nav-filter:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.sidebar li.hide, .nav-part.hide { display: none; }

/* ---------- copy buttons on plain code blocks ---------- */
.code-wrap { position: relative; margin: 0 0 1.2rem; }
.code-wrap pre { margin: 0; }
.code-wrap .copy { position: absolute; top: .5rem; right: .5rem; opacity: 0; transition: opacity .12s; }
.code-wrap:hover .copy, .code-wrap .copy:focus { opacity: 1; }
@media (hover: none) { .code-wrap .copy { opacity: 1; } }

/* ---------- mobile refinements ---------- */
@media (max-width: 1239px) {
  .menu-btn { display: inline-block; }
}
@media (max-width: 900px) {
  .topbar { display: flex; }
  .sidebar { padding-top: 1.1rem; }
  .exercise { padding: .95rem 1rem; }
  .prompt pre code { font-size: .8rem; }
  .cards { grid-template-columns: 1fr; }
  .page-head { margin-bottom: 1.8rem; }
  .brand { margin-bottom: 1rem; }
  table { font-size: .85rem; }
  th, td { padding: .5rem .55rem; }
  .table-wrap { border: 1px solid var(--line); border-radius: var(--radius); padding: .2rem .6rem; }
}
@media (max-width: 900px) { .side-head .theme-btn { display: none; } }
@media print { .topbar, .toc { display: none !important; } }

/* ---------- menu button corrections ---------- */
.topbar .menu-btn { display: inline-block; width: auto; position: static; }
@media (min-width: 901px) { .topbar { display: none; } .menu-btn { display: none; } }

/* ---------- diagrams ---------- */
figure.diagram {
  margin: 1.8rem 0; padding: 1rem 1rem .3rem; max-width: 44rem;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
figure.diagram svg { display: block; width: 100%; height: auto; }
figure.diagram .d-text { font-family: var(--sans); }
figure.diagram figcaption { margin: .9rem 0 .8rem; font-size: .8rem; color: var(--muted); line-height: 1.5; }
ol.legend { counter-reset: none; list-style: none; padding: 0; margin: 1rem 0 1.4rem; max-width: 44rem; }
ol.legend > li {
  position: relative; padding-left: 2.2rem; margin-bottom: .7rem; font-size: .92rem;
}
ol.legend > li > .n {
  position: absolute; left: 0; top: .05rem; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent); color: var(--accent-on); display: grid; place-items: center;
  font-size: .74rem; font-weight: 700;
}

/* ---------- call to action ---------- */
.co-cta {
  border: 1px solid var(--accent); border-left-width: 4px;
  background: var(--accent-wash); padding: 1.2rem 1.3rem .4rem;
}
.co-cta .co-title { font-family: var(--serif); font-size: 1.25rem; letter-spacing: -.01em; color: var(--accent-ink); }
.co-cta p { font-size: .95rem; }
.cta-btn {
  display: inline-block; margin: .2rem 0 1.1rem; padding: .6rem 1.2rem;
  background: var(--accent); color: var(--accent-on); border-radius: 999px;
  text-decoration: none; font-weight: 650; font-size: .92rem;
}
.cta-btn:hover { filter: brightness(1.08); }
.cta-note { font-size: .82rem !important; color: var(--muted); }
