/* ============================================
   Design System — Linear + Apple Style (Dark)
   Felix Homepage v2 — Optimized
   Fixes: mobile menu, reduced-motion, GPU accel
   ============================================ */

:root {
  --bg-primary: #08090a;
  --bg-secondary: #0f1011;
  --bg-tertiary: #191d20;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --surface: #0f1011;
  --surface-2: #191d20;

  --text: #e2e4e7;
  --text-2: #8a8f98;
  --text-3: #5c6370;

  --border: rgba(255, 255, 255, 0.1);
  --border-2: rgba(255, 255, 255, 0.06);

  --accent-blue: #56cdff;
  --accent-purple: #a78bfa;
  --accent-teal: #34d399;
  --accent-orange: #fb923c;
  --accent-green: #22c55e;
  --accent-blue-dim: rgba(86, 205, 255, 0.12);
  --accent-purple-dim: rgba(167, 139, 250, 0.12);

  --container: 780px;
  --radius: 12px;
  --radius-sm: 8px;

  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --duration: 0.2s;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
  scroll-behavior: smooth;
  font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
body { min-height: 100vh; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 24px; }

/* ============================================
   Cursor Glow — GPU accelerated
   ============================================ */

.cursor-glow {
  position: fixed;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(86, 205, 255, 0.05) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
  transform: translate(-50%, -50%);
  transition: opacity 0.3s ease;
  opacity: 0;
  will-change: left, top;
}

.cursor-glow.active { opacity: 1; }

/* ============================================
   Navigation
   ============================================ */

.nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(8, 9, 10, 0.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--border-2);
  padding: 14px 0;
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

.nav.scrolled {
  background: rgba(8, 9, 10, 0.95);
  box-shadow: 0 1px 0 var(--border-2);
}

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

.nav-brand {
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.nav-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

.nav-links { display: flex; gap: 24px; }

.nav-links a {
  font-size: 13px;
  color: var(--text-3);
  transition: color var(--duration) var(--ease);
}

.nav-links a:hover { color: var(--text); }

/* ============================================
   Hero
   ============================================ */

.hero { padding: 72px 0 56px; }

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent-blue);
  letter-spacing: 0.04em;
  background: var(--accent-blue-dim);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 24px;
}

.hero-title {
  font-size: 3rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin-bottom: 20px;
  color: var(--text);
}

.typewrite {
  background: linear-gradient(90deg, var(--accent-blue) 0%, var(--accent-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.cursor-blink {
  font-weight: 300;
  color: var(--accent-blue);
  animation: blink 0.8s step-end infinite;
  margin-left: 2px;
}

@keyframes blink { 50% { opacity: 0; } }

.hero-sub {
  font-size: 15px;
  color: var(--text-2);
  max-width: 500px;
  line-height: 1.75;
  margin-bottom: 36px;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 52px;
}

/* ============================================
   Buttons
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity var(--duration), transform 0.1s;
  position: relative;
  overflow: hidden;
}

.btn:hover { opacity: 0.85; transform: translateY(-1px); }

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--ripple-x, 50%) var(--ripple-y, 50%), rgba(255,255,255,0.12) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.btn:hover::after { opacity: 1; }

.btn-primary { background: var(--accent-blue); color: #08090a; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

/* ============================================
   Stats
   ============================================ */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  background: var(--surface);
  padding: 20px 16px;
  text-align: center;
}

.stat-val {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.stat-key {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.03em;
}

/* ============================================
   Section
   ============================================ */

.section { padding: 52px 0; border-top: 1px solid var(--border-2); }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 28px;
}

.section-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--text-3);
  text-transform: uppercase;
  white-space: nowrap;
}

.section-rule {
  flex: 1;
  height: 1px;
  background: var(--border-2);
}

/* ============================================
   About
   ============================================ */

.about-layout {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 40px;
  align-items: start;
}

.about-text p { color: var(--text-2); line-height: 1.8; margin-bottom: 14px; font-size: 13px; }
.about-text p:last-child { margin-bottom: 0; }

.about-aside {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.aside-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 14px;
  background: var(--surface);
}

.aside-label {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.03em;
}

.aside-val {
  font-size: 12px;
  font-weight: 500;
  text-align: right;
}

.aside-val.accent { color: var(--accent-green); }

/* ============================================
   Focus Cards
   ============================================ */

.focus-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.focus-card {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 22px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}

.focus-card:hover { border-color: var(--border); transform: translateY(-2px); }

.focus-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--card-accent, var(--accent-blue));
}

.focus-card:nth-child(1) { --card-accent: var(--accent-blue); }
.focus-card:nth-child(2) { --card-accent: var(--accent-purple); }
.focus-card:nth-child(3) { --card-accent: var(--accent-teal); }
.focus-card:nth-child(4) { --card-accent: var(--accent-orange); }

.focus-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
  font-size: 18px;
}

.focus-card h3 { font-size: 14px; font-weight: 500; margin-bottom: 8px; }
.focus-card p { font-size: 13px; color: var(--text-2); line-height: 1.6; }

/* ============================================
   Projects
   ============================================ */

.project-list { display: flex; flex-direction: column; gap: 10px; }

.project {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: start;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}

.project:hover { border-color: var(--border); }

.project-num {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-3);
  font-family: "SF Mono", "Fira Code", monospace;
  padding-top: 2px;
}

.project-body h3 { font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.project-body p { font-size: 13px; color: var(--text-2); line-height: 1.6; margin-bottom: 10px; }

.tag-row { display: flex; gap: 6px; flex-wrap: wrap; }

.tag {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-3);
  border: 1px solid var(--border-2);
}

.project-link {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
  padding-top: 2px;
  transition: color var(--duration);
}

.project-link:hover { color: var(--text); }

/* ============================================
   Tech Stack
   ============================================ */

.stack-categories { display: flex; flex-direction: column; gap: 16px; }

.stack-row { display: flex; align-items: baseline; gap: 14px; }

.stack-cat {
  font-size: 12px;
  color: var(--text-3);
  width: 100px;
  flex-shrink: 0;
}

.stack-items { display: flex; flex-wrap: wrap; gap: 7px; }

.stack-tag {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--surface);
}

.stack-tag.hi {
  background: var(--accent-blue-dim);
  color: var(--accent-blue);
  border-color: rgba(86, 205, 255, 0.15);
}

/* ============================================
   Principles
   ============================================ */

.principles { display: flex; flex-direction: column; gap: 10px; }

.principle {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
}

.principle-num {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 11px;
  color: var(--text-3);
  padding-top: 2px;
  min-width: 24px;
}

.principle-content { font-size: 13px; color: var(--text-2); line-height: 1.7; }
.principle-content strong { color: var(--text); font-weight: 500; }

/* ============================================
   Writing
   ============================================ */

.posts { display: flex; flex-direction: column; }

.post {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-2);
  transition: opacity var(--duration);
}

.post:first-child { border-top: 1px solid var(--border-2); }
.post:hover { opacity: 0.65; }

.post-title { font-size: 14px; font-weight: 500; }
.post-meta { font-size: 12px; color: var(--text-3); font-family: "SF Mono", "Fira Code", monospace; white-space: nowrap; margin-left: 16px; }

.writing-more { margin-top: 16px; }
.writing-more .btn { font-size: 13px; }

/* ============================================
   Contact
   ============================================ */

.contact-block {
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 32px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.contact-block h3 { font-size: 18px; font-weight: 500; margin-bottom: 8px; }
.contact-block p { font-size: 13px; color: var(--text-2); max-width: 340px; }

.contact-links { display: flex; gap: 10px; flex-wrap: wrap; }

.contact-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  transition: border-color var(--duration), transform 0.1s;
}

.contact-link:hover { border-color: var(--border); transform: translateY(-1px); }

/* ============================================
   Footer
   ============================================ */

.footer {
  padding: 32px 0;
  border-top: 1px solid var(--border-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
}

.footer-brand {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 2px;
}

.footer p { font-size: 12px; color: var(--text-3); }

.footer-copy { font-size: 11px; color: var(--text-3); opacity: 0.5; }

.footer-links { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.footer-links a { color: var(--text-3); transition: color var(--duration); }
.footer-links a:hover { color: var(--text-2); }
.footer-links span { color: var(--text-3); opacity: 0.4; }

.footer-beian { margin-top: 0; }
.footer-beian a { color: var(--text-3); transition: color var(--duration); display: inline-flex; align-items: center; gap: 4px; }
.footer-beian a:hover { color: var(--text-2); }
.beian-sep { color: var(--text-3); opacity: 0.4; margin: 0 2px; }
.beian-ga { display: inline-flex; align-items: center; gap: 4px; }
.beian-icon { flex-shrink: 0; opacity: 0.8; vertical-align: middle; }

/* ============================================
   Preloader
   ============================================ */

.preloader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.preloader-logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  animation: breathe 2s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.97); }
}

.preloader-bar {
  width: 180px;
  height: 2px;
  background: var(--border-2);
  border-radius: 2px;
  overflow: hidden;
}

.preloader-progress {
  width: 0;
  height: 100%;
  background: var(--accent-blue);
  border-radius: 2px;
  animation: loadProgress 1.5s ease-out forwards;
}

@keyframes loadProgress {
  0% { width: 0; }
  60% { width: 70%; }
  100% { width: 100%; }
}

/* ============================================
   Scroll Progress
   ============================================ */

.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple));
  z-index: 200;
  transition: width 0.05s linear;
}

/* ============================================
   Mobile Menu — FIX: toggle display properly
   ============================================ */

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
}

.menu-toggle svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  fill: none;
}

.mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  background: rgba(8, 9, 10, 0.98);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-menu.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.mobile-menu a {
  font-size: 20px;
  font-weight: 500;
  color: var(--text-2);
  transition: color var(--duration);
}

.mobile-menu a:hover { color: var(--text); }

/* ============================================
   Scroll Reveal
   ============================================ */

.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1), transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.visible { opacity: 1; transform: translateY(0); }

.reveal .focus-card,
.reveal .project,
.reveal .principle,
.reveal .post {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.reveal.visible .focus-card,
.reveal.visible .project,
.reveal.visible .principle,
.reveal.visible .post {
  opacity: 1;
  transform: translateY(0);
}

.reveal.visible .focus-card:nth-child(1),
.reveal.visible .project:nth-child(1),
.reveal.visible .principle:nth-child(1),
.reveal.visible .post:nth-child(1) { transition-delay: 0.05s; }

.reveal.visible .focus-card:nth-child(2),
.reveal.visible .project:nth-child(2),
.reveal.visible .principle:nth-child(2),
.reveal.visible .post:nth-child(2) { transition-delay: 0.1s; }

.reveal.visible .focus-card:nth-child(3),
.reveal.visible .project:nth-child(3),
.reveal.visible .principle:nth-child(3),
.reveal.visible .post:nth-child(3) { transition-delay: 0.15s; }

.reveal.visible .focus-card:nth-child(4),
.reveal.visible .project:nth-child(4),
.reveal.visible .principle:nth-child(4),
.reveal.visible .post:nth-child(4) { transition-delay: 0.2s; }

.reveal.visible .post:nth-child(5) { transition-delay: 0.25s; }

/* ============================================
   Magnetic Effect
   ============================================ */

.magnetic {
  position: relative;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s, border-color 0.2s;
}

/* ============================================
   Reduced Motion — Accessibility
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .reveal { opacity: 1; transform: none; }
  .reveal .focus-card,
  .reveal .project,
  .reveal .principle,
  .reveal .post { opacity: 1; transform: none; }
  .cursor-glow { display: none; }
  .scroll-progress { display: none; }
  html { scroll-behavior: auto; }
}

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

@media (max-width: 640px) {
  .hero-title { font-size: 2.2rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .focus-grid { grid-template-columns: 1fr; }
  .about-layout { grid-template-columns: 1fr; }
  .about-aside { display: none; }
  .project { grid-template-columns: 32px 1fr; }
  .project-link { display: none; }
  .nav-links { display: none; }
  .menu-toggle { display: block; }
  .hero-actions { flex-direction: column; }
  .hero-actions .btn { text-align: center; justify-content: center; }
  .contact-block { flex-direction: column; text-align: center; }
  .contact-block p { max-width: 100%; }
  .footer { padding: 24px 0; }
  .post-meta { display: none; }
}
