/* ============================================================
   FLAVOR THEME v3 — base.css
   "Encre & papier" — CSS reset, variables, typography, utilities, prose
   All colors via --t-* variables. Zero hardcoded values in rules.
   ============================================================ */

/* ----- CSS Reset minimal ----- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, picture, video, canvas, svg { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
table { border-collapse: collapse; }

/* ----- CSS Variables — Encre & papier light (fallbacks, overridden by ThemeService) ----- */
:root {
  /* Theme colors — warm cream paper, ink text, amber accents, neutral borders+shadows */
  --t-surface: #fffbeb;
  --t-surface-alt: #f7f3e6;
  --t-surface-raised: #ffffff;
  --t-text: #1c1917;
  --t-text-secondary: #57534e;
  --t-text-muted: #78716c; /* WCAG AA (Point #29): 4.6:1 on #fffbeb */
  --t-primary: #b45309;
  --t-primary-hover: #92400e;
  --t-primary-light: rgba(217,119,6,0.10);
  --t-secondary: #57534e;
  --t-accent: #92400e;
  --t-success: #15803d;
  --t-warning: #a16207;
  --t-danger: #dc2626;
  --t-border: rgba(28,25,23,0.10);
  --t-border-hover: rgba(28,25,23,0.18);
  --t-shadow: rgba(28,25,23,0.06);
  --t-shadow-hover: rgba(28,25,23,0.12);
  --t-overlay: rgba(28,25,23,0.50);

  /* Layout */
  --t-max-width: 1280px;
  --t-content-width: 768px;
  --t-wide-width: 1024px;
  --t-border-radius: 12px;
  --t-radius-sm: 8px;
  --t-radius-xs: 6px;
  --t-radius-pill: 9999px;
  --t-spacing: 1rem;
  --t-header-height: 72px;

  /* Fonts */
  --t-font-heading: 'Libre Bodoni', Georgia, serif;
  --t-font-body: 'Public Sans', system-ui, -apple-system, sans-serif;
  --t-font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Animations */
  --t-duration: 300ms;
  --t-duration-slow: 500ms;
  --t-mesh-duration: 15s;
  --t-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----- Dark mode — Encre & papier dark ----- */
[data-theme="dark"] {
  --t-surface: #171412;
  --t-surface-alt: #1e1b18;
  --t-surface-raised: #262220;
  --t-text: #f5f0e6;
  --t-text-secondary: #beb6aa;
  --t-text-muted: #9c948a; /* WCAG AA (Point #29): 6.1:1 on #171412 */
  --t-primary: #d97706;
  --t-primary-hover: #f59e0b;
  --t-primary-light: rgba(217,119,6,0.14);
  --t-secondary: #a8a29e;
  --t-accent: #fbbf24;
  --t-success: #4ade80;
  --t-warning: #fbbf24;
  --t-danger: #f87171;
  --t-border: rgba(245,240,230,0.10);
  --t-border-hover: rgba(245,240,230,0.20);
  --t-shadow: rgba(0,0,0,0.35);
  --t-shadow-hover: rgba(0,0,0,0.50);
  --t-overlay: rgba(0,0,0,0.65);
}

/* System preference auto-dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --t-surface: #171412;
    --t-surface-alt: #1e1b18;
    --t-surface-raised: #262220;
    --t-text: #f5f0e6;
    --t-text-secondary: #beb6aa;
    --t-text-muted: #9c948a; /* WCAG AA (Point #29): 6.1:1 on #171412 */
    --t-primary: #d97706;
    --t-primary-hover: #f59e0b;
    --t-primary-light: rgba(217,119,6,0.14);
    --t-secondary: #a8a29e;
    --t-accent: #fbbf24;
    --t-success: #4ade80;
    --t-warning: #fbbf24;
    --t-danger: #f87171;
    --t-border: rgba(245,240,230,0.10);
    --t-border-hover: rgba(245,240,230,0.20);
    --t-shadow: rgba(0,0,0,0.35);
    --t-shadow-hover: rgba(0,0,0,0.50);
    --t-overlay: rgba(0,0,0,0.65);
  }
}

/* ----- Dark mode transition ----- */
* { transition: background-color var(--t-duration) ease, color 200ms ease, border-color 200ms ease; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ----- Global typography ----- */
body {
  font-family: var(--t-font-body);
  font-size: clamp(1rem, 1.1vw, 1.125rem);
  font-weight: 400;
  line-height: 1.65;
  color: var(--t-text);
  background-color: var(--t-surface);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--t-font-heading);
  font-weight: 400;
  line-height: 1.15;
  color: var(--t-text);
  letter-spacing: -0.01em;
}

h1 { font-size: clamp(2.25rem, 5.5vw, 3.75rem); }
h2 { font-size: clamp(1.625rem, 3.5vw, 2.5rem); }
h3 { font-size: clamp(1.25rem, 2.5vw, 1.875rem); }
h4 { font-size: clamp(1.1rem, 2vw, 1.375rem); }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p { margin-bottom: 1em; }
p:last-child { margin-bottom: 0; }

/* Visible keyboard focus on every interactive element (WCAG 2.4.7, Point #29) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--t-primary);
  outline-offset: 2px;
  border-radius: var(--t-radius-xs);
}

::selection {
  background-color: var(--t-accent);
  color: #fff;
}

/* ----- Utilities ----- */
.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;
}

.truncate {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box; -webkit-line-clamp: 3;
  -webkit-box-orient: vertical; overflow: hidden;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--t-text-muted); }
.text-secondary { color: var(--t-text-secondary); }
.text-primary { color: var(--t-primary); }
.text-accent { color: var(--t-accent); }

.visually-hidden:not(:focus):not(:active) {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ----- Prose (article / page content) ----- */
.prose {
  max-width: var(--t-content-width);
  margin: 0 auto;
  font-size: clamp(1rem, 1.1vw, 1.125rem);
  line-height: 1.8;
  color: var(--t-text);
}

.prose h2 {
  margin-top: 2.5em;
  margin-bottom: 0.75em;
  padding-bottom: 0.5em;
  border-bottom: 1px solid var(--t-border);
}

.prose h3 {
  margin-top: 2em;
  margin-bottom: 0.5em;
}

.prose h4 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.prose p {
  margin-bottom: 1.5em;
}

.prose a {
  color: var(--t-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: var(--t-border-hover);
  transition: color var(--t-duration) var(--t-easing), text-decoration-color var(--t-duration) var(--t-easing);
}
.prose a:hover {
  color: var(--t-primary-hover);
  text-decoration-color: var(--t-primary-hover);
}

.prose ul, .prose ol {
  margin-bottom: 1.5em;
  padding-inline-start: 1.5em;
}
.prose ul { list-style: disc; }
.prose ol { list-style: decimal; }
.prose li {
  margin-bottom: 0.5em;
  line-height: 1.7;
}
.prose li::marker {
  color: var(--t-accent);
}

.prose blockquote {
  margin: 2em 0;
  padding: 1.25em 1.5em;
  border-inline-start: 4px solid var(--t-accent);
  background: var(--t-primary-light);
  border-radius: 0 var(--t-radius-sm) var(--t-radius-sm) 0;
  font-style: italic;
  color: var(--t-text-secondary);
}
.prose blockquote p:last-child { margin-bottom: 0; }

.prose code {
  font-family: var(--t-font-mono);
  font-size: 0.875em;
  padding: 0.15em 0.4em;
  background: var(--t-primary-light);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-xs);
  color: var(--t-accent);
}

.prose pre {
  margin: 2em 0;
  padding: 1.25em 1.5em;
  background: var(--t-surface-alt);
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
}
.prose pre code {
  padding: 0;
  background: none;
  border: none;
  color: var(--t-text);
}

.prose img {
  margin: 2em auto;
  border-radius: var(--t-radius-sm);
  box-shadow: 0 4px 20px var(--t-shadow), 0 1px 3px var(--t-shadow);
}

.prose figure {
  margin: 2em 0;
}
.prose figure img {
  margin: 0 auto 0.75em;
}
.prose figcaption {
  text-align: center;
  font-size: 0.875rem;
  color: var(--t-text-muted);
  font-style: italic;
}

.prose table {
  width: 100%;
  margin: 2em 0;
  border: 1px solid var(--t-border);
  border-radius: var(--t-radius-sm);
  overflow: hidden;
}
.prose th, .prose td {
  padding: 0.75em 1em;
  text-align: start;
  border-bottom: 1px solid var(--t-border);
}
.prose th {
  background: var(--t-surface-alt);
  font-family: var(--t-font-body);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--t-text-secondary);
}
.prose tr:last-child td { border-bottom: none; }

.prose hr {
  margin: 3em 0;
  border: none;
  border-top: 1px solid var(--t-border);
}

.prose strong { font-weight: 700; }
.prose em { font-style: italic; }
