/* =============================================
   TOKENS
   ============================================= */
:root {
  --bg: #0b0b0c;
  --surface: #17171a;
  --border: #2a2a2e;
  --text: #f2f2f3;
  --muted: #9a9a9f;
  --accent: #4d8dff;
  --accent-contrast: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.6);
  --maxw: 1040px;
  --transition: 0.15s ease;
}

:root[data-theme="light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e2e2e5;
  --text: #141414;
  --muted: #68686d;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --backdrop: rgba(0, 0, 0, 0.35);
}

/* =============================================
   RESET & BASE
   ============================================= */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.65;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

img { display: block; max-width: 100%; height: auto; }
ul { list-style: none; padding: 0; margin: 0; }

/* =============================================
   TYPOGRAPHY
   ============================================= */
h1, h2, h3 {
  font-family: 'Inter', system-ui, sans-serif;
  font-weight: 700;
  line-height: 1.05;
  margin: 0;
}

h2 { font-size: clamp(1.8rem, 3.5vw, 2.5rem); }
h3 { font-size: 1.15rem; }

p { color: var(--muted); margin: 0 0 1rem 0; }
p:last-child { margin-bottom: 0; }
strong { color: var(--text); font-weight: 600; }
em { font-style: italic; color: inherit; }

/* =============================================
   LAYOUT
   ============================================= */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 40px;
}

.section { padding: 100px 0; }

.section-alt {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.section-header { margin-bottom: 56px; }

.section-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}

/* =============================================
   SKIP LINK
   ============================================= */
.skip-link {
  position: absolute;
  left: -999px;
  top: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border: 1px solid var(--border);
  z-index: 9999;
  font-size: 0.875rem;
}
.skip-link:focus { left: 12px; }

/* =============================================
   HEADER & NAV
   ============================================= */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  gap: 20px;
}

.wordmark {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.wordmark:hover { color: var(--accent); }
.dot { color: var(--accent); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 32px;
}

nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color var(--transition);
}
nav a:hover { color: var(--accent); }
.nav-external { color: var(--accent) !important; }
nav a[aria-current="page"] { color: var(--accent); }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.nav-toggle span {
  display: block;
  width: 20px;
  height: 1.5px;
  background: var(--text);
}
.nav-toggle[aria-expanded="true"] span:first-child {
  transform: translateY(6.5px) rotate(45deg);
}
.nav-toggle[aria-expanded="true"] span:last-child {
  transform: translateY(-6.5px) rotate(-45deg);
}

/* =============================================
   THEME TOGGLE
   ============================================= */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  transition: border-color var(--transition), color var(--transition);
}
.theme-toggle:hover { border-color: var(--muted); }
.theme-toggle .icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .icon-light { display: none; }
:root[data-theme="light"] .theme-toggle .icon-dark { display: inline; }

/* =============================================
   FOCUS
   ============================================= */
a:focus-visible, button:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid var(--border);
  transition: opacity var(--transition), border-color var(--transition), color var(--transition), background var(--transition);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.btn-outline {
  background: transparent;
  color: var(--text);
}
.btn-outline:hover { opacity: 0.6; }

/* =============================================
   HERO
   ============================================= */
.hero {
  min-height: 100svh;
  display: flex;
  align-items: center;
  padding: 120px 0 80px;
}

.hero-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 24px;
}

.hero-name {
  font-size: clamp(3rem, 9vw, 7rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-bottom: 28px;
}

.accent-dot { color: var(--accent); }

.hero-sub {
  font-size: 1rem;
  color: var(--muted);
  max-width: 420px;
  margin-bottom: 40px;
}

.hero-cta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* =============================================
   ABOUT
   ============================================= */
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 72px;
  align-items: center;
}

.about-photo {
  width: 100%;
  max-width: 400px;
  filter: grayscale(15%);
  border: 1px solid var(--border);
}

.about-text h2 { margin: 12px 0 20px; }
.about-text p { margin-bottom: 12px; }
.about-text .btn { margin-top: 8px; }

/* =============================================
   SKILLS
   ============================================= */
.skills-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border: 1px solid var(--border);
}

.skill-group {
  padding: 32px;
  border-right: 1px solid var(--border);
}
.skill-group:last-child { border-right: none; }

.skill-group-title {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 16px;
}

.skill-list { display: flex; flex-direction: column; }

.skill-list li {
  color: var(--text);
  font-size: 0.9rem;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.skill-list li:last-child { border-bottom: none; }

/* =============================================
   PROJECTS
   ============================================= */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--border);
}

.project-tile {
  display: flex;
  flex-direction: column;
  padding: 32px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  position: relative;
}

.project-tile:hover {
  background: var(--surface);
}

/* Remove right border on every 3rd tile */
.project-tile:nth-child(3n) {
  border-right: none;
}

/* Remove bottom border on last row */
.project-tile:nth-last-child(-n+3):nth-child(3n+1),
.project-tile:nth-last-child(-n+3):nth-child(3n+1) ~ .project-tile {
  border-bottom: none;
}

.project-img-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 24px;
  background: var(--border);
}

.project-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  filter: grayscale(30%);
}

.project-tile:hover .project-img { filter: grayscale(0%); }

.project-tile-body {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.project-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin-bottom: 10px;
  align-items: center;
}

.project-tag {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.project-tag + .project-tag::before {
  content: ' · ';
  color: var(--border);
}

.project-badge {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 7px;
  margin-left: auto;
}

.project-title {
  font-size: 1.1rem;
  color: var(--text);
  margin: 0 0 10px;
}

.project-desc {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0;
  flex: 1;
  line-height: 1.6;
}

.project-links { margin-top: 24px; }

/* =============================================
   ZONE DIVIDERS
   ============================================= */
.zone-divider {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 40px;
  max-width: var(--maxw);
  margin: 0 auto;
}

.zone-divider::before,
.zone-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.zone-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

/* =============================================
   RESEARCH
   ============================================= */
.research-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
}

.research-item {
  padding: 36px 40px;
  border-bottom: 1px solid var(--border);
}
.research-item:last-child { border-bottom: none; }

.research-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.research-org {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.research-title {
  font-size: 1.15rem;
  color: var(--text);
  margin: 0;
}

.research-badge {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 3px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.research-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 16px;
  max-width: 680px;
}

.research-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.research-tag {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 3px 8px;
}

/* =============================================
   PROJECT PLACEHOLDER
   ============================================= */
.project-img-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.placeholder-wordmark {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 2rem;
  font-weight: 800;
  color: var(--border);
  letter-spacing: 0.05em;
}

/* =============================================
   CONTACT
   ============================================= */
.section-contact { border-top: 1px solid var(--border); }

.contact-inner { text-align: center; }

.contact-inner h2 {
  margin: 12px 0 20px;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
}

.contact-inner p {
  max-width: 420px;
  margin: 0 auto 36px;
}

.contact-links {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* =============================================
   FOOTER
   ============================================= */
footer {
  padding: 24px 0;
  border-top: 1px solid var(--border);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.footer-wordmark {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--muted);
}

footer p {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* =============================================
   BACK TO TOP
   ============================================= */
#back-to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 40px;
  height: 40px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 1rem;
  cursor: pointer;
  display: none;
  z-index: 200;
  transition: color var(--transition), border-color var(--transition);
}
#back-to-top:hover { color: var(--text); border-color: var(--muted); }

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 900px) {
  .about-grid { grid-template-columns: 1fr; gap: 40px; }
  .about-photo { max-width: 280px; margin: 0 auto; }
  .skills-grid { grid-template-columns: 1fr; }
  .skill-group { border-right: none; border-bottom: 1px solid var(--border); }
  .skill-group:last-child { border-bottom: none; }
  .projects-grid { grid-template-columns: repeat(2, 1fr); }
  .project-tile:nth-child(3n) { border-right: 1px solid var(--border); }
  .project-tile:nth-child(2n) { border-right: none; }
  .project-tile:nth-last-child(-n+3):nth-child(3n+1),
  .project-tile:nth-last-child(-n+3):nth-child(3n+1) ~ .project-tile { border-bottom: 1px solid var(--border); }
  .project-tile:nth-last-child(-n+2):nth-child(2n+1),
  .project-tile:nth-last-child(-n+2):nth-child(2n+1) ~ .project-tile { border-bottom: none; }
  .research-header { flex-direction: column; gap: 10px; }
  .footer-inner { flex-direction: column; gap: 8px; text-align: center; }
}

@media (max-width: 640px) {
  .container { padding: 0 24px; }
  .section { padding: 72px 0; }
  nav {
    display: none;
    position: fixed;
    inset: 60px 0 0 0;
    background: var(--bg);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    z-index: 99;
    border-top: 1px solid var(--border);
  }
  nav.open { display: flex; }
  .nav-links { flex-direction: column; align-items: center; gap: 28px; }
  nav a { font-size: 1.1rem; }
  .nav-toggle { display: flex; }
  .hero-name { font-size: clamp(2.8rem, 14vw, 4.5rem); }
  .hero-cta { flex-direction: column; }
  .projects-grid { grid-template-columns: 1fr; }
  .project-tile { border-right: none !important; }
  .project-tile:last-child { border-bottom: none; }
  .research-item { padding: 28px 24px; }
  .zone-divider { padding: 0 24px; }
  .contact-links { flex-direction: column; align-items: center; }
}

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