/* ============================================================
   hub.css — Shared design tokens, CSS reset, and site-wide nav
   The Astigmatic Actuary — theastigmaticactuary.com
   Served at /css/hub.css
   ============================================================ */

/* ============================================================
   1. UNIFIED DESIGN TOKENS (--color-* naming)
   ============================================================ */
:root, [data-theme="light"] {
  --color-bg: #f7f6f2;
  --color-surface: #ffffff;
  --color-surface-2: #eeece6;
  --color-surface-offset: #f0eeea;
  --color-border: #e0ddd7;
  --color-text: #1a1a1a;
  --color-text-secondary: #4a4a4a;
  --color-text-muted: #6b6b6b;
  --color-text-faint: #999999;
  --color-accent: #0e7490;
  --color-accent-light: #196f97;
  --color-accent-hover: #0b6078;
  --color-accent-active: #094d60;
  --color-accent-subtle: #e6f0f7;
  --font-display: 'Newsreader', Georgia, serif;
  --font-body: 'Inter', -apple-system, system-ui, sans-serif;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.07);

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

  /* Type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: clamp(1.75rem, 1.2rem + 2.5vw, 2.75rem);
  --text-3xl: clamp(2rem, 1.5rem + 2.5vw, 3rem);

  /* Layout widths */
  --content-max: 720px;
  --content-narrow: 640px;
  --content-prose: 640px;
  --content-wide: 960px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-interactive: 0.15s ease;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  /* Grid table columns (desktop) */
  --grid-cols: 1.4fr 2.5fr 0.8fr 0.7fr;

  /* Nav height — used by app-headers to position below the site nav */
  --nav-height: 60px;

  /* Legacy aliases — used by blog-style.css and portfolio-style.css */
  --bg: #f7f6f2;
  --bg-card: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #6b6b6b;
  --accent: #0e7490;
  --accent-hover: #196f97;
  --border: #e0ddd7;
  --nav-bg: rgba(247, 246, 242, 0.92);
  --callout-bg: #e6f0f7;
  --color-divider: #e0ddd7;
  --tag-bg: #e6f0f7;
  --tag-text: #0e7490;
}

[data-theme="dark"] {
  --color-bg: #111111;
  --color-surface: #1a1a1a;
  --color-surface-2: #222222;
  --color-surface-offset: #1e1e1e;
  --color-border: #404040;
  --color-text: #e2e2e0;
  --color-text-secondary: #b0b0ae;
  --color-text-muted: #808080;
  --color-text-faint: #666666;
  --color-accent: #22d3ee;
  --color-accent-light: #38bef0;
  --color-accent-hover: #1ab8d1;
  --color-accent-active: #139db4;
  --color-accent-subtle: #0f2535;
  /* Legacy aliases */
  --bg: #111111;
  --bg-card: #1a1a1a;
  --text-primary: #e2e2e0;
  --text-secondary: #b0b0ae;
  --text-muted: #808080;
  --accent: #22d3ee;
  --accent-hover: #38bef0;
  --border: #404040;
  --nav-bg: rgba(17, 17, 17, 0.92);
  --callout-bg: #0f2535;
  --color-divider: #404040;
  --tag-bg: #0f2535;
  --tag-text: #22d3ee;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #111111;
    --color-surface: #1a1a1a;
    --color-surface-2: #222222;
    --color-surface-offset: #1e1e1e;
    --color-border: #404040;
    --color-text: #e2e2e0;
    --color-text-secondary: #b0b0ae;
    --color-text-muted: #808080;
    --color-text-faint: #666666;
    --color-accent: #22d3ee;
    --color-accent-light: #38bef0;
    --color-accent-hover: #1ab8d1;
    --color-accent-active: #139db4;
    --color-accent-subtle: #0f2535;
  }
}

/* ============================================================
   2. CSS RESET
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Eliminate 300ms tap delay on iOS */
button, a, [role="button"], input, select, textarea {
  touch-action: manipulation;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* ============================================================
   3. SITE-WIDE NAV (.site-header)
   Identical on every page — NK monogram, Newsreader brand,
   desktop links, mobile slide-out drawer, theme toggle.
   ============================================================ */

/* --- Required inline script for theme persistence ---
   Pages should include this in <head> before any stylesheet:
   <script>(function(){var t=localStorage.getItem('theme');if(t)document.documentElement.setAttribute('data-theme',t);})()</script>
*/

.site-header {
  position: sticky;
  top: 0;
  z-index: 1100;
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease, border-color 0.3s ease;
}

.header-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
  color: var(--text-primary);
}

.header-brand svg {
  flex-shrink: 0;
}

/* Monogram uses currentColor — inherits from .header-brand color automatically.
   Dark mode adaptation happens via the color property, no hardcoded fills needed. */
.header-brand .nk-monogram {
  color: var(--text-primary);
  transition: color 0.3s ease;
}
.header-brand:hover .nk-monogram {
  color: var(--accent);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 500;
  letter-spacing: -0.01em;
}

/* Desktop nav */
.header-nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}

.header-nav a {
  font-size: var(--text-sm);
  font-weight: 450;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.header-nav a:hover,
.header-nav a.active {
  color: var(--accent);
}

/* Theme Toggle */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

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

/* Default (light or no preference): show moon */
.theme-toggle .icon-moon { display: block; }

/* Dark mode: show sun, hide moon */
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

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

/* Close button (hidden on desktop) */
.nav-close {
  display: none;
}

.nav-overlay {
  display: none;
}

/* Hamburger menu button (hidden on desktop) */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.menu-toggle:hover {
  color: var(--accent);
}

/* ============================================================
   MOBILE NAV (≤640px) — Slide-out drawer
   ============================================================ */
@media (max-width: 640px) {
  .header-inner {
    padding: var(--space-3) var(--space-4);
  }

  .brand-name {
    font-size: 1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 120px);
  }

  /* Show hamburger, hide desktop nav */
  .menu-toggle {
    display: flex;
    align-items: center;
    order: 3;
  }

  .header-nav {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    background: var(--bg);
    border-left: none;
    flex-direction: column;
    align-items: flex-start;
    padding: var(--space-20) var(--space-8) var(--space-8);
    gap: var(--space-6);
    /* iOS-safe: use only transform to hide; pointer-events to block interaction */
    -webkit-transform: translateX(100%);
            transform: translateX(100%);
    pointer-events: none;
    -webkit-transition: -webkit-transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
            transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1200;
    /* Avoid iOS compositing issues */
    -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
    will-change: transform;
  }

  .header-nav.open {
    -webkit-transform: translateX(0);
            transform: translateX(0);
    pointer-events: auto;
  }

  /* Ensure links inside open drawer are always tappable on iOS */
  .header-nav.open a,
  .header-nav.open button {
    pointer-events: auto;
  }

  .header-nav a {
    font-size: var(--text-base);
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Overlay */
  .nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1199;
  }

  .nav-overlay.open {
    display: block;
  }

  /* Close button inside mobile nav */
  .nav-close {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    color: var(--text-secondary);
    cursor: pointer;
    background: none;
    border: none;
    min-width: 44px;
    min-height: 44px;
  }
}


/* ============================================================
   FOCUS STYLES
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--accent, var(--color-accent));
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
