:root { --sidebar: 280px; }

/* Warm (default) */
:root, [data-theme="warm"] {
  --bg: #f7f2e9;
  --panel: #efe7d9;
  --fg: #2b241d;
  --text: #3d352c;
  --muted: #8f8474;
  --rule: #e2d8c6;
  --strong: #2b241d;
  --shade-1: #e8dfcf;
  --shade-2: #dbcfba;
  --shade-3: #4a3f34;
  --on-shade-3: #f7f2e9;
  color-scheme: light;
}
[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f7f7f7;
  --fg: #111111;
  --text: #2b2b2b;
  --muted: #8a8a8a;
  --rule: #e8e8e8;
  --strong: #111111;
  --shade-1: #ececec;
  --shade-2: #d6d6d6;
  --shade-3: #3a3a3a;
  --on-shade-3: #ffffff;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f0f0f;
  --panel: #161616;
  --fg: #f2f2f2;
  --text: #d4d4d4;
  --muted: #7a7a7a;
  --rule: #262626;
  --strong: #f2f2f2;
  --shade-1: #1f1f1f;
  --shade-2: #2e2e2e;
  --shade-3: #d9d9d9;
  --on-shade-3: #111111;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.75 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}

a { color: var(--fg); text-decoration-color: var(--muted); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--fg); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--rule);
  padding: 40px 24px;
}

.brand { display: block; font-weight: 700; font-size: 20px; letter-spacing: -0.02em; color: var(--fg); text-decoration: none; }
.tagline { margin: 2px 0 36px; font-size: 13px; color: var(--muted); }
.tagline a { color: var(--muted); }
.tagline a:hover { color: var(--fg); }

.sidebar .month {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); margin: 24px 0 8px;
}
.sidebar .month:first-child { margin-top: 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li a {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 7px 10px; margin: 0 -10px; border-radius: 6px;
  font-size: 14.5px; line-height: 1.4; color: var(--text); text-decoration: none;
}
.sidebar li a:hover { background: var(--shade-1); color: var(--fg); }
.sidebar li a[aria-current="page"] { background: var(--shade-2); color: var(--fg); font-weight: 600; }
.sidebar time { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.content { padding: 72px 48px 96px; min-width: 0; }
.content > * { max-width: 660px; margin-left: auto; margin-right: auto; }

/* Mobile top bar (hidden on desktop) */
.topbar { display: none; }
.topbar .theme-switch { display: flex; }

@media (max-width: 860px) {
  .layout { display: block; }
  .topbar {
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 10;
    padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--rule);
  }
  .menu-toggle {
    font: inherit; font-size: 14px; color: var(--fg); background: none;
    border: 1px solid var(--rule); border-radius: 6px; padding: 4px 12px; cursor: pointer;
  }
  .sidebar { display: none; position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--rule); padding: 20px 16px; }
  .sidebar .brand, .sidebar .theme-switch { display: none; }
  .sidebar .tagline { margin-bottom: 20px; }
  .topbar-right { display: flex; align-items: center; gap: 8px; }
  .topbar .theme-switch button { padding: 6px; }
  .topbar .theme-switch button span { display: none; }
  body.nav-open .sidebar { display: block; }
  .content { padding: 40px 16px 72px; }
}

/* ---------- Article ---------- */
.eyebrow { font-size: 13px; color: var(--muted); margin: 0 0 12px; font-variant-numeric: tabular-nums; }
h1 { font-size: clamp(32px, 5vw, 44px); line-height: 1.1; letter-spacing: -0.03em; color: var(--fg); font-weight: 700; margin: 0 0 40px; }
article p { margin: 0 0 22px; }
article strong { color: var(--strong); font-weight: 600; }
article ol { padding-left: 22px; margin: 0 0 22px; }
article ol li { margin-bottom: 16px; padding-left: 4px; }
article ol li::marker { color: var(--muted); font-weight: 600; }

article h2 { font-size: 22px; line-height: 1.3; letter-spacing: -0.01em; color: var(--fg); font-weight: 600; margin: 0 0 18px; }

.break { text-align: center; letter-spacing: 12px; color: var(--muted); margin: 48px auto; }

/* Epigraph: a quote set right, with its source beneath */
.epigraph { margin: 0 0 32px; text-align: right; }
.epigraph p { margin: 0 0 4px; color: var(--fg); }
.epigraph footer { font-size: 13px; line-height: 1.5; color: var(--muted); }

/* Previous / next */
.prev-next {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 64px; padding-top: 24px; border-top: 1px solid var(--rule);
}
.prev-next a { text-decoration: none; color: var(--fg); font-weight: 500; font-size: 15px; line-height: 1.4; }
.prev-next a span { display: block; font-size: 12px; font-weight: 400; color: var(--muted); margin-bottom: 2px; }
.prev-next .next { text-align: right; margin-left: auto; }
.prev-next a:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Theme switcher ---------- */
.theme-switch { display: flex; gap: 4px; }
.sidebar .theme-switch { margin-top: auto; padding-top: 32px; }
.theme-switch button {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 12px; text-transform: capitalize; line-height: 1;
  color: var(--muted); background: none;
  border: 1px solid transparent; border-radius: 999px; padding: 6px 10px; cursor: pointer;
}
.theme-switch button:hover { color: var(--fg); }
.theme-switch button[aria-pressed="true"] { color: var(--fg); border-color: var(--shade-2); background: var(--bg); }
.sw { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--muted); display: inline-block; }
.sw-warm { background: #efe2c8; }
.sw-light { background: #ffffff; }
.sw-dark { background: #111111; }

/* ---------- 2x2 matrix ---------- */
.matrix-wrap { overflow-x: auto; margin: 36px auto 40px; }
table.matrix {
  border-collapse: separate; border-spacing: 4px;
  font-size: 14px; line-height: 1.4;
  margin: 0 auto;
}
table.matrix th, table.matrix td { padding: 10px 12px; text-align: center; border-radius: 6px; }
table.matrix th { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
table.matrix td.box {
  width: 170px; height: 96px;
  text-align: left; vertical-align: top;
  background: var(--bg); border: 1px solid var(--shade-2);
  color: var(--fg); font-weight: 500;
}
table.matrix td.box b { display: block; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
table.matrix .low { background: var(--shade-1); color: var(--text); }
table.matrix .high { background: var(--shade-3); color: var(--on-shade-3); }
table.matrix .axis { background: none; color: var(--muted); }
table.matrix .vert { writing-mode: vertical-rl; transform: rotate(180deg); }

@media (max-width: 520px) {
  table.matrix { font-size: 13px; border-spacing: 3px; }
  table.matrix th, table.matrix td { padding: 8px; }
  table.matrix td.box { width: auto; height: 84px; }
  table.matrix th.axis:first-child { padding: 8px 2px; }
}
