/*
  ========================================
  Shared CSS — Lemma Design System
  Noir grid · math annotations · lowercase · serif accents
  ========================================
*/

/* ========================================
   1. CSS Custom Properties
   ======================================== */
:root {
  /* Palette */
  --bg-primary: #030305;
  --bg-secondary: #0a0a0e;
  --bg-tertiary: #131316;
  --text-primary: #ffffff;
  --text-secondary: #888;
  --text-muted: #555;
  --text-faint: #333;
  --text-ghost: #1e1e1e;
  --accent-saffron: #FF9933;
  --accent-red: #DC143C;
  --accent-gradient: linear-gradient(135deg, #FF9933 0%, #DC143C 100%);

  /* Typography */
  --font-heading: 'Space Grotesk', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-serif: 'Playfair Display', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Cards */
  --card-bg: #030305;
  --card-gap-color: rgba(255, 255, 255, 0.03);
  --card-hover: rgba(255, 153, 51, 0.025);

  /* Grid background */
  --grid-opacity: 0.025;
  --grid-size: 60px;

  /* Nav */
  --nav-height: 56px;
  --nav-bg: rgba(3, 3, 5, 0.9);

  /* Easing */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #f5f5f3;
  --bg-secondary: #eeeee9;
  --bg-tertiary: #e0e0db;
  --text-primary: #1a1a1a;
  --text-secondary: #555;
  --text-muted: #777;
  --text-faint: #aaa;
  --text-ghost: #ccc;
  --card-bg: #f5f5f3;
  --card-gap-color: rgba(0, 0, 0, 0.06);
  --card-hover: rgba(255, 153, 51, 0.05);
  --grid-opacity: 0.06;
  --nav-bg: rgba(245, 245, 243, 0.9);
}

/* ========================================
   2. Global Resets
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  max-width: 100vw;
  overflow-x: hidden;
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  scroll-behavior: smooth;
  cursor: crosshair;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Grid-line background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, var(--grid-opacity)) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, var(--grid-opacity)) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  pointer-events: none;
  z-index: -1;
}

[data-theme="light"] body::before {
  background-image:
    linear-gradient(rgba(0, 0, 0, var(--grid-opacity)) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, var(--grid-opacity)) 1px, transparent 1px);
}

/* Typography */
h1, h2, h3 {
  text-transform: lowercase;
}

h2 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

a {
  color: var(--text-primary);
  text-decoration: none;
  cursor: pointer;
}

/* Focus styles */
a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent-saffron);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ========================================
   3. Mouse-Following Spotlight
   ======================================== */
.lem-glow {
  position: fixed;
  width: 700px;
  height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 153, 51, 0.07) 0%, rgba(220, 20, 60, 0.03) 35%, transparent 65%);
  pointer-events: none;
  transform: translate(-50%, -50%);
  will-change: left, top;
  transition: left 0.5s var(--ease-out), top 0.5s var(--ease-out);
  z-index: 0;
}

[data-theme="light"] .lem-glow {
  background: radial-gradient(circle, rgba(255, 153, 51, 0.05) 0%, rgba(220, 20, 60, 0.02) 35%, transparent 65%);
}

/* ========================================
   4. SVG Ribbon
   ======================================== */
.lem-ribbon {
  position: fixed;
  top: 0;
  left: -10%;
  width: 120%;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
  opacity: 0.25;
}

.lem-ribbon svg {
  width: 100%;
  height: 100%;
}

[data-theme="light"] .lem-ribbon {
  opacity: 0.15;
}

/* ========================================
   5. Navigation — Fixed Top Bar
   ======================================== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--nav-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

[data-theme="light"] .top-nav {
  border-bottom-color: rgba(0, 0, 0, 0.06);
}

/* Brand */
.nav-brand {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: lowercase;
  color: var(--accent-saffron);
  transition: opacity 0.3s ease;
}

.nav-brand:hover {
  opacity: 0.8;
}

/* Links Container */
.nav-links {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  list-style: none;
}

.nav-links a {
  display: block;
  padding: 0.5rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-faint);
  letter-spacing: 0.5px;
  border-radius: 6px;
  transition: color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .nav-links a:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.04);
  }
}

.nav-links a.active-section {
  color: var(--text-primary);
}

[data-theme="light"] .nav-links a {
  color: var(--text-faint);
}

[data-theme="light"] .nav-links a.active-section {
  color: var(--text-primary);
}

/* Divider */
.nav-divider {
  width: 1px;
  height: 20px;
  background: rgba(255, 255, 255, 0.06);
  margin: 0 0.5rem;
  list-style: none;
}

[data-theme="light"] .nav-divider {
  background: rgba(0, 0, 0, 0.08);
}

/* External links */
.nav-links a.external-link {
  color: var(--text-faint);
  font-size: 0.75rem;
}

/* Nav Controls */
.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Theme Toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: transform 0.25s var(--ease-out), border-color 0.25s var(--ease-out);
}

[data-theme="light"] .theme-toggle {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
}

@media (hover: hover) and (pointer: fine) {
  .theme-toggle:hover {
    transform: scale(1.08);
    border-color: rgba(255, 153, 51, 0.2);
  }
}

.theme-toggle:active {
  transform: scale(0.96);
}

/* Hamburger Menu Icon */
.menu-icon {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: transform 0.25s var(--ease-out);
  gap: 5px;
}

.menu-icon .bar {
  height: 2px;
  width: 20px;
  background: var(--text-primary);
  border-radius: 2px;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-icon.active .bar:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
  background: var(--accent-saffron);
}

.menu-icon.active .bar:nth-child(2) {
  opacity: 0;
  transform: translateX(20px);
}

.menu-icon.active .bar:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
  background: var(--accent-red);
}

/* Mobile slide-out menu */
@media (max-width: 1024px) {
  .menu-icon {
    display: flex;
  }

  .nav-links {
    position: fixed;
    top: var(--nav-height);
    right: -100%;
    width: 280px;
    height: calc(100vh - var(--nav-height));
    background: rgba(3, 3, 5, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    padding: 1.5rem;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
  }

  [data-theme="light"] .nav-links {
    background: rgba(245, 245, 243, 0.95);
    border-left-color: rgba(0, 0, 0, 0.06);
  }

  .nav-links.active {
    right: 0;
  }

  .nav-links li {
    width: 100%;
  }

  .nav-links a {
    width: 100%;
    padding: 0.9rem 1rem;
    font-size: 0.9rem;
  }

  .nav-divider {
    width: 100%;
    height: 1px;
    margin: 0.5rem 0;
  }
}

/* Hide top nav on mobile, show pill instead */
@media (max-width: 1024px) {
  .top-nav {
    display: none;
  }
}

/* ========================================
   5b. Mobile Bottom Pill Navigation
   ======================================== */
.mobile-pill {
  display: none;
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.6rem;
  border-radius: 999px;
  background: rgba(3, 3, 5, 0.9);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

[data-theme="light"] .mobile-pill {
  background: rgba(245, 245, 243, 0.9);
  border-color: rgba(0, 0, 0, 0.08);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.mobile-pill-link {
  padding: 0.45rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 999px;
  transition: color 0.2s ease, background 0.2s ease;
  white-space: nowrap;
}

.mobile-pill-link.active-section {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] .mobile-pill-link.active-section {
  background: rgba(0, 0, 0, 0.06);
}

.mobile-pill-theme {
  width: 32px;
  height: 32px;
  font-size: 16px;
  margin-left: 0.15rem;
  box-shadow: none;
}

@media (max-width: 1024px) {
  .mobile-pill {
    display: flex;
  }
}

/* ========================================
   6. Card System — Grid Cells
   ======================================== */
.lem-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--card-gap-color);
  max-width: 1200px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.lem-card {
  background: var(--card-bg);
  padding: 2.5rem;
  position: relative;
  transition: background 0.4s var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .lem-card:hover {
    background: var(--card-hover);
  }

  .lem-card {
    transform-style: preserve-3d;
  }
}

.lem-card:active {
  transform: scale(0.97);
  transition: transform 160ms var(--ease-out);
}

/* Card index — italic serif numeral */
.lem-card-idx {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 1.1rem;
  color: var(--text-faint);
  margin-bottom: 1.2rem;
}

/* Card title */
.lem-card h3 {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  text-transform: lowercase;
}

/* Card description */
.lem-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

/* Card tags */
.lem-card-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lem-tag {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: rgba(255, 153, 51, 0.7);
  letter-spacing: 0.3px;
}

.lem-tag::before {
  content: '\2202';
  opacity: 0.35;
  margin-right: 2px;
}

[data-theme="light"] .lem-tag {
  color: rgba(200, 120, 20, 0.85);
}

/* ========================================
   7. Math Annotations
   ======================================== */

/* Random epigraph (hero label) */
.lem-epigraph {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 2px;
  margin-bottom: 1.5rem;
}

/* Section-head pattern */
.lem-section-head {
  position: relative;
  z-index: 1;
  margin-bottom: 2rem;
}

/* Theorem-style annotation under section headings */
.lem-def {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-faint);
  margin-top: 0.4rem;
  letter-spacing: 0.5px;
}

.lem-def em {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--text-muted);
}

/* Coordinate / symbol block */
.lem-coord {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  text-align: right;
  line-height: 2.2;
  z-index: 1;
}

.lem-coord .sym {
  color: var(--text-muted);
}

/* Margin annotations — scattered math along edges */
.lem-margin-note {
  position: absolute;
  right: 2rem;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  color: var(--text-ghost);
  z-index: 1;
  pointer-events: none;
  letter-spacing: 0.5px;
}

/* QED footer flourish */
.lem-qed {
  text-align: center;
  padding: 3rem 0 2rem;
  position: relative;
  z-index: 1;
}

.lem-qed span {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 3px;
}

/* ========================================
   8. Contact / Footer
   ======================================== */
#contact {
  padding: 3rem 2rem;
  background: var(--bg-primary);
  text-align: center;
  position: relative;
  z-index: 1;
}

#contact h2 {
  margin-bottom: 1.5rem;
}

.social-icons {
  margin-bottom: 2rem;
}

.icon-link {
  margin: 0 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent-saffron);
  letter-spacing: 0.3px;
  transition: opacity 0.2s ease;
}

@media (hover: hover) and (pointer: fine) {
  .icon-link:hover {
    opacity: 0.7;
  }
}

/* ========================================
   9. Animations & Micro-interactions
   ======================================== */
@keyframes blink {
  50% { opacity: 0; }
}

/* Press feedback */
.lem-card:active,
.theme-toggle:active,
.mobile-pill-link:active,
.icon-link:active,
.nav-links a:active {
  transform: scale(0.97);
  transition: transform 160ms var(--ease-out);
}

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

  .lem-glow {
    display: none;
  }

  body {
    cursor: default;
  }
}

/* ========================================
   10. Responsive
   ======================================== */
@media (max-width: 992px) {
  .lem-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .lem-cards {
    grid-template-columns: 1fr;
  }

  .lem-card {
    padding: 2rem 1.5rem;
  }

  .lem-margin-note {
    display: none;
  }
}

/* ========================================
   11. JS-off Fallback
   ======================================== */
.no-js .lem-card,
.no-js .lem-section-head,
.no-js .lem-coord,
.no-js .lem-epigraph,
.no-js .timeline-item,
.no-js .timeline-line,
.no-js #contact > * {
  opacity: 1 !important;
  transform: none !important;
}
