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

:root {
  --bg-primary: #0a0a0b;
  --bg-secondary: #111113;
  --bg-card: #18181b;
  --bg-card-hover: #1f1f23;
  --text-primary: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --accent-primary: #3b82f6;
  --accent-secondary: #8b5cf6;
  --accent-soft: rgba(59, 130, 246, 0.15);
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #ec4899 100%);
  --border-color: #27272a;
  --border-subtle: rgba(255,255,255,0.06);
  --header-bg: rgba(10, 10, 11, 0.8);
  --button-shadow: rgba(255,255,255,0.15);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f4f4f5;
  --bg-card: #fafafa;
  --bg-card-hover: #f0f0f2;
  --text-primary: #18181b;
  --text-secondary: #52525b;
  --text-muted: #71717a;
  --accent-primary: #2563eb;
  --accent-secondary: #7c3aed;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --border-color: #e4e4e7;
  --border-subtle: rgba(0,0,0,0.06);
  --header-bg: rgba(255, 255, 255, 0.8);
  --button-shadow: rgba(0,0,0,0.15);
}

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

a { color: var(--accent-primary); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--accent-secondary); }
svg { flex-shrink: 0; }

.skip-link {
  position: absolute; top: 0; left: -9999px; z-index: 200;
  background: var(--accent-primary); color: #fff; padding: 8px;
}
.skip-link:focus { left: 0; }

/* Header */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 1rem 2rem;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.3s, border-color 0.3s;
}
.site-header .inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; gap: 2rem;
}
.logo { font-weight: 700; font-size: 1.1rem; color: var(--text-primary); white-space: nowrap; }
.logo:hover { color: var(--text-primary); }

.nav-links { display: flex; gap: 2rem; list-style: none; }
.nav-links a { color: var(--text-secondary); font-size: 0.9rem; font-weight: 500; }
.nav-links a:hover { color: var(--text-primary); }

.nav-actions { display: flex; align-items: center; gap: 1rem; }
.social-icons { display: flex; gap: 0.75rem; }

.icon-button, .social-icons a {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
}
.social-icons a:hover { background: var(--accent-primary); border-color: var(--accent-primary); color: #fff; }
.icon-button:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.icon-button svg, .social-icons svg { width: 18px; height: 18px; }
.social-icons svg { opacity: 0.85; }
.social-icons a:hover svg { opacity: 1; }

.theme-toggle svg { transition: transform 0.3s; }
.theme-toggle:hover svg { transform: rotate(15deg); }
.theme-toggle .sun-icon { display: none; }
[data-theme="light"] .theme-toggle .sun-icon { display: block; }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }

.hamburger { display: none; flex-direction: column; gap: 5px; padding: 8px; }
.hamburger span {
  display: block; width: 100%; height: 2px;
  background: var(--text-primary); border-radius: 2px; transition: all 0.3s;
}
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

.mobile-menu {
  display: none;
  position: fixed; top: 68px; left: 0; right: 0; z-index: 99;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1.5rem 2rem;
  transform: translateY(-120%);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}
.mobile-menu.active { transform: translateY(0); opacity: 1; visibility: visible; }
.mobile-menu ul { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.mobile-menu a {
  display: block; padding: 0.75rem 1rem;
  color: var(--text-secondary); font-size: 1rem; font-weight: 500;
  border-radius: 8px; transition: all 0.2s;
}
.mobile-menu a:hover { background: var(--bg-card); color: var(--text-primary); }

/* Hero */
.hero {
  min-height: 100vh;
  display: flex; align-items: center;
  padding: 8rem 2rem 4rem;
  position: relative; overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 800px; height: 800px; max-width: 100%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%);
  pointer-events: none;
}
.hero .inner {
  max-width: 1200px; margin: 0 auto; width: 100%;
  display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 4rem; align-items: center;
  position: relative; z-index: 1;
}
.eyebrow { font-size: 1rem; color: var(--text-secondary); font-weight: 500; margin-bottom: 0.5rem; }
.hero h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 800; line-height: 1.1; letter-spacing: -0.03em;
  margin-bottom: 1rem;
}
.gradient-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
}
.tagline {
  font-size: 1.2rem; font-weight: 600;
  margin-bottom: 2rem; padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}
.intro { font-size: 1.1rem; color: var(--text-secondary); line-height: 1.8; margin-bottom: 2rem; }
.intro strong { color: var(--text-primary); font-weight: 600; }

.hero-cta { display: flex; gap: 1rem; flex-wrap: wrap; }
.primary-button, .ghost-button {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.875rem 1.75rem; border-radius: 10px;
  font-size: 0.95rem; font-weight: 600;
  transition: all 0.2s; cursor: pointer;
}
.primary-button { background: var(--text-primary); color: var(--bg-primary); border: 1px solid var(--text-primary); }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 10px 40px var(--button-shadow); color: var(--bg-primary); }
.ghost-button { background: transparent; color: var(--text-primary); border: 1px solid var(--border-color); }
.ghost-button:hover { background: var(--bg-card); border-color: var(--text-muted); color: var(--text-primary); }

.hero-portrait {
  width: 380px; height: 380px; max-width: 100%;
  justify-self: center;
  border-radius: 50%;
  object-fit: cover; object-position: center 20%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  outline: 1px solid var(--border-color);
  outline-offset: 8px;
}

/* Sections */
.portfolio { padding: 6rem 2rem; }
.portfolio.alt { background: var(--bg-secondary); transition: background-color 0.3s; }
.portfolio .inner { max-width: 1200px; margin: 0 auto; }
.section-heading { text-align: center; margin-bottom: 4rem; }
.section-heading h2 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 700; letter-spacing: -0.02em; margin-bottom: 1rem;
}
.section-heading p { color: var(--text-secondary); font-size: 1.1rem; max-width: 600px; margin: 0 auto; }

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.5rem; }
.card-grid.two { grid-template-columns: repeat(2, 1fr); max-width: 900px; margin: 0 auto; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
  transition: all 0.3s;
}
.card:hover { background: var(--bg-card-hover); transform: translateY(-4px); border-color: var(--text-muted); }
.card.accent::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--accent-gradient); opacity: 0; transition: opacity 0.3s;
}
.card.accent:hover::before { opacity: 1; }

.card-icon {
  width: 44px; height: 44px; margin-bottom: 1.25rem;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-primary);
}
.card-icon svg { width: 22px; height: 22px; }

.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.75rem; }
.category {
  display: inline-block; padding: 0.25rem 0.75rem;
  background: var(--accent-soft); color: var(--accent-primary);
  border-radius: 100px; font-size: 0.75rem; font-weight: 600;
}
.date { color: var(--text-muted); font-size: 0.8rem; }
.outlet { color: var(--text-secondary); font-size: 0.85rem; font-weight: 500; }

.card h3 { font-size: 1.15rem; font-weight: 600; line-height: 1.4; margin-bottom: 0.75rem; color: var(--text-primary); }
.card h3 a { color: var(--text-primary); }
.card h3 a:hover { color: var(--accent-primary); }
.card p { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.7; margin-bottom: 1rem; }
.card p:last-child { margin-bottom: 0; }
.card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem; color: var(--text-primary);
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: 6px; padding: 0.1rem 0.4rem;
  overflow-wrap: anywhere;
}

.card-links { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: auto; padding-top: 0.5rem; }
.card-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary); font-size: 0.85rem; font-weight: 500;
  transition: all 0.2s;
}
.card-link:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--text-muted); }
.card-link svg { width: 14px; height: 14px; }

/* Highlights (stats row) */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5rem; margin-bottom: 1.5rem; }
.stat { text-align: center; }
.stat .value { font-size: 2.25rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; margin-bottom: 0.5rem; }
.stat p { margin: 0; }

/* Skills */
.skills-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tag {
  padding: 0.35rem 0.8rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 100px;
  color: var(--text-secondary); font-size: 0.8rem; font-weight: 500;
}

.section-cta { text-align: center; margin-top: 2rem; }

/* Footer */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 4rem 2rem 2rem;
  text-align: center;
  transition: background-color 0.3s, border-color 0.3s;
}
.site-footer h2 { font-size: clamp(1.75rem, 3vw, 2.25rem); font-weight: 700; letter-spacing: -0.02em; margin-bottom: 0.75rem; }
.site-footer .lead { color: var(--text-secondary); margin-bottom: 2rem; }
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 3rem; }
.footer-meta { color: var(--text-muted); font-size: 0.85rem; }

/* Inner pages */
.nav-links a[aria-current="page"], .mobile-menu a[aria-current="page"] { color: var(--text-primary); }
.page-hero {
  padding: 10rem 2rem 4rem;
  position: relative; overflow: hidden;
  text-align: center;
}
.page-hero::before {
  content: '';
  position: absolute; top: -200px; left: 50%; transform: translateX(-50%);
  width: 800px; height: 600px; max-width: 100%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.15) 0%, transparent 70%);
  pointer-events: none;
}
.page-hero .inner { max-width: 760px; margin: 0 auto; position: relative; z-index: 1; }
.page-hero h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 800; line-height: 1.1; letter-spacing: -0.03em;
  margin-bottom: 1.25rem;
}
.page-hero .intro { margin-bottom: 0; }
.back-link {
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--text-secondary); font-size: 0.9rem; font-weight: 500;
  margin-bottom: 1.5rem;
}
.back-link:hover { color: var(--text-primary); }
.page-section { padding: 4rem 2rem; }
.page-section:last-of-type { padding-bottom: 6rem; }
.page-section .inner { max-width: 1200px; margin: 0 auto; }
.page-section h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700; letter-spacing: -0.02em; margin-bottom: 1.5rem;
  display: flex; align-items: center; gap: 0.75rem;
}
.page-section h2 .count { color: var(--text-muted); font-size: 1rem; font-weight: 500; }

.card.empty {
  border-style: dashed; background: transparent;
  align-items: center; justify-content: center; text-align: center;
  min-height: 180px;
}
.card.empty:hover { transform: none; background: var(--bg-card); border-color: var(--border-color); }
.card.empty .card-icon { margin-bottom: 1rem; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.5rem; }
.book-cover {
  height: 140px;
  margin: -1.5rem -1.5rem 1.25rem;
  width: calc(100% + 3rem);
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 1.25rem 1.5rem;
  background: var(--accent-gradient);
  color: #fff;
  position: relative;
}
.book-cover::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 30%, rgba(0,0,0,0.45));
}
.book-cover > * { position: relative; z-index: 1; }
.book-cover .subject {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  opacity: 0.85; margin-bottom: 0.25rem;
}
.book-cover .author { font-size: 1.35rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.2; }
.book-cover.math { background: linear-gradient(135deg, #3b82f6, #8b5cf6); }
.book-cover.electronics { background: linear-gradient(135deg, #8b5cf6, #ec4899); }
.book-cover.programming { background: linear-gradient(135deg, #0ea5e9, #3b82f6); }
.book-cover.telecom { background: linear-gradient(135deg, #ec4899, #f59e0b); }
.card-link[aria-disabled="true"] { opacity: 0.6; cursor: default; pointer-events: none; }

/* Responsive */
@media (max-width: 968px) {
  .hero .inner { grid-template-columns: 1fr; text-align: center; gap: 3rem; }
  .hero-portrait { width: 280px; height: 280px; order: -1; }
  .hero-cta { justify-content: center; }
  .nav-links { display: none; }
  .hamburger { display: flex; }
  .mobile-menu { display: block; }
  .card-grid.two, .skills-grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .site-header { padding: 1rem; }
  .social-icons { display: none; }
  .hero { padding: 7rem 1.5rem 3rem; }
  .portfolio { padding: 4rem 1.5rem; }
  .page-hero { padding: 8rem 1.5rem 3rem; }
  .page-section { padding: 3rem 1.5rem; }
  .card-grid { grid-template-columns: 1fr; }
  .hero-cta { flex-direction: column; align-items: center; }
  .primary-button, .ghost-button { width: 100%; max-width: 280px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; }
}
