/* ============================================
   Design tokens (single source of truth)
   ============================================ */
:root {
  /* Spacing scale (4px base) */
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Typography */
  --font-heading: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-body: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* Border radius */
  --radius-md: 6px;
  --radius-full: 9999px;

  /* Motion */
  --duration-ui: 280ms;
  --duration-reveal: 450ms;
  --duration-bar: 700ms;
  --ease-out: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);

  /* Shadows (light mode) */
  --shadow-sm: 0 1px 2px rgba(75, 46, 43, 0.06);
  --shadow-md: 0 4px 12px rgba(75, 46, 43, 0.08);

  /* Light theme (default) */
  --bg-primary: #FFF8F0;
  --bg-surface: #FFF8F0;
  --text-primary: #4B2E2B;
  --text-secondary: #8C5A3C;
  --accent: #C08552;
  --accent-muted: #8C5A3C;
  --border: rgba(75, 46, 43, 0.12);
}

[data-theme="dark"] {
  --bg-primary: #222831;
  --bg-surface: #393E46;
  --text-primary: #DFD0B8;
  --text-secondary: #948979;
  --accent: #948979;
  --accent-muted: #b5a090;
  --border: rgba(223, 208, 184, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* ============================================
   Base & layout
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg-primary);
  overscroll-behavior: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: color var(--duration-ui) var(--ease-out);
}

main {
  visibility: hidden;
}

body.is-ready main {
  visibility: visible;
}

.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ============================================
   Header & nav
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  transition: background-color var(--duration-ui) var(--ease-out),
    border-color var(--duration-ui) var(--ease-out);
}

.header-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 56px;
  gap: var(--space-4);
}

.header-inner > nav {
  grid-column: 2;
  justify-self: center;
}

.header-inner > .theme-toggle {
  grid-column: 3;
  justify-self: end;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-links a {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  transition: color var(--duration-ui) var(--ease-out),
    background-color var(--duration-ui) var(--ease-out);
}

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

.nav-links a.is-active {
  color: var(--accent);
  background-color: color-mix(in srgb, var(--accent) 12%, transparent);
}

.nav-links a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Theme toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color var(--duration-ui) var(--ease-out),
    color var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out);
}

.theme-toggle:hover {
  background-color: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
}

.theme-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform var(--duration-ui) var(--ease-out);
}

.theme-toggle .icon-moon {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: block;
}

/* ============================================
   Sections (shared)
   ============================================ */
section {
  padding: var(--space-6) 0;
}

section:first-of-type {
  padding-top: var(--space-4);
}

.section-title {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin: 0 0 var(--space-6);
  line-height: var(--leading-tight);
}

/* Reveal animation (will be toggled by JS) */
.reveal {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity var(--duration-reveal) var(--ease-out-expo),
    transform var(--duration-reveal) var(--ease-out-expo);
}

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

.reveal-stagger > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--duration-reveal) var(--ease-out-expo),
    transform var(--duration-reveal) var(--ease-out-expo);
}

.reveal-stagger.is-visible > * {
  opacity: 1;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .reveal.is-visible,
  .reveal-stagger > *,
  .reveal-stagger.is-visible > * {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* ============================================
   Hero
   ============================================ */
.hero {
  text-align: center;
  padding: var(--space-6) 0 var(--space-4);
}

.hero h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin: 0 0 var(--space-4);
  line-height: var(--leading-tight);
}

.hero-avatar-wrap {
  margin: 0 auto var(--space-4);
  width: 120px;
  height: 120px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background-color: var(--border);
}

.hero-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-avatar-wrap.is-empty {
  display: none;
}

.hero .tagline {
  font-size: var(--text-lg);
  color: var(--text-secondary);
  margin: 0 0 var(--space-4);
}

.hero .contact-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
}

.hero .contact-links a {
  font-size: var(--text-sm);
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--duration-ui) var(--ease-out),
    text-decoration-color var(--duration-ui) var(--ease-out);
}

.hero .contact-links a:hover {
  color: var(--accent-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.hero .contact-links a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================
   Profile
   ============================================ */
.profile p {
  font-size: var(--text-lg);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  margin: 0;
  max-width: 60ch;
}

/* ============================================
   Skills & languages (bars)
   ============================================ */
.skills-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  /* Reserve space so JSON-injected content doesn't cause large layout shifts */
  min-height: 180px;
}

.languages-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.skill-item,
.language-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.skill-item label,
.language-item label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
}

.bar-track {
  height: 8px;
  background-color: var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  max-width: var(--bar-width, 0%);
  background-color: var(--accent);
  border-radius: var(--radius-full);
  transition: width var(--duration-bar) var(--ease-out-expo);
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill {
    transition: none;
  }
}

/* ============================================
   Cards (Projects, Work, Courses, Education)
   ============================================ */
.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  /* Reserve space for cards populated via JavaScript */
  min-height: 220px;
}

.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-ui) var(--ease-out),
    border-color var(--duration-ui) var(--ease-out),
    transform var(--duration-ui) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-md);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.card:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
}

.card .meta {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.card ul {
  margin: 0;
  padding-left: var(--space-6);
  color: var(--text-primary);
  line-height: var(--leading-relaxed);
}

.card li {
  margin-bottom: var(--space-2);
}

.card li:last-child {
  margin-bottom: 0;
}

/* ============================================
   Achievements
   ============================================ */
.achievements-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  list-style: none;
  margin: 0;
  padding: 0;
  /* Avoid big shift when achievements are injected */
  min-height: 60px;
}

.achievements-list li {
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
  background-color: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  transition: border-color var(--duration-ui) var(--ease-out),
    color var(--duration-ui) var(--ease-out);
}

.achievements-list li:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ============================================
   Footer
   ============================================ */
.site-footer {
  padding: var(--space-12) 0;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.site-footer .footer-links {
  margin: 0 0 var(--space-2);
  line-height: var(--leading-snug);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ============================================
   Responsive: mobile nav
   ============================================ */
@media (max-width: 640px) {
  .header-inner {
    grid-template-columns: 1fr auto;
  }

  .header-inner > nav {
    grid-column: 1;
    justify-self: start;
  }

  .header-inner > .theme-toggle {
    grid-column: 2;
  }

  .nav-links {
    display: none;
  }

  .nav-links.is-open {
    display: flex;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    padding: var(--space-4);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    gap: 0;
  }

  .nav-links.is-open a {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
  }

  .nav-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
}

@media (min-width: 641px) {
  .nav-toggle {
    display: none;
  }
}
