/* Art direction: Rails + AI curated editorial collection → confident, contrarian, manifesto
   Palette: warm dark surfaces (dark charcoal), deep ruby red (#CC0000) accent — Rails-inspired
   Typography: Fraunces (display serif — editorial warmth, slight quirkiness) + DM Sans (clean, geometric body)
   Density: spacious, editorial — generous whitespace, magazine-like rhythm */

/* ===== TYPE SCALE ===== */
:root {
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);
  --text-3xl:  clamp(2.5rem,   1rem    + 4vw,    5rem);
  --text-hero: clamp(3rem,     0.5rem  + 7vw,    8rem);

  /* ===== SPACING ===== */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* ===== FONT FAMILIES ===== */
  --font-display: 'Fraunces', 'Georgia', serif;
  --font-body: 'DM Sans', 'Helvetica Neue', sans-serif;

  /* ===== RADIUS ===== */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* ===== TRANSITIONS ===== */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* ===== CONTENT WIDTHS ===== */
  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;
}

/* ===== DARK MODE (DEFAULT) ===== */
:root, [data-theme="dark"] {
  /* Surfaces — warm dark charcoal */
  --color-bg:             #141414;
  --color-surface:        #1a1a1a;
  --color-surface-2:      #222222;
  --color-surface-offset: #1e1e1e;
  --color-surface-offset-2: #282828;
  --color-surface-dynamic: #2e2e2e;
  --color-divider:        #333333;
  --color-border:         #3d3d3d;

  /* Text — warm cream/white */
  --color-text:           #ede8e0;
  --color-text-muted:     #9a9590;
  --color-text-faint:     #5e5a56;
  --color-text-inverse:   #141414;

  /* Primary accent — Rails Ruby Red */
  --color-primary:        #e63939;
  --color-primary-hover:  #cc0000;
  --color-primary-active: #a30000;
  --color-primary-highlight: #3a2020;

  /* Semantic colors */
  --color-success:        #6daa45;
  --color-warning:        #d4952b;
  --color-error:          #e63939;

  /* Shadows */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
}

/* ===== LIGHT MODE ===== */
[data-theme="light"] {
  /* Surfaces — warm off-white */
  --color-bg:             #f5f0e8;
  --color-surface:        #faf7f2;
  --color-surface-2:      #ffffff;
  --color-surface-offset: #ede8df;
  --color-surface-offset-2: #e5dfd6;
  --color-surface-dynamic: #ddd7cd;
  --color-divider:        #d4cec4;
  --color-border:         #c9c2b8;

  /* Text — warm dark */
  --color-text:           #1a1714;
  --color-text-muted:     #6b6560;
  --color-text-faint:     #a09a94;
  --color-text-inverse:   #f5f0e8;

  /* Primary accent — Rails Ruby Red (deeper for contrast on light) */
  --color-primary:        #cc0000;
  --color-primary-hover:  #a30000;
  --color-primary-active: #8a0000;
  --color-primary-highlight: #fce8e8;

  /* Semantic */
  --color-success:        #437a22;
  --color-warning:        #964219;
  --color-error:          #cc0000;

  /* Shadows */
  --shadow-sm: 0 1px 2px oklch(0.2 0.01 80 / 0.06);
  --shadow-md: 0 4px 12px oklch(0.2 0.01 80 / 0.08);
  --shadow-lg: 0 12px 32px oklch(0.2 0.01 80 / 0.12);
}

/* System preference fallback for dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:             #141414;
    --color-surface:        #1a1a1a;
    --color-surface-2:      #222222;
    --color-surface-offset: #1e1e1e;
    --color-surface-offset-2: #282828;
    --color-surface-dynamic: #2e2e2e;
    --color-divider:        #333333;
    --color-border:         #3d3d3d;
    --color-text:           #ede8e0;
    --color-text-muted:     #9a9590;
    --color-text-faint:     #5e5a56;
    --color-text-inverse:   #141414;
    --color-primary:        #e63939;
    --color-primary-hover:  #cc0000;
    --color-primary-active: #a30000;
    --color-primary-highlight: #3a2020;
    --color-success:        #6daa45;
    --color-warning:        #d4952b;
    --color-error:          #e63939;
    --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.2);
    --shadow-md: 0 4px 12px oklch(0 0 0 / 0.3);
    --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.4);
  }
}

/* ===== COMPONENT STYLES ===== */

/* Container */
.container {
  max-width: var(--content-wide);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.container--narrow {
  max-width: var(--content-default);
}

/* Section spacing */
.section {
  padding-block: clamp(var(--space-12), 8vw, var(--space-32));
}

/* Typography styles */
.display-font {
  font-family: var(--font-display);
  font-weight: 700;
}

.body-font {
  font-family: var(--font-body);
}

/* Links */
a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-interactive),
              text-decoration-color var(--transition-interactive);
}

a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 500;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background var(--transition-interactive),
              color var(--transition-interactive),
              box-shadow var(--transition-interactive),
              transform var(--transition-interactive);
}

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-text-muted);
  transform: translateY(-1px);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn-ghost:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
  text-decoration: none;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: box-shadow var(--transition-interactive),
              transform var(--transition-interactive),
              border-color var(--transition-interactive);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.card--featured {
  border-color: var(--color-primary);
  border-width: 2px;
  background: color-mix(in oklab, var(--color-surface) 94%, var(--color-primary) 6%);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-primary {
  background: var(--color-primary-highlight);
  color: var(--color-primary);
}

.badge-muted {
  background: var(--color-surface-dynamic);
  color: var(--color-text-muted);
}

/* Divider */
.divider {
  height: 1px;
  background: var(--color-divider);
  border: none;
}

/* Scroll animations — CSS-native */
.fade-in {
  opacity: 1;
}

@supports (animation-timeline: scroll()) {
  .fade-in {
    opacity: 0;
    animation: reveal-fade linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 100%;
  }
}

@keyframes reveal-fade {
  to { opacity: 1; }
}

/* Scroll animations — JS fallback */
.fade-in-js {
  opacity: 0;
  transition: opacity 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.fade-in-js.is-visible {
  opacity: 1;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: oklch(from var(--color-bg) l c h / 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--color-divider);
  transition: box-shadow 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.site-header--scrolled {
  box-shadow: var(--shadow-sm);
}

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: color var(--transition-interactive),
              background var(--transition-interactive);
}

.theme-toggle:hover {
  color: var(--color-text);
  background: var(--color-surface-2);
}

/* Category section */
.category-section {
  border-top: 1px solid var(--color-divider);
}

/* Stat counter */
.stat-number {
  font-family: var(--font-display);
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}

.stat-label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Quote styling */
.article-quote {
  font-style: italic;
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: 1.6;
  border-left: 2px solid var(--color-primary);
  padding-left: var(--space-4);
  margin-top: var(--space-3);
}

/* Author info */
.author-name {
  font-weight: 600;
  color: var(--color-text);
  font-size: var(--text-sm);
}

.author-role {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* Article type badge */
.type-badge {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-faint);
  font-weight: 500;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-divider);
  padding-block: var(--space-12);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.site-footer a {
  color: var(--color-text-muted);
  transition: color var(--transition-interactive);
}

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

/* Hero section */
.hero {
  padding-block: clamp(var(--space-16), 12vw, var(--space-32));
  position: relative;
  overflow: hidden;
}

.hero-tagline {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-text);
  max-width: 16ch;
}

.hero-subtitle {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  max-width: 48ch;
  line-height: 1.5;
}

/* Thesis section */
.thesis-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.thesis-card h3 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.thesis-card p {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.6;
}

/* Grid layouts */
.articles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr));
  gap: var(--space-6);
}

.thesis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
  gap: var(--space-6);
}

/* Category heading */
.category-heading {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
}

.category-count {
  font-size: var(--text-sm);
  color: var(--color-text-faint);
  font-weight: 400;
}

/* Card link wrapper */
.card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.card-link:hover {
  text-decoration: none;
  color: inherit;
}

.card-link .card-title {
  transition: color var(--transition-interactive);
}

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

.card-title {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
}

.card-date {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* Arrow icon on card hover */
.card-arrow {
  color: var(--color-text-faint);
  transition: color var(--transition-interactive),
              transform var(--transition-interactive);
}

.card-link:hover .card-arrow {
  color: var(--color-primary);
  transform: translateX(4px);
}

/* Red accent line */
.accent-line {
  width: 48px;
  height: 3px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
}

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

@media (max-width: 768px) {
  .mobile-nav-toggle {
    display: flex;
  }
  .desktop-nav {
    display: none;
  }
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  background: var(--color-primary);
  color: #ffffff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  z-index: 100;
  font-size: var(--text-sm);
}

.skip-link:focus {
  top: var(--space-2);
}
