/* ── Tokens ──────────────────────────────────────────────────── */
:root {
  --bg:        #0f0f10;
  --surface:   #1a1a1c;
  --surface-2: #222225;
  --border:    #2c2c30;
  --border-2:  #404046;
  --text:      #f0ece4;
  --text-2:    #c5c0b9;
  --text-3:    #9c9690;
  --gold:      #d4a847;
  --gold-dim:  #ab8435;
  --gold-glow: rgba(212,168,71,.1);
  --focus:     #d4a847;
  --red:       #e06c6c;
  --red-soft:  rgba(224,108,108,.12);

  /* Type scale — 6 steps */
  --text-xs:   0.9375rem;  /* 15px — unified with text-sm */
  --text-sm:   0.9375rem;  /* 15px — UI controls: chips, buttons, nav, card titles */
  --text-base: 1.0625rem;  /* 17px — body: textarea, reading text, descriptions */
  --text-lg:   1.375rem;   /* 22px — logo, article subheadings (h2), mobile titles */
  --text-xl:   1.75rem;    /* 28px — page & article titles (h1) */
  --text-2xl:  2.25rem;    /* 36px — hero display heading */

  /* Vertical rhythm / line-heights */
  --leading-none:    1;
  --leading-tight:   1.25;
  --leading-normal:  1.5;
  --leading-relaxed: 1.75;

  /* Tracking / letter-spacings */
  --tracking-tight:  -0.02em;
  --tracking-normal: 0;
  --tracking-wide:   0.04em;

  /* Font weights */
  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;

  --r:    8px;
  --r-lg: 12px;
  --max:  820px;

  --sidebar-w: 290px;
  --header-h:  56px;
}

:root[data-theme="light"] {
  --bg:        #f8f6f0;
  --surface:   #ffffff;
  --surface-2: #efebe2;
  --border:    #dfd8cc;
  --border-2:  #c8c0b2;
  --text:      #1a1714;
  --text-2:    #3d3832;
  --text-3:    #5c564f;
  --gold:      #855306;
  --gold-dim:  #996007;
  --gold-glow: rgba(133,83,6,.12);
  --focus:     #855306;
  --red:       #903030;
  --red-soft:  rgba(144,48,48,.08);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:        #f8f6f0;
    --surface:   #ffffff;
    --surface-2: #efebe2;
    --border:    #dfd8cc;
    --border-2:  #c8c0b2;
    --text:      #1a1714;
    --text-2:    #3d3832;
    --text-3:    #5c564f;
    --gold:      #855306;
    --gold-dim:  #996007;
    --gold-glow: rgba(133,83,6,.12);
    --focus:     #855306;
    --red:       #903030;
    --red-soft:  rgba(144,48,48,.08);
  }
}

:root[data-theme="dark"] {
  --bg:        #0f0f10;
  --surface:   #1a1a1c;
  --surface-2: #222225;
  --border:    #2c2c30;
  --border-2:  #404046;
  --text:      #f0ece4;
  --text-2:    #c5c0b9;
  --text-3:    #9c9690;
  --gold:      #d4a847;
  --gold-dim:  #ab8435;
  --gold-glow: rgba(212,168,71,.1);
  --focus:     #d4a847;
  --red:       #e06c6c;
  --red-soft:  rgba(224,108,108,.12);
}

/* ── Reset ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', 'Courier New', monospace;
  font-size: var(--text-sm);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Focus & Accessibility ──────────────────────────────────── */
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r); }
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Page shell ──────────────────────────────────────────────── */
.page { width: 100%; max-width: var(--max); padding: 0 24px; margin: 0 auto; }

/* ── Top bar ─────────────────────────────────────────────────── */
.topbar {
  width: 100%; height: var(--header-h); min-height: var(--header-h);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  display: flex; justify-content: center;
  align-items: center;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
}
.topbar-inner {
  width: 100%; max-width: var(--max); padding: 0 24px; height: 100%;
  display: flex; align-items: center; justify-content: space-between;
}

.logo, h1.logo {
  font-size: inherit; font-weight: inherit; margin: 0;
}
.logo a { text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: 'DM Mono', monospace;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}
.brand-link:hover { text-decoration: none; }
.brand-icon {
  width: 24px;
  height: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--gold);
  line-height: 1;
  flex-shrink: 0;
}
.brand-text {
  font-family: 'DM Mono', monospace;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-text span { color: var(--gold); }
.logo-a {
  font-family: 'Fraunces', Georgia, serif;
  font-optical-sizing: auto; font-weight: 600;
  font-size: var(--text-lg); letter-spacing: -0.02em;
  line-height: 1; color: var(--text);
}
.logo-b {
  font-family: 'Fraunces', Georgia, serif;
  font-optical-sizing: auto; font-weight: 200; font-style: italic;
  font-size: var(--text-lg); letter-spacing: -0.02em;
  line-height: 1; color: var(--gold);
}

.nav-links {
  display: flex; gap: 6px; align-items: center;
}
.nav-links a {
  font-size: var(--text-sm); color: var(--text-2);
  text-decoration: none; letter-spacing: 0;
  padding: 6px 12px; border-radius: 100px;
  transition: color .12s, background .12s;
  white-space: nowrap;
}
.nav-links a:hover { color: var(--text); background: var(--surface-2); }
.nav-links a.active {
  color: var(--gold); background: var(--gold-glow);
}
.nav-sep {
  width: 1px; height: 16px; background: var(--border);
  margin: 0 4px; flex-shrink: 0;
}

/* Theme Toggle Button in Topbar */
.theme-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-2);
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-size: var(--text-sm);
  line-height: 1;
  transition: color .12s, background .12s, border-color .12s;
  flex-shrink: 0;
  margin-left: 4px;
}
.theme-toggle-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-2);
}
.theme-toggle-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-color: var(--focus);
}

/* ── Footer ──────────────────────────────────────────────────── */
footer {
  width: 100%; flex-shrink: 0;
  border-top: 1px solid var(--border);
  display: flex; justify-content: center;
  margin-top: 40px;
  background: var(--surface);
}
.footer-inner {
  width: 100%; max-width: var(--max);
  padding: 36px 24px 48px;
  display: flex; flex-direction: column; gap: 24px;
}
.footer-section { display: flex; flex-direction: column; gap: 12px; }
.footer-heading {
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-2);
}
.footer-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px 16px;
}
.footer-grid a {
  font-size: var(--text-sm); color: var(--text-3);
  text-decoration: none; letter-spacing: 0;
  padding: 4px 0; transition: color .12s;
}
.footer-grid a:hover { color: var(--gold); }
.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: 20px;
  display: flex; flex-direction: column; gap: 14px;
}
.footer-links {
  display: flex; gap: 16px; flex-wrap: wrap;
}
.footer-links a {
  font-size: var(--text-sm); color: var(--text-2);
  text-decoration: none; font-weight: 500;
  letter-spacing: 0; transition: color .12s;
}
.footer-links a:hover { color: var(--gold); }
.footer-desc {
  font-size: var(--text-sm);
  color: var(--text-3);
  line-height: 1.6;
}
.footer-desc a {
  color: var(--text-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.footer-desc a:hover { color: var(--gold); }
.footer-copy {
  font-size: var(--text-sm);
  color: var(--text-3);
  line-height: 1.5;
}
.footer-made {
  font-size: var(--text-sm);
  color: var(--text-3);
  text-align: center;
}
.footer-sep { width: 100%; height: 1px; background: var(--border); }
.footer-doodle {
  display: block; margin: 12px auto 0; width: 160px; height: auto;
  opacity: .18; transition: opacity .3s;
  filter: invert(1) brightness(1.5);
}
.footer-doodle:hover { opacity: .35; }

[data-theme="light"] .footer-doodle { filter: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .footer-doodle { filter: none; }
}

/* ── Blog Index & Article Typography ────────────────────────── */
header.page { padding-top: 40px; padding-bottom: 24px; }
main.page { padding-bottom: 86px; display: flex; flex-direction: column; gap: 24px; }

.hero {
  text-align: center;
  padding-top: 10px;
  margin-bottom: 24px;
}
.hero-tagline, .page-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: var(--text-2xl);
  font-weight: 200;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 8px;
  padding-top: 40px;
}
.hero-tagline em {
  font-style: italic;
  color: var(--gold);
  font-weight: 300;
}
.hero-sub {
  margin-top: 10px;
  font-size: var(--text-sm);
  color: var(--text-3);
  max-width: 580px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.5;
}

/* Post Cards Grid (Blog Index) */
.blog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 680px) {
  .blog-grid {
    grid-template-columns: 1fr;
  }
}
.post-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  transition: border-color .12s, background .12s, transform .12s, box-shadow .12s;
}
.post-card:hover {
  border-color: var(--border-2);
  background: var(--surface-2);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
}
.post-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--gold);
  background: var(--gold-glow);
  border: 1px solid rgba(212,168,71,.2);
  white-space: nowrap;
}
[data-theme="light"] .cat-pill {
  border-color: rgba(133,83,6,.2);
}
.post-card-date {
  font-size: var(--text-xs);
  color: var(--text-3);
  letter-spacing: var(--tracking-wide);
  margin: 0;
}
.post-card-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text);
  margin-bottom: 8px;
  line-height: var(--leading-tight);
}
.post-card-desc {
  font-size: var(--text-sm);
  color: var(--text-2);
  line-height: var(--leading-relaxed);
  flex-grow: 1;
  margin-bottom: 14px;
}
.post-card-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: auto;
}
.post-card-arrow {
  font-size: var(--text-sm);
  color: var(--gold);
  font-weight: 500;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: transform .12s;
}
.post-card:hover .post-card-arrow {
  transform: translate(2px, -2px);
}

/* Article Reading View */
article.page { padding-top: 40px; padding-bottom: 86px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--text-3);
  text-decoration: none;
  margin-bottom: 24px;
  transition: color .12s, transform .12s;
}
.back-link:hover {
  color: var(--gold);
  transform: translateX(-2px);
  text-decoration: none;
}
.article-header {
  margin-bottom: 32px;
}
.article-meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.article-date {
  font-size: var(--text-sm);
  color: var(--text-3);
  letter-spacing: var(--tracking-wide);
  margin: 0;
}
.article-read-time {
  font-size: var(--text-sm);
  color: var(--text-3);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.article-read-time::before {
  content: "•";
  color: var(--border-2);
  margin-right: 6px;
}
.article-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: var(--text-2xl);
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text);
  margin: 0 0 16px;
}

article h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
  line-height: var(--leading-tight);
  color: var(--text);
  margin: 40px 0 16px;
}

article h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text);
  margin: 28px 0 12px;
}

article p {
  color: var(--text-2);
  margin-bottom: 20px;
  line-height: var(--leading-relaxed);
}

article a {
  color: var(--gold);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--gold-dim);
  transition: color .12s;
}
article a:hover { color: var(--text); }

article ul, article ol {
  color: var(--text-2);
  margin: 0 0 20px 20px;
  line-height: 2;
}

article blockquote {
  border-left: 3px solid var(--gold-dim);
  padding: 12px 20px;
  margin: 24px 0;
  background: var(--gold-glow);
  border-radius: 0 var(--r) var(--r) 0;
  color: var(--text-2);
  font-style: italic;
}

article code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: var(--text-sm);
  color: var(--gold);
}

article kbd, .kbd-hint {
  font-family: 'DM Mono', monospace;
  font-size: var(--text-xs);
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border-2);
  border-radius: 4px;
  padding: 2px 6px;
  box-shadow: 0 1px 0 var(--border-2);
}

.table-wrap {
  overflow-x: auto;
  margin: 24px 0 32px;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: var(--text-sm);
  color: var(--text-2);
}

th, td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 500;
  font-family: 'DM Mono', monospace;
  font-size: var(--text-sm);
}

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

.cta-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 32px 24px;
  margin: 44px 0 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,.1);
}
.cta-box h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text);
  margin: 0 0 8px;
}
.cta-box p {
  color: var(--text-2);
  font-size: var(--text-sm);
  max-width: 520px;
  margin: 0 auto 20px;
  line-height: var(--leading-relaxed);
}
.cta-link, .btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--gold);
  color: #0f0f10;
  font-family: 'DM Mono', monospace;
  font-size: var(--text-sm);
  font-weight: 500;
  padding: 11px 24px;
  border-radius: var(--r);
  border: none;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, transform .12s, box-shadow .12s;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.cta-link:hover, .btn-primary:hover {
  background: var(--gold-dim);
  color: #0f0f10;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--gold-glow);
  text-decoration: none;
}
[data-theme="light"] .cta-link,
[data-theme="light"] .btn-primary {
  background: #855306;
  color: #ffffff;
}
[data-theme="light"] .cta-link:hover,
[data-theme="light"] .btn-primary:hover {
  background: #6b4205;
  color: #ffffff;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .cta-link,
  :root:not([data-theme="dark"]) .btn-primary {
    background: #855306;
    color: #ffffff;
  }
  :root:not([data-theme="dark"]) .cta-link:hover,
  :root:not([data-theme="dark"]) .btn-primary:hover {
    background: #6b4205;
    color: #ffffff;
  }
}

.cta-link.secondary, .btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  box-shadow: none;
}
.cta-link.secondary:hover, .btn-secondary:hover {
  background: var(--border);
  color: var(--text);
  box-shadow: none;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .page { padding: 0 16px; }
  .topbar-inner { padding: 0 16px; }
  .footer-inner { padding: 32px 16px 40px; }
  .footer-grid { grid-template-columns: repeat(2, 1fr); }
  article.page { padding-top: 24px; }
  .article-title { font-size: var(--text-xl); }
  .hero-tagline, .page-title { font-size: var(--text-xl); padding-top: 24px; }
}

@media (max-width: 380px) {
  .footer-grid { grid-template-columns: 1fr; }
}
