/* ============================================================
   FLAVOR THEME v2 — base.css
   "Vivid" — 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 — Vivid light (fallbacks, overridden by ThemeService) ----- */
:root {
  /* Theme colors — warm white, indigo/coral/violet accents, tinted borders+shadows */
  --t-surface: #fefdfb;
  --t-surface-alt: #f8f7f4;
  --t-surface-raised: #ffffff;
  --t-text: #1a1a2e;
  --t-text-secondary: #52525b;
  --t-text-muted: #a1a1aa;
  --t-primary: #4f46e5;
  --t-primary-hover: #4338ca;
  --t-primary-light: rgba(79,70,229,0.08);
  --t-secondary: #f97316;
  --t-accent: #8b5cf6;
  --t-success: #059669;
  --t-warning: #d97706;
  --t-danger: #dc2626;
  --t-border: rgba(79,70,229,0.10);
  --t-border-hover: rgba(79,70,229,0.22);
  --t-shadow: rgba(79,70,229,0.07);
  --t-shadow-hover: rgba(79,70,229,0.14);
  --t-overlay: rgba(26,26,46,0.5);

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

  /* Fonts */
  --t-font-heading: 'Instrument Serif', Georgia, serif;
  --t-font-body: 'Inter', 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 — Vivid dark ----- */
[data-theme="dark"] {
  --t-surface: #0a0a0f;
  --t-surface-alt: #141420;
  --t-surface-raised: #1e1e2e;
  --t-text: #f4f4f5;
  --t-text-secondary: #a1a1aa;
  --t-text-muted: #71717a;
  --t-primary: #6366f1;
  --t-primary-hover: #818cf8;
  --t-primary-light: rgba(99,102,241,0.12);
  --t-secondary: #fb923c;
  --t-accent: #a78bfa;
  --t-success: #10b981;
  --t-warning: #fbbf24;
  --t-danger: #f87171;
  --t-border: rgba(99,102,241,0.15);
  --t-border-hover: rgba(99,102,241,0.30);
  --t-shadow: rgba(0,0,0,0.25);
  --t-shadow-hover: rgba(0,0,0,0.40);
  --t-overlay: rgba(0,0,0,0.7);
}

/* System preference auto-dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --t-surface: #0a0a0f;
    --t-surface-alt: #141420;
    --t-surface-raised: #1e1e2e;
    --t-text: #f4f4f5;
    --t-text-secondary: #a1a1aa;
    --t-text-muted: #71717a;
    --t-primary: #6366f1;
    --t-primary-hover: #818cf8;
    --t-primary-light: rgba(99,102,241,0.12);
    --t-secondary: #fb923c;
    --t-accent: #a78bfa;
    --t-success: #10b981;
    --t-warning: #fbbf24;
    --t-danger: #f87171;
    --t-border: rgba(99,102,241,0.15);
    --t-border-hover: rgba(99,102,241,0.30);
    --t-shadow: rgba(0,0,0,0.25);
    --t-shadow-hover: rgba(0,0,0,0.40);
    --t-overlay: rgba(0,0,0,0.7);
  }
}

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

a: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-left: 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-left: 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: left;
  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; }
