/* =============================================================
   The AI Downside — stylesheet
   Modern newspaper aesthetic. No frameworks. No build.
   ============================================================= */

/* ---------- Design tokens ---------- */
:root {
  --font-serif: Georgia, "Times New Roman", "Iowan Old Style", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

  --maxw: 1200px;
  --measure: 68ch;
  --radius: 6px;
  --gap: 1.5rem;

  /* Light theme */
  --bg: #faf8f4;
  --bg-elev: #ffffff;
  --bg-sunken: #f1ede5;
  --text: #1a1a1a;
  --text-muted: #5c574e;
  --border: #ddd6c9;
  --border-strong: #1a1a1a;
  --accent: #b3261e;      /* newsprint red */
  --accent-ink: #ffffff;
  --link: #98211b;
  --link-hover: #6f1712;
  --tag-bg: #ece6d9;
  --tag-text: #4a453c;
  --focus: #1a56db;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
}

:root[data-theme="dark"],
html.dark {
  --bg: #14130f;
  --bg-elev: #1c1b16;
  --bg-sunken: #100f0c;
  --text: #eceae3;
  --text-muted: #a49f92;
  --border: #33312a;
  --border-strong: #eceae3;
  --accent: #e0655d;
  --accent-ink: #14130f;
  --link: #eea59f;
  --link-hover: #f4c4c0;
  --tag-bg: #262420;
  --tag-text: #cbc6ba;
  --focus: #7aa2f7;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --bg-elev: #1c1b16;
    --bg-sunken: #100f0c;
    --text: #eceae3;
    --text-muted: #a49f92;
    --border: #33312a;
    --border-strong: #eceae3;
    --accent: #e0655d;
    --accent-ink: #14130f;
    --link: #eea59f;
    --link-hover: #f4c4c0;
    --tag-bg: #262420;
    --tag-text: #cbc6ba;
    --focus: #7aa2f7;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  }
}

/* ---------- Reset-ish ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  font-size: 1.0625rem;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--link-hover); }
h1, h2, h3, h4 { font-family: var(--font-serif); line-height: 1.2; font-weight: 700; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }
code, pre { font-family: var(--font-mono); font-size: .92em; }
blockquote {
  margin: 1.5rem 0; padding: .25rem 0 .25rem 1.25rem;
  border-left: 4px solid var(--accent); color: var(--text-muted); font-style: italic;
}

/* ---------- Skip link ---------- */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 200;
  background: var(--accent); color: var(--accent-ink);
  padding: .6rem 1rem; border-radius: 0 0 var(--radius) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 1.25rem; }
.reading-progress {
  position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 120;
  background: var(--accent); width: 0%; transform-origin: left;
}

/* ---------- Masthead ---------- */
.masthead {
  border-bottom: 2px solid var(--border-strong);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 100;
}
.masthead__bar {
  display: flex; align-items: center; gap: 1rem;
  padding: .7rem 1.25rem; max-width: var(--maxw); margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--text); }
.brand__logo { width: 34px; height: 34px; flex: none; }
.brand__name { font-family: var(--font-serif); font-weight: 700; font-size: 1.25rem; letter-spacing: -.01em; }
.brand__name small { display: block; font-family: var(--font-sans); font-weight: 500; font-size: .62rem; letter-spacing: .18em; text-transform: uppercase; color: var(--text-muted); }
.nav { margin-left: auto; }
.nav ul { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; }
.nav a { display: block; padding: .45rem .7rem; border-radius: var(--radius); text-decoration: none; color: var(--text); font-weight: 600; font-size: .95rem; }
.nav a:hover, .nav a[aria-current="page"] { background: var(--bg-sunken); color: var(--link-hover); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 1px solid var(--border); background: var(--bg-elev);
  color: var(--text); border-radius: var(--radius); cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg-sunken); }
.icon-btn svg { width: 20px; height: 20px; }
.nav-toggle { display: none; }

/* ---------- Grid: content + sidebar ---------- */
.layout { display: grid; grid-template-columns: minmax(0,1fr) 300px; gap: 2.5rem; padding: 2rem 0 3rem; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } .sidebar { display: none; } }

/* ---------- Hero ---------- */
.hero { border-bottom: 1px solid var(--border); padding: 2rem 0 1.5rem; }
.hero__grid { display: grid; grid-template-columns: 1.15fr .85fr; gap: 2rem; align-items: stretch; }
@media (max-width: 760px) { .hero__grid { grid-template-columns: 1fr; } }
.kicker { font-family: var(--font-sans); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 700; color: var(--accent); margin: 0 0 .5rem; }
.hero__lead h1 { font-size: clamp(2rem, 5vw, 3.1rem); margin: 0 0 .6rem; letter-spacing: -.02em; }
.hero__lead p { font-size: 1.15rem; color: var(--text-muted); margin: 0 0 1rem; max-width: var(--measure); }
.hero__media { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--bg-sunken); }
.hero__media img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Section headers ---------- */
.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  border-bottom: 2px solid var(--border-strong); padding-bottom: .4rem; margin: 2.5rem 0 1.25rem;
}
.section-head h2 { font-size: 1.35rem; margin: 0; }
.section-head a { font-size: .85rem; font-weight: 600; font-family: var(--font-sans); }

/* ---------- Article cards ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--gap); }
.card {
  display: flex; flex-direction: column; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card__media { aspect-ratio: 16 / 9; background: var(--bg-sunken); border-bottom: 1px solid var(--border); }
.card__media img { width: 100%; height: 100%; object-fit: cover; }
.card__body { padding: 1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .5rem; flex: 1; }
.card__cat { font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; font-weight: 700; color: var(--accent); }
.card__title { font-size: 1.2rem; margin: 0; line-height: 1.25; }
.card__title a { color: var(--text); text-decoration: none; }
.card__title a:hover { color: var(--link-hover); }
.card__excerpt { color: var(--text-muted); font-size: .95rem; margin: 0; }
.card__meta { margin-top: auto; font-size: .8rem; color: var(--text-muted); display: flex; gap: .6rem; flex-wrap: wrap; }

/* list variant (archive) */
.post-list { list-style: none; margin: 0; padding: 0; }
.post-list li { padding: 1.1rem 0; border-bottom: 1px solid var(--border); }
.post-list h3 { margin: 0 0 .25rem; font-size: 1.3rem; }
.post-list h3 a { color: var(--text); text-decoration: none; }
.post-list h3 a:hover { color: var(--link-hover); }
.post-list .card__meta { margin-top: .35rem; }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 1.75rem; }
.widget { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.15rem; }
.widget h3 { margin: 0 0 .8rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; font-family: var(--font-sans); color: var(--text-muted); border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
.widget ul { list-style: none; margin: 0; padding: 0; }
.widget li + li { margin-top: .6rem; }
.widget a { text-decoration: none; color: var(--text); font-weight: 600; font-size: .95rem; }
.widget a:hover { color: var(--link-hover); }
.widget .muted { color: var(--text-muted); font-weight: 400; font-size: .82rem; }

/* ---------- Tag chips ---------- */
.tags { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag {
  display: inline-block; padding: .2rem .6rem; border-radius: 999px;
  background: var(--tag-bg); color: var(--tag-text); font-size: .78rem; font-weight: 600;
  text-decoration: none; font-family: var(--font-sans);
}
.tag:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- Article page ---------- */
.article { max-width: var(--measure); margin: 0 auto; }
.article__header { margin: 1rem 0 1.5rem; }
.article__header h1 { font-size: clamp(1.9rem, 4.5vw, 2.9rem); margin: .4rem 0 .6rem; letter-spacing: -.02em; }
.article__sub { font-size: 1.2rem; color: var(--text-muted); margin: 0 0 1rem; }
.byline { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; font-size: .88rem; color: var(--text-muted); font-family: var(--font-sans); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: .7rem 0; }
.byline strong { color: var(--text); }
.article__hero { margin: 1.5rem 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.prose { font-family: var(--font-serif); font-size: 1.18rem; line-height: 1.75; }
.prose p { margin: 0 0 1.3rem; }
.prose h2 { font-size: 1.7rem; margin: 2.2rem 0 .8rem; }
.prose h3 { font-size: 1.32rem; margin: 1.8rem 0 .6rem; }
.prose ul, .prose ol { margin: 0 0 1.3rem; padding-left: 1.4rem; }
.prose li { margin: .3rem 0; }
.prose a { color: var(--link); }
.prose figure { margin: 1.8rem 0; }
.prose figcaption { font-family: var(--font-sans); font-size: .85rem; color: var(--text-muted); text-align: center; margin-top: .5rem; }
.callout { font-family: var(--font-sans); background: var(--bg-sunken); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 1rem 1.2rem; margin: 1.8rem 0; font-size: 1rem; }
.article__footer { margin: 2.5rem 0; padding-top: 1.5rem; border-top: 2px solid var(--border-strong); }

/* ---------- Comments / newsletter ---------- */
.comment { display: flex; gap: .85rem; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.comment__avatar { width: 40px; height: 40px; border-radius: 999px; background: var(--bg-sunken); flex: none; display: grid; place-items: center; font-weight: 700; color: var(--text-muted); font-family: var(--font-sans); }
.comment__meta { font-size: .82rem; color: var(--text-muted); font-family: var(--font-sans); }
.comment__body { margin: .2rem 0 0; }
.newsletter { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; }
.newsletter h2 { margin: 0 0 .4rem; }
.newsletter p { color: var(--text-muted); margin: 0 0 1rem; }
.newsletter form { display: flex; gap: .5rem; max-width: 440px; margin: 0 auto; flex-wrap: wrap; }
.newsletter input { flex: 1 1 200px; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 1rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .65rem 1.1rem; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: var(--radius); font-weight: 700; cursor: pointer; text-decoration: none; font-family: var(--font-sans); font-size: 1rem;
}
.btn:hover { background: var(--link-hover); border-color: var(--link-hover); color: #fff; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--ghost:hover { background: var(--bg-sunken); color: var(--text); }
.form-note { font-size: .82rem; color: var(--text-muted); margin: .6rem 0 0; }

/* ---------- Search ---------- */
.search-box { display: flex; gap: .5rem; margin: 1.5rem 0; }
.search-box input { flex: 1; padding: .8rem 1rem; font-size: 1.1rem; border: 2px solid var(--border-strong); border-radius: var(--radius); background: var(--bg-elev); color: var(--text); }
.search-filters { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.chip { padding: .35rem .8rem; border: 1px solid var(--border); background: var(--bg-elev); color: var(--text); border-radius: 999px; cursor: pointer; font-size: .85rem; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.search-status { color: var(--text-muted); font-family: var(--font-sans); margin-bottom: 1rem; }
mark { background: var(--accent); color: var(--accent-ink); padding: 0 .15em; border-radius: 3px; }

/* ---------- Back to top ---------- */
.to-top {
  position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 90;
  opacity: 0; visibility: hidden; transition: opacity .2s ease;
}
.to-top.show { opacity: 1; visibility: visible; }

/* ---------- Footer ---------- */
.site-footer { border-top: 2px solid var(--border-strong); background: var(--bg-elev); margin-top: 3rem; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 2rem; padding: 2.5rem 0; }
@media (max-width: 700px) { .footer-grid { grid-template-columns: 1fr; gap: 1.5rem; } }
.footer-grid h4 { margin: 0 0 .7rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .12em; font-family: var(--font-sans); color: var(--text-muted); }
.footer-grid ul { list-style: none; margin: 0; padding: 0; }
.footer-grid li + li { margin-top: .45rem; }
.footer-grid a { text-decoration: none; color: var(--text); font-size: .92rem; }
.footer-grid a:hover { color: var(--link-hover); }
.footer-bottom { border-top: 1px solid var(--border); padding: 1.2rem 0; font-size: .82rem; color: var(--text-muted); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* ---------- Utilities ---------- */
.muted { color: var(--text-muted); }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.lead { font-size: 1.2rem; color: var(--text-muted); }
.pill-row { display: flex; flex-wrap: wrap; gap: .5rem; }

/* ---------- Mobile nav ---------- */
@media (max-width: 720px) {
  .nav-toggle { display: inline-flex; }
  .nav { position: fixed; inset: 0 0 0 auto; width: min(80vw, 320px); background: var(--bg-elev); border-left: 1px solid var(--border); transform: translateX(100%); transition: transform .2s ease; padding: 4.5rem 1rem 1rem; margin: 0; z-index: 110; box-shadow: var(--shadow); }
  .nav.open { transform: translateX(0); }
  .nav ul { flex-direction: column; gap: .2rem; }
  .nav a { padding: .7rem .8rem; font-size: 1.05rem; }
  body.nav-open { overflow: hidden; }
}
