@font-face {
  font-family: "JetBrains Mono";
  src: url("../fonts/jetbrains-mono-v24-latin-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-display: Palatino, "Palatino Linotype", "Book Antiqua", Georgia, ui-serif, serif;
  --font-body: "Inter Tight", "Avenir Next", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", "Cascadia Mono", ui-monospace, monospace;
  --measure: 68ch;
  --bg: #0e0d13;
  --bar-bg: #0a0912;
  --surface: #171520;
  --surface-2: rgba(255, 247, 232, 0.045);
  --ink: #f4eadb;
  --ink-strong: #fff7e8;
  --ink-muted: rgba(244, 234, 219, 0.76);
  --ink-faint: rgba(244, 234, 219, 0.52);
  --ink-dim: rgba(244, 234, 219, 0.36);
  --line: rgba(244, 218, 165, 0.18);
  --line-strong: rgba(244, 218, 165, 0.30);
  --accent-amber: #d7ba7d;
  --accent-teal: #4ec9b0;
  --accent-violet: #c586c0;
  --accent-green: #6a9955;
  --accent-blue: #569cd6;
  --accent-orange: #ad652c;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f8f5ef;
  --bar-bg: #ece6dc;
  --surface: #fffaf2;
  --surface-2: rgba(42, 32, 24, 0.045);
  --ink: #2a201a;
  --ink-strong: #17100b;
  --ink-muted: rgba(42, 32, 24, 0.76);
  --ink-faint: rgba(42, 32, 24, 0.52);
  --ink-dim: rgba(42, 32, 24, 0.36);
  --line: rgba(127, 88, 32, 0.22);
  --line-strong: rgba(127, 88, 32, 0.34);
  --accent-amber: #946b2d;
  --accent-teal: #0e7a6b;
  --accent-violet: #8f4ab8;
  --accent-green: #4d7a2e;
  --accent-blue: #2e6bbd;
  --accent-orange: #ad652c;
  color-scheme: light;
}

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

html { scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 50% -8%, rgba(132, 54, 230, 0.08), transparent 52%),
    var(--bg);
  color: var(--ink-muted);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.72;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }
::selection { background: rgba(78, 201, 176, 0.22); }

#topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 9, 18, 0.92);
  backdrop-filter: blur(14px);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 32px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-family: var(--font-body);
}

#topbar .left {
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 0;
}

.tab {
  padding: 0 1.5ch;
  height: 32px;
  display: flex;
  align-items: center;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.005em;
  border-radius: 0;
  position: relative;
  margin-right: 2px;
  background: transparent;
  text-decoration: none;
  transition: color 120ms ease, background 120ms ease;
}

.tab:first-child { padding-left: 1ch; }

.tab.active {
  color: var(--ink-strong);
  box-shadow: inset 0 -1px 0 var(--accent-amber);
}

.tab:hover:not(.active) {
  color: var(--ink-muted);
  background: rgba(255, 247, 232, 0.045);
}

.tab .tab-idx {
  color: var(--accent-green);
  margin-right: 0.5ch;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}

.tab-dd {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
}

.tab-dd > .tab::after {
  content: " \25BE";
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--ink-dim);
  margin-left: 0.3ch;
}

.tab-dd-menu {
  display: none;
  position: absolute;
  top: 32px;
  left: 0;
  min-width: 176px;
  background: rgba(10, 9, 18, 0.98);
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
  z-index: 120;
}

.tab-dd.open .tab-dd-menu { display: block; }

@media (hover: hover) and (pointer: fine) {
  .tab-dd:hover .tab-dd-menu { display: block; }
}

.tab-dd-menu a {
  display: block;
  padding: 6px 1.5ch;
  color: var(--ink-muted);
  font-size: 13px;
  text-decoration: none;
}

.tab-dd-menu a:hover {
  color: var(--ink-strong);
  background: rgba(255, 247, 232, 0.05);
}

#topbar .right {
  display: flex;
  align-items: center;
  gap: 2ch;
  padding-right: 1.5ch;
  font-family: var(--font-mono);
  font-size: 12px;
}

#theme-toggle {
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink-dim);
  cursor: pointer;
  font: inherit;
}

#theme-toggle:hover { color: var(--ink-strong); }

:root[data-theme="light"] #topbar {
  background: rgba(236, 230, 220, 0.92);
}

:root[data-theme="light"] .tab-dd-menu {
  background: rgba(236, 230, 220, 0.98);
}

#reading-progress-track {
  position: sticky;
  top: 32px;
  z-index: 90;
  height: 2px;
  background: transparent;
}

#reading-progress {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-teal), var(--accent-amber), var(--accent-violet));
  box-shadow: 0 0 18px rgba(78, 201, 176, 0.22);
}

.journal-entry-nav {
  width: min(var(--measure), calc(100% - 32px));
  margin: 1.1rem auto 0;
}

.journal-back {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.42rem 0.65rem;
  background: rgba(255, 247, 232, 0.03);
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  line-height: 1;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
  transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}

.journal-back:hover {
  border-color: var(--line-strong);
  background: rgba(255, 247, 232, 0.055);
  color: var(--ink-strong);
}

.article {
  width: min(var(--measure), calc(100% - 32px));
  margin: 0 auto;
  padding: 3.5rem 0 5rem;
}

.journal-entry-nav + .article {
  padding-top: 2rem;
}

.kicker,
.article-meta,
.caption,
.source-note,
.article-footer,
.label,
th,
code,
pre {
  font-family: var(--font-mono);
}

.kicker {
  margin: 0 0 0.75rem;
  color: var(--accent-teal);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  line-height: 1.4;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  color: var(--ink-strong);
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5.4vw, 3.45rem);
  line-height: 1.04;
}

.subtitle {
  margin: 1rem 0 0;
  color: var(--ink-muted);
  font-size: 1.08rem;
  line-height: 1.58;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  margin: 1.7rem 0 0;
  color: var(--ink-faint);
  font-size: 0.72rem;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.article-header {
  padding-bottom: 2.2rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2.4rem;
}

p { margin: 0 0 1.15rem; }

strong { color: var(--ink-strong); font-weight: 650; }
em { color: var(--ink); font-style: italic; }

.article a {
  color: var(--accent-blue);
  text-decoration: underline;
  text-decoration-color: rgba(86, 156, 214, 0.35);
  text-underline-offset: 0.18em;
}

.article a:hover {
  color: var(--accent-teal);
  text-decoration-color: currentColor;
}

h2 {
  margin: 2.8rem 0 0.8rem;
  font-size: clamp(1.45rem, 2.8vw, 1.9rem);
  line-height: 1.16;
}

h3 {
  margin: 2rem 0 0.5rem;
  font-size: 1.12rem;
  line-height: 1.28;
}

.section-sep {
  width: 100%;
  height: 1px;
  margin: 2.65rem 0;
  border: 0;
  background: linear-gradient(90deg, transparent, var(--line-strong), transparent);
}

blockquote,
.pullquote {
  margin: 1.8rem 0;
  padding: 0.15rem 0 0.15rem 1.25rem;
  border-left: 3px solid var(--accent-violet);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.22rem;
  font-style: italic;
  line-height: 1.48;
}

.wager-quote {
  margin: 2.6rem 0;
  padding: 1.8rem 0 1.6rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.wager-quote p {
  max-width: 92%;
  margin: 0 auto;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.4vw, 1.28rem);
  font-weight: 500;
  line-height: 1.42;
}

.callout,
.skepticism {
  margin: 1.7rem 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.skepticism {
  border-left: 3px solid var(--accent-orange);
  font-size: 0.94rem;
  line-height: 1.62;
}

.callout p:last-child { margin-bottom: 0; }

.label,
.skepticism .lbl {
  display: block;
  margin-bottom: 0.45rem;
  color: var(--accent-amber);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.skepticism ul { margin: 0; padding-left: 1.1rem; }
.skepticism li { margin-bottom: 0.45rem; color: var(--ink-muted); }
.skepticism li:last-child { margin-bottom: 0; }

figure {
  margin: 2rem 0;
}

.figure-frame {
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(78, 201, 176, 0.12), transparent 35%),
    linear-gradient(180deg, rgba(215, 186, 125, 0.10), transparent),
    var(--surface);
  display: grid;
  place-items: center;
  color: var(--ink-dim);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.caption,
.visual-caption {
  margin-top: 0.65rem;
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.55;
}

.visual-caption {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.visual-container {
  margin: 2rem 0 2.5rem;
  padding: 0;
}

.visual-container svg {
  display: block;
  width: 100%;
  height: auto;
}

.table-wrap {
  margin: 1.5rem 0 1.8rem;
  overflow-x: auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap table {
  min-width: 560px;
}

.article > table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.article > table thead,
.article > table tbody {
  display: table;
  width: 100%;
  min-width: 560px;
}

th,
td {
  padding: 0.72rem 0.75rem;
  border-bottom: 1px solid rgba(244, 218, 165, 0.10);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--ink-faint);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

td {
  color: var(--ink-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

tr:last-child td { border-bottom: 0; }

code {
  color: var(--accent-amber);
  font-size: 0.88em;
}

pre {
  margin: 1.5rem 0;
  padding: 1rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--ink-muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

pre code {
  color: inherit;
  font-size: inherit;
}

.source-note {
  margin: 1.35rem 0 0;
  color: var(--ink-faint);
  font-size: 0.76rem;
  line-height: 1.6;
}

.closing {
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 0.85rem;
  font-style: italic;
  line-height: 1.6;
}

.article-footer {
  margin-top: 3.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  color: var(--ink-faint);
  font-size: 0.72rem;
  line-height: 1.7;
}

@media (max-width: 720px) {
  #topbar {
    overflow: visible;
    height: auto;
    flex-wrap: wrap;
  }

  #topbar .left {
    flex: 1 1 100%;
    height: 40px;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: none;
  }

  #topbar .left::-webkit-scrollbar { display: none; }

  #topbar .right {
    flex: 1 1 100%;
    height: 28px;
    justify-content: flex-end;
    border-top: 1px solid var(--line);
  }

  .tab,
  .tab-dd > .tab {
    min-height: 40px;
    padding-left: 1.1ch;
    padding-right: 1.1ch;
    font-size: 13px;
  }

  .tab-dd { height: 40px; }

  .tab-dd-menu {
    position: fixed;
    top: 68px;
    left: 16px;
    min-width: 200px;
  }

  #reading-progress-track { top: 69px; }

  .journal-entry-nav {
    width: min(100% - 28px, var(--measure));
    margin-top: 0.9rem;
  }

  .journal-back {
    min-height: 30px;
    padding: 0.4rem 0.58rem;
    font-size: 0.64rem;
  }

  .article {
    width: min(100% - 28px, var(--measure));
    padding: 2.2rem 0 3.5rem;
  }

  .journal-entry-nav + .article {
    padding-top: 1.45rem;
  }

  h1 {
    font-size: clamp(1.85rem, 12vw, 2.75rem);
    line-height: 1.08;
  }

  .subtitle { font-size: 1rem; }

  .article-header {
    padding-bottom: 1.8rem;
    margin-bottom: 2rem;
  }

  blockquote,
  .pullquote {
    padding-left: 1rem;
    font-size: 1.08rem;
  }

  .wager-quote {
    margin: 2rem 0;
    padding: 1.4rem 0;
  }

  .wager-quote p { font-size: 1.04rem; }

  .figure-frame { min-height: 180px; }
  .visual-container { margin: 1.7rem 0 2.2rem; }
  pre { font-size: 0.72rem; }
}
