/*
 * Duneed blog — hand-written, self-contained stylesheet (plan 18 §3).
 * Deliberately NOT wired into apps/web's Tailwind build: a cache-forever
 * static asset with zero build-pipeline coupling, served straight off
 * Django's staticfiles/whitenoise.
 *
 * Brand tokens below are copied as literal values from the actual web
 * app's design tokens at apps/web/src/index.css (`@theme` block) — same
 * font stack, same surface/text/brand colors, same radii — so the blog
 * reads as the same product, not a bolt-on. That file has no dark-mode
 * palette yet (the web app is light-only today); the dark values here are
 * this file's OWN derivation (a standard slate-family inversion, brand hue
 * kept but lightened for on-dark contrast), not copied from anywhere —
 * flagged in the phase B2 report as a judgment call.
 */

:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Surfaces */
  --color-canvas: #f8fafc;
  --color-surface: #ffffff;
  --color-muted-surface: #f1f5f9;
  --color-border: #e2e8f0;

  /* Text */
  --color-fg: #0f172a;
  --color-fg-body: #334155;
  --color-fg-muted: #64748b;
  --color-fg-faint: #94a3b8;

  /* Brand (teal) — apps/web/src/index.css: white-on-primary verified
     WCAG AA 4.5:1 (#0f766e measures 5.47:1), reused here verbatim. */
  --color-primary: #0f766e;
  --color-primary-hover: #115e59;
  --color-primary-subtle: #f0fdfa;

  /* Warning (draft-preview banner) — also copied from apps/web/src/index.css. */
  --color-warning-fg: #92400e;
  --color-warning-surface: #fffbeb;
  --color-warning-border: #fde68a;

  /* Radii — apps/web/src/index.css */
  --radius-input: 8px;
  --radius-card: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Derived, not copied (see file header) — standard slate-900/800
       inversion; teal lightened a step (teal-400/300) so text/links keep
       solid contrast against a dark surface instead of the light-mode
       teal-700, which reads muddy on near-black. */
    --color-canvas: #0f172a;
    --color-surface: #1e293b;
    --color-muted-surface: #273449;
    --color-border: #334155;

    --color-fg: #f1f5f9;
    --color-fg-body: #cbd5e1;
    --color-fg-muted: #94a3b8;
    --color-fg-faint: #64748b;

    --color-primary: #2dd4bf;
    --color-primary-hover: #5eead4;
    --color-primary-subtle: rgba(45, 212, 191, 0.12);

    --color-warning-fg: #fcd34d;
    --color-warning-surface: rgba(180, 83, 9, 0.16);
    --color-warning-border: rgba(252, 211, 77, 0.35);
  }
}

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

body {
  margin: 0;
}

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

/* --- Base --------------------------------------------------------------- */
body {
  background: var(--color-canvas);
  color: var(--color-fg-body);
  font-family: var(--font-sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
}

.wrap {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

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

/* --- Header / footer brand shell ---------------------------------------- */
.site-header {
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: 3.5rem;
}

.wordmark {
  font-weight: 700;
  font-size: 1.0625rem;
  color: var(--color-primary);
  text-decoration: none;
}

.section-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-fg-muted);
  text-decoration: none;
  border-left: 1px solid var(--color-border);
  padding-left: 0.75rem;
}

.section-label:hover {
  color: var(--color-primary);
}

.site-main {
  padding: 2.5rem 1.25rem 4rem;
}

@media (min-width: 640px) {
  .site-main {
    padding-top: 3.5rem;
    padding-bottom: 5rem;
  }
}

.site-footer {
  border-top: 1px solid var(--color-border);
}

.site-footer__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem 1.25rem;
  font-size: 0.8125rem;
  color: var(--color-fg-muted);
}

@media (min-width: 640px) {
  .site-footer__inner {
    flex-direction: row;
    justify-content: space-between;
  }
}

.back-link {
  text-decoration: none;
  color: var(--color-fg-muted);
}

.back-link:hover {
  color: var(--color-primary);
}

/* --- Index: post cards ---------------------------------------------------- */
.index-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--color-fg);
  margin: 0 0 2rem;
}

.post-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 640px) {
  .post-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.post-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.post-card__image-link {
  display: block;
  background: var(--color-muted-surface);
}

.post-card__image {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.post-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
}

.post-card__title {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1.35;
  margin: 0;
}

.post-card__title a {
  color: var(--color-fg);
  text-decoration: none;
}

.post-card__title a:hover {
  color: var(--color-primary);
}

.post-card__excerpt {
  color: var(--color-fg-muted);
  font-size: 0.9375rem;
  margin: 0;
}

.post-card__date {
  color: var(--color-fg-faint);
  font-size: 0.8125rem;
}

.empty-state {
  color: var(--color-fg-muted);
  font-size: 0.9375rem;
}

/* --- Category/tag listing header (phase B3) ----------------------------- */
.taxonomy-description {
  color: var(--color-fg-muted);
  font-size: 0.9375rem;
  max-width: 60ch;
  margin: -1.25rem 0 2rem;
}

/* --- Pagination ----------------------------------------------------------- */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin: 2.5rem 0 0;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  padding: 0.45em 0.85em;
  border-radius: var(--radius-input);
  border: 1px solid var(--color-border);
  font-size: 0.875rem;
  text-decoration: none;
  color: var(--color-fg-body);
}

.pagination a:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.pagination .is-current {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  font-weight: 600;
}

.pagination .is-disabled {
  opacity: 0.4;
}

/* --- Draft preview banner --------------------------------------------- */
.draft-banner {
  background: var(--color-warning-surface);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-fg);
  border-radius: var(--radius-input);
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  margin-bottom: 2rem;
}

/* --- 410 gone state ------------------------------------------------------- */
.gone-state {
  padding: 3rem 0;
}

.gone-state h1 {
  font-size: 1.5rem;
  color: var(--color-fg);
}

/* --- Article ------------------------------------------------------------- */
.article-header h1 {
  font-size: 1.875rem;
  font-weight: 800;
  line-height: 1.25;
  color: var(--color-fg);
  margin: 0 0 0.75rem;
}

@media (min-width: 640px) {
  .article-header h1 {
    font-size: 2.25rem;
  }
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  color: var(--color-fg-muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

.article-hero {
  width: 100%;
  border-radius: var(--radius-card);
  margin-bottom: 2rem;
}

/* --- Prose: the sanitized body_html typographic block ------------------ */
.prose {
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--color-fg-body);
}

.prose > *:first-child {
  margin-top: 0;
}

.prose h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-fg);
  margin: 2.2em 0 0.75em;
}

.prose h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-fg);
  margin: 1.8em 0 0.6em;
}

.prose h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-fg);
  margin: 1.6em 0 0.5em;
}

.prose p {
  margin: 0 0 1.25em;
}

.prose a {
  color: var(--color-primary);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.prose a:hover {
  color: var(--color-primary-hover);
}

.prose ul,
.prose ol {
  margin: 0 0 1.25em;
  padding-left: 1.4em;
}

.prose li {
  margin-bottom: 0.4em;
}

.prose blockquote {
  margin: 1.5em 0;
  padding: 0.25em 0 0.25em 1.1em;
  border-left: 3px solid var(--color-primary);
  color: var(--color-fg-muted);
  font-style: italic;
}

.prose figure {
  margin: 1.75em 0;
}

.prose figure img {
  border-radius: var(--radius-input);
  margin: 0 auto;
}

.prose figcaption {
  margin-top: 0.6em;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-fg-muted);
}

.prose code {
  background: var(--color-muted-surface);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

.prose pre {
  background: var(--color-muted-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-input);
  padding: 1em;
  overflow-x: auto;
  margin: 0 0 1.5em;
}

.prose pre code {
  background: none;
  padding: 0;
  font-size: 0.875em;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1.5em;
  font-size: 0.9375rem;
}

.prose th,
.prose td {
  border: 1px solid var(--color-border);
  padding: 0.5em 0.75em;
  text-align: left;
}

.prose thead th {
  background: var(--color-muted-surface);
  font-weight: 600;
}

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