@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;1,6..72,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #EDEFEE;
  --surface: #E1E5E3;
  --surface-2: #D6DBD8;
  --ink: #1C201C;
  --ink-muted: #5B615C;
  --ink-faint: #8A908B;
  --accent: #B85A2A;
  --accent-ink: #FBF3EC;
  --accent-quiet: #445468;
  --border: #C9CEC9;
  --shadow: rgba(28, 32, 28, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171A;
    --surface: #1C2023;
    --surface-2: #262B2E;
    --ink: #EBE8E1;
    --ink-muted: #979E96;
    --ink-faint: #656B63;
    --accent: #E08145;
    --accent-ink: #1A1310;
    --accent-quiet: #8FA2B8;
    --border: #303539;
    --shadow: rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #14171A;
  --surface: #1C2023;
  --surface-2: #262B2E;
  --ink: #EBE8E1;
  --ink-muted: #979E96;
  --ink-faint: #656B63;
  --accent: #E08145;
  --accent-ink: #1A1310;
  --accent-quiet: #8FA2B8;
  --border: #303539;
  --shadow: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Newsreader', Georgia, 'Times New Roman', serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: var(--accent-ink); }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

.mono {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.display {
  font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400;
}

/* ---- Header ---- */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(20px, 5vw, 56px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease, background 0.3s ease;
}
.site-header.scrolled { border-bottom-color: var(--border); }

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 26px; height: 26px;
  opacity: 0;
  transform: translateY(-4px) scale(0.85);
  transition: opacity 0.5s ease, transform 0.5s ease;
  filter: drop-shadow(0 1px 1px var(--shadow));
}
.site-header.scrolled .brand-mark { opacity: 1; transform: translateY(0) scale(1); }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-name { font-size: 13px; font-weight: 600; color: var(--ink); }

.site-nav { display: flex; align-items: center; gap: 28px; list-style: none; margin: 0; padding: 0; }
.site-nav li { display: inline-flex; }
.site-nav a { font-size: 12px; color: var(--ink-muted); transition: color 0.2s ease; }
.site-nav a:hover { color: var(--accent); }

.theme-toggle {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface);
  cursor: pointer; color: var(--ink-muted); font-size: 13px;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ---- Hero (homepage only) ---- */
.hero {
  position: relative;
  height: 88vh;
  min-height: 560px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}
.hero-img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  object-position: center 38%;
  transform: scale(1.03);
}
.hero-scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--bg) 8%, transparent) 0%,
    color-mix(in srgb, var(--bg) 8%, transparent) 45%,
    color-mix(in srgb, var(--bg) 92%, transparent) 92%,
    var(--bg) 100%);
}
.hero-content { position: relative; z-index: 2; padding: 0 clamp(20px, 5vw, 56px) 56px; width: 100%; }
.hero-eyebrow { font-size: 11px; color: var(--ink-muted); margin: 0 0 14px; }
.hero-title { font-size: clamp(48px, 9vw, 108px); line-height: 0.98; margin: 0; text-wrap: balance; color: var(--ink); }
.hero-sub { font-family: 'Newsreader', serif; font-style: italic; font-size: clamp(16px, 2vw, 20px); color: var(--ink-muted); max-width: 46ch; margin: 18px 0 0; }

/* ---- Shared content column ---- */
.section { padding: 72px clamp(20px, 5vw, 56px); max-width: 780px; margin: 0 auto; }
.section-tight { padding-top: 140px; }

.bio { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; border-bottom: 1px solid var(--border); padding-bottom: 56px; }
.bio-mark { width: 52px; height: 52px; flex-shrink: 0; filter: drop-shadow(0 1px 2px var(--shadow)); }
.bio-mark img { width: 100%; height: 100%; object-fit: contain; }
.bio p { margin: 0; font-size: 18px; color: var(--ink); }

/* ---- Post list ---- */
.list-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 56px 0 8px; }
.list-heading h2 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 30px; margin: 0; }
.list-heading .mono { font-size: 11px; color: var(--ink-faint); }

.post-row { display: block; padding: 28px 0; border-bottom: 1px solid var(--border); transition: padding-left 0.25s ease; }
.post-row:hover { padding-left: 8px; }
.post-meta { display: flex; gap: 14px; align-items: center; font-size: 11px; color: var(--ink-faint); margin-bottom: 8px; }
.post-meta .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--ink-faint); }
.post-row h3 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 27px; margin: 0 0 8px; color: var(--ink); transition: color 0.2s ease; }
.post-row:hover h3 { color: var(--accent); }
.post-row p { margin: 0; font-size: 15.5px; color: var(--ink-muted); max-width: 62ch; }

.pagination { display: flex; align-items: center; justify-content: space-between; margin: 40px 0 0; }
.pagination a, .pagination span { font-size: 12px; color: var(--ink-muted); border-bottom: 1px solid var(--border); padding-bottom: 3px; transition: color 0.2s ease, border-color 0.2s ease; }
.pagination a:hover { color: var(--accent); border-color: var(--accent); }
.pagination .page-count { border-bottom: none; color: var(--ink-faint); }

/* ---- Single post ---- */
.post-header { max-width: 780px; margin: 0 auto; padding: 140px clamp(20px, 5vw, 56px) 0; }
.post-header .post-meta { margin-bottom: 18px; }
.post-header h1 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: clamp(38px, 6vw, 62px); line-height: 1.04; margin: 0 0 20px; text-wrap: balance; }
.post-excerpt { font-family: 'Newsreader', serif; font-style: italic; font-size: 19px; color: var(--ink-muted); max-width: 62ch; margin: 0 0 40px; }

.post-content { max-width: 700px; margin: 0 auto; padding: 0 clamp(20px, 5vw, 56px) 40px; font-size: 19px; line-height: 1.75; }
.post-content p { margin: 0 0 1.4em; }
.post-content h2 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 32px; margin: 1.6em 0 0.6em; }
.post-content h3 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 26px; margin: 1.4em 0 0.5em; }
.post-content a { color: var(--accent); border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.post-content a:hover { border-color: var(--accent); }
.post-content blockquote { margin: 1.8em 0; padding-left: 22px; border-left: 2px solid var(--accent); font-style: italic; color: var(--ink-muted); }
.post-content figure { margin: 2em 0; }
.post-content figure img { border-radius: 3px; }
.post-content figcaption { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 0.04em; color: var(--ink-faint); margin-top: 10px; text-align: center; }
.post-content code { font-family: 'JetBrains Mono', monospace; font-size: 0.86em; background: var(--surface); padding: 2px 6px; border-radius: 3px; }
.post-content pre { background: var(--surface); padding: 20px; border-radius: 6px; overflow-x: auto; border: 1px solid var(--border); }
.post-content pre code { background: none; padding: 0; }
.post-content hr { border: none; border-top: 1px solid var(--border); margin: 3em 0; }
.post-content ul, .post-content ol { padding-left: 1.4em; margin: 0 0 1.4em; }

.post-content .kg-width-wide {
  position: relative;
  left: 50%;
  width: 85vw;
  max-width: 1100px;
  transform: translateX(-50%);
}
.post-content .kg-width-full {
  position: relative;
  left: 50%;
  width: 100vw;
  transform: translateX(-50%);
}
.post-content .kg-width-full img { border-radius: 0; }

.post-footer { max-width: 700px; margin: 0 auto; padding: 40px clamp(20px, 5vw, 56px) 0; border-top: 1px solid var(--border); }
.back-link { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-muted); }
.back-link:hover { color: var(--accent); }

/* ---- 404 ---- */
.error-page { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 40px 20px; }
.error-page .bio-mark { width: 64px; height: 64px; margin-bottom: 24px; }
.error-page h1 { font-family: 'Instrument Serif', serif; font-weight: 400; font-size: 40px; margin: 0 0 10px; }
.error-page p { color: var(--ink-muted); margin: 0 0 24px; }

/* ---- Footer ---- */
.site-footer {
  padding: 48px clamp(20px, 5vw, 56px) 64px;
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 16px;
}
.site-footer .mono { font-size: 11px; color: var(--ink-faint); }
.footer-links { display: flex; gap: 20px; }
.footer-links a { font-size: 11px; color: var(--ink-muted); }
.footer-links a:hover { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 640px) {
  .bio { grid-template-columns: 1fr; }
  .bio-mark { width: 40px; height: 40px; }
  .site-nav :not(.theme-toggle-item) { display: none; }
}
