/* ============================================
   TRANSNATIONAL NEWS - ACCESSIBLE DESIGN SYSTEM
   Based on DESIGN_SYSTEM_REFERENCE.md (January 2026)
   Pure CSS - No build tools required
   ============================================ */

/* ================================================
   CSS RESET (Modern Normalize)
   ================================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  font-size: 100%;
  -webkit-text-size-adjust: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

ul, ol {
  list-style: none;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: inherit;
}

/* ================================================
   PRIMITIVE TOKENS (Raw values - don't use directly)
   ================================================ */
:root {
  /* Neutral Scale (Slate) */
  --primitive-slate-50: #f8fafc;
  --primitive-slate-100: #f1f5f9;
  --primitive-slate-200: #e2e8f0;
  --primitive-slate-300: #cbd5e1;
  --primitive-slate-400: #94a3b8;
  --primitive-slate-500: #64748b;
  --primitive-slate-600: #475569;
  --primitive-slate-700: #334155;
  --primitive-slate-800: #1e293b;
  --primitive-slate-900: #0f172a;
  --primitive-slate-950: #020617;

  /* Primary Scale (Blue) */
  --primitive-blue-50: #eff6ff;
  --primitive-blue-100: #dbeafe;
  --primitive-blue-200: #bfdbfe;
  --primitive-blue-300: #93c5fd;
  --primitive-blue-400: #60a5fa;
  --primitive-blue-500: #3b82f6;
  --primitive-blue-600: #2563eb;
  --primitive-blue-700: #1d4ed8;
  --primitive-blue-800: #1e40af;
  --primitive-blue-900: #1e3a8a;

  /* Secondary Scale (Purple) */
  --primitive-purple-400: #a78bfa;
  --primitive-purple-500: #8b5cf6;
  --primitive-purple-600: #7c3aed;

  /* Tertiary Scale (Cyan) */
  --primitive-cyan-400: #22d3ee;
  --primitive-cyan-500: #06b6d4;
  --primitive-cyan-600: #0891b2;

  /* Semantic Colors */
  --primitive-green-50: #f0fdf4;
  --primitive-green-600: #16a34a;
  --primitive-green-700: #15803d;
  --primitive-red-50: #fef2f2;
  --primitive-red-500: #ef4444;
  --primitive-red-600: #dc2626;
  --primitive-red-700: #b91c1c;
  --primitive-amber-50: #fffbeb;
  --primitive-amber-600: #d97706;
  --primitive-amber-700: #b45309;

  /* ================================================
     SEMANTIC TOKENS - LIGHT THEME (Use these!)
     ================================================ */

  /* Text Colors - All meet 4.5:1 contrast on respective backgrounds */
  --color-text-primary: var(--primitive-slate-900);      /* 15.8:1 on white */
  --color-text-secondary: var(--primitive-slate-600);    /* 7.0:1 on white */
  --color-text-muted: var(--primitive-slate-500);        /* 4.6:1 on white */
  --color-text-disabled: var(--primitive-slate-400);     /* Decorative only */
  --color-text-inverse: #ffffff;
  --color-text-link: var(--primitive-blue-600);          /* 4.7:1 on white */
  --color-text-link-hover: var(--primitive-blue-700);

  /* Background Colors */
  --color-bg-page: #ffffff;
  --color-bg-surface: var(--primitive-slate-50);
  --color-bg-surface-raised: #ffffff;
  --color-bg-surface-sunken: var(--primitive-slate-100);
  --color-bg-overlay: rgba(15, 23, 42, 0.5);

  /* Interactive Colors */
  --color-bg-interactive: var(--primitive-blue-600);
  --color-bg-interactive-hover: var(--primitive-blue-700);
  --color-bg-interactive-active: var(--primitive-blue-800);
  --color-bg-interactive-subtle: var(--primitive-blue-50);

  /* Border Colors */
  --color-border-default: var(--primitive-slate-200);
  --color-border-strong: var(--primitive-slate-300);
  --color-border-subtle: var(--primitive-slate-100);
  --color-border-focus: var(--primitive-blue-500);

  /* Status Colors - Pre-validated accessible pairings */
  --color-status-success-bg: #dcfce7;
  --color-status-success-text: var(--primitive-green-700);
  --color-status-success-border: var(--primitive-green-600);

  --color-status-error-bg: #fee2e2;
  --color-status-error-text: var(--primitive-red-700);
  --color-status-error-border: var(--primitive-red-600);

  --color-status-warning-bg: #fef3c7;
  --color-status-warning-text: var(--primitive-amber-700);
  --color-status-warning-border: var(--primitive-amber-600);

  --color-status-info-bg: var(--primitive-blue-50);
  --color-status-info-text: var(--primitive-blue-700);
  --color-status-info-border: var(--primitive-blue-600);

  /* Focus Ring */
  --color-focus: var(--primitive-blue-500);
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --shadow-focus: 0 0 0 3px rgb(59 130 246 / 0.3);
  --shadow-focus-error: 0 0 0 3px rgb(220 38 38 / 0.3);

  /* Brand Gradient */
  --gradient-brand: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #06b6d4 100%);

  /* Category Colors */
  --color-cat-ai: var(--primitive-blue-500);
  --color-cat-ml: var(--primitive-purple-500);
  --color-cat-tech: var(--primitive-cyan-500);

  /* ================================================
     TYPOGRAPHY TOKENS
     ================================================ */

  /* Font Families */
  --font-family-sans: 'Inter', -apple-system, BlinkMacSystemFont,
                      'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-family-serif: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-family-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

  /* Font Sizes (Fluid - scales with viewport) */
  --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --font-size-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  --font-size-lg: clamp(1.125rem, 1rem + 0.6vw, 1.25rem);
  --font-size-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --font-size-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
  --font-size-3xl: clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);
  --font-size-4xl: clamp(2.25rem, 1.8rem + 2vw, 3rem);
  --font-size-5xl: clamp(3rem, 2.2rem + 3vw, 4rem);

  /* Font Weights */
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Line Heights */
  --line-height-tight: 1.25;
  --line-height-snug: 1.375;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* Letter Spacing */
  --letter-spacing-tight: -0.025em;
  --letter-spacing-normal: 0;
  --letter-spacing-wide: 0.025em;
  --letter-spacing-wider: 0.05em;

  /* ================================================
     SPACING TOKENS (8px base grid)
     ================================================ */

  --spacing-0: 0;
  --spacing-1: 0.25rem;
  --spacing-2: 0.5rem;
  --spacing-3: 0.75rem;
  --spacing-4: 1rem;
  --spacing-5: 1.25rem;
  --spacing-6: 1.5rem;
  --spacing-8: 2rem;
  --spacing-10: 2.5rem;
  --spacing-12: 3rem;
  --spacing-16: 4rem;
  --spacing-20: 5rem;
  --spacing-24: 6rem;

  /* Semantic Spacing */
  --spacing-page-margin: var(--spacing-4);
  --spacing-section-gap: var(--spacing-12);
  --spacing-component-padding: var(--spacing-4);
  --spacing-element-gap: var(--spacing-3);
  --spacing-inline-gap: var(--spacing-2);

  /* ================================================
     SIZING TOKENS
     ================================================ */

  /* Touch Targets - WCAG 2.5.8 */
  --size-touch-target: 2.75rem;   /* 44px minimum */
  --size-touch-target-lg: 3rem;   /* 48px recommended */

  /* Button Heights */
  --size-button-sm: 2rem;
  --size-button-md: 2.5rem;
  --size-button-lg: 3rem;

  /* Input Heights */
  --size-input-sm: 2rem;
  --size-input-md: 2.5rem;
  --size-input-lg: 3rem;

  /* Icon Sizes */
  --size-icon-sm: 1rem;
  --size-icon-md: 1.25rem;
  --size-icon-lg: 1.5rem;
  --size-icon-xl: 2rem;

  /* ================================================
     BORDER RADIUS TOKENS
     ================================================ */

  --radius-none: 0;
  --radius-sm: 0.125rem;
  --radius-md: 0.25rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-2xl: 1rem;
  --radius-3xl: 1.5rem;
  --radius-full: 9999px;

  /* ================================================
     SHADOW TOKENS
     ================================================ */

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* ================================================
     MOTION TOKENS
     ================================================ */

  --duration-instant: 0ms;
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 350ms;

  --ease-default: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-out: cubic-bezier(0, 0, 0.2, 1);

  /* ================================================
     LAYOUT TOKENS
     ================================================ */

  --max-width-prose: 65ch;
  --max-width-content: 80rem;
  --max-width-wide: 90rem;
  --container-max: 1280px;
  --container-padding: clamp(1rem, 5vw, 2rem);
  --content-width: 720px;
  --wide-width: 1024px;

  /* Color scheme for browser defaults */
  color-scheme: light;
}

/* ================================================
   DARK THEME - Three-State System
   ================================================ */

/* System preference dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-text-primary: var(--primitive-slate-100);
    --color-text-secondary: var(--primitive-slate-400);
    --color-text-muted: var(--primitive-slate-500);

    /* Links need brighter blue for dark mode contrast */
    --color-text-link: var(--primitive-blue-400);
    --color-text-link-hover: var(--primitive-blue-300);

    /* Category colors - brighter for dark mode */
    --color-cat-ai: var(--primitive-blue-400);
    --color-cat-ml: #a78bfa; /* purple-400 */
    --color-cat-tech: #22d3ee; /* cyan-400 */

    --color-bg-page: var(--primitive-slate-900);
    --color-bg-surface: var(--primitive-slate-800);
    --color-bg-surface-raised: var(--primitive-slate-800);

    --color-border-default: var(--primitive-slate-700);
    --color-border-strong: var(--primitive-slate-600);

    --color-bg-interactive: var(--primitive-blue-500);
    --color-bg-interactive-hover: var(--primitive-blue-400);
    --color-bg-interactive-subtle: rgba(59, 130, 246, 0.15);
    --color-bg-interactive-active: var(--primitive-blue-600);

    --color-focus: var(--primitive-blue-400);

    /* Header backdrop for dark mode */
    --header-backdrop-bg: rgb(15 23 42 / 0.9);

    color-scheme: dark;
  }
}

/* Explicit dark mode override */
[data-theme="dark"] {
  --color-text-primary: var(--primitive-slate-100);
  --color-text-secondary: var(--primitive-slate-400);
  --color-text-muted: var(--primitive-slate-500);

  /* Links need brighter blue for dark mode contrast */
  --color-text-link: var(--primitive-blue-400);
  --color-text-link-hover: var(--primitive-blue-300);

  /* Category colors - brighter for dark mode */
  --color-cat-ai: var(--primitive-blue-400);
  --color-cat-ml: #a78bfa; /* purple-400 */
  --color-cat-tech: #22d3ee; /* cyan-400 */

  --color-bg-page: var(--primitive-slate-900);
  --color-bg-surface: var(--primitive-slate-800);
  --color-bg-surface-raised: var(--primitive-slate-800);

  --color-border-default: var(--primitive-slate-700);
  --color-border-strong: var(--primitive-slate-600);

  --color-bg-interactive: var(--primitive-blue-500);
  --color-bg-interactive-hover: var(--primitive-blue-400);
  --color-bg-interactive-subtle: rgba(59, 130, 246, 0.15);
  --color-bg-interactive-active: var(--primitive-blue-600);

  --color-focus: var(--primitive-blue-400);

  /* Header backdrop for dark mode */
  --header-backdrop-bg: rgb(15 23 42 / 0.9);

  color-scheme: dark;
}

/* Explicit light mode override */
[data-theme="light"] {
  color-scheme: light;
}

/* ================================================
   BASE STYLES
   ================================================ */

html {
  font-size: 100%; /* Respect user preferences */
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

/* REQUIRED: Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

body {
  background-color: var(--color-bg-page);
  color: var(--color-text-primary);
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--duration-normal) var(--ease-default),
              color var(--duration-normal) var(--ease-default);
}

/* ================================================
   FOCUS STATES - REQUIRED for accessibility
   ================================================ */

:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}

/* Link focus needs border-radius per spec */
a:focus-visible {
  border-radius: 2px;
}

/* Remove default focus for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
  outline: none;
}

/* ================================================
   GLOBAL TOUCH TARGETS - REQUIRED for accessibility
   ================================================ */

button,
a,
[role="button"] {
  min-height: 44px;
  min-width: 44px;
}

/* ================================================
   SKIP LINK - REQUIRED for accessibility
   ================================================ */

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--spacing-4);
  z-index: 9999;
  padding: var(--spacing-2) var(--spacing-4);
  background: var(--color-bg-interactive);
  color: white;
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: top var(--duration-fast) var(--ease-out);
}

.skip-link:focus {
  top: var(--spacing-4);
}

/* ================================================
   TYPOGRAPHY
   ================================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-family-sans);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
  margin-top: 0;
  margin-bottom: var(--spacing-4);
}

h1 {
  font-size: var(--font-size-4xl);
  letter-spacing: var(--letter-spacing-tight);
}

h2 {
  font-size: var(--font-size-3xl);
  letter-spacing: var(--letter-spacing-tight);
}

h3 {
  font-size: var(--font-size-2xl);
}

h4 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
}

h5 {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

h6 {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
}

p {
  margin-top: 0;
  margin-bottom: var(--spacing-4);
  max-width: var(--max-width-prose);
}

/* Long-form content - per spec */
.prose {
  font-size: var(--font-size-base);
  line-height: var(--line-height-relaxed);
  max-width: var(--max-width-prose);
}

.prose p {
  margin-bottom: 1.5em; /* WCAG: paragraph spacing 2x font size */
}

/* Small text needs wider spacing - per spec */
.text-sm {
  font-size: var(--font-size-sm);
  letter-spacing: var(--letter-spacing-wide);
}

/* Links - REQUIRED: underline for non-color differentiation */
a {
  color: var(--color-text-link);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  transition: color var(--duration-fast) var(--ease-default);
}

a:hover {
  color: var(--color-text-link-hover);
}

/* Navigation links can omit underline if other differentiation exists */
.nav-link,
.btn,
.article-card a,
.category-badge {
  text-decoration: none;
}

/* Brand gradient text */
.text-gradient {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ================================================
   LAYOUT
   ================================================ */

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding-left: var(--container-padding);
  padding-right: var(--container-padding);
}

/* ================================================
   HEADER
   ================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background-color: var(--color-bg-page);
  border-bottom: 1px solid var(--color-border-default);
  transition: transform var(--duration-normal) var(--ease-default);
}

.site-header.scrolled {
  background-color: rgb(255 255 255 / 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

[data-theme="dark"] .site-header.scrolled {
  background-color: rgb(15 23 42 / 0.9);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-header.scrolled {
    background-color: rgb(15 23 42 / 0.9);
  }
}

.site-header.hidden {
  transform: translateY(-100%);
}

/* ================================================
   NAVIGATION
   ================================================ */

.nav-link {
  display: flex;
  align-items: center;
  padding: var(--spacing-2) var(--spacing-3);
  min-height: var(--size-touch-target);
  color: var(--color-text-secondary);
  border-radius: var(--radius-md);
  transition: color var(--duration-fast) var(--ease-default),
              background-color var(--duration-fast) var(--ease-default);
}

.nav-link:hover {
  color: var(--color-text-primary);
  background-color: var(--color-bg-surface);
}

/* Current page - use aria-current="page" per spec */
.nav-link[aria-current="page"] {
  color: var(--color-bg-interactive);
  font-weight: var(--font-weight-medium);
  background: var(--color-bg-interactive-subtle);
}

/* Dark mode override for current page nav link */
[data-theme="dark"] .nav-link[aria-current="page"] {
  background: rgba(59, 130, 246, 0.2);
  color: var(--primitive-blue-300);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .nav-link[aria-current="page"] {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primitive-blue-300);
  }
}

.nav-link:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}

/* Mobile Navigation */
.mobile-nav {
  position: fixed;
  inset: 0;
  z-index: 100;
  background-color: var(--color-bg-page);
  transform: translateX(100%);
  transition: transform var(--duration-slow) var(--ease-default);
  overflow-y: auto;
}

.mobile-nav.open {
  transform: translateX(0);
}

.mobile-nav-link {
  display: block;
  padding: var(--spacing-4) 0;
  min-height: var(--size-touch-target);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  text-align: center;
  border-bottom: 1px solid var(--color-border-subtle);
  transition: color var(--duration-fast) var(--ease-default);
}

.mobile-nav-link:hover {
  color: var(--color-text-link);
}

/* ================================================
   BUTTONS - Per spec exactly
   ================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-2);
  min-height: var(--size-touch-target);
  min-width: var(--size-touch-target);
  padding: var(--spacing-2) var(--spacing-4);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  text-decoration: none;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) var(--ease-default),
    border-color var(--duration-fast) var(--ease-default),
    color var(--duration-fast) var(--ease-default);
}

/* Focus - REQUIRED */
.btn:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}

/* Primary */
.btn-primary {
  background: var(--color-bg-interactive);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-bg-interactive-hover);
}

.btn-primary:active:not(:disabled) {
  background: var(--color-bg-interactive-active);
}

/* Secondary */
.btn-secondary {
  background: transparent;
  color: var(--color-bg-interactive);
  border-color: var(--color-bg-interactive);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg-interactive-subtle);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--color-text-primary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--color-bg-surface);
}

/* Danger */
.btn-danger {
  background: var(--color-status-error-border);
  color: white;
}

/* Disabled State */
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading State - REQUIRED per design system */
.btn[aria-busy="true"] {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.75s linear infinite;
}

.btn-primary[aria-busy="true"]::after {
  border-color: white;
  border-right-color: transparent;
}

.btn-secondary[aria-busy="true"]::after,
.btn-outline[aria-busy="true"]::after,
.btn-ghost[aria-busy="true"]::after {
  border-color: var(--color-text-primary);
  border-right-color: transparent;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ================================================
   ICON BUTTONS / THEME TOGGLE - Meet touch target
   ================================================ */

.theme-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--size-touch-target);
  height: var(--size-touch-target);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-surface);
  color: var(--color-text-secondary);
  cursor: pointer;
  border: none;
  transition: background-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default);
}

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

.theme-toggle svg {
  width: var(--size-icon-md);
  height: var(--size-icon-md);
  transition: transform var(--duration-normal) var(--ease-default);
}

.theme-toggle:hover svg {
  transform: rotate(15deg);
}

/* Sun/Moon icon visibility */
.theme-toggle .sun-icon {
  display: block;
}

.theme-toggle .moon-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun-icon {
    display: none;
  }

  :root:not([data-theme="light"]) .theme-toggle .moon-icon {
    display: block;
  }
}

/* ================================================
   CARDS - Per spec exactly
   ================================================ */

.card {
  display: flex;
  flex-direction: column;
  background: var(--color-bg-surface-raised);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: box-shadow var(--duration-normal) var(--ease-default);
}

/* Interactive card */
.card-interactive {
  position: relative;
}

.card-interactive:hover {
  box-shadow: var(--shadow-md);
}

/* Full-card click target */
.card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.card-link:focus-visible::after {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
}

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

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-2);
  padding: var(--spacing-4);
}

.card-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin: 0;
}

.card-description {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin: 0;
}

/* ================================================
   ARTICLE CARDS (extends .card pattern)
   ================================================ */

.article-card {
  display: flex;
  flex-direction: column;
  background-color: var(--color-bg-surface-raised);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: transform var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default);
}

.article-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

/* Full-card link target with proper focus */
.article-card-link {
  position: relative;
}

.article-card-link::after {
  content: "";
  position: absolute;
  inset: 0;
}

.article-card-link:focus-visible::after {
  outline: var(--focus-ring-width) solid var(--color-focus);
  outline-offset: var(--focus-ring-offset);
  border-radius: var(--radius-xl);
}

.article-card-image {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

.article-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--duration-slow) var(--ease-default);
}

.article-card:hover .article-card-image img {
  transform: scale(1.05);
}

/* ================================================
   CATEGORY BADGES
   ================================================ */

.category-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--spacing-1) var(--spacing-3);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-interactive-subtle);
  color: var(--color-text-link);
  transition: background-color var(--duration-fast) var(--ease-default);
}

.category-badge:hover {
  background-color: var(--color-bg-interactive);
  color: var(--color-text-inverse);
}

.category-badge.cat-ai {
  background-color: rgb(59 130 246 / 0.1);
  color: var(--color-cat-ai);
}

.category-badge.cat-ai:hover {
  background-color: var(--color-cat-ai);
  color: var(--color-text-inverse);
}

.category-badge.cat-ml {
  background-color: rgb(139 92 246 / 0.1);
  color: var(--color-cat-ml);
}

.category-badge.cat-ml:hover {
  background-color: var(--color-cat-ml);
  color: var(--color-text-inverse);
}

.category-badge.cat-tech {
  background-color: rgb(6 182 212 / 0.1);
  color: var(--color-cat-tech);
}

.category-badge.cat-tech:hover {
  background-color: var(--color-cat-tech);
  color: var(--color-text-inverse);
}

/* ================================================
   HERO CARD
   ================================================ */

.hero-card {
  position: relative;
  border-radius: var(--radius-3xl);
  overflow: hidden;
  aspect-ratio: 16 / 9;
}

@media (min-width: 768px) {
  .hero-card {
    aspect-ratio: 21 / 9;
  }
}

.hero-card-overlay {
  position: absolute;
  inset: 0;
  /* Use slate-900 instead of pure black to avoid halation */
  background: linear-gradient(to top, rgb(15 23 42 / 0.9) 0%, rgb(15 23 42 / 0.5) 50%, transparent 100%);
}

.hero-card-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--spacing-6);
  color: white;
}

/* All text inside hero must be white for contrast */
.hero-card-content,
.hero-card-content a,
.hero-card-content h1,
.hero-card-content h2,
.hero-card-content h3,
.hero-card-content p,
.hero-card-content span {
  color: white !important;
}

.hero-card-content a:hover {
  opacity: 0.9;
}

/* Category badge inside hero - white bg, dark text for contrast */
.hero-card-content .category-badge {
  background-color: rgba(255, 255, 255, 0.2) !important;
  color: white !important;
  backdrop-filter: blur(4px);
}

.hero-card-content .category-badge:hover {
  background-color: rgba(255, 255, 255, 0.3) !important;
}

@media (min-width: 768px) {
  .hero-card-content {
    padding: var(--spacing-10);
    max-width: 70%;
  }
}

/* ================================================
   ARTICLE CONTENT - Long-form reading
   ================================================ */

.article-content {
  max-width: var(--content-width);
  margin: 0 auto;
}

.article-content h1,
.article-content h2,
.article-content h3,
.article-content h4,
.article-content h5,
.article-content h6 {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-bold);
}

.article-content h2 {
  font-size: var(--font-size-2xl);
  margin-top: var(--spacing-10);
  margin-bottom: var(--spacing-4);
}

.article-content h3 {
  font-size: var(--font-size-xl);
  margin-top: var(--spacing-8);
  margin-bottom: var(--spacing-3);
}

.article-content p {
  font-size: var(--font-size-base);
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--spacing-6);
  color: var(--color-text-secondary);
}

.article-content a {
  color: var(--color-text-link);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.article-content a:hover {
  color: var(--color-text-link-hover);
}

.article-content blockquote {
  border-left: 4px solid var(--color-bg-interactive);
  padding-left: var(--spacing-6);
  margin: var(--spacing-8) 0;
  font-style: italic;
  color: var(--color-text-secondary);
}

.article-content pre {
  background-color: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-6);
  overflow-x: auto;
  margin: var(--spacing-8) 0;
}

.article-content code {
  font-family: var(--font-family-mono);
  font-size: 0.875em;
}

.article-content img {
  border-radius: var(--radius-lg);
  margin: var(--spacing-8) 0;
}

.article-content ul,
.article-content ol {
  margin: var(--spacing-6) 0;
  padding-left: var(--spacing-6);
}

.article-content li {
  margin-bottom: var(--spacing-2);
  color: var(--color-text-secondary);
}

/* Reading Progress */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: var(--gradient-brand);
  z-index: 100;
  width: 0%;
  transition: width 50ms linear;
}

/* ================================================
   SHARE BUTTONS
   ================================================ */

.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--size-touch-target);
  height: var(--size-touch-target);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-surface);
  color: var(--color-text-secondary);
  transition: background-color var(--duration-fast) var(--ease-default),
              color var(--duration-fast) var(--ease-default),
              transform var(--duration-fast) var(--ease-default);
}

.share-btn:hover {
  background-color: var(--color-bg-interactive);
  color: var(--color-text-inverse);
  transform: translateY(-2px);
}

/* ================================================
   FOOTER
   ================================================ */

.site-footer {
  background-color: var(--color-bg-surface);
  border-top: 1px solid var(--color-border-default);
  margin-top: var(--spacing-16);
}

/* Newsletter Section */
.footer-newsletter {
  background: var(--gradient-brand);
  border-radius: var(--radius-3xl);
  padding: var(--spacing-8);
  text-align: center;
  color: var(--color-text-inverse);
}

@media (min-width: 768px) {
  .footer-newsletter {
    padding: var(--spacing-12);
  }
}

.newsletter-input {
  width: 100%;
  height: var(--size-input-md);
  padding: var(--spacing-3) var(--spacing-4);
  border-radius: var(--radius-lg);
  border: 2px solid transparent;
  background-color: rgb(255 255 255 / 0.2);
  color: var(--color-text-inverse);
  font-size: var(--font-size-base);
  transition: background-color var(--duration-fast) var(--ease-default),
              border-color var(--duration-fast) var(--ease-default);
}

.newsletter-input::placeholder {
  color: rgb(255 255 255 / 0.7);
}

.newsletter-input:focus {
  outline: none;
  background-color: rgb(255 255 255 / 0.3);
  border-color: rgb(255 255 255 / 0.5);
}

/* ================================================
   SEARCH MODAL
   ================================================ */

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 10vh var(--spacing-4);
  background-color: var(--color-bg-overlay);
  backdrop-filter: blur(4px);
}

.search-modal.open {
  display: flex;
}

.search-modal-content {
  width: 100%;
  max-width: 600px;
  background-color: var(--color-bg-surface-raised);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: var(--spacing-4);
  padding: var(--spacing-4) var(--spacing-6);
  border-bottom: 1px solid var(--color-border-default);
}

.search-input {
  flex: 1;
  height: var(--size-input-md);
  border: none;
  background: transparent;
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
}

.search-input:focus {
  outline: none;
}

.search-input::placeholder {
  color: var(--color-text-muted);
}

/* ================================================
   FORMS - Accessible inputs
   ================================================ */

.form-field {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-1);
}

.form-label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-text-primary);
}

.form-label-required::after {
  content: " *";
  color: var(--color-status-error-text);
}

.form-input {
  height: var(--size-input-md);
  padding: var(--spacing-2) var(--spacing-3);
  font-family: inherit;
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background: var(--color-bg-page);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  transition: border-color var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}

.form-input:focus-visible {
  outline: none;
  border-color: var(--color-focus);
  box-shadow: var(--shadow-focus);
}

.form-input[aria-invalid="true"] {
  border-color: var(--color-status-error-border);
}

.form-input[aria-invalid="true"]:focus-visible {
  box-shadow: var(--shadow-focus-error);
}

.form-input::placeholder {
  color: var(--color-text-muted);
}

.form-error {
  display: flex;
  align-items: center;
  gap: var(--spacing-1);
  font-size: var(--font-size-sm);
  color: var(--color-status-error-text);
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

/* ================================================
   ALERTS - Never use color alone
   ================================================ */

.alert {
  display: flex;
  gap: var(--spacing-3);
  padding: var(--spacing-4);
  border-radius: var(--radius-md);
  border-left: 4px solid;
}

.alert-icon {
  flex-shrink: 0;
  width: var(--size-icon-lg);
  height: var(--size-icon-lg);
}

.alert-content {
  flex: 1;
}

.alert-title {
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--spacing-1);
}

.alert-description {
  font-size: var(--font-size-sm);
}

.alert-error {
  background-color: var(--color-status-error-bg);
  border-color: var(--color-status-error-border);
  color: var(--color-status-error-text);
}

.alert-success {
  background-color: var(--color-status-success-bg);
  border-color: var(--color-status-success-border);
  color: var(--color-status-success-text);
}

.alert-warning {
  background-color: var(--color-status-warning-bg);
  border-color: var(--color-status-warning-border);
  color: var(--color-status-warning-text);
}

.alert-info {
  background-color: var(--color-status-info-bg);
  border-color: var(--color-status-info-border);
  color: var(--color-status-info-text);
}

/* ================================================
   UTILITIES
   ================================================ */

.skeleton {
  background: linear-gradient(90deg,
    var(--color-bg-surface) 25%,
    var(--color-bg-surface-sunken) 50%,
    var(--color-bg-surface) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.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;
}

.aspect-video {
  aspect-ratio: 16 / 9;
}

.aspect-card {
  aspect-ratio: 3 / 2;
}

/* Visually hidden utility (for screen readers) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Animations */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-fade-in {
  animation: fade-in var(--duration-slow) var(--ease-out) forwards;
}

@keyframes slide-in-right {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.animate-slide-in {
  animation: slide-in-right var(--duration-slow) var(--ease-out) forwards;
}

/* ================================================
   WORDPRESS BLOCK STYLES
   ================================================ */

.wp-block-image img {
  border-radius: var(--radius-lg);
}

.wp-block-quote {
  border-left: 4px solid var(--color-bg-interactive);
  padding-left: var(--spacing-6);
  font-style: italic;
}

.wp-block-code {
  background-color: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--spacing-6);
}

.wp-block-separator {
  border-color: var(--color-border-default);
}

/* ================================================
   FOOTER LINKS
   ================================================ */

.footer-link {
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-default);
}

.footer-link:hover {
  color: var(--color-text-link) !important;
}

/* ================================================
   PWA - NATIVE APP EXPERIENCE
   Per FRONTEND_03_PWA_NATIVE_EXPERIENCE.md
   ================================================ */

/* Safe Area Insets for Notched Devices */
@supports (padding: env(safe-area-inset-top)) {
  .site-header {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .site-footer {
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .mobile-nav {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* Native Feel - Disable Browser Defaults */
html {
  /* Prevent pull-to-refresh on overscroll */
  overscroll-behavior-y: contain;
  /* Prevent text selection on double-tap */
  -webkit-user-select: none;
  user-select: none;
}

/* Allow text selection in content areas */
.article-content,
.prose,
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* Remove tap highlight on mobile */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Smooth momentum scrolling */
.mobile-nav,
.search-modal-content {
  -webkit-overflow-scrolling: touch;
}

/* ================================================
   PWA Install Banner
   ================================================ */

.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  padding: var(--spacing-4);
  padding-bottom: calc(var(--spacing-4) + env(safe-area-inset-bottom, 0px));
  background-color: var(--color-bg-surface-raised);
  border-top: 1px solid var(--color-border-default);
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform var(--duration-normal) var(--ease-out);
}

.install-banner.show {
  transform: translateY(0);
}

.install-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-4);
  max-width: var(--container-max);
  margin: 0 auto;
}

.install-banner-text {
  flex: 1;
}

.install-banner-text strong {
  display: block;
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.install-banner-text p {
  margin: var(--spacing-1) 0 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.install-banner-actions {
  display: flex;
  gap: var(--spacing-2);
  flex-shrink: 0;
}

/* Small button variant for install banner */
.btn-sm {
  min-height: var(--size-button-sm);
  padding: var(--spacing-1) var(--spacing-3);
  font-size: var(--font-size-xs);
}

/* ================================================
   Offline Indicator
   ================================================ */

.offline-indicator {
  position: fixed;
  bottom: var(--spacing-4);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  z-index: 200;
  padding: var(--spacing-3) var(--spacing-6);
  background-color: var(--color-status-warning-bg);
  color: var(--color-status-warning-text);
  border: 1px solid var(--color-status-warning-border);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-lg);
  transition: transform var(--duration-normal) var(--ease-out);
}

.offline-indicator.show {
  transform: translateX(-50%) translateY(0);
}

/* ================================================
   PWA Standalone Mode Adjustments
   ================================================ */

@media (display-mode: standalone) {
  /* Hide browser-specific elements in standalone mode */
  .install-banner {
    display: none;
  }

  /* Adjust header for standalone */
  .site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }

  /* Add padding to body to account for fixed header */
  body {
    padding-top: calc(60px + env(safe-area-inset-top, 0px));
  }
}

/* Also apply for fullscreen and minimal-ui modes */
@media (display-mode: fullscreen), (display-mode: minimal-ui) {
  .install-banner {
    display: none;
  }
}

/* ================================================
   Touch Interactions Enhancement
   ================================================ */

/* Active state feedback for touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn:active:not(:disabled) {
    transform: scale(0.97);
    transition: transform 0.1s ease;
  }

  .article-card:active {
    transform: translateY(-2px);
  }

  .share-btn:active {
    transform: translateY(-1px);
  }
}

/* ================================================
   Loading States for PWA
   ================================================ */

/* Page transition loading indicator */
.page-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-brand);
  transform: scaleX(0);
  transform-origin: left;
  z-index: 300;
}

.page-loading.active {
  animation: page-load 2s ease-out forwards;
}

@keyframes page-load {
  0% { transform: scaleX(0); }
  50% { transform: scaleX(0.7); }
  100% { transform: scaleX(1); }
}

/* ================================================
   Print Styles - Accessible printing
   ================================================ */

@media print {
  .site-header,
  .site-footer,
  .mobile-nav,
  .search-modal,
  .share-btn,
  .install-banner,
  .offline-indicator,
  .reading-progress,
  .skip-link {
    display: none !important;
  }

  body {
    background: white;
    color: black;
    font-size: 12pt;
    line-height: 1.5;
  }

  a {
    color: black;
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
  }

  .article-content {
    max-width: 100%;
  }
}

/* ================================================
   UTILITY CLASSES
   Replaces Tailwind utilities for templates
   ================================================ */

/* Display */
.hidden { display: none; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.inline-flex { display: inline-flex; }

/* Positioning */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.inset-0 { inset: 0; }
.top-0 { top: 0; }
.right-0 { right: 0; }
.bottom-0 { bottom: 0; }
.left-0 { left: 0; }
.z-10 { z-index: 10; }
.z-20 { z-index: 20; }
.z-50 { z-index: 50; }

/* Flexbox */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-shrink-0 { flex-shrink: 0; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }

/* Gap */
.gap-1 { gap: var(--spacing-1); }
.gap-2 { gap: var(--spacing-2); }
.gap-3 { gap: var(--spacing-3); }
.gap-4 { gap: var(--spacing-4); }
.gap-6 { gap: var(--spacing-6); }
.gap-8 { gap: var(--spacing-8); }

/* Width/Height */
.w-5 { width: 1.25rem; }
.w-6 { width: 1.5rem; }
.w-12 { width: 3rem; }
.w-full { width: 100%; }
.h-5 { height: 1.25rem; }
.h-6 { height: 1.5rem; }
.h-12 { height: 3rem; }
.h-16 { height: 4rem; }
.h-full { height: 100%; }
.max-w-xs { max-width: 20rem; }
.max-w-2xl { max-width: 42rem; }

/* Object Fit */
.object-cover { object-fit: cover; }
.object-contain { object-fit: contain; }

/* Padding */
.p-4 { padding: var(--spacing-4); }
.px-2 { padding-left: var(--spacing-2); padding-right: var(--spacing-2); }
.py-1 { padding-top: var(--spacing-1); padding-bottom: var(--spacing-1); }
.py-4 { padding-top: var(--spacing-4); padding-bottom: var(--spacing-4); }

/* Margin */
.mb-4 { margin-bottom: var(--spacing-4); }
.mb-6 { margin-bottom: var(--spacing-6); }
.mb-8 { margin-bottom: var(--spacing-8); }
.my-6 { margin-top: var(--spacing-6); margin-bottom: var(--spacing-6); }

/* Typography */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }
.text-center { text-align: center; }
.font-bold { font-weight: var(--font-weight-bold); }
.font-semibold { font-weight: var(--font-weight-semibold); }

/* Border */
.rounded { border-radius: var(--radius-md); }

/* Responsive - Mobile first */
@media (min-width: 640px) {
  .sm\:inline { display: inline; }
}

@media (min-width: 768px) {
  .md\:flex { display: flex; }
  .md\:inline-flex { display: inline-flex; }
  .md\:hidden { display: none; }
  .md\:h-20 { height: 5rem; }
  .md\:text-2xl { font-size: var(--font-size-2xl); }
  .md\:gap-3 { gap: var(--spacing-3); }
}

/* ================================================
   VIEW TRANSITIONS (Navigation API)
   Enables smooth page transitions for enhanced UX
   ================================================ */
@view-transition {
  navigation: auto;
}

/* Default cross-fade for all elements */
::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: var(--duration-normal);
  animation-timing-function: var(--ease-default);
}

/* Preserve header during page transitions */
.site-header {
  view-transition-name: header;
}

::view-transition-old(header),
::view-transition-new(header) {
  animation: none;
  mix-blend-mode: normal;
}

/* Article cards slide in for same-origin navigations */
.article-card {
  view-transition-name: var(--card-transition-name, none);
}

/* ================================================
   CONTAINER QUERIES
   Component-based responsive design
   ================================================ */

/* Article card container */
.article-card-container {
  container-type: inline-size;
  container-name: article-card;
}

/* Card layout adapts to container width */
@container article-card (min-width: 400px) {
  .article-card {
    flex-direction: row;
    gap: var(--spacing-4);
  }

  .article-card .card-image {
    flex: 0 0 40%;
    aspect-ratio: 4 / 3;
  }

  .article-card .card-content {
    flex: 1;
    padding: var(--spacing-4);
  }
}

@container article-card (max-width: 399px) {
  .article-card {
    flex-direction: column;
  }

  .article-card .card-image {
    aspect-ratio: 16 / 9;
  }
}

/* Grid container for sidebar widgets */
.sidebar-container {
  container-type: inline-size;
  container-name: sidebar;
}

@container sidebar (min-width: 300px) {
  .widget-posts-list {
    display: grid;
    gap: var(--spacing-4);
  }
}

/* ================================================
   SCROLL-DRIVEN ANIMATIONS (Progressive Enhancement)
   ================================================ */
@supports (animation-timeline: scroll()) {
  /* Reading progress indicator */
  .reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-ai);
    transform-origin: left;
    animation: progress-grow linear;
    animation-timeline: scroll();
    z-index: 1001;
  }

  @keyframes progress-grow {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }

  /* Fade-in on scroll for article cards */
  @keyframes fade-in-up {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .animate-on-scroll {
    animation: fade-in-up linear both;
    animation-timeline: view();
    animation-range: entry 0% entry 100%;
  }
}

/* ================================================
   :has() SELECTOR - Content-Aware Styling
   ================================================ */

/* Article cards with images get different styling */
.article-card:has(img) {
  overflow: hidden;
}

/* Cards without images show larger text */
.article-card:not(:has(img)) h3 {
  font-size: var(--font-size-xl);
}

/* Form groups with invalid inputs */
.form-group:has(input:invalid) {
  border-color: var(--color-status-error);
}

/* Navigation with active link gets indicator */
nav:has(.active) .active {
  color: var(--color-accent);
}

/* Section with no meaningful content - only hide truly empty sections */
section:empty {
  display: none;
}

/* ================================================
   @scope - Widget Isolation
   Prevents style leakage in widgets
   ================================================ */
@scope (.widget) to (.widget-content) {
  :scope {
    background: var(--color-bg-surface);
    border-radius: var(--radius-lg);
    padding: var(--spacing-4);
  }

  h3 {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    margin-bottom: var(--spacing-3);
    color: var(--color-text-primary);
  }

  ul {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-2);
  }

  a {
    color: var(--color-text-secondary);
    transition: color var(--duration-fast);
  }

  a:hover {
    color: var(--color-accent);
  }
}

@scope (.newsletter-widget) {
  :scope {
    background: var(--gradient-brand);
    color: white;
  }

  input {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
  }

  input::placeholder {
    color: rgba(255, 255, 255, 0.7);
  }
}

/* ================================================
   light-dark() Function - Theme Switching
   Automatic value selection based on color-scheme
   ================================================ */
:root {
  color-scheme: light dark;
}

/* Elements using light-dark() for automatic theming */
.auto-theme-border {
  border-color: light-dark(var(--primitive-slate-200), var(--primitive-slate-700));
}

.auto-theme-shadow {
  box-shadow: 0 4px 6px light-dark(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.4));
}

.auto-theme-text {
  color: light-dark(var(--primitive-slate-700), var(--primitive-slate-300));
}

/* ================================================
   CSS Nesting (Relaxed Syntax)
   Modern nested selectors for maintainability
   ================================================ */
.article-detail {
  max-width: 65ch;
  margin: 0 auto;

  & header {
    margin-bottom: var(--spacing-8);

    & h1 {
      font-size: var(--font-size-4xl);
      line-height: var(--line-height-tight);
      margin-bottom: var(--spacing-4);
    }

    & .meta {
      display: flex;
      gap: var(--spacing-4);
      color: var(--color-text-muted);
      font-size: var(--font-size-sm);
    }
  }

  & .content {
    & p {
      margin-bottom: var(--spacing-4);
      line-height: var(--line-height-relaxed);
    }

    & h2 {
      font-size: var(--font-size-2xl);
      font-weight: var(--font-weight-bold);
      margin-top: var(--spacing-8);
      margin-bottom: var(--spacing-4);
    }

    & h3 {
      font-size: var(--font-size-xl);
      font-weight: var(--font-weight-semibold);
      margin-top: var(--spacing-6);
      margin-bottom: var(--spacing-3);
    }

    & blockquote {
      border-left: 4px solid var(--color-accent);
      padding-left: var(--spacing-4);
      margin: var(--spacing-6) 0;
      font-style: italic;
      color: var(--color-text-secondary);
    }

    & ul, & ol {
      margin: var(--spacing-4) 0;
      padding-left: var(--spacing-6);

      & li {
        margin-bottom: var(--spacing-2);
      }
    }

    & ul {
      list-style: disc;
    }

    & ol {
      list-style: decimal;
    }

    & pre {
      background: var(--color-bg-surface-sunken);
      padding: var(--spacing-4);
      border-radius: var(--radius-md);
      overflow-x: auto;
      margin: var(--spacing-4) 0;

      & code {
        font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
        font-size: var(--font-size-sm);
      }
    }

    & figure {
      margin: var(--spacing-6) 0;

      & img {
        border-radius: var(--radius-lg);
      }

      & figcaption {
        text-align: center;
        font-size: var(--font-size-sm);
        color: var(--color-text-muted);
        margin-top: var(--spacing-2);
      }
    }
  }
}

/* ================================================
   TRANSNATIONALNEWS.COM - 2026 DESIGN OVERHAUL
   Visual polish, micro-interactions, modern aesthetics
   ================================================ */

/* ================================================
   ENHANCED DARK MODE - Richer, More Depth
   ================================================ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --color-bg-page: #000000;
    --color-bg-surface: #0a0f1c;
    --color-bg-surface-raised: #111827;
    --color-bg-surface-sunken: #030712;
    --color-border-default: rgba(148, 163, 184, 0.1);
    --color-border-strong: rgba(148, 163, 184, 0.2);
  }
}

[data-theme="dark"] {
  --color-bg-page: #000000;
  --color-bg-surface: #0a0f1c;
  --color-bg-surface-raised: #111827;
  --color-bg-surface-sunken: #030712;
  --color-border-default: rgba(148, 163, 184, 0.1);
  --color-border-strong: rgba(148, 163, 184, 0.2);
}

/* ================================================
   ENHANCED TYPOGRAPHY - More Dramatic Scale
   ================================================ */
h1 { letter-spacing: -0.03em; }
h2 { letter-spacing: -0.025em; }

.hero-card h2 {
  letter-spacing: -0.04em;
  font-weight: 800;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.3);
}

/* ================================================
   ELEVATED HEADER - Glassmorphism
   ================================================ */
.site-header {
  background-color: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .site-header,
:root:not([data-theme="light"]) .site-header {
  background-color: rgba(10, 15, 28, 0.8);
  border-bottom-color: rgba(148, 163, 184, 0.1);
}

.site-header.scrolled {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  background-color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .site-header.scrolled {
  background-color: rgba(10, 15, 28, 0.95);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* ================================================
   HERO SECTION - Premium Treatment
   ================================================ */
.hero-card {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  transition: transform var(--duration-slow) var(--ease-default),
              box-shadow var(--duration-slow) var(--ease-default);
}

.hero-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.35);
}

.hero-card-overlay {
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.95) 0%,
    rgba(0, 0, 0, 0.7) 30%,
    rgba(0, 0, 0, 0.4) 60%,
    rgba(0, 0, 0, 0.1) 85%,
    transparent 100%
  );
}

/* Animated gradient fallback */
.hero-gradient-fallback,
.hero-card .bg-gradient-to-br {
  background: linear-gradient(
    135deg,
    #667eea 0%,
    #764ba2 25%,
    #f093fb 50%,
    #4facfe 75%,
    #00f2fe 100%
  );
  background-size: 200% 200%;
  animation: gradient-shift 15s ease infinite;
}

@keyframes gradient-shift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

.hero-card-content {
  animation: hero-fade-in 1s var(--ease-out) 0.3s backwards;
}

@keyframes hero-fade-in {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ================================================
   ARTICLE CARDS - Elevated, Premium Look
   ================================================ */
.article-card {
  background-color: var(--color-bg-surface-raised);
  border: 1px solid var(--color-border-default);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: transform var(--duration-normal) var(--ease-default),
              box-shadow var(--duration-normal) var(--ease-default),
              border-color var(--duration-normal) var(--ease-default);
  position: relative;
  overflow: hidden;
}

.article-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  border-color: var(--color-border-strong);
}

[data-theme="dark"] .article-card:hover {
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.article-card-image::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  transition: background var(--duration-normal) var(--ease-default);
}

.article-card:hover .article-card-image::after {
  background: rgba(0, 0, 0, 0.1);
}

.article-card-image img {
  transition: transform var(--duration-slow) var(--ease-default);
}

.article-card:hover .article-card-image img {
  transform: scale(1.08);
}

/* Card gradient fallback */
.article-card-image .w-full.h-full[style*="background"] {
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #06b6d4 100%) !important;
}

/* ================================================
   CATEGORY BADGES - More Refined
   ================================================ */
.category-badge {
  padding: var(--spacing-1) var(--spacing-3);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all var(--duration-fast) var(--ease-default);
}

.category-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* ================================================
   NEWSLETTER SECTION - Elegant, Not Garish
   ================================================ */
.footer-newsletter {
  background: linear-gradient(135deg,
    rgba(59, 130, 246, 0.95) 0%,
    rgba(139, 92, 246, 0.95) 50%,
    rgba(6, 182, 212, 0.95) 100%
  );
  position: relative;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(59, 130, 246, 0.3);
  border-radius: var(--radius-2xl);
  padding: var(--spacing-12) var(--spacing-6);
  text-align: center;
  color: white;
}

.footer-newsletter::before {
  content: "";
  position: absolute;
  inset: -50%;
  background: radial-gradient(circle at 30% 50%, rgba(255, 255, 255, 0.15) 0%, transparent 50%),
              radial-gradient(circle at 70% 50%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
  animation: mesh-move 20s ease-in-out infinite;
  pointer-events: none;
}

@keyframes mesh-move {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  50% { transform: translate(10%, 10%) rotate(180deg); }
}

/* Newsletter Input Styling */
.newsletter-input {
  background-color: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-md);
  padding: var(--spacing-3) var(--spacing-4);
  color: white;
  font-size: var(--font-size-base);
  min-height: var(--size-touch-target);
  transition: all var(--duration-fast) var(--ease-default);
}

.newsletter-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.newsletter-input:focus {
  outline: none;
  background-color: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.15);
}

/* ================================================
   BUTTON ENHANCEMENTS - More Tactile
   ================================================ */
.btn-primary {
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  transition: all var(--duration-fast) var(--ease-default);
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
  transform: translateY(-2px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

/* ================================================
   NAVIGATION ENHANCEMENTS
   ================================================ */
.nav-link {
  position: relative;
  font-weight: 500;
}

.nav-link::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--gradient-brand);
  transition: width var(--duration-normal) var(--ease-default),
              left var(--duration-normal) var(--ease-default);
}

.nav-link:hover::after,
.nav-link[aria-current="page"]::after {
  width: 100%;
  left: 0;
}

/* ================================================
   THEME TOGGLE - More Delightful
   ================================================ */
.theme-toggle {
  backdrop-filter: blur(8px);
  transition: all var(--duration-normal) var(--ease-default);
}

.theme-toggle:hover {
  transform: rotate(15deg) scale(1.05);
}

/* ================================================
   FOOTER REFINEMENT
   ================================================ */
.site-footer {
  background: linear-gradient(to bottom,
    var(--color-bg-page) 0%,
    var(--color-bg-surface) 100%
  );
  border-top: 1px solid var(--color-border-default);
}

.footer-link {
  position: relative;
  display: inline-block;
}

.footer-link::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 1px;
  background: var(--color-text-link);
  transition: width var(--duration-normal) var(--ease-default);
}

.footer-link:hover::after {
  width: 100%;
}

/* ================================================
   SCROLL ANIMATIONS - Progressive Enhancement
   ================================================ */
@media (prefers-reduced-motion: no-preference) {
  .article-card {
    animation: card-fade-in 0.6s var(--ease-out) backwards;
  }

  @keyframes card-fade-in {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .grid .article-card:nth-child(1) { animation-delay: 0ms; }
  .grid .article-card:nth-child(2) { animation-delay: 100ms; }
  .grid .article-card:nth-child(3) { animation-delay: 200ms; }
  .grid .article-card:nth-child(4) { animation-delay: 300ms; }
  .grid .article-card:nth-child(5) { animation-delay: 400ms; }
  .grid .article-card:nth-child(6) { animation-delay: 500ms; }
}

/* ================================================
   GLASSMORPHISM UTILITIES
   ================================================ */
.backdrop-blur-sm { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.backdrop-blur-md { backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.backdrop-blur-lg { backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }

.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.shadow-glow {
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

/* ================================================
   SEARCH MODAL - Glassmorphism
   ================================================ */
.search-modal {
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  background-color: rgba(0, 0, 0, 0.7);
}

.search-modal-content {
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--color-border-default);
}

/* ================================================
   MOBILE NAV - Smoother
   ================================================ */
.mobile-nav {
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.mobile-nav-link:hover {
  transform: translateX(8px);
  color: var(--color-text-link);
}

/* ================================================
   RESPONSIVE REFINEMENTS
   ================================================ */
@media (max-width: 767px) {
  .article-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  }
}

@media (min-width: 768px) {
  .article-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius-xl);
    opacity: 0;
    background: linear-gradient(135deg,
      rgba(59, 130, 246, 0.05) 0%,
      rgba(139, 92, 246, 0.05) 100%
    );
    transition: opacity var(--duration-normal) var(--ease-default);
    pointer-events: none;
    z-index: 1;
  }

  .article-card:hover::before {
    opacity: 1;
  }
}
