/* ==========================================================================
   Design tokens
   Palette: "ink & reed" — cool paper + deep teal ink, warm clay accent used
   sparingly for tags/highlights only. Serif for editorial voice (titles),
   Plex Sans for UI chrome, Plex Mono for meta/data (dates, tags, read time).
   ========================================================================== */
:root {
  --bg: #F3F4EF;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --text: #1C2321;
  --text-muted: #5B645F;
  --text-faint: #8A938D;
  --border: #DEE1D9;
  --border-strong: #C7CCC3;
  --accent: #2B6F5C;
  --accent-ink: #1F5548;
  --accent-warm: #C7793A;
  --accent-warm-bg: #F3E4D3;
  --shadow: 0 1px 2px rgba(28, 35, 33, 0.06), 0 4px 16px rgba(28, 35, 33, 0.05);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --focus-ring: 0 0 0 3px rgba(43, 111, 92, 0.35);
}

[data-theme="dark"] {
  --bg: #14181A;
  --surface: #1B2124;
  --surface-raised: #202729;
  --text: #E7EAE6;
  --text-muted: #98A29B;
  --text-faint: #6C7570;
  --border: #2B3335;
  --border-strong: #38423F;
  --accent: #4FB89A;
  --accent-ink: #6FCBB1;
  --accent-warm: #E0A15C;
  --accent-warm-bg: #3A2E20;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 180ms ease, color 180ms ease;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

h1, h2, h3 {
  font-family: "Source Serif 4", Georgia, "Times New Roman", serif;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.01em;
}

.meta, .eyebrow, time, .tag-pill, .read-time {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 64px;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-logo {
  font-family: "Source Serif 4", serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.site-logo::before {
  content: "◆";
  color: var(--accent);
  font-size: 13px;
  margin-right: 8px;
  vertical-align: middle;
}

.site-header nav {
  display: flex;
  gap: 4px;
}
.site-header nav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-muted);
  transition: background 150ms ease, color 150ms ease;
}
.site-header nav a:hover, .site-header nav a.active {
  background: var(--bg);
  color: var(--text);
}

.header-search {
  flex: 1;
  max-width: 340px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-faint);
  font-size: 14px;
}
.header-search svg { flex-shrink: 0; opacity: 0.7; }
.header-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  width: 100%;
  font-family: inherit;
}
.header-search input::placeholder { color: var(--text-faint); }

.header-spacer { flex: 1; }

.btn-write {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}
.btn-write:hover { background: var(--bg); border-color: var(--accent); }

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.theme-toggle:hover { background: var(--bg); color: var(--text); }
.theme-toggle svg { width: 19px; height: 19px; }
[data-theme="dark"] .theme-toggle .icon-moon,
:root:not([data-theme="dark"]) .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun,
:root:not([data-theme="dark"]) .theme-toggle .icon-moon { display: block; }

/* ==========================================================================
   Shell: sidebar + main + rail
   ========================================================================== */
.shell {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 300px;
  gap: 32px;
  align-items: start;
}

.side-nav {
  position: sticky;
  top: 88px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 28px;
}
.side-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  color: var(--text-muted);
  transition: background 150ms ease, color 150ms ease;
}
.side-nav a svg { width: 19px; height: 19px; opacity: 0.85; flex-shrink: 0; }
.side-nav a:hover { background: var(--surface); color: var(--text); }
.side-nav a.active { color: var(--text); font-weight: 600; background: var(--surface); box-shadow: inset 2px 0 0 var(--accent); }
.side-nav .divider { height: 1px; background: var(--border); margin: 12px 4px; }
.side-nav .side-heading {
  font-size: 12px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 12px 4px;
}

main.feed { padding-top: 28px; min-width: 0; }

.feed-tabs {
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.feed-tabs a {
  padding: 10px 2px 14px;
  font-size: 14.5px;
  color: var(--text-faint);
  border-bottom: 2px solid transparent;
}
.feed-tabs a.active { color: var(--text); border-color: var(--text); font-weight: 600; }

/* ==========================================================================
   Feed card
   ========================================================================== */
.feed-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 20px;
  padding: 28px 0;
  border-bottom: 1px solid var(--border);
}
.feed-card:first-of-type { padding-top: 24px; }

.feed-card .eyebrow {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.feed-card .eyebrow .pub { color: var(--text); font-weight: 600; font-family: "IBM Plex Sans", sans-serif; }
.feed-card .eyebrow .dot { color: var(--text-faint); }

.feed-card h2 {
  font-size: 21px;
  margin-bottom: 6px;
}
.feed-card h2 a { background-image: linear-gradient(var(--accent), var(--accent)); background-size: 0 1px; background-repeat: no-repeat; background-position: 0 100%; transition: background-size 200ms ease; }
.feed-card h2 a:hover { background-size: 100% 1px; }

.feed-card p.excerpt {
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 0 0 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.feed-card .card-foot {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-faint);
  font-size: 12.5px;
}
.tag-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-warm-bg);
  color: var(--accent-warm);
  font-size: 11.5px;
  letter-spacing: 0.01em;
}
.read-time::before { content: "· "; }

.feed-card .thumb {
  width: 140px;
  height: 100px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--border);
}
.feed-card .thumb img { width: 100%; height: 100%; object-fit: cover; }

.empty-feed {
  padding: 60px 0;
  text-align: center;
  color: var(--text-muted);
}

/* ==========================================================================
   Right rail
   ========================================================================== */
.rail {
  position: sticky;
  top: 88px;
  padding-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}
.rail h3 {
  font-size: 15px;
  margin-bottom: 14px;
}
.rail-item { padding: 14px 0; border-top: 1px solid var(--border); }
.rail-item:first-of-type { border-top: none; padding-top: 0; }
.rail-item .rail-eyebrow { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.rail-item h4 { font-size: 15px; font-weight: 600; font-family: "IBM Plex Sans", sans-serif; line-height: 1.35; }
.rail-item h4 a:hover { color: var(--accent); }
.rail-item time { font-size: 11.5px; color: var(--text-faint); display: block; margin-top: 6px; }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-cloud a {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text-muted);
  transition: border-color 150ms ease, color 150ms ease;
}
.tag-cloud a:hover { border-color: var(--accent); color: var(--accent); }

/* ==========================================================================
   Article page
   ========================================================================== */
.article-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 48px 24px 80px;
}
.article-title { font-size: 38px; margin-bottom: 18px; }
.article-meta { display: flex; gap: 10px; align-items: center; color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }
.article-cover { width: 100%; border-radius: var(--radius-lg); margin-bottom: 28px; }
.article-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 32px; }
.article-content { font-size: 18px; line-height: 1.75; color: var(--text); }
.article-content p { margin: 0 0 22px; }
.article-content h2, .article-content h3 { margin: 36px 0 14px; }
.article-content img { border-radius: var(--radius-md); margin: 24px 0; }
.article-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.article-content pre { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; overflow-x: auto; }
.article-content blockquote {
  margin: 24px 0; padding: 4px 0 4px 20px; border-left: 3px solid var(--accent);
  color: var(--text-muted); font-style: italic; font-size: 19px;
}
.back-link { margin-top: 48px; }
.back-link a { color: var(--accent); font-size: 14.5px; }
.back-link a:hover { text-decoration: underline; }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 28px 24px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1080px) {
  .shell { grid-template-columns: 72px minmax(0, 1fr) 260px; }
  .side-nav a span.label { display: none; }
  .side-nav a { justify-content: center; }
  .side-nav .side-heading { display: none; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side-nav, .rail { display: none; }
  .header-search { display: none; }
  .article-title { font-size: 30px; }
}

@media (max-width: 560px) {
  .feed-card { grid-template-columns: 1fr; }
  .feed-card .thumb { width: 100%; height: 160px; order: -1; }
  .site-header { padding: 0 16px; gap: 12px; }
  .btn-write span.label { display: none; }
}