/* ============================================================================
   sunilbhatia.ai — Option B, "Engineering Log"
   White ground, mono for chrome, sans for prose, one amber accent.
   Syntax highlighting lives in syntax.css.
   ========================================================================= */

/* ── Theme ───────────────────────────────────────────────────────────────
   Three states, not two. An explicit choice stamps data-theme on <html>;
   the default ("system") stamps nothing, and only prefers-color-scheme
   separates light from dark. So: bare :root carries the complete light
   palette, the media query overrides tokens unless light was explicitly
   chosen, and [data-theme="dark"] overrides them again so the toggle wins
   in both directions.

   Every colour in this file comes from a token. Nothing is styled inside a
   media block — a colour defined only behind prefers-color-scheme never
   applies in the un-stamped state, which is how you get dark text on a dark
   ground for the majority of visitors who never touch the toggle.
   ──────────────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;

  --bg: #FFFFFF;
  --surface: #FAFAF8;      /* raised panels: table headers, code */
  --ink: #111417;          /* headings, emphasis */
  --body: #363C43;         /* running prose */
  --muted: #626A72;        /* excerpts, secondary prose */
  --soft: #737B84;         /* labels, nav */
  --faint: #6E767E;        /* mono metadata — 4.6:1, AA at 10px */
  --mono-v: #2A2F35;       /* rail values — a touch darker than body */
  --rule: #E6E9EC;
  --rule-soft: #F0F2F4;

  --accent: #8C4A0F;       /* the single accent — amber-brown */
  --accent-wash: #FBEBD8;  /* highlight behind emphasised text */
  --accent-line: #E7C79E;  /* underlines on accent links */
  --marker: #C9A47A;       /* the § before article section headings */

  --inline-bg: #F4F5F3;    /* `code` inside a sentence */
  --inline-fg: #7A4110;
  --inline-border: #EAEBE7;

  /* Typography.
     These are system stacks so the site renders instantly with no webfont
     request and no layout shift. To self-host a real pair later, drop the
     .woff2 files in /public/fonts, add @font-face rules here, and put the
     family names at the front of --sans and --mono. Nothing else changes. */
  --sans: "Avenir Next", "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --measure: 66ch;
  --page: 1000px;
  --gutter: 40px;
}

/* Dark. Not an inversion — a warm-neutral ground chosen so the amber accent
   still reads as the same accent, body text is a warm off-white rather than
   pure #FFF (which glares at long-form sizes), and the accent is lifted from
   #8C4A0F to #E0A56A because the original is unreadable on a dark ground. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15161A;
    --surface: #1B1D22;
    --ink: #F0EEEA;
    --body: #D2CFC9;
    --muted: #A29D96;
    --soft: #8E8983;
    --faint: #8C877F;
    --mono-v: #C6C3BD;
    --rule: #2A2D33;
    --rule-soft: #212429;

    --accent: #E0A56A;
    --accent-wash: rgba(224, 165, 106, 0.16);
    --accent-line: rgba(224, 165, 106, 0.45);
    --marker: #A8845A;

    --inline-bg: #21242A;
    --inline-fg: #E3B183;
    --inline-border: #2E323A;
  }
}

:root[data-theme="dark"] {
  --bg: #15161A;
  --surface: #1B1D22;
  --ink: #F0EEEA;
  --body: #D2CFC9;
  --muted: #A29D96;
  --soft: #8E8983;
  --faint: #8C877F;
  --mono-v: #C6C3BD;
  --rule: #2A2D33;
  --rule-soft: #212429;

  --accent: #E0A56A;
  --accent-wash: rgba(224, 165, 106, 0.16);
  --accent-line: rgba(224, 165, 106, 0.45);
  --marker: #A8845A;

  --inline-bg: #21242A;
  --inline-fg: #E3B183;
  --inline-border: #2E323A;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a { color: inherit; }

img { max-width: 100%; height: auto; }

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

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg);
  color: var(--ink);
  padding: 10px 16px;
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  z-index: 10;
}
.skip:focus { left: 8px; top: 8px; }

/* ── header ──────────────────────────────────────────────────────────── */
.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding: 18px var(--gutter);
  border-bottom: 1px solid var(--rule);
  max-width: var(--page);
  width: 100%;
  margin: 0 auto;
}
.mark {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-decoration: none;
  color: var(--ink);
}
.topright { display: flex; align-items: baseline; gap: 20px; }
.nav { display: flex; gap: 20px; }
.nav a { font-size: 13px; color: var(--soft); text-decoration: none; }
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--accent); box-shadow: inset 0 -1px 0 var(--accent-line); }

/* Hidden unless theme.js ran — a control that cannot work should not be shown. */
.themetoggle { display: none; }
.js .themetoggle {
  display: inline-block;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1;
  color: var(--soft);
  background: none;
  border: 0;
  padding: 2px 4px;
  cursor: pointer;
}
.js .themetoggle:hover { color: var(--accent); }

/* ── layout: metadata rail + content ─────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  gap: 44px;
  align-items: start;
  padding: 34px var(--gutter) 40px;
  max-width: var(--page);
  width: 100%;
  margin: 0 auto;
  flex: 1 0 auto;
}
.grid.narrow { grid-template-columns: minmax(0, 1fr); }

/* The rail is a <details>. On a phone it collapses so the article starts at
   the top of the screen; on a wide screen it is never collapsed and the
   summary is hidden. Native <details> means it works with JavaScript off and
   gets keyboard support and the right ARIA state for free. */
.rail {
  border-right: 1px solid var(--rule);
  padding-right: 22px;
  position: sticky;
  top: 24px;
}
.railbody {
  display: flex;
  flex-direction: column;
  gap: 19px;
}
.rail > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 2px 0 10px;
}
.rail > summary::-webkit-details-marker { display: none; }
.rail > summary::after {
  content: "\25BE";
  font-size: 11px;
  transition: transform 0.15s ease;
}
.rail[open] > summary::after { transform: rotate(180deg); }
.rail > summary:hover { color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .rail > summary::after { transition: none; }
}

/* Wide screens: no toggle, and the content shows whether or not the element
   carries [open]. Chrome hides it via ::details-content, other engines via a
   display rule on the child — override both. */
@media (min-width: 821px) {
  .rail > summary { display: none; }
  .rail > .railbody { display: flex; }
  .rail::details-content { content-visibility: visible; block-size: auto; }
}
.meta { display: flex; flex-direction: column; gap: 4px; }
.k {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}
.v {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--mono-v);
}
.v.live { color: var(--accent); }
.v a { color: var(--mono-v); text-decoration: none; border-bottom: 1px solid var(--rule); }
.v a:hover { color: var(--accent); border-bottom-color: var(--accent-line); }

.railnav { display: flex; flex-direction: column; gap: 7px; font-family: var(--mono); font-size: 12.5px; }
.railnav a { color: var(--soft); text-decoration: none; }
.railnav a:hover { color: var(--ink); }
.railnav a.on { color: var(--accent); }

.toc { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.toc a { color: var(--soft); text-decoration: none; line-height: 1.45; }
.toc a:hover { color: var(--accent); }
.toc a.sub { padding-left: 10px; font-size: 11.5px; }

.main { display: flex; flex-direction: column; gap: 26px; min-width: 0; }

/* ── identity block ──────────────────────────────────────────────────── */
.id { display: flex; align-items: center; gap: 18px; }
.portrait {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  box-shadow: 0 0 0 1px var(--rule);
}
.id h1 {
  font-family: var(--mono);
  font-size: 26px;
  margin: 0 0 5px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.id .sub { font-size: 13px; color: var(--soft); margin: 0; line-height: 1.55; }

.lede { font-size: 16.5px; line-height: 1.8; color: var(--body); margin: 0; max-width: 64ch; }
.lede b { font-weight: 600; color: var(--ink); box-shadow: inset 0 -7px 0 var(--accent-wash); }

.pagetitle { font-size: 26px; margin: 0; font-weight: 600; letter-spacing: -0.02em; }
.pagetitle .filter { color: var(--accent); font-weight: 400; }

.sechead {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 400;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sechead::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

.more { font-family: var(--mono); font-size: 12.5px; color: var(--accent); text-decoration: none; align-self: flex-start; }
.more span { border-bottom: 1px solid var(--accent-line); padding-bottom: 2px; }

/* ── post list ───────────────────────────────────────────────────────── */
.posts { display: flex; flex-direction: column; }
.post {
  padding: 18px 0;
  border-bottom: 1px solid var(--rule-soft);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.post:first-child { padding-top: 4px; }
.pmeta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.pmeta .tg { color: var(--accent); }
.post h3 { font-size: 18.5px; margin: 0; font-weight: 600; letter-spacing: -0.012em; line-height: 1.35; }
.post h3 a { text-decoration: none; color: var(--ink); }
.post h3 a:hover { color: var(--accent); }
.post p { margin: 0; font-size: 14.5px; line-height: 1.7; color: var(--muted); max-width: var(--measure); }

/* ── article ─────────────────────────────────────────────────────────── */
.art { gap: 22px; }
.crumb { font-family: var(--mono); font-size: 11.5px; color: var(--faint); margin: 0; }
.crumb a { color: var(--soft); text-decoration: none; }
.crumb a:hover { color: var(--accent); }

.art h1 {
  font-size: 30px;
  line-height: 1.25;
  margin: 0;
  max-width: 24ch;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--ink);
  text-wrap: balance;
}
.amet {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}
.amet .tg { color: var(--accent); }

.body { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.body > p { font-size: 17px; line-height: 1.8; color: var(--body); margin: 0; max-width: var(--measure); }
.body h2 {
  font-size: 16px;
  margin: 14px 0 0;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.005em;
  scroll-margin-top: 20px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.body h2::before { content: "§"; color: var(--marker); font-family: var(--mono); font-size: 13px; }
.body h3 {
  font-size: 14.5px;
  margin: 8px 0 0;
  font-weight: 600;
  color: var(--ink);
  scroll-margin-top: 20px;
}
.body ul, .body ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: var(--measure);
}
.body li { font-size: 17px; line-height: 1.75; color: var(--body); }
.body a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-line); }
.body a:hover { border-bottom-width: 2px; }
.body blockquote {
  margin: 4px 0;
  padding: 2px 0 2px 18px;
  border-left: 2px solid var(--accent-line);
  font-size: 17px;
  line-height: 1.75;
  color: var(--muted);
  max-width: 64ch;
}
.body blockquote p { margin: 0; }
.body hr { border: 0; border-top: 1px solid var(--rule); margin: 8px 0; }
.body img { border-radius: 4px; box-shadow: 0 0 0 1px var(--rule); }
.body table {
  border-collapse: collapse;
  font-size: 14.5px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.body th, .body td { border: 1px solid var(--rule); padding: 8px 12px; text-align: left; }
.body th { background: var(--surface); font-weight: 600; }

/* Markdown's other code block: four-space indentation. It bypasses the fence
   renderer, so it arrives as a bare <pre> with no language and no caption.
   Give it the same surface as a fenced block rather than leaving it naked. */
.body > pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.75;
  color: var(--code-fg);
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 5px;
  max-width: 100%;
}
.body > pre code {
  font-family: inherit;
  font-size: inherit;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
}

/* Inline code, distinct from block code. */
.body p code, .body li code, .body td code, .body h2 code, .body h3 code {
  font-family: var(--mono);
  font-size: 0.84em;
  background: var(--inline-bg);
  color: var(--inline-fg);
  padding: 2px 5px;
  border-radius: 3px;
  border: 1px solid var(--inline-border);
}

.artnav {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  border-top: 1px solid var(--rule);
  padding-top: 18px;
  margin-top: 8px;
}
.artnav a {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--soft);
  text-decoration: none;
  max-width: 30ch;
  line-height: 1.5;
}
.artnav a:hover { color: var(--ink); }
.artnav a.next { text-align: right; margin-left: auto; }
.artnav a b {
  display: block;
  color: var(--accent);
  font-weight: 400;
  margin-bottom: 4px;
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ── archive ─────────────────────────────────────────────────────────── */
.arch { display: flex; flex-direction: column; gap: 26px; }
.year { display: flex; flex-direction: column; gap: 2px; }
.yr {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--faint);
  padding-bottom: 8px;
  margin: 0;
  font-weight: 400;
}
.arow {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid var(--rule-soft);
  align-items: baseline;
}
.arow .d { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.arow .t { font-size: 15px; color: var(--ink); text-decoration: none; line-height: 1.45; }
.arow .t:hover { color: var(--accent); }
.arow .g { font-family: var(--mono); font-size: 10.5px; color: var(--accent); }

/* ── books ───────────────────────────────────────────────────────────── */
.books { display: flex; flex-direction: column; }
.book { padding: 16px 0; border-bottom: 1px solid var(--rule-soft); display: flex; gap: 18px; align-items: baseline; }
.book .st {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  width: 88px;
  flex: none;
  padding-top: 3px;
}
.book .st.now { color: var(--accent); }
.book .bi { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.book .bt { font-size: 16px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
.book .ba { font-family: var(--mono); font-size: 11.5px; color: var(--faint); }
.book .bn { font-size: 14.5px; line-height: 1.7; color: var(--muted); max-width: 60ch; margin-top: 2px; }
.book .bn a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-line); }

/* ── legal / about prose ─────────────────────────────────────────────── */
.legal { display: flex; flex-direction: column; gap: 18px; max-width: var(--measure); }
.legal h1 { font-size: 27px; margin: 0; font-weight: 600; letter-spacing: -0.02em; }
.legal .dt {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--soft);
  border-left: 2px solid var(--accent-line);
  padding-left: 12px;
  margin: 0;
}
.legal h2 {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 12px 0 0;
  font-weight: 600;
}
.legal p { font-size: 16.5px; line-height: 1.8; color: var(--body); margin: 0; }
.legal ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.legal li { font-size: 16.5px; line-height: 1.75; color: var(--body); }
.legal b, .legal strong { color: var(--ink); font-weight: 600; }
.legal a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-line); }

/* ── footer ──────────────────────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--rule);
  padding: 16px var(--gutter) 28px;
  max-width: var(--page);
  width: 100%;
  margin: 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.foot a { color: var(--soft); text-decoration: none; }
.foot a:hover { color: var(--accent); }

/* ── responsive ──────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  :root { --gutter: 22px; }

  .grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
    padding-top: 26px;
  }

  /* Collapsed by default: the article is what you came for. Tapping the
     summary opens the metadata as a wrapped row rather than a tall column. */
  .rail {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 0 0 4px;
  }
  .rail[open] { padding-bottom: 16px; }
  .railbody {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 16px 26px;
  }
  .railnav, .toc { flex-direction: row; flex-wrap: wrap; gap: 6px 14px; }

  .art h1 { font-size: 26px; }
  .id { gap: 14px; }
  .portrait { width: 68px; height: 68px; }
  .id h1 { font-size: 22px; }
  .arow { grid-template-columns: 72px minmax(0, 1fr); }
  .arow .g { display: none; }
  .book { flex-direction: column; gap: 8px; }
  .book .st { width: auto; padding-top: 0; }
}

@media print {
  .top, .rail, .foot, .artnav, .skip { display: none; }
  .grid { gap: 0; }
  .grid { grid-template-columns: 1fr; padding: 0; }
  body { font-size: 12pt; }
}
