@font-face {
  font-family: 'Inter';
  src: url('/fonts/inter-latin-variable.woff2') format('woff2');
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/fonts/jetbrains-mono-latin-variable.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

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

@layer base {
  :root {
    color-scheme: dark;

    /* ── Apple dark system palette (default) ─────────────── */
    /* bumped off pure black to avoid halos on OLED-ish displays */
    --bg-system: #101012;
    --bg-elevated: #1C1C1F;
    --bg-raised: #2A2A2E;
    --bg-surface: #3A3A3D;
    --bg-inset: #0C0C0E;
    --dock-bg: rgba(28, 28, 31, 0.68);
    --dock-bg-mobile: rgba(28, 28, 31, 0.36);

    --fill-primary: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.24);
    --fill-tertiary: rgba(118, 118, 128, 0.16);
    --fill-quaternary: rgba(116, 116, 128, 0.10);

    --separator: rgba(84, 84, 88, 0.65);
    --separator-thin: rgba(255, 255, 255, 0.08);
    --separator-hairline: rgba(255, 255, 255, 0.05);

    --text-primary: #FFFFFF;
    --text-secondary: rgba(235, 235, 245, 0.62);
    --text-tertiary: rgba(235, 235, 245, 0.38);
    --text-quaternary: rgba(235, 235, 245, 0.22);

    /* slightly desaturated colors for dark mode comfort */
    --sys-blue: #409CFF;
    --sys-purple: #C47BF0;
    --sys-green: #4CD471;
    --sys-red: #FF6961;
    --sys-orange: #FFB443;
    --sys-yellow: #FFE066;
    --sys-teal: #7AD6F5;
    --sys-indigo: #7A78E8;
    --sys-pink: #FF6B8F;

    /* soft card shadow — barely visible in dark, gives subtle depth */
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    --dock-shadow: 0 16px 56px -10px rgba(0, 0, 0, 0.55), 0 2px 10px rgba(0, 0, 0, 0.35);

    /* scrollbar (theme-aware) */
    --scrollbar-thumb: rgba(255, 255, 255, 0.10);
    --scrollbar-thumb-hover: rgba(255, 255, 255, 0.18);

    /* typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Menlo', 'Consolas', monospace;

    /* motion */
    --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-inout: cubic-bezier(0.45, 0, 0.15, 1);
  }

  :root[data-theme="light"] {
    color-scheme: light;

    /* ── Apple light system palette ──────────────────────── */
    /* inverted hierarchy: body is light gray, cards pop as white */
    --bg-system: #F2F2F5;
    --bg-elevated: #FFFFFF;
    --bg-raised: #F5F5F7;
    --bg-surface: #E9E9EC;
    --bg-inset: #FAFAFC;
    --dock-bg: rgba(255, 255, 255, 0.68);
    --dock-bg-mobile: rgba(255, 255, 255, 0.48);

    --fill-primary: rgba(120, 120, 128, 0.18);
    --fill-secondary: rgba(120, 120, 128, 0.14);
    --fill-tertiary: rgba(118, 118, 128, 0.10);
    --fill-quaternary: rgba(116, 116, 128, 0.06);

    --separator: rgba(60, 60, 67, 0.36);
    --separator-thin: rgba(60, 60, 67, 0.12);
    --separator-hairline: rgba(60, 60, 67, 0.06);

    --text-primary: #1C1C1E;
    --text-secondary: rgba(60, 60, 67, 0.78);
    --text-tertiary: rgba(60, 60, 67, 0.54);
    --text-quaternary: rgba(60, 60, 67, 0.36);

    /* Apple system colors (light) */
    --sys-blue: #007AFF;
    --sys-purple: #AF52DE;
    --sys-green: #34C759;
    --sys-red: #FF3B30;
    --sys-orange: #FF9500;
    --sys-yellow: #B8860B;
    --sys-teal: #30B0C7;
    --sys-indigo: #5856D6;
    --sys-pink: #FF2D55;

    /* light-mode cards need a visible shadow for depth */
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.03);
    --dock-shadow: 0 12px 40px -12px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);

    --scrollbar-thumb: rgba(0, 0, 0, 0.14);
    --scrollbar-thumb-hover: rgba(0, 0, 0, 0.28);
  }

  html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    font-family: var(--font-sans);
    background: var(--bg-system);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv11', 'ss01', 'ss03';
    letter-spacing: -0.011em;
  }

  code, pre, .font-mono {
    font-family: var(--font-mono);
    font-feature-settings: 'zero';
  }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    letter-spacing: -0.02em;
    font-weight: 600;
  }
}

/* ── motion presets ──────────────────────────────────────── */

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.animate-in { animation: fade-in-up 0.6s var(--ease-out) both; }
.animate-fade { animation: fade-in 0.4s var(--ease-out) both; }
.animate-scale { animation: scale-in 0.5s var(--ease-out) both; }

.stagger-1 { animation-delay: 40ms; }
.stagger-2 { animation-delay: 80ms; }
.stagger-3 { animation-delay: 120ms; }
.stagger-4 { animation-delay: 160ms; }
.stagger-5 { animation-delay: 200ms; }
.stagger-6 { animation-delay: 240ms; }

.press:active { transform: scale(0.97); }


/* ── scrollbar ──────────────────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }
.hover-scrollbar {
  overflow-x: hidden;
  scrollbar-width: none;
}
.hover-scrollbar:hover {
  overflow-x: auto;
  scrollbar-color: var(--scrollbar-thumb) transparent;
  scrollbar-width: thin;
}
.hover-scrollbar::-webkit-scrollbar { width: 0; height: 0; }
.hover-scrollbar:hover::-webkit-scrollbar { width: 8px; height: 8px; }
.hover-scrollbar::-webkit-scrollbar-thumb { background: transparent; }
.hover-scrollbar:hover::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); }
.hover-scrollbar:hover::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ── focus ring ─────────────────────────────────────────── */

:where(button, [role="button"], [role="checkbox"], [role="menuitem"], a[href], summary):focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.45);
  border-radius: inherit;
}

/* ── prose ──────────────────────────────────────────────── */

.prose {
  font-family: var(--font-sans);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.65;
  max-width: none;
}
.prose p { margin-bottom: 1rem; color: var(--text-primary); }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-top: 1.8rem;
  margin-bottom: 0.6rem;
}
.prose h1 { font-size: 1.75rem; }
.prose h2 { font-size: 1.4rem; }
.prose h3 { font-size: 1.2rem; }
.prose ul, .prose ol { margin: 0.75rem 0; padding-left: 1.5rem; }
.prose li { margin: 0.25rem 0; line-height: 1.65; }
.prose blockquote {
  border-left: 3px solid var(--sys-blue);
  padding: 0.1rem 0 0.1rem 1rem;
  margin: 1.25rem 0;
  color: var(--text-secondary);
}
.prose pre {
  font-family: var(--font-mono);
  background: var(--bg-inset);
  border: 1px solid var(--separator-thin);
  border-radius: 12px;
  padding: 1rem 1.125rem;
  margin: 1.25rem 0;
  font-size: 13px;
  line-height: 1.55;
  overflow-x: auto;
}
.prose code:not(pre code) {
  font-family: var(--font-mono);
  background: var(--fill-tertiary);
  color: var(--text-primary);
  padding: 0.12em 0.35em;
  border-radius: 4px;
  font-size: 0.88em;
}
.prose a { color: var(--sys-blue); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose strong { color: var(--text-primary); font-weight: 600; }
.prose hr { border-color: var(--separator-thin); margin: 2rem 0; }

/* ── glossary / sidebar helpers ─────────────────────────── */

.glossary-keyword {
  color: var(--sys-yellow);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: rgba(255, 214, 10, 0.5);
  text-underline-offset: 3px;
  transition: color 180ms var(--ease-out);
}
.glossary-keyword:hover {
  color: #FFF;
  text-decoration-color: var(--sys-yellow);
}

.glossary-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.12em 0.45em;
  background: var(--fill-tertiary);
  color: var(--text-secondary);
  border: 0;
  border-radius: 5px;
  font-size: 11px;
  font-family: var(--font-mono);
}
:root[data-theme="light"] .glossary-tag {
  background: #F3F4F6;
  color: #374151;
}
.glossary-tag:hover { background: var(--fill-secondary); }

.disclosure-box {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 159, 10, 0.10);
  border: 1px solid rgba(255, 159, 10, 0.25);
  border-radius: 12px;
  color: var(--sys-orange);
  font-size: 14px;
  line-height: 1.55;
}
.disclosure-box svg {
  flex-shrink: 0;
  margin-top: 0.18rem;
  color: var(--sys-orange);
}

.sidebar-panel {
  background: var(--bg-system);
  border-right: 1px solid var(--separator-thin);
}

.cross-domain-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15em 0.4em;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--sys-purple);
  background: rgba(191, 90, 242, 0.15);
  border-radius: 4px;
}

.child-card {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  padding: 1rem 1.125rem;
  background: var(--bg-elevated);
  border: 1px solid var(--separator-thin);
  border-radius: 14px;
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: background-color 240ms var(--ease-spring), border-color 240ms var(--ease-spring), transform 180ms var(--ease-spring);
}
.child-card:hover {
  background: var(--bg-raised);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px);
}
.child-card:active { transform: translateY(0); }

.child-card-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.35;
  letter-spacing: -0.01em;
}
.child-card-desc {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 0.25rem;
  font-family: var(--font-mono);
}
.child-card-snippet {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── skeleton ───────────────────────────────────────────── */

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--fill-quaternary) 25%, var(--fill-tertiary) 50%, var(--fill-quaternary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
  border-radius: 8px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
