@tailwind base;
@tailwind components;
@tailwind utilities;

/* Dark theme (default) - CSS custom properties */
:root {
  --bg: #060b10;
  --bg2: #0c1520;
  --bg2-rgb: 12, 21, 32;
  --surface: #101e2d;
  --surface-rgb: 16, 30, 45;
  --border: #182840;
  --accent: #a855f7;
  --accent2: #00ff88;
  --accent-glow: rgba(168, 85, 247, 0.12);
  --text: #c4d6e8;
  --text-dim: #7a9bb8;
  --muted: #304860;
  /* Article type colors - dark */
  --type-tech: #a855f7;
  --type-life: #f59e0b;
  --type-quote: #00ff88;
  --type-link: #38bdf8;
  --type-photo: #ec4899;
}

/* Light theme overrides */
html.theme-light {
  --bg: #ffffff;
  --bg2: #f8f9fa;
  --bg2-rgb: 248, 249, 250;
  --surface: #f0f3f7;
  --surface-rgb: 240, 243, 247;
  --border: #d9dfe8;
  --accent: #9333ea;
  --accent2: #10b981;
  --accent-glow: rgba(147, 51, 234, 0.1);
  --text: #1f2937;
  --text-dim: #374151;
  --muted: #d1d5db;
  /* Article type colors - light */
  --type-tech: #7c3aed;
  --type-life: #d97706;
  --type-quote: #008f5a;
  --type-link: #0284c7;
  --type-photo: #be185d;
}

/* No-JS fallback: prefers-color-scheme light */
@media (prefers-color-scheme: light) {
  html:not(.theme-dark) {
    --bg: #ffffff;
    --bg2: #f8f9fa;
    --bg2-rgb: 248, 249, 250;
    --surface: #f0f3f7;
    --surface-rgb: 240, 243, 247;
    --border: #d9dfe8;
    --accent: #9333ea;
    --accent2: #10b981;
    --accent-glow: rgba(147, 51, 234, 0.1);
    --text: #1f2937;
    --text-dim: #374151;
    --muted: #d1d5db;
    --type-tech: #7c3aed;
    --type-life: #d97706;
    --type-quote: #008f5a;
    --type-link: #0284c7;
    --type-photo: #be185d;
  }
}

@layer base {
  body {
    @apply bg-bg text-text font-body;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    @apply font-bold;
    font-family: 'Oxanium', monospace;
  }

  h1 {
    @apply text-3xl md:text-4xl;
  }

  h2 {
    @apply text-2xl md:text-3xl;
  }

  h3 {
    @apply text-xl md:text-2xl;
  }

  a {
    @apply text-accent hover:opacity-80 transition-opacity;
  }

  code {
    @apply font-mono bg-surface border border-border px-1.5 py-0.5 rounded text-accent2;
  }

  pre {
    background-color: rgba(var(--surface-rgb), 0.8);
    @apply p-4 rounded border border-border overflow-x-auto;
  }

  pre code {
    @apply bg-transparent border-0 p-0 text-text;
  }

  *:focus-visible {
    @apply ring-2 ring-accent ring-offset-2;
    ring-offset-color: var(--bg);
  }

  button,
  input,
  textarea,
  select {
    @apply transition-colors duration-200;
  }
}

@layer components {
  .container {
    @apply max-w-4xl mx-auto;
  }

  /* Background utilities */
  .bg-bg {
    background-color: var(--bg);
  }

  .bg-bg2 {
    background-color: var(--bg2);
  }

  .bg-surface {
    background-color: var(--surface);
  }

  /* Border utilities */
  .border-border {
    border-color: var(--border);
  }

  /* Text color utilities */
  .text-accent {
    color: var(--accent);
  }

  .text-accent2 {
    color: var(--accent2);
  }

  .text-text {
    color: var(--text);
  }

  .text-text-dim {
    color: var(--text-dim);
  }

  /* Additional semantic utilities */
  .text-muted {
    color: var(--muted);
  }

  .bg-muted {
    background-color: var(--muted);
  }

  /* Glow effect utility */
  .glow-accent {
    box-shadow: 0 0 20px var(--accent-glow);
  }

  /* Frosted glass bar (header/footer) */
  .frosted-bar {
    background-color: rgba(var(--bg2-rgb), 0.75);
    backdrop-filter: blur(10px);
    box-shadow: 0 0 20px var(--accent-glow);
    /* border applied via utility classes in templates */
  }

  /* Border utilities for frosted-bar component */
  .frosted-bar.border-b,
  .frosted-bar.border-t {
    border-color: var(--border);
  }

  /* Article type badge styles */
  .type-tech {
    color: var(--type-tech);
    background-color: rgba(168, 85, 247, 0.1);
  }

  .type-life {
    color: var(--type-life);
    background-color: rgba(245, 158, 11, 0.1);
  }

  .type-quote {
    color: var(--type-quote);
    background-color: rgba(0, 255, 136, 0.1);
  }

  .type-link {
    color: var(--type-link);
    background-color: rgba(56, 189, 248, 0.1);
  }

  .type-photo {
    color: var(--type-photo);
    background-color: rgba(236, 72, 153, 0.1);
  }

  /* Hero typography with fluid sizing */
  .hero-title {
    font-size: clamp(2rem, 5vw + 1rem, 4.5rem);
  }

  .section-title {
    font-size: clamp(1.5rem, 3vw + 0.5rem, 2.5rem);
  }
}

/* Prose overrides for light theme */
html.theme-light .prose,
html.theme-light .prose-invert {
  color: var(--text);
}

html.theme-light .prose a,
html.theme-light .prose-invert a {
  color: var(--accent);
}

html.theme-light .prose strong,
html.theme-light .prose-invert strong {
  color: var(--text);
}

html.theme-light .prose code,
html.theme-light .prose-invert code {
  color: var(--accent2);
}

html.theme-light .prose pre,
html.theme-light .prose-invert pre {
  background-color: var(--surface);
  color: var(--text);
}

html.theme-light .prose h1,
html.theme-light .prose h2,
html.theme-light .prose h3,
html.theme-light .prose h4,
html.theme-light .prose h5,
html.theme-light .prose h6,
html.theme-light .prose-invert h1,
html.theme-light .prose-invert h2,
html.theme-light .prose-invert h3,
html.theme-light .prose-invert h4,
html.theme-light .prose-invert h5,
html.theme-light .prose-invert h6 {
  color: var(--text);
}

html.theme-light .prose blockquote,
html.theme-light .prose-invert blockquote {
  color: var(--text);
  border-left-color: var(--accent);
}

/* Responsive container utilities - mobile-first */
.container {
  @apply max-w-full px-4;
}

@media (min-width: 768px) {
  .container {
    @apply max-w-4xl px-6;
  }
}

@media (min-width: 1060px) {
  .container {
    @apply max-w-5xl px-8;
  }
}

/* Respect user's motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Matrix rain canvas background */
#matrix-rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

/* Dark theme: 13% opacity (inner pages) */
html.theme-dark #matrix-rain {
  opacity: 0.13;
}

/* Light theme: 18% opacity (inner pages) */
html.theme-light #matrix-rain {
  opacity: 0.18;
}

/* Homepage: more prominent background */
html.theme-dark body[data-page-kind="home"] #matrix-rain {
  opacity: 0.28;
}

html.theme-light body[data-page-kind="home"] #matrix-rain {
  opacity: 0.35;
}

/* Reduced motion: hide canvas entirely */
@media (prefers-reduced-motion: reduce) {
  #matrix-rain {
    display: none;
  }
}

/* Content grid background — blocks rain under text, visible in gutters (single pages only) */
.grid.md\:grid-cols-3.gap-8.max-w-7xl.content-grid {
  position: relative;
  z-index: 10;
  background-color: var(--bg);
  padding: 2rem;
  border: 1px solid var(--border);
  box-shadow: 0 0 20px var(--accent-glow);
}

/* Article list items — soft glow effect */
article.border.border-border\/30.rounded-lg.overflow-hidden.group.bg-bg {
  border-color: var(--border);
  box-shadow: 0 0 20px var(--accent-glow);
}
