/*
Theme Name: Dispatch
Theme URI: https://example.com
Author: Rippah
Description: An editorial theme for machine-published blogs. Timeline feed, sticky table of contents, monetisation slots, and a manual dark mode toggle. Built for a Claude + WordPress REST API pipeline.
Version: 3.1
Requires at least: 6.0
Requires PHP: 7.4
Text Domain: dispatch
*/

/* ============================================================
   1. TOKENS
   ============================================================ */
:root {
  --paper:      #FFFFFF;
  --surface:    #F5F7F8;
  --raise:      #FFFFFF;
  --ink:        #11161A;
  --ink-soft:   #4C575D;
  --ink-faint:  #7B868C;
  --rule:       #DFE5E7;
  --rule-soft:  #EDF1F2;
  --accent:     #8C2333;
  --accent-lit: #B0384B;
  --accent-wash:#F6E6E9;
  --code-bg:    #11161A;
  --code-fg:    #DFE6E7;

  --font-display: 'Bodoni Moda', Georgia, serif;
  --font-prose:   'Newsreader', Georgia, serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --measure: 68ch;
  --shell:   1200px;
  --shell-narrow: 860px;
  --rail:    296px;
  --spine:   96px;

  --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.075rem);
  --step-1: clamp(1.18rem, 1.1rem + 0.45vw, 1.4rem);
  --step-2: clamp(1.45rem, 1.28rem + 0.9vw, 1.95rem);
  --step-3: clamp(1.95rem, 1.5rem + 2.2vw, 3.2rem);
}

/* Dark tokens — applied by explicit toggle, or by OS preference
   when the reader has not chosen. */
:root[data-theme="dark"],
:root:not([data-theme]) {
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:      #14181A;
    --surface:    #1C2124;
    --raise:      #232A2D;
    --ink:        #E4E9EA;
    --ink-soft:   #94A0A5;
    --ink-faint:  #6A757A;
    --rule:       #2B3236;
    --rule-soft:  #232A2D;
    --accent:     #D4677A;
    --accent-lit: #E88A9A;
    --accent-wash:#2E2023;
    --code-bg:    #0C1012;
    --code-fg:    #DDE4E5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper:      #14181A;
  --surface:    #1C2124;
  --raise:      #232A2D;
  --ink:        #E4E9EA;
  --ink-soft:   #94A0A5;
  --ink-faint:  #6A757A;
  --rule:       #2B3236;
  --rule-soft:  #232A2D;
  --accent:     #D4677A;
  --accent-lit: #E88A9A;
  --accent-wash:#2E2023;
  --code-bg:    #0C1012;
  --code-fg:    #DDE4E5;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 90px; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-prose);
  font-size: var(--step-0);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration-color: var(--accent); text-underline-offset: 3px; }
a:hover { color: var(--accent-lit); }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
img { max-width: 100%; height: auto; display: block; }

.mono { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.screen-reader-text {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.shell { max-width: var(--shell); margin: 0 auto; padding-inline: 28px; }
.shell-narrow { max-width: var(--shell-narrow); margin: 0 auto; padding-inline: 28px; }

/* ============================================================
   2. READING PROGRESS
   ============================================================ */
#progress { position: fixed; inset: 0 auto auto 0; height: 2px; width: 0; background: var(--accent); z-index: 99; }

/* ============================================================
   3. MASTHEAD
   ============================================================ */
.masthead {
  position: sticky; top: 0; z-index: 50;
  border-bottom: 1px solid var(--rule);
  padding-block: 16px;
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
}
.masthead .shell { display: flex; align-items: center; gap: 14px 24px; flex-wrap: wrap; }
.brand { font-family: var(--font-display); font-weight: 700; font-size: var(--step-2); letter-spacing: -0.02em; line-height: 1; margin: 0; margin-right: auto; }
.brand a { text-decoration: none; }
.brand a:hover { color: var(--accent); }

.masthead-side { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.nav { display: flex; gap: 18px; margin: 0; padding: 0; list-style: none; }
.nav a { text-decoration: none; color: var(--ink-soft); }
.nav a:hover { color: var(--accent); }

/* Theme toggle */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; padding: 0;
  background: transparent; color: var(--ink-soft);
  border: 1px solid var(--rule); border-radius: 50%;
  cursor: pointer; transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--surface); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: none; }
}

/* Mobile nav disclosure */
.nav-toggle { display: none; }

/* ============================================================
   4. FEED
   ============================================================ */
.feed { position: relative; padding-block: 8px 52px; }
.feed::before {
  content: ""; position: absolute; left: calc(var(--spine) - 16px);
  top: 46px; bottom: 96px; width: 1px; background: var(--rule);
}
.entry { position: relative; display: grid; grid-template-columns: var(--spine) 1fr; gap: 30px; padding-block: 30px; }
.entry-mark { position: relative; text-align: right; padding-top: 7px; color: var(--ink-faint); }
.entry-mark::after {
  content: ""; position: absolute; right: -20px; top: 12px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--paper); border: 1px solid var(--rule); z-index: 1;
  transition: background .2s ease, border-color .2s ease;
}
.entry:hover .entry-mark::after { background: var(--accent); border-color: var(--accent); }
.entry-no { display: block; color: var(--accent); font-weight: 500; }

.entry-title {
  font-family: var(--font-display); font-weight: 600; font-size: var(--step-1);
  line-height: 1.25; letter-spacing: -0.01em; margin: 0 0 10px; max-width: 38ch;
}
.entry-title a { text-decoration: none; }
.entry:hover .entry-title a { color: var(--accent); }
.entry-dek { margin: 0 0 14px; color: var(--ink-soft); max-width: 58ch; }
.entry-foot { display: flex; gap: 14px; color: var(--ink-faint); flex-wrap: wrap; }
.entry-foot a { text-decoration: none; color: var(--ink-faint); }
.entry-foot a:hover { color: var(--accent); }

/* ============================================================
   5. POST LAYOUT (content + rail)
   ============================================================ */
.layout { display: grid; grid-template-columns: minmax(0,1fr) var(--rail); gap: 56px; align-items: start; }
.layout-main { min-width: 0; }

.rail { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 28px; }

/* ============================================================
   6. ARTICLE
   ============================================================ */
.article { padding-block: 48px 40px; }
.article-head { margin-bottom: 36px; }
.eyebrow { color: var(--accent); margin: 0 0 16px; }
.article-title {
  font-family: var(--font-display); font-weight: 600; font-size: var(--step-3);
  line-height: 1.08; letter-spacing: -0.025em; margin: 0 0 16px; max-width: 24ch;
}
.byline { color: var(--ink-soft); margin: 0; font-size: 0.95rem; }
.byline a { text-decoration: none; }
.article-media { margin: 36px 0; }
.article-media img { border-radius: 3px; }

/* ---------- Prose ---------- */
.prose { max-width: var(--measure); font-size: var(--step-1); line-height: 1.75; }
.prose > * + * { margin-top: 1.3em; }
.prose p { margin: 0; }
.prose h2 {
  font-family: var(--font-display); font-weight: 600; font-size: var(--step-2);
  line-height: 1.2; letter-spacing: -0.015em; margin-top: 2.1em; margin-bottom: 0.5em;
  scroll-margin-top: 94px;
}
.prose h3 {
  font-family: var(--font-prose); font-weight: 600; font-size: 1.15em;
  margin-top: 1.8em; margin-bottom: 0.4em; scroll-margin-top: 94px;
}
.prose a { color: var(--accent); text-decoration: underline; }
.prose ul, .prose ol { padding-left: 1.3em; margin-top: 1.1em; }
.prose li + li { margin-top: 0.5em; }
.prose li::marker { color: var(--accent); }
.prose blockquote {
  margin-inline: 0; margin-block: 1.9em; padding: 2px 0 2px 26px;
  border-left: 2px solid var(--accent); font-family: var(--font-display);
  font-weight: 600; font-size: 1.28em; line-height: 1.35; letter-spacing: -0.01em;
}
.prose blockquote p { margin: 0; }
.prose pre {
  background: var(--code-bg); color: var(--code-fg); padding: 20px;
  border-radius: 3px; overflow-x: auto; font-family: var(--font-mono);
  font-size: 0.8rem; line-height: 1.6;
}
.prose code {
  font-family: var(--font-mono); font-size: 0.82em; background: var(--surface);
  border: 1px solid var(--rule); border-radius: 2px; padding: 1px 5px;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.9em; }
.prose th, .prose td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--rule); }
.prose th { font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-soft); }
.prose figcaption { color: var(--ink-faint); font-size: 0.85em; margin-top: 8px; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2.4em 0; }

.article-foot {
  max-width: var(--measure); margin-top: 48px; padding-top: 20px;
  border-top: 1px solid var(--rule); color: var(--ink-faint);
}
.article-foot a { text-decoration: none; color: var(--ink-soft); }
.article-foot a:hover { color: var(--accent); }

/* ============================================================
   7. TABLE OF CONTENTS
   ============================================================ */
.toc {
  border: 1px solid var(--rule); border-radius: 4px;
  background: var(--surface); padding: 18px 20px;
}
.toc-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink-faint); margin: 0 0 12px; }
.toc-list { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; line-height: 1.45; }
.toc-list li { margin: 0; }
.toc-list a {
  display: block; padding: 6px 0 6px 12px;
  border-left: 2px solid transparent; color: var(--ink-soft);
  text-decoration: none; transition: color .15s ease, border-color .15s ease;
}
.toc-list a:hover { color: var(--accent); border-left-color: var(--rule); }
.toc-list a.is-active { color: var(--ink); border-left-color: var(--accent); font-weight: 500; }
.toc-list .lvl-3 a { padding-left: 26px; font-size: 0.86rem; }

/* Mobile TOC — collapsible */
.toc-mobile { display: none; margin-bottom: 32px; }
.toc-mobile summary {
  cursor: pointer; list-style: none; padding: 14px 16px;
  border: 1px solid var(--rule); border-radius: 4px; background: var(--surface);
  color: var(--ink-soft); font-family: var(--font-mono); font-size: 0.72rem;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.toc-mobile summary::-webkit-details-marker { display: none; }
.toc-mobile[open] summary { border-radius: 4px 4px 0 0; border-bottom: 0; }
.toc-mobile .toc { border-radius: 0 0 4px 4px; }

/* ============================================================
   8. AD SLOTS
   ============================================================ */
.ad {
  display: block; width: 100%; overflow: hidden;
  text-align: center; line-height: 0;
}
.ad-label {
  display: block; font-family: var(--font-mono); font-size: 0.6rem;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-faint);
  line-height: 1.4; margin-bottom: 8px; text-align: left;
}
.ad-header { padding-block: 20px 4px; }
.ad-incontent { margin-block: 2.4em; padding-block: 8px; border-block: 1px solid var(--rule-soft); }
.ad-footer { padding-block: 32px 8px; border-top: 1px solid var(--rule-soft); }
.ad-rail { min-height: 0; }
.ad-placeholder {
  border: 1px dashed var(--rule); border-radius: 4px; background: var(--surface);
  color: var(--ink-faint); font-family: var(--font-mono); font-size: 0.68rem;
  letter-spacing: 0.08em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: center;
  min-height: 96px; line-height: 1.5; padding: 16px; text-align: center;
}
.ad-placeholder.tall { min-height: 250px; }

/* ============================================================
   9. AFFILIATE
   ============================================================ */
.aff {
  border: 1px solid var(--rule); border-radius: 4px;
  background: var(--surface); padding: 20px; position: relative;
}
.aff-tag {
  display: inline-block; margin-bottom: 10px; padding: 3px 8px;
  background: var(--accent-wash); color: var(--accent);
  border-radius: 2px; font-family: var(--font-mono);
  font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase;
}
.aff-title { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; line-height: 1.25; margin: 0 0 8px; }
.aff-desc { margin: 0 0 14px; font-size: 0.92rem; color: var(--ink-soft); line-height: 1.55; }
.aff-price { display: block; font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink); margin-bottom: 12px; }
.aff-cta {
  display: inline-block; padding: 9px 18px; background: var(--accent); color: #fff;
  border-radius: 3px; text-decoration: none; font-family: var(--font-mono);
  font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase;
  transition: background .15s ease;
}
.aff-cta:hover { background: var(--accent-lit); color: #fff; }
.aff-note { display: block; margin-top: 12px; font-size: 0.72rem; color: var(--ink-faint); line-height: 1.5; }

/* Inline affiliate inside prose */
.prose .aff { margin-block: 2em; }
.prose .aff-desc, .prose .aff-title { max-width: none; }

/* ============================================================
   10. FORMS + COMMENTS
   ============================================================ */
input[type="text"], input[type="email"], input[type="url"],
input[type="search"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  font-family: var(--font-prose);
  font-size: 1rem;
  color: var(--ink);
  background: var(--raise);
  border: 1px solid var(--rule);
  border-radius: 3px;
  padding: 11px 14px;
  line-height: 1.5;
  transition: border-color .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--ink-faint); }
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
  outline: none;
}
textarea { min-height: 170px; resize: vertical; }

button, input[type="submit"], .btn {
  display: inline-block; font-family: var(--font-mono);
  font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 3px; padding: 11px 22px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
button:hover, input[type="submit"]:hover, .btn:hover { background: var(--accent-lit); border-color: var(--accent-lit); color: #fff; }
.theme-toggle { background: transparent; border-color: var(--rule); }

/* Search */
.search-form { display: flex; gap: 8px; }
.search-form input[type="search"] { flex: 1; }

/* Comments */
.comments {
  max-width: var(--measure);
  margin-top: 56px; padding-top: 36px;
  border-top: 1px solid var(--rule);
}
.comments-title {
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--step-2); letter-spacing: -0.015em; margin: 0 0 28px;
}
.comment-list { list-style: none; margin: 0 0 40px; padding: 0; }
.comment-list ol.children { list-style: none; margin: 20px 0 0; padding-left: 24px; border-left: 1px solid var(--rule); }
.comment-body {
  padding: 18px 0; border-bottom: 1px solid var(--rule-soft);
}
.comment-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.comment-meta img { border-radius: 50%; }
.comment-author { font-weight: 600; font-size: 0.95rem; }
.comment-author a { text-decoration: none; }
.comment-date { color: var(--ink-faint); font-family: var(--font-mono); font-size: 0.66rem; letter-spacing: 0.07em; text-transform: uppercase; }
.comment-content p { margin: 0 0 10px; }
.comment-content p:last-child { margin-bottom: 0; }
.comment-reply-link {
  font-family: var(--font-mono); font-size: 0.65rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--ink-soft); text-decoration: none;
}
.comment-reply-link:hover { color: var(--accent); }

.comment-respond { background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 26px; }
.comment-reply-title { font-family: var(--font-display); font-weight: 600; font-size: 1.35rem; margin: 0 0 6px; }
.comment-notes, .logged-in-as { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 20px; }
.comment-form p { margin: 0 0 18px; }
.comment-form label {
  display: block; margin-bottom: 7px;
  font-family: var(--font-mono); font-size: 0.66rem;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft);
}
.comment-form .required { color: var(--accent); }
.comment-form-cookies-consent { display: flex; align-items: flex-start; gap: 10px; }
.comment-form-cookies-consent input { width: auto; margin-top: 4px; }
.comment-form-cookies-consent label { margin: 0; font-family: var(--font-prose); font-size: 0.88rem; text-transform: none; letter-spacing: 0; color: var(--ink-soft); }
.form-submit { margin-bottom: 0; }
.comment-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }

/* ============================================================
   11. POST NAV / PAGINATION / FOOTER / 404
   ============================================================ */
.post-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1px;
  background: var(--rule); border: 1px solid var(--rule); border-radius: 3px;
  margin-top: 44px; overflow: hidden; max-width: var(--measure);
}
.post-nav > * { background: var(--paper); padding: 20px; min-height: 92px; }
.post-nav a { text-decoration: none; display: block; }
.post-nav a:hover { background: var(--surface); }
.post-nav .dir { color: var(--ink-faint); display: block; margin-bottom: 8px; }
.post-nav .ttl { font-family: var(--font-display); font-size: 1.05rem; line-height: 1.3; }
.post-nav .next { text-align: right; }

.pagination { display: flex; justify-content: space-between; padding-block: 24px 0; border-top: 1px solid var(--rule); }
.pagination a { text-decoration: none; color: var(--ink-soft); }
.pagination a:hover { color: var(--accent); }

.notice { padding-block: 80px 110px; max-width: var(--measure); }
.notice h1 { font-family: var(--font-display); font-size: var(--step-3); letter-spacing: -0.025em; line-height: 1.1; margin: 14px 0 16px; }

.site-foot { border-top: 1px solid var(--rule); padding-block: 24px 40px; color: var(--ink-faint); }
.site-foot .shell { display: flex; gap: 16px; flex-wrap: wrap; }

/* ============================================================
   12. RESPONSIVE
   ============================================================ */
@media (max-width: 1080px) {
  :root { --rail: 260px; }
  .layout { gap: 40px; }
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .rail { position: static; flex-direction: row; flex-wrap: wrap; gap: 20px; margin-top: 40px; }
  .rail > * { flex: 1 1 260px; }
  .rail .toc { display: none; }      /* desktop TOC hidden; mobile disclosure used instead */
  .toc-mobile { display: block; }
  .article { padding-block: 36px 32px; }
}

@media (max-width: 680px) {
  .shell, .shell-narrow { padding-inline: 20px; }
  html { scroll-padding-top: 76px; }

  .masthead { padding-block: 10px; }
  .masthead .shell { gap: 0 12px; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .masthead-side {
    order: 3; flex: 1 1 100%; gap: 16px;
    padding-top: 9px; margin-top: 9px;
    border-top: 1px solid var(--rule-soft);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .masthead-side::-webkit-scrollbar { display: none; }
  .nav { gap: 16px; }
  .nav li { white-space: nowrap; }
  .theme-toggle { flex: none; }

  .feed::before { display: none; }
  .entry { grid-template-columns: 1fr; gap: 8px; padding-block: 26px; }
  .entry-mark { text-align: left; padding-top: 0; }
  .entry-mark::after { display: none; }
  .entry-no { display: inline; margin-right: 8px; }
  .entry-title { max-width: none; }

  .prose { font-size: 1.06rem; }
  .prose pre { padding: 14px; font-size: 0.74rem; }
  .prose table { display: block; overflow-x: auto; white-space: nowrap; }

  .rail { flex-direction: column; }
  .rail > * { flex: 1 1 auto; }

  .comment-fields { grid-template-columns: 1fr; }
  .comment-respond { padding: 20px; }
  .comment-list ol.children { padding-left: 14px; }

  .post-nav { grid-template-columns: 1fr; }
  .post-nav .next { text-align: left; }

}

@media (max-width: 380px) {
  .shell, .shell-narrow { padding-inline: 16px; }
  .brand { font-size: 1.25rem; }
}

/* ============================================================
   13. MOTION + PRINT
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  #progress { display: none; }
}

@media print {
  .masthead, .rail, .ad, .aff, .post-nav, .comments, .site-foot, #progress, .toc-mobile { display: none !important; }
  body { background: #fff; color: #000; }
  .layout { display: block; }
}
