/* ==========================================================================
   Something Big Already Happened — Core Theme
   A premium dark-theme design system for a tech book
   ========================================================================== */

/* --- Google Fonts --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Playfair+Display:ital,wght@0,400;0,700;0,900;1,400;1,700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================================================
   Design Tokens (CSS Custom Properties)
   ========================================================================== */

:root {
  /* --- Colors --- */
  --bg-primary: #0D0D1A;
  --bg-secondary: #1A1A2E;
  --bg-card: #16213E;
  --bg-elevated: #1E2A4A;
  --bg-code: #0A0A1A;

  --accent: #FF6B35;
  --accent-light: #FF9F6B;
  --accent-dark: #CC5529;
  --accent2: #6366F1;
  --accent2-light: #A5B4FC;
  --accent2-dark: #4F46E5;

  --success: #10B981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --error: #EF4444;
  --error-bg: rgba(239, 68, 68, 0.15);

  --text-primary: #E8E8F0;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --text-inverse: #0D0D1A;

  --border: #2D2D44;
  --border-light: #3D3D5C;
  --border-accent: rgba(255, 107, 53, 0.3);

  /* --- Typography --- */
  --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;

  --text-xs: clamp(0.6875rem, 0.65rem + 0.15vw, 0.75rem);     /* ~11-12px */
  --text-sm: clamp(0.8125rem, 0.775rem + 0.15vw, 0.875rem);    /* ~13-14px */
  --text-base: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);        /* ~16-17px */
  --text-lg: clamp(1.125rem, 1.05rem + 0.3vw, 1.25rem);        /* ~18-20px */
  --text-xl: clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);           /* ~20-24px */
  --text-2xl: clamp(1.5rem, 1.3rem + 0.8vw, 2rem);             /* ~24-32px */
  --text-3xl: clamp(2rem, 1.6rem + 1.5vw, 3rem);               /* ~32-48px */
  --text-4xl: clamp(2.25rem, 1.8rem + 2vw, 4rem);              /* ~36-64px */

  --leading-tight: 1.1;
  --leading-snug: 1.3;
  --leading-normal: 1.6;
  --leading-relaxed: 1.8;
  --leading-loose: 2.0;

  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.05em;
  --tracking-widest: 0.25em;

  /* --- Spacing --- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* --- Layout --- */
  --content-width: 780px;
  --content-wide: 960px;
  --content-narrow: 640px;
  --page-gutter: 24px;

  /* --- Borders --- */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* --- Shadows --- */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.4);
  --shadow-glow-accent: 0 0 12px rgba(255, 107, 53, 0.5);
  --shadow-glow-accent2: 0 0 12px rgba(99, 102, 241, 0.5);

  /* --- Transitions --- */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 350ms ease;
}

/* ==========================================================================
   Global Reset
   ========================================================================== */

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Base Body
   ========================================================================== */

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  font-weight: 400;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================================================
   Selection
   ========================================================================== */

::selection {
  background-color: rgba(99, 102, 241, 0.35);
  color: #fff;
}

::-moz-selection {
  background-color: rgba(99, 102, 241, 0.35);
  color: #fff;
}

/* ==========================================================================
   Scrollbar (Dark Themed)
   ========================================================================== */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-primary);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg-primary);
}

/* ==========================================================================
   Focus States (Accessible)
   ========================================================================== */

:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ==========================================================================
   Typography — Headings
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: #fff;
  line-height: var(--leading-tight);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-4xl);
  font-weight: 900;
  line-height: 1.05;
  margin-bottom: var(--space-6);
}

h2 {
  font-size: var(--text-2xl);
  margin-top: var(--space-16);
  margin-bottom: var(--space-6);
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

h3 {
  font-family: var(--font-body);
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--accent2-light);
  margin-top: var(--space-10);
  margin-bottom: var(--space-4);
  letter-spacing: var(--tracking-normal);
}

h4 {
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-top: var(--space-8);
  margin-bottom: var(--space-3);
  letter-spacing: var(--tracking-normal);
}

h5 {
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--accent);
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
}

h6 {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-muted);
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
}

/* ==========================================================================
   Typography — Body Text
   ========================================================================== */

p {
  margin-bottom: var(--space-5);
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

strong, b {
  font-weight: 700;
  color: #fff;
}

em, i {
  font-style: italic;
}

small {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ==========================================================================
   Links
   ========================================================================== */

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 3px;
  transition: color var(--transition-fast), text-decoration var(--transition-fast);
}

a:hover {
  color: var(--accent-light);
  text-decoration: underline;
}

a:visited {
  color: var(--accent2-light);
}

/* ==========================================================================
   Lists
   ========================================================================== */

ul, ol {
  margin-bottom: var(--space-5);
  padding-left: var(--space-6);
  color: var(--text-primary);
}

li {
  margin-bottom: var(--space-2);
  line-height: var(--leading-relaxed);
}

li::marker {
  color: var(--accent);
}

/* ==========================================================================
   Horizontal Rule
   ========================================================================== */

hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  margin: var(--space-12) 0;
}

/* ==========================================================================
   Images & Media
   ========================================================================== */

img, svg, video {
  max-width: 100%;
  height: auto;
  display: block;
}

figure {
  margin: var(--space-10) 0;
}

figcaption {
  font-size: var(--text-sm);
  color: var(--text-muted);
  font-style: italic;
  margin-top: var(--space-3);
  text-align: center;
}

/* ==========================================================================
   Tables (base)
   ========================================================================== */

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-10) 0;
  font-size: var(--text-sm);
}

th {
  background: var(--bg-card);
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}

tr:hover td {
  background: rgba(99, 102, 241, 0.05);
}

/* ==========================================================================
   Code (inline)
   ========================================================================== */

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-secondary);
  color: var(--accent2-light);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
}

/* ==========================================================================
   Preformatted / Code Blocks (base)
   ========================================================================== */

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-5) var(--space-6);
  overflow-x: auto;
  margin: var(--space-6) 0;
  color: var(--accent2-light);
}

/* ==========================================================================
   Content Container
   ========================================================================== */

.content,
.page-content,
#quarto-content .content-body {
  max-width: var(--content-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--page-gutter);
  padding-right: var(--page-gutter);
  padding-bottom: var(--space-24);
}

/* ==========================================================================
   Quarto-specific Overrides
   ========================================================================== */

/* Override Quarto's default body background */
body.quarto-dark,
body {
  background-color: var(--bg-primary);
}

/* Override Quarto sidebar if present */
#quarto-sidebar {
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border);
}

#quarto-sidebar .sidebar-title {
  color: #fff;
  font-family: var(--font-heading);
}

#quarto-sidebar .sidebar-item a {
  color: var(--text-secondary);
}

#quarto-sidebar .sidebar-item a:hover,
#quarto-sidebar .sidebar-item a.active {
  color: var(--accent);
}

/* Quarto navbar */
.navbar {
  background-color: var(--bg-primary) !important;
  border-bottom: 1px solid var(--border);
}

.navbar-brand {
  font-family: var(--font-heading);
  color: #fff !important;
  font-weight: 700;
}

/* Quarto table of contents (right margin sidebar) */
#quarto-margin-sidebar {
  background-color: var(--bg-primary);
  border-left: 1px solid var(--border);
}

#quarto-margin-sidebar .toc-actions a {
  color: var(--text-muted);
}

#quarto-margin-sidebar .toc-actions a:hover {
  color: var(--accent);
}

#TOC a {
  color: var(--text-secondary);
}

#TOC a:hover,
#TOC a.active {
  color: var(--accent);
}

#TOC .active {
  border-left-color: var(--accent);
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 768px) {
  :root {
    --page-gutter: 16px;
  }

  h2 {
    margin-top: var(--space-10);
  }

  h3 {
    margin-top: var(--space-8);
  }
}

@media (max-width: 480px) {
  body {
    font-size: 16px;
  }
}
