/* ---------------------------------------------------------------
   CCH Blog — a quiet, reading-first stylesheet.
   Light and dark are both first-class; the toggle stamps
   data-theme on <html> and must beat the media query.
   --------------------------------------------------------------- */

:root {
  --bg:          #fbfaf8;
  --bg-raised:   #ffffff;
  --text:        #17171a;
  --text-muted:  #63656b;
  --text-faint:  #8b8d94;
  --rule:        #e5e2dc;
  --accent:      #0072bc;
  --accent-soft: rgba(0, 114, 188, 0.09);
  --shadow:      0 1px 2px rgba(20, 20, 25, .04), 0 8px 24px -12px rgba(20, 20, 25, .12);
  --logo-filter: brightness(0);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans:  ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono:  ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --measure: 40rem;   /* comfortable reading column */
  --page:    46rem;   /* page shell */
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #101012;
    --bg-raised:   #17171a;
    --text:        #e9e8e4;
    --text-muted:  #a2a3a8;
    --text-faint:  #74757b;
    --rule:        #2a2a2f;
    --accent:      #55aeea;
    --accent-soft: rgba(85, 174, 234, 0.12);
    --shadow:      0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --logo-filter: brightness(0) invert(1);
  }
}

/* Explicit toggle wins over the media query in both directions. */
:root[data-theme="light"] {
  --bg: #fbfaf8; --bg-raised: #ffffff; --text: #17171a;
  --text-muted: #63656b; --text-faint: #8b8d94; --rule: #e5e2dc;
  --accent: #0072bc; --accent-soft: rgba(0, 114, 188, 0.09);
  --shadow: 0 1px 2px rgba(20,20,25,.04), 0 8px 24px -12px rgba(20,20,25,.12);
  --logo-filter: brightness(0);
}
:root[data-theme="dark"] {
  --bg: #101012; --bg-raised: #17171a; --text: #e9e8e4;
  --text-muted: #a2a3a8; --text-faint: #74757b; --rule: #2a2a2f;
  --accent: #55aeea; --accent-soft: rgba(85,174,234,.12);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  --logo-filter: brightness(0) invert(1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

img { max-width: 100%; height: auto; display: block; }

.shell {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ------------------------------- header ------------------------ */

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(1.4) blur(8px);
}

.site-header .shell {
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 60px;
}

.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  text-decoration: none;
  color: inherit;
  margin-right: auto;
}

.brand img {
  height: 17px;
  width: auto;
  filter: var(--logo-filter);
  opacity: .82;
  transition: opacity .2s ease;
}
.brand:hover img { opacity: 1; }

.brand span {
  font-size: .78rem;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-left: .7rem;
  border-left: 1px solid var(--rule);
}

.theme-toggle {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: border-color .2s, color .2s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--text-faint); }
.theme-toggle svg { width: 15px; height: 15px; }
/* The icon shows the theme you'd switch TO: moon while light, sun while dark. */
.icon-moon { display: block; }
.icon-sun  { display: none; }
@media (prefers-color-scheme: dark) {
  .icon-moon { display: none; }
  .icon-sun  { display: block; }
}
/* An explicit choice outranks the OS preference (higher specificity). */
:root[data-theme="light"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun  { display: none; }
:root[data-theme="dark"]  .icon-moon { display: none; }
:root[data-theme="dark"]  .icon-sun  { display: block; }

/* ------------------------------- index ------------------------- */

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

/* There's no masthead, so the first card carries the top breathing room. */
.post-list li:first-child .post-card { padding-top: 4.5rem; }

.post-list li { border-bottom: 1px solid var(--rule); }

.post-card {
  display: block;
  padding: 2.25rem 0;
  text-decoration: none;
  color: inherit;
  transition: opacity .18s ease;
}
.post-card:hover h2 { color: var(--accent); }

.post-meta {
  font-size: .76rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-faint);
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  align-items: center;
  margin-bottom: .6rem;
}
.post-meta .dot { opacity: .45; }

.post-card h2 {
  font-family: var(--serif);
  font-size: 1.55rem;
  line-height: 1.25;
  letter-spacing: -0.01em;
  font-weight: 600;
  margin: 0 0 .55rem;
  transition: color .18s ease;
}

.post-card p {
  margin: 0 0 .9rem;
  color: var(--text-muted);
  max-width: var(--measure);
}

.tag {
  font-size: .7rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: .2rem .6rem;
}

.read-more {
  font-size: .82rem;
  color: var(--accent);
  letter-spacing: .02em;
}

/* ------------------------------- article ---------------------- */

.back-link {
  display: inline-block;
  margin: 2.5rem 0 0;
  font-size: .82rem;
  color: var(--text-muted);
  text-decoration: none;
}
.back-link:hover { color: var(--accent); }

.article-header {
  padding: 1.75rem 0 2.5rem;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 2.5rem;
}

.article-header h1 {
  font-family: var(--serif);
  font-size: clamp(1.9rem, 5.4vw, 2.65rem);
  line-height: 1.15;
  letter-spacing: -0.017em;
  font-weight: 600;
  margin: 0 0 1rem;
  max-width: 32ch;
}

.byline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem;
  font-size: .82rem;
  color: var(--text-muted);
}
.byline strong { color: var(--text); font-weight: 600; }

.prose { max-width: var(--measure); }

.prose p,
.prose ul,
.prose ol {
  font-family: var(--serif);
  font-size: 1.11rem;
  line-height: 1.72;
  margin: 0 0 1.45rem;
}

.prose h2 {
  font-family: var(--sans);
  font-size: .8rem;
  font-weight: 650;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 3.25rem 0 1.1rem;
  padding-bottom: .7rem;
  border-bottom: 1px solid var(--rule);
}

.prose h3 {
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 600;
  margin: 2.25rem 0 .8rem;
}

.prose strong { font-weight: 650; }

.prose blockquote {
  margin: 2rem 0;
  padding: 0 0 0 1.4rem;
  border-left: 2px solid var(--accent);
}
.prose blockquote p {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.45;
  letter-spacing: -0.01em;
  color: var(--text);
}

.prose code {
  font-family: var(--mono);
  font-size: .87em;
  background: var(--accent-soft);
  color: var(--accent);
  padding: .12em .38em;
  border-radius: 4px;
}

.prose pre {
  background: var(--bg-raised);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-size: .88rem;
}
.prose pre code { background: none; color: var(--text); padding: 0; }

.prose li { margin-bottom: .4rem; }

.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* Figures break out slightly wider than the text column on large screens. */
.prose figure {
  margin: 2.5rem 0;
  width: 100%;
}
@media (min-width: 56rem) {
  .prose figure { width: calc(100% + 6rem); margin-left: -3rem; }
}

.prose figure img {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: var(--bg-raised);
}

.prose figcaption {
  margin-top: .75rem;
  font-family: var(--sans);
  font-size: .8rem;
  line-height: 1.5;
  color: var(--text-faint);
  text-align: center;
  padding: 0 1rem;
}

/* Reading progress bar */
.progress {
  position: fixed;
  top: 0; left: 0;
  height: 2px;
  width: 0;
  background: var(--accent);
  z-index: 20;
  transition: width .1s linear;
}

/* ------------------------------- footer ----------------------- */

.site-footer {
  margin-top: 5rem;
  border-top: 1px solid var(--rule);
  padding: 2rem 0 3rem;
}

.site-footer .shell {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: .8rem;
  color: var(--text-faint);
}

.site-footer img {
  height: 13px;
  width: auto;
  filter: var(--logo-filter);
  opacity: .3;
}

.site-footer .spacer { margin-left: auto; }

.status { padding: 3rem 0; color: var(--text-muted); }
