/* ============================================================
   valah.blog — editorial theme
   Light/dark via [data-theme] on <html>; defaults to system pref.
   ============================================================ */

:root {
  --measure: 42rem;
  --radius: 4px;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* light palette */
  --bg: #fdfcfa;
  --bg-raised: #ffffff;
  --ink: #1b1a18;
  --ink-soft: #4a4742;
  --muted: #6d6862;
  --rule: #e3ded6;
  --accent: #8f2557;
  --accent-soft: #b8497e;
  --code-bg: #f4f1ec;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16151a;
    --bg-raised: #1e1d23;
    --ink: #eeeaf2;
    --ink-soft: #c9c3d1;
    --muted: #9a94a3;
    --rule: #302e37;
    --accent: #e58cc0;
    --accent-soft: #f0a9d3;
    --code-bg: #232128;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

:root[data-theme="dark"] {
  --bg: #16151a;
  --bg-raised: #1e1d23;
  --ink: #eeeaf2;
  --ink-soft: #c9c3d1;
  --muted: #9a94a3;
  --rule: #302e37;
  --accent: #e58cc0;
  --accent-soft: #f0a9d3;
  --code-bg: #232128;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1.0625rem/1.7 var(--font-serif);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.skip {
  position: absolute;
  left: -9999px;
}
.skip:focus {
  left: 1rem;
  top: 1rem;
  padding: 0.5rem 1rem;
  background: var(--ink);
  color: var(--bg);
  z-index: 100;
  border-radius: var(--radius);
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

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

.site-header {
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}
/* Header layout: the publication name sits on its own line, with the
   navigation centred on the line below it. The nav needs ~630px on one row,
   which is why it is not placed beside the title. */
.site-header .wrap {
  max-width: 72rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding-top: 1rem;
  padding-bottom: 0.75rem;
}

.site-title {
  font-family: var(--font-serif);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  text-align: center;
}

.site-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.site-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
}
.site-nav a:hover { color: var(--accent); }

/* theme switch */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  padding: 0;
  background: none;
  border: 1px solid var(--rule);
  border-radius: 50%;
  color: var(--ink-soft);
  cursor: pointer;
  font: inherit;
  line-height: 1;
  -webkit-appearance: none;
  appearance: none;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.theme-toggle svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
  pointer-events: none;
}

/* Show the icon for the theme you would switch TO:
   in light mode show a moon, in dark mode show a sun. */
.theme-toggle .icon-sun { fill: none; stroke: currentColor; stroke-width: 2; display: none; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; display: block; }

:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* mobile nav (pure CSS checkbox) */
.nav-toggle-label { display: none; }
#nav-toggle:checked ~ .site-nav { display: flex; }

@media (max-width: 46rem) {
  /* Title and hamburger share the top row; the menu drops beneath them. */
  .site-header .wrap {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 0.25rem 0.75rem;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }
  .site-title {
    grid-column: 1;
    grid-row: 1;
    font-size: 1.5rem;
    text-align: left;
  }
  .nav-toggle-label {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 2.25rem;
    height: 2.25rem;
    cursor: pointer;
  }
  .nav-toggle-label span,
  .nav-toggle-label::before,
  .nav-toggle-label::after {
    content: "";
    display: block;
    height: 2px;
    width: 1.4rem;
    background: var(--ink);
    border-radius: 2px;
  }
  .site-nav {
    grid-column: 1 / -1;
    grid-row: 2;
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    padding: 0.5rem 0 0;
    border-top: 1px solid var(--rule);
    width: 100%;
  }
  .site-nav a {
    padding: 0.6rem 0;
    width: 100%;
    font-size: 1rem;
  }
  .theme-toggle {
    margin-top: 0.5rem;
  }
}

/* ---------------- typography ---------------- */

h1, h2, h3, h4 {
  line-height: 1.25;
  letter-spacing: -0.015em;
  font-weight: 700;
  font-family: var(--font-serif);
}

.page-title {
  font-size: clamp(1.9rem, 5vw, 2.4rem);
  margin: 0 0 0.4rem;
}
.intro {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 0 2.25rem;
  font-family: var(--font-sans);
}

/* ---------------- post list ---------------- */

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

.post-item {
  padding: 1.6rem 0;
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
.post-item:first-child { border-top: 0; padding-top: 0; }

@media (min-width: 40rem) {
  .post-item:has(.post-thumb) {
    grid-template-columns: 8.5rem 1fr;
    align-items: start;
  }
}

.post-thumb { display: block; }
.post-thumb img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  display: block;
  background: var(--code-bg);
}

.post-item h2 { font-size: 1.35rem; margin: 0 0 0.3rem; }
.post-item h2 a { color: var(--ink); text-decoration: none; }
.post-item h2 a:hover { color: var(--accent); text-decoration: underline; }

.post-meta {
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--font-sans);
  margin: 0.2rem 0 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: baseline;
}
.post-meta .sep { opacity: 0.5; }

.post-excerpt { margin: 0.45rem 0 0; color: var(--ink-soft); }

.tag {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}
.tag:hover { color: var(--accent); border-bottom-style: solid; }

/* ---------------- single post ---------------- */

.post-header { margin-bottom: 1.6rem; }
.post-header h1 {
  font-size: clamp(1.75rem, 5.5vw, 2.4rem);
  margin: 0 0 0.5rem;
  text-wrap: balance;
}

/* Feature image: slightly wider than the text column, centred.
   Uses a capped max-width with auto margins so it never overflows the
   viewport on small screens. The measure is 42rem, so 120% ≈ 50.4rem. */
.post-feature {
  margin: 0 0 2rem;
  max-width: 50.4rem;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 56rem) {
  /* Centre the wider figure on the column, not on the page gutters. */
  .post-feature {
    width: calc(100% + 8.4rem);
    max-width: 50.4rem;
    margin-left: calc(50% - 25.2rem);
  }
}

.post-feature img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
}
.post-feature figcaption {
  margin-top: 0.55rem;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
  overflow-wrap: anywhere;
}
.post-feature figcaption a { color: var(--muted); }

.post-content { font-size: 1.075rem; }
.post-content > *:first-child { margin-top: 0; }
.post-content p { margin: 0 0 1.25em; }
.post-content h2 { font-size: 1.5rem; margin: 2rem 0 0.75rem; }
.post-content h3 { font-size: 1.2rem; margin: 1.75rem 0 0.6rem; }

/* In-body images: allow them to use the wider figure width on large screens.
   Kept simple and non-overflowing: they stay within the text column by
   default, and can opt into the wider measure with .kg-width-wide. */
.post-content figure.kg-width-wide,
.post-content figure.kg-width-full {
  max-width: 50.4rem;
  margin-left: auto;
  margin-right: auto;
}

@media (min-width: 56rem) {
  .post-content figure.kg-width-wide,
  .post-content figure.kg-width-full {
    width: calc(100% + 8.4rem);
    max-width: 50.4rem;
    margin-left: calc(50% - 25.2rem);
  }
}

.post-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  display: block;
  margin: 1.5em auto;
}

.post-content blockquote {
  margin: 1.5em 0;
  padding: 0.1em 0 0.1em 1.2rem;
  border-left: 3px solid var(--accent);
  color: var(--ink-soft);
  font-style: italic;
}
.post-content blockquote p:last-child { margin-bottom: 0; }

.post-content hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 2.5em 0;
}

.post-content pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.55;
}
.post-content code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.post-content pre code { background: none; padding: 0; }

.post-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.92rem;
  font-family: var(--font-sans);
  display: block;
  overflow-x: auto;
}
.post-content th, .post-content td {
  border: 1px solid var(--rule);
  padding: 0.5rem 0.7rem;
  text-align: left;
  vertical-align: top;
}
.post-content th { background: var(--code-bg); }

/* Ghost card classes that survive the export */
.kg-card { margin: 1.5em 0; }
.kg-image-card figcaption,
.kg-gallery-card figcaption {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  margin-top: 0.5rem;
}
.kg-bookmark-card, .kg-callout-card, .kg-embed-card {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1rem;
  background: var(--bg-raised);
}
.kg-callout-card { display: flex; gap: 0.75rem; align-items: flex-start; }
.kg-callout-emoji { font-size: 1.3rem; line-height: 1; }
.kg-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

.post-nav {
  margin: 3rem 0 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}

/* ---------------- comments ---------------- */

.comments {
  margin: 3rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
}
.comments h2 { font-size: 1.05rem; margin: 0 0 0.35rem; font-family: var(--font-sans); }
.comments-note { color: var(--muted); font-size: 0.84rem; font-style: italic; margin: 0 0 1.25rem; }

.comment-list { list-style: none; margin: 0; padding: 0; }
.comment { padding: 1.1rem 0; border-top: 1px solid var(--rule); }
.comment:first-child { border-top: 0; }
.comment-meta {
  margin: 0 0 0.45rem;
  font-size: 0.82rem;
  font-family: var(--font-sans);
  color: var(--muted);
}
.comment-meta strong { color: var(--ink); }
.comment-meta time { margin-left: 0.5rem; }
.comment-body { font-size: 0.98rem; }
.comment-body p { margin: 0 0 0.7em; }
.comment-body p:last-child { margin-bottom: 0; }
.comment-reply {
  margin: 0.9rem 0 0 1.25rem;
  padding-left: 0.9rem;
  border-top: 0;
  border-left: 2px solid var(--rule);
}

/* ---------------- pagination + footer ---------------- */

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 2.25rem 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.pagination span { color: var(--muted); }

.site-footer {
  margin-top: 4rem;
  padding: 1.75rem 0 2.5rem;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 0.85rem;
}
/* Centre the colophon lines and keep them aligned to the text measure. */
.site-footer .wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  text-align: center;
}
.colophon { margin: 0; }
.site-footer a { color: var(--ink-soft); }
.site-footer a:hover { color: var(--accent); }

.not-found { padding: 2rem 0; }
