/* =========================
   Tokens
   ========================= */
:root {
  --bg: #FAFAFA;
  --bg-soft: #F0F0F0;
  --text: #111111;
  --text-soft: #555555;
  --border: #1a1a1a;
  --border-soft: rgba(0, 0, 0, 0.12);

  --font-display: 'Caveat', cursive;
  --font-body: 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, monospace;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --space-6: 3rem;
  --space-7: 5rem;

  --radius: 0.5rem;
  --transition: 0.25s ease;
  --max-width: 820px;
}

:root[data-theme="dark"] {
  --bg: #0E0E0E;
  --bg-soft: #1a1a1a;
  --text: #FAFAFA;
  --text-soft: #AAAAAA;
  --border: #FAFAFA;
  --border-soft: rgba(255, 255, 255, 0.15);
}

/* =========================
   Reset
   ========================= */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background var(--transition), color var(--transition);
}

a { color: inherit; }

button {
  font: inherit;
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
}

ul { list-style: none; }

img { display: block; max-width: 100%; }

/* =========================
   Layout
   ========================= */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) 0;
  gap: var(--space-4);
}

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--space-4);
}

section {
  padding: var(--space-6) 0;
}

/* =========================
   Top bar
   ========================= */
.logo {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  gap: var(--space-4);
  font-size: 0.875rem;
}

.nav a {
  color: var(--text-soft);
  text-decoration: none;
  transition: color var(--transition);
}

.nav a:hover, .nav a:focus-visible {
  color: var(--text);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), background var(--transition), color var(--transition);
}

.theme-toggle:hover {
  transform: rotate(15deg);
}

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

/* =========================
   Hero
   ========================= */
.hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: var(--space-5);
  align-items: center;
  min-height: 70vh;
  padding-top: var(--space-5);
}

.hero-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.avatar-wrap {
  position: relative;
  width: 80px;
  height: 80px;
  margin-bottom: var(--space-3);
  flex-shrink: 0;
}

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--bg-soft);
}

.avatar-fallback {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--text-soft);
  color: var(--bg);
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 1.5rem;
  font-weight: 500;
  display: none;
}

.avatar-frame {
  position: absolute;
  inset: 0;
  width: 80px;
  height: 80px;
  pointer-events: none;
}

.name-wrap {
  position: relative;
  display: inline-block;
  padding: 0.5rem 1.25rem 0.25rem;
  margin-bottom: var(--space-2);
}

.name {
  font-family: var(--font-display);
  font-size: clamp(2.75rem, 7vw, 4rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.01em;
}

.name-scribble {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tagline {
  color: var(--text-soft);
  font-size: 1rem;
  max-width: 22rem;
  margin-bottom: var(--space-4);
}

.socials {
  display: flex;
  gap: var(--space-2);
}

.socials a {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: transform var(--transition), background var(--transition), color var(--transition);
}

.socials a:hover, .socials a:focus-visible {
  background: var(--text);
  color: var(--bg);
  transform: translateY(-2px) rotate(-3deg);
}

.hero-right {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 320px;
}

#voxel-canvas-container {
  width: 100%;
  height: 340px;
  position: relative;
}

#voxel-canvas-container canvas {
  cursor: grab;
  display: block;
}

#voxel-canvas-container canvas:active {
  cursor: grabbing;
}

/* =========================
   Section title (shared)
   ========================= */
.section-title {
  position: relative;
  display: inline-block;
  font-family: var(--font-display);
  font-size: clamp(1.875rem, 4vw, 2.5rem);
  font-weight: 700;
  line-height: 1;
  padding-bottom: 0.5rem;
  margin-bottom: var(--space-4);
  letter-spacing: -0.01em;
}

.title-underline {
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 8px;
}

/* =========================
   About
   ========================= */
.about-content {
  max-width: 36rem;
  color: var(--text-soft);
  font-size: 1.0625rem;
}

.about-content p + p {
  margin-top: var(--space-3);
}

.about-content a {
  color: var(--text);
}

/* =========================
   Interests
   ========================= */
.interest-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.interest {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
  color: var(--text-soft);
  transition: color var(--transition);
}

.interest-icon {
  width: 56px;
  height: 56px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.interest:hover { color: var(--text); }
.interest:hover .interest-icon {
  transform: rotate(-8deg) scale(1.08);
}

/* =========================
   Projects
   ========================= */
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}

.project-card {
  position: relative;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--bg);
  transition: transform var(--transition), box-shadow var(--transition);
}

.project-card:hover {
  transform: translate(-3px, -3px);
  box-shadow: 4px 4px 0 var(--border);
}

.project-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 0.25rem;
}

.project-desc {
  color: var(--text-soft);
  font-size: 0.9375rem;
  flex-grow: 1;
}

.project-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.project-tag {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

.project-links {
  display: flex;
  gap: var(--space-3);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.project-links a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-style: wavy;
  text-decoration-thickness: 1px;
  transition: opacity var(--transition);
}

.project-links a:hover { opacity: 0.65; }

/* =========================
   Contact
   ========================= */
.contact-text {
  font-size: 1.0625rem;
  color: var(--text-soft);
  max-width: 32rem;
}

.contact-text a {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-style: wavy;
  text-decoration-thickness: 1px;
}

/* =========================
   Footer
   ========================= */
.footer {
  border-top: 1px solid var(--border-soft);
  padding: var(--space-5) var(--space-4);
  text-align: center;
  color: var(--text-soft);
  font-size: 0.8125rem;
  margin-top: var(--space-5);
}

/* =========================
   Doodle draw-on animation
   ========================= */
.draw-path {
  stroke-dasharray: 1200;
  stroke-dashoffset: 1200;
}

.draw-path.drawn {
  animation: draw 1.1s cubic-bezier(0.5, 0, 0.2, 1) forwards;
}

@keyframes draw {
  to { stroke-dashoffset: 0; }
}

/* =========================
   Focus styles
   ========================= */
a:focus-visible,
button:focus-visible {
  outline: 2px dashed var(--text);
  outline-offset: 3px;
  border-radius: var(--radius);
}

/* =========================
   Reduced motion
   ========================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
  .draw-path {
    stroke-dasharray: none;
    stroke-dashoffset: 0;
  }
}

/* =========================
   Mobile
   ========================= */
@media (max-width: 720px) {
  .hero {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: var(--space-3);
  }

  .hero-right {
    order: -1;
    min-height: 240px;
  }

  #voxel-canvas-container {
    height: 240px;
  }

  .nav {
    display: none;
  }

  .topbar {
    padding-top: var(--space-3);
  }

  section {
    padding: var(--space-5) 0;
  }
}
