:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #0a0a0a;
  --muted: #525252;
  --border: #e5e5e5;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

::selection {
  background: var(--text);
  color: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif;
  font-feature-settings: "kern" 1;
  font-size: 1rem;
  line-height: 1.7;
  overflow-x: hidden;
}

.container {
  width: min(720px, 88vw);
  margin: 0 auto;
}

/* ─── Header ─── */

.site-header {
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

@supports (padding: max(0px)) {
  .site-header {
    padding-top: max(env(safe-area-inset-top), 0px);
  }
}

.bar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.125rem;
  font-weight: 300;
  letter-spacing: 0.025em;
  transition: color 0.3s ease;
}

.brand:hover {
  color: var(--muted);
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 300;
  transition: color 0.3s ease;
}

.nav-link:hover {
  color: var(--text);
}

/* ─── Content ─── */

.content {
  padding: 4rem 0 6rem;
  animation: enter 0.6s ease-out both;
}

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .content {
    animation: none;
  }
}

.kicker {
  font-size: 0.875rem;
  font-weight: 300;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

h1 {
  font-size: clamp(2.25rem, 6vw, 3.25rem);
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.025em;
}

/* ─── Post List ─── */

.post-list {
  padding: 0;
  list-style: none;
}

.post-list li + li {
  margin-top: 3rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border);
}

.post-list a {
  display: block;
  color: var(--text);
  text-decoration: none;
}

.post-date {
  display: block;
  font-size: 0.875rem;
  font-weight: 300;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.post-title {
  font-size: clamp(1.375rem, 3vw, 1.75rem);
  font-weight: 300;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin-bottom: 0.5rem;
}

.post-list a:hover .post-title {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

.post-excerpt {
  color: var(--muted);
  font-weight: 300;
  line-height: 1.6;
  max-width: 60ch;
}

/* ─── Article Entry ─── */

.entry {
  max-width: 65ch;
}

.entry h1 {
  margin-bottom: 2.5rem;
}

.entry h1 + p {
  font-size: 1.125rem;
  line-height: 1.7;
}

.entry p {
  margin-bottom: 1.2rem;
  color: var(--text);
  line-height: 1.75;
}

.entry a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
  transition: text-decoration-color 0.15s ease;
}

.entry a:hover {
  text-decoration-color: var(--muted);
}

.entry .back-link {
  display: inline-block;
  margin-top: 3rem;
  font-size: 0.875rem;
  font-weight: 300;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.3s ease;
}

.entry .back-link:hover {
  color: var(--text);
}

/* ─── Footer ─── */

.site-footer {
  border-top: 1px solid var(--border);
}

.site-footer .bar {
  min-height: 64px;
}

.site-footer span {
  font-size: 0.8125rem;
  font-weight: 300;
  color: var(--muted);
}

/* ─── Focus ─── */

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

/* ─── Article Visuals ─── */

.entry h2 {
  font-size: clamp(1.25rem, 3vw, 1.5rem);
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.entry h3 {
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1.75rem 0;
}

.entry table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  line-height: 1.55;
}

.entry thead {
  border-bottom: 2px solid var(--text);
}

.entry th {
  text-align: left;
  font-weight: 500;
  padding: 0.6rem 0.75rem;
  font-size: 0.8125rem;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.entry td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.entry tbody tr:last-child td {
  border-bottom: none;
}

.entry .diagram {
  margin: 2rem 0;
  display: flex;
  justify-content: center;
}

.entry .diagram pre.mermaid {
  width: 100%;
  max-width: 100%;
}

.entry .figure {
  margin: 2rem 0;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.entry .figure-caption {
  display: block;
  text-align: center;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-top: 1rem;
}

.entry .stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px;
  margin: 2rem 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.entry .stat-card {
  padding: 1.25rem 1rem;
  background: var(--bg);
  text-align: center;
}

.entry .stat-value {
  display: block;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.entry .stat-label {
  display: block;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-top: 0.35rem;
}

.entry .bar-chart {
  margin: 2rem 0;
}

.entry .bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.entry .bar-label {
  flex: 0 0 120px;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  text-align: right;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.entry .bar-track {
  flex: 1;
  height: 24px;
  background: #f5f5f5;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.entry .bar-fill {
  height: 100%;
  background: var(--text);
  border-radius: 3px;
  opacity: 0.8;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
}

.entry .bar-val {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--bg);
  white-space: nowrap;
}

.entry .timeline {
  margin: 2rem 0;
  padding-left: 1.5rem;
  border-left: 2px solid var(--border);
}

.entry .timeline-item {
  position: relative;
  padding-bottom: 1.5rem;
}

.entry .timeline-item:last-child {
  padding-bottom: 0;
}

.entry .timeline-item::before {
  content: "";
  position: absolute;
  left: -1.5rem;
  top: 0.45rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text);
  transform: translateX(-4.5px);
}

.entry .timeline-date {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.entry .timeline-text {
  font-size: 0.9375rem;
  margin-top: 0.2rem;
  line-height: 1.5;
}

.entry .callout {
  margin: 2rem 0;
  padding: 1.25rem 1.5rem;
  border-left: 3px solid var(--text);
  background: #fafafa;
  font-size: 0.9375rem;
}

.entry .callout p {
  margin-bottom: 0;
}

/* Mermaid theming */
.mermaid {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Arial, sans-serif !important;
}

/* ─── Mobile ─── */

@media (max-width: 600px) {
  .content {
    padding: 3rem 0 4rem;
  }

  .post-list li + li {
    margin-top: 2.5rem;
    padding-top: 2.5rem;
  }

  .entry h1 {
    margin-bottom: 2rem;
  }

  .entry table {
    font-size: 0.8125rem;
    white-space: nowrap;
  }

  .entry th,
  .entry td {
    padding: 0.5rem 0.6rem;
  }

  .entry .figure {
    padding: 1rem;
  }

  .entry .bar-label {
    flex: 0 0 80px;
    font-size: 0.6875rem;
  }

  .entry .callout {
    padding: 1rem 1.15rem;
  }
}
