/*
 * Shared stylesheet for the static (non-React) pages: About, Contact,
 * Terms, Privacy, the guides index, and every article.
 *
 * Deliberately hand-written plain CSS rather than Tailwind. These pages
 * are static HTML with no build step and no JS — a crawler (or a reader
 * with JS disabled) gets the fully styled page from the HTML alone.
 * Colour values mirror tailwind.config.js (neutral scale + brand purple)
 * so the static pages and the React app look like one site.
 *
 * Copied to /public/pages.css by tools/build_pages.py — edit this file,
 * not the copy in /public.
 */

/*
 * Theming
 * -------
 * These pages share a theme preference with the React app, which stores
 * localStorage['theme'] as 'system' | 'light' | 'dark' and toggles a .dark
 * class on <html> (Tailwind's darkMode: 'class'). So the static pages must
 * key off the same class, not off prefers-color-scheme alone — otherwise
 * picking "dark" on the calculator would not carry over to a guide page.
 *
 * Three selectors, in order:
 *   :root            light theme, the default
 *   html.dark        explicit dark — set by the inline bootstrap script in
 *                    the <head> (see PAGE_TEMPLATE in tools/build_pages.py)
 *   media query      dark OS with no explicit choice. The :not(.light) guard
 *                    means an explicit "light" choice still wins, and the
 *                    rule still applies with JavaScript disabled, so a
 *                    dark-mode reader (or crawler) gets a sane page.
 *
 * The dark values are duplicated between the class and the media query
 * because a selector list cannot span a media query. Keep the two blocks
 * identical.
 */

:root {
  color-scheme: light;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #e5e5e5;
  --border-soft: #ededed;
  --text: #171717;
  --text-muted: #525252;
  --text-faint: #737373;
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --code-bg: #eff6ff;
  --table-head: #ededed;
  --callout-bg: #eff6ff;
  --callout-border: #bfdbfe;
  --toggle-hover: #e5e5e5;
}

html.dark {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #141414;
  --border: #262626;
  --border-soft: #1f1f1f;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-faint: #737373;
  --brand: #60a5fa;
  --brand-hover: #93c5fd;
  --code-bg: #101d33;
  --table-head: #1a1a1a;
  --callout-bg: #0f1c30;
  --callout-border: #1e3a5f;
  --toggle-hover: #262626;
}

@media (prefers-color-scheme: dark) {
  html:not(.light) {
    color-scheme: dark;
    --bg: #0a0a0a;
    --surface: #141414;
    --border: #262626;
    --border-soft: #1f1f1f;
    --text: #f5f5f5;
    --text-muted: #a3a3a3;
    --text-faint: #737373;
    --brand: #60a5fa;
    --brand-hover: #93c5fd;
    --code-bg: #101d33;
    --table-head: #1a1a1a;
    --callout-bg: #0f1c30;
    --callout-border: #1e3a5f;
    --toggle-hover: #262626;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/*
 * Layout widths
 * -------------
 * --shell must match the React app's container in App.jsx exactly, or the
 * nav and footer visibly jump sideways when moving between the calculator
 * and a static page:
 *     App.jsx:  max-w-5xl (64rem) + px-4 sm:px-6
 * So: 64rem wide, 1rem padding, rising to 1.5rem at Tailwind's sm
 * breakpoint (640px). Change one, change the other.
 *
 * --measure is deliberately narrower. Article body text sits at ~46rem to
 * keep lines around 70-80 characters; the tool page can be wide because it
 * is mostly tables, but running prose at 64rem is hard to read.
 */
:root {
  --shell: 64rem;
  --measure: 46rem;
  --gutter: 1rem;
}

@media (min-width: 640px) {
  :root { --gutter: 1.5rem; }
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- site header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding-top: 0.9rem;
  padding-bottom: 0.9rem;
  max-width: var(--shell);
}

.brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand span { color: var(--brand); }

.site-nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.875rem;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-nav a:hover { color: var(--brand); }
.site-nav a[aria-current="page"] { color: var(--brand); font-weight: 500; }

/* ---------- theme toggle ---------- */
/* Mirrors src/components/ThemeToggle.jsx so the control looks and behaves
   identically on the tool page and the static pages. Hidden when JS is
   off, since without JS it cannot do anything. */

.theme-toggle {
  display: none;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  margin-left: auto;
}

html.js .theme-toggle { display: flex; }

.theme-toggle button {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}

.theme-toggle button:hover { background: var(--toggle-hover); color: var(--text); }

.theme-toggle button[aria-pressed="true"],
.theme-toggle button[aria-pressed="true"]:hover {
  background: #2563eb;
  color: #ffffff;
}

.theme-toggle svg { width: 14px; height: 14px; }

@media (max-width: 600px) {
  .theme-toggle button span { display: none; }
  .theme-toggle button { padding: 0.375rem 0.5rem; }
}

/* ---------- article ---------- */

main { padding: 2.5rem 0 1rem; }

.breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-faint);
  margin: 0 0 1.5rem;
}

.breadcrumb a { color: var(--text-muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--brand); text-decoration: underline; }

h1 {
  font-size: 2.125rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

.standfirst {
  font-size: 1.1875rem;
  line-height: 1.6;
  color: var(--text-muted);
  margin: 0 0 1.5rem;
}

.byline {
  font-size: 0.8125rem;
  color: var(--text-faint);
  margin: 0 0 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

h2 {
  font-size: 1.5rem;
  line-height: 1.3;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 2.75rem 0 0.875rem;
}

h3 {
  font-size: 1.1875rem;
  font-weight: 600;
  margin: 2rem 0 0.625rem;
}

p { margin: 0 0 1.125rem; }

a { color: var(--brand); }
a:hover { color: var(--brand-hover); }

ul, ol { margin: 0 0 1.125rem; padding-left: 1.5rem; }
li { margin-bottom: 0.5rem; }

strong { font-weight: 600; color: var(--text); }

code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.875em;
  background: var(--code-bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.125rem;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
  margin: 0 0 1.25rem;
}

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

blockquote {
  margin: 0 0 1.25rem;
  padding: 0.25rem 0 0.25rem 1.25rem;
  border-left: 3px solid var(--callout-border);
  color: var(--text-muted);
  font-style: italic;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2.5rem 0; }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; margin: 0 0 1.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

th {
  text-align: left;
  padding: 0.625rem 0.875rem;
  background: var(--table-head);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  white-space: nowrap;
}

td {
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--border-soft);
  vertical-align: top;
}

td.num { font-family: "JetBrains Mono", monospace; font-size: 0.875rem; white-space: nowrap; }

caption {
  caption-side: bottom;
  font-size: 0.8125rem;
  color: var(--text-faint);
  text-align: left;
  padding-top: 0.625rem;
}

/* ---------- callout ---------- */

.callout {
  background: var(--callout-bg);
  border: 1px solid var(--callout-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 0 0 1.5rem;
  font-size: 0.9375rem;
}

.callout p:last-child { margin-bottom: 0; }
.callout .callout-label {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--brand);
  margin-bottom: 0.375rem;
}

/* ---------- key takeaways box ---------- */

.takeaways {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin: 0 0 2rem;
}

.takeaways h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin: 0 0 0.75rem;
  font-weight: 700;
}

.takeaways ul { margin: 0; padding-left: 1.25rem; }
.takeaways li { font-size: 0.9375rem; }
.takeaways li:last-child { margin-bottom: 0; }

/* ---------- guides index cards ---------- */

.card-list {
  list-style: none;
  padding: 0;
  margin: 0 0 2rem;
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.375rem;
  margin: 0;
}

.card h2 {
  font-size: 1.125rem;
  margin: 0 0 0.375rem;
  line-height: 1.35;
}

.card h2 a { text-decoration: none; color: var(--text); }
.card h2 a:hover { color: var(--brand); }

.card p {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.card .meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- next/prev article nav ---------- */

.article-footer-nav {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.9375rem;
}

.article-footer-nav p { margin: 0 0 0.5rem; }

/* ---------- ad slot ---------- */

.ad-slot {
  margin: 2.5rem 0;
  text-align: center;
  min-height: 1px;
}

/* ---------- footer ---------- */

.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 2rem 0;
  font-size: 0.8125rem;
  color: var(--text-faint);
  line-height: 1.65;
}

.site-footer .wrap { max-width: var(--shell); }
.site-footer p { margin: 0 0 0.75rem; }
.site-footer p:last-child { margin-bottom: 0; }
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--brand); text-decoration: underline; }

.footer-links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem !important;
}

.footer-legal { font-size: 0.75rem; color: var(--text-faint); }

@media (max-width: 600px) {
  body { font-size: 16px; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.3125rem; }
  .standfirst { font-size: 1.0625rem; }
  main { padding-top: 1.75rem; }
}
