/* ==========================================================================
   Base.css — Design Tokens, Reset, Typography, Primitives
   "High-End Research Lab" OLED Dark Mode
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Colors — OLED Dark (Research Lab Palette) */
  --bg-primary: #000000;
  --bg-surface: #0a0a0a;
  --bg-elevated: #141414;
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --text-primary: #E8E8E8;
  --text-secondary: #707070;
  --accent: #10B981;           /* Muted emerald instead of bright blue */
  --accent-hover: #34D399;

  /* Typography Scale (Golden Ratio, base 16px) */
  --font-size-xs: 0.72rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-h3: 1.25rem;
  --font-size-h2: 1.618rem;
  --font-size-h1: 2.618rem;
  --font-size-hero: clamp(2.5rem, 5vw, 3.5rem);

  /* Font Families */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-editorial: 'Playfair Display', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Border Radius — Tight, Engineered */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-precision: 6px;

  /* Shadows — Minimal */
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lift: 0 4px 16px rgba(0, 0, 0, 0.4);

  /* Transitions */
  --ease-out-expo: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast: 0.3s var(--ease-out-expo);
  --transition-medium: 0.6s var(--ease-out-expo);
}

/* --------------------------------------------------------------------------
   2. Reset & Global Defaults
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

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

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
}

h1 { 
  font-size: var(--font-size-h1); 
  letter-spacing: -0.04em;
}
h2 { 
  font-size: var(--font-size-h2); 
  letter-spacing: -0.04em;
}
h3 { font-size: var(--font-size-h3); }

p {
  color: var(--text-secondary);
  line-height: 1.7;
}

ul, ol {
  list-style: none;
}

/* --------------------------------------------------------------------------
   3. Link Styles — Precise Underline Animation
   -------------------------------------------------------------------------- */
a {
  color: var(--text-primary);
  text-decoration: none;
  position: relative;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

a.link-accent {
  color: var(--text-primary);
  text-decoration: underline;
  text-decoration-color: var(--text-secondary);
  text-underline-offset: 3px;
}

a.link-accent:hover {
  text-decoration-color: var(--text-primary);
}

a.underline {
  display: inline-block;
}

a.underline::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 2px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--transition-fast);
}

a.underline:hover::after,
a.underline:focus-visible::after {
  transform: scaleX(1);
}

/* --------------------------------------------------------------------------
   4. Focus States — Accessibility
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-md);
}

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

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

/* --------------------------------------------------------------------------
   6. Noise Overlay — Tactile Black
   -------------------------------------------------------------------------- */
.noise-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.025;
  z-index: 9999;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

/* --------------------------------------------------------------------------
   7. Glass Panel — Lab Hairline
   -------------------------------------------------------------------------- */
.glass-panel {
  background: rgba(17, 17, 17, 0.70);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.glass-panel:hover {
  background: rgba(26, 26, 26, 0.72);
}

/* --------------------------------------------------------------------------
   8. Navigation — Elite Sticky Top-Bar
   -------------------------------------------------------------------------- */
.glass-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  /* OLED Blur backdrop */
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  border-radius: 0;
  padding: var(--space-sm) var(--space-xl);
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.glass-nav.nav-hidden {
  transform: translateY(-100%);
  opacity: 0;
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xl);
  max-width: 1200px;
  margin: 0 auto;
}

/* Left-aligned logo */
.nav-brand {
  font-weight: 600;
  font-size: var(--font-size-sm);
  letter-spacing: 0.02em;
  color: var(--text-primary);
}

/* Right-aligned links */
.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.nav-link {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  padding: var(--space-sm) var(--space-md);
  border-radius: 0;
  /* 0.5s fade transition */
  transition: color 0.5s var(--ease-out-expo);
  min-height: 44px;
  display: flex;
  align-items: center;
  background: transparent;
}

/* Active indicator: text-white only, no box */
.nav-link:hover {
  color: var(--text-primary);
  background: transparent;
}

.nav-link[aria-current="page"] {
  color: var(--text-primary);
  background: transparent;
}

/* --------------------------------------------------------------------------
   9. Monospace Metadata — Lab Report
   -------------------------------------------------------------------------- */
.tag-mono,
.mono {
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-secondary);
}

/* Badge — Minimal, no box */
.badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  /* No border, no background — just text */
}

.meta-row {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   10. Editorial Accent — Playfair Italic
   -------------------------------------------------------------------------- */
.editorial {
  font-family: var(--font-editorial);
  font-style: italic;
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   11. Page Shell — Layout Container
   -------------------------------------------------------------------------- */
.page-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-xl);
  padding-top: 80px; /* Account for sticky nav height */
}

.section-shell {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
}

/* --------------------------------------------------------------------------
   12. Reveal Animations (Progressive Enhancement)
   -------------------------------------------------------------------------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 
 * Content is always visible by default.
 * The .reveal-ready class is added by JS to elements that should animate.
 * This ensures no content is ever hidden if JS fails.
 */
.reveal-ready {
  opacity: 0;
  transform: translateY(16px);
}

.reveal-ready.is-visible {
  animation: fadeInUp 0.5s var(--ease-out-expo) forwards;
}

.reveal-ready.is-visible[style*="--stagger"] {
  animation-delay: var(--stagger, 0s);
}

/* Text Mask Reveal - also progressive enhancement */
.text-mask-ready > span {
  display: inline-block;
  transform: translateY(110%);
}

.text-mask-ready.is-visible > span {
  animation: textRise 0.6s var(--ease-out-expo) forwards;
}

@keyframes textRise {
  to {
    transform: translateY(0%);
  }
}

/* --------------------------------------------------------------------------
   13. Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  font-size: var(--font-size-sm);
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  min-height: 44px;
}

.btn:hover {
  background: var(--bg-elevated);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Ghost button — outline only, no fill */
.btn-primary {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.btn-primary:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 1);
}

/* --------------------------------------------------------------------------
   14. Cards — Transparent with Hairline Border
   -------------------------------------------------------------------------- */
.card {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  transition: border-color var(--transition-fast);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.18);
}

/* --------------------------------------------------------------------------
   15. Tags — Tech Stack Pills
   -------------------------------------------------------------------------- */
.tag {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  font-family: var(--font-mono);
  font-size: var(--font-size-xs);
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
}

/* --------------------------------------------------------------------------
   16. Social Icons — Minimal, no boxes, depth through opacity
   -------------------------------------------------------------------------- */
.social-icons {
  display: flex;
  gap: var(--space-lg);
}

.social-icons a {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  opacity: 0.5;
  transition: opacity var(--transition-fast);
}

.social-icons a:hover {
  opacity: 1;
}

.social-icons a i {
  font-size: 1.3rem;
}

/* --------------------------------------------------------------------------
   17. Responsive — Mobile "Technical Field Guide" Design
   -------------------------------------------------------------------------- */

/* Tablet breakpoint */
@media (max-width: 1024px) {
  .page-shell {
    padding: var(--space-lg);
    padding-top: 100px;
  }
}

/* Mobile breakpoint — Iron Wall alignment, 24px padding */
@media (max-width: 768px) {
  /* Enable elastic/bounce scroll for premium feel */
  html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }

  body {
    overscroll-behavior-y: auto;
  }

  /* Container — 24px side padding (px-6 equivalent) */
  .page-shell {
    padding: 24px;
    padding-top: 100px;
  }

  /* Typography — maintain technical aesthetic */
  h1 {
    font-size: clamp(1.875rem, 8vw, 2.25rem); /* text-3xl to text-4xl */
    letter-spacing: -0.04em;
  }

  /* Mono labels stay small — feels more "technical" */
  .mono,
  .tag-mono,
  .badge {
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  /* Glass Navigation — hide on mobile (will use bottom dock) */
  .glass-nav {
    display: none;
  }

  /* Section shell maintains slim padding */
  .section-shell {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
  }

  /* Cards — maintain 1px hairlines even on high-DPI */
  .card,
  .glass-panel {
    border-width: 1px;
    border-color: rgba(255, 255, 255, 0.08);
  }

  /* Touch targets — minimum 44px for accessibility */
  .btn,
  .nav-link,
  .category-btn,
  .tab-btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* Social icons — slightly larger for touch */
  .social-icons a {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .page-shell {
    padding: 20px;
    padding-top: 90px;
  }

  h1 {
    font-size: clamp(1.75rem, 10vw, 2rem);
  }
}

/* --------------------------------------------------------------------------
   18. Mobile Bottom Navigation Dock — iOS-style premium nav
   -------------------------------------------------------------------------- */
.mobile-nav-dock {
  display: none;
}

/* --------------------------------------------------------------------------
   19. Mobile Interaction States
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* Active scroll state — borders brighten when card is centered */
  .feed-card.is-active-scroll,
  .snippets-post.is-active-scroll,
  .project-card.is-active-scroll {
    border-color: rgba(255, 255, 255, 0.18);
  }

  /* Touch feedback state */
  .feed-card.is-touching,
  .snippets-post.is-touching,
  .project-card.is-touching {
    transform: scale(0.98);
    border-color: rgba(255, 255, 255, 0.25);
  }

  /* Horizontal scroll indicators */
  .system-status.scroll-right::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-primary));
    pointer-events: none;
  }

  .system-status.scroll-left::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, transparent, var(--bg-primary));
    pointer-events: none;
    z-index: 1;
  }

  .system-status {
    position: relative;
  }

  /* Category scroll indicators */
  .categories.scroll-right::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg-surface));
    pointer-events: none;
  }

  .categories.scroll-left::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, transparent, var(--bg-surface));
    pointer-events: none;
    z-index: 1;
  }

  .categories {
    position: relative;
  }

  /* Elastic scroll behavior (for supported browsers) */
  html {
    scroll-behavior: smooth;
  }

  body {
    /* iOS-style elastic overscroll */
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 768px) {
  .mobile-nav-dock {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: var(--space-sm) var(--space-md);
    padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: center;
  }

  .mobile-nav-dock .dock-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: var(--space-xs) var(--space-sm);
    min-width: 60px;
    min-height: 44px;
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: color var(--transition-fast);
  }

  .mobile-nav-dock .dock-link i {
    font-size: 1.1rem;
    margin-bottom: 2px;
  }

  .mobile-nav-dock .dock-link:hover,
  .mobile-nav-dock .dock-link.active {
    color: var(--text-primary);
  }

  .mobile-nav-dock .dock-link.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
  }

  .mobile-nav-dock .dock-link {
    position: relative;
  }

  /* Add padding at bottom of pages to account for dock */
  .page-shell {
    padding-bottom: calc(80px + env(safe-area-inset-bottom));
  }
}
