/* Review-site styles for The Second Law.
   Minimal, reader-focused.

   Theme model:
   - Default = light values below.
   - ``:root[data-theme="dark"]`` — user explicitly picked dark.
   - @media (prefers-color-scheme: dark) — applied only when the user
     has NOT explicitly chosen a theme (i.e. no ``data-theme`` attr).
   The three-state toggle in the header (static/theme.js) sets/removes
   the attribute and persists the choice in localStorage. */

:root {
  --text-color: #222;
  --bg-color: #fcfcfa;
  --accent: #0366d6;
  --muted: #666;
  --border: #ddd;
  --code-bg: rgba(127, 127, 127, 0.08);
  --content-max: 42rem;
  --font-body: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

:root[data-theme="dark"] {
  --text-color: #e8e8e8;
  --bg-color: #17181a;
  --accent: #58a6ff;
  --muted: #9a9a9a;
  --border: #2f3236;
  --code-bg: rgba(255, 255, 255, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --text-color: #e8e8e8;
    --bg-color: #17181a;
    --accent: #58a6ff;
    --muted: #9a9a9a;
    --border: #2f3236;
    --code-bg: rgba(255, 255, 255, 0.05);
  }
}

* { box-sizing: border-box; }

html { font-size: 17px; }

body {
  margin: 0;
  padding: 0;
  color: var(--text-color);
  background: var(--bg-color);
  font-family: var(--font-body);
  line-height: 1.65;
}

/* ---------- Header ---------- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  background: var(--bg-color);
  z-index: 10;
}

.site-header__title a {
  color: var(--text-color);
  text-decoration: none;
  font-weight: 600;
}

.site-header__subtitle {
  color: var(--muted);
  font-weight: 400;
  margin-left: 0.5rem;
  font-size: 0.85em;
}

.site-header__version {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  color: var(--muted);
}

.site-header__version select {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  background: var(--bg-color);
  color: var(--text-color);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* ---------- Theme toggle ---------- */

.theme-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.theme-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.25rem 0.6rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  cursor: pointer;
  line-height: 1.2;
}

.theme-toggle button + button {
  border-left: 1px solid var(--border);
}

.theme-toggle button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--bg-color);
}

.theme-toggle button:not([aria-pressed="true"]):hover {
  color: var(--text-color);
}

/* ---------- Layout ---------- */

.site-layout {
  display: grid;
  grid-template-columns: minmax(0, 220px) minmax(0, var(--content-max));
  gap: 3rem;
  justify-content: center;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.site-layout > .chapter {
  max-width: var(--content-max);
  margin: 0;
  padding: 0;
  min-width: 0;
}

.chapter-sidebar {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  min-width: 0;
}

.chapter-sidebar nav {
  position: sticky;
  top: 4rem;
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding-right: 0.5rem;
}

.chapter-toc__heading {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
}

.chapter-toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: chapter-toc;
}

.chapter-toc__list > li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.35;
}

.chapter-toc__list a {
  color: var(--muted);
  text-decoration: none;
}

.chapter-toc__list a:hover {
  color: var(--text-color);
}

.chapter-toc__list > li.current > a {
  color: var(--accent);
  font-weight: 600;
}

.chapter-toc__list > li.current {
  border-bottom-color: var(--accent);
}

/* Nested section list under the current chapter. Only renders on the
   chapter currently being viewed; populated by versions.js from the
   page's own ``<h2 id>`` elements. */
.chapter-toc__sections {
  list-style: none;
  padding-left: 0.75rem;
  margin: 0.4rem 0 0.25rem;
  border-left: 2px solid var(--border);
}

.chapter-toc__sections li {
  padding: 0.15rem 0;
  border-bottom: none;
  font-size: 0.88em;
  line-height: 1.3;
}

.chapter-toc__sections a {
  color: var(--muted);
}

.chapter-toc__sections a:hover {
  color: var(--text-color);
}

@media (max-width: 900px) {
  .site-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1.5rem;
  }
  .chapter-sidebar {
    display: none;
  }
}

/* ---------- Main content ---------- */

.chapter,
main {
  max-width: var(--content-max);
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.chapter__title {
  font-family: var(--font-ui);
  font-size: 2.2rem;
  line-height: 1.2;
  margin-top: 0;
  margin-bottom: 1.5rem;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-ui);
  line-height: 1.3;
  margin-top: 2.5rem;
  margin-bottom: 0.5rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }

p { margin: 0.75rem 0; }

a { color: var(--accent); }

em { font-style: italic; }
strong { font-weight: 600; }

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

pre {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.4;
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 4px;
  overflow-x: auto;
  margin: 1.25rem 0;
}

pre code {
  background: none;
  padding: 0;
  font-size: inherit;
}

blockquote {
  border-left: 3px solid var(--border);
  margin: 1.25rem 0;
  padding: 0.25rem 1rem;
  color: var(--muted);
}

blockquote strong:first-child {
  color: var(--accent);
}

/* Labelled blockquotes — classes added by filters/labelled-blockquote.lua.
   The filter wraps each labelled blockquote in a div with ``.labelled``
   plus a label-specific class, so CSS targets via the wrapper.

   "The Law" (the thesis-bearing block) gets distinctive treatment: thicker
   accent border, subtle accent-tinted background, block-level label in
   small caps. Resets the inner blockquote's own ornament so the outer
   wrapper can own the visual styling without double borders. */

.labelled-the-law {
  border-left: 5px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  color: var(--text-color);
  border-radius: 4px;
}

.labelled-the-law > blockquote {
  border-left: none;
  padding: 0;
  margin: 0;
  color: inherit;
}

.labelled-the-law strong:first-child {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 0.78em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.75rem auto;
}

ul, ol {
  padding-left: 1.5rem;
}

li { margin: 0.35rem 0; }

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5rem auto;
  max-width: 8rem;
}

/* ---------- Listings (index / version TOC) ---------- */

.version-list,
.chapter-list {
  list-style: none;
  padding-left: 0;
}

.version-list li,
.chapter-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.version-list a,
.chapter-list a {
  font-family: var(--font-ui);
}

.updated,
.updated-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.05em 0.45em;
  font-size: 0.75em;
  font-family: var(--font-ui);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Footer ---------- */

.site-footer {
  max-width: var(--content-max);
  margin: 3rem auto 2rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer code {
  background: none;
  padding: 0;
}

.site-footer a {
  color: var(--muted);
}
