/* =============================================================
   Design tokens
   ============================================================= */

:root {
  /* Color — light */
  --color-bg: #fafaf7;
  --color-surface: #ffffff;
  --color-fg: #111111;
  --color-muted: #5e5e5e;
  --color-subtle: #8a8a8a;
  --color-border: #e6e3dc;
  --color-accent: #4338ca;
  --color-accent-fg: #ffffff;
  --color-code-bg: #efece4;

  /* Typography */
  --font-sans:
    ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono:
    ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --font-serif:
    ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;

  /* Type scale — 1.25 modular */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --text-4xl: 3rem;
  --text-5xl: 4rem;

  /* Line heights */
  --leading-tight: 1.15;
  --leading-snug: 1.3;
  --leading-normal: 1.55;
  --leading-relaxed: 1.7;

  /* Weight */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing — 4px base */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.1);

  /* Layout */
  --content-width: 720px;
  --gutter: var(--space-6);

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 120ms;
  --duration-base: 220ms;
}

/* Dark theme — system preference */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0c0c0c;
    --color-surface: #141414;
    --color-fg: #f4f4f1;
    --color-muted: #a8a8a3;
    --color-subtle: #6f6f6c;
    --color-border: #222220;
    --color-accent: #a3a0ff;
    --color-accent-fg: #0c0c0c;
    --color-code-bg: #1c1c1a;
  }
}

/* Manual overrides */
[data-theme="light"] {
  --color-bg: #fafaf7;
  --color-surface: #ffffff;
  --color-fg: #111111;
  --color-muted: #5e5e5e;
  --color-subtle: #8a8a8a;
  --color-border: #e6e3dc;
  --color-accent: #4338ca;
  --color-accent-fg: #ffffff;
  --color-code-bg: #efece4;
}

[data-theme="dark"] {
  --color-bg: #0c0c0c;
  --color-surface: #141414;
  --color-fg: #f4f4f1;
  --color-muted: #a8a8a3;
  --color-subtle: #6f6f6c;
  --color-border: #222220;
  --color-accent: #a3a0ff;
  --color-accent-fg: #0c0c0c;
  --color-code-bg: #1c1c1a;
}

/* =============================================================
   Reset & base
   ============================================================= */

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

html {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: var(--leading-normal);
  color: var(--color-fg);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
}

main {
  max-width: var(--content-width);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

section {
  padding-block: var(--space-16) var(--space-8);
  border-top: 1px solid var(--color-border);
}

section:first-of-type {
  border-top: 0;
}

h1,
h2,
h3 {
  margin: 0 0 var(--space-4);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
}

h1 {
  font-size: var(--text-5xl);
  letter-spacing: -0.03em;
  margin-bottom: var(--space-6);
}

h2 {
  font-size: var(--text-xl);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-muted);
  font-weight: var(--weight-medium);
  margin-bottom: var(--space-8);
}

h3 {
  font-size: var(--text-lg);
}

p {
  margin: 0 0 var(--space-4);
  max-width: 60ch;
}

a {
  color: var(--color-fg);
  text-decoration-color: var(--color-subtle);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--duration-fast) var(--ease-out),
    text-decoration-color var(--duration-fast) var(--ease-out);
}

a:hover {
  color: var(--color-accent);
  text-decoration-color: var(--color-accent);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--color-code-bg);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* =============================================================
   Layout — header, hero, footer
   ============================================================= */

.site-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  max-width: var(--content-width);
  margin-inline: auto;
  padding: var(--space-6) var(--gutter);
  position: sticky;
  top: 0;
  background: color-mix(in oklab, var(--color-bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  z-index: 10;
  border-bottom: 1px solid transparent;
}

.brand {
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
  font-size: var(--text-base);
  text-decoration: none;
  letter-spacing: 0.02em;
}

.site-header nav {
  margin-left: auto;
  display: flex;
  gap: var(--space-6);
  font-size: var(--text-sm);
}

.site-header nav a {
  text-decoration: none;
  color: var(--color-muted);
}

.site-header nav a:hover {
  color: var(--color-fg);
}

.theme-toggle {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-fg);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  transition: background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.theme-toggle:hover {
  background: var(--color-surface);
  border-color: var(--color-muted);
}

.hero {
  padding-block: var(--space-20) var(--space-10);
  border-top: 0;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-muted);
  margin-bottom: var(--space-6);
}

.lede {
  font-size: var(--text-xl);
  line-height: var(--leading-snug);
  color: var(--color-fg);
  max-width: 38ch;
  margin-bottom: var(--space-8);
}

.lede a {
  text-decoration-thickness: 1.5px;
}

.meta {
  font-size: var(--text-sm);
  color: var(--color-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.meta a {
  text-decoration: none;
  color: var(--color-muted);
}

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

/* =============================================================
   Skill card (about section)
   ============================================================= */

.skill-card-wrap {
  margin: 0 0 var(--space-8);
  max-width: 60ch;
}

.skill-filename {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-subtle);
  letter-spacing: 0.04em;
  padding: 0 var(--space-3) var(--space-2);
}

.skill-card {
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  color: var(--color-fg);
  white-space: pre-wrap;
  margin: 0;
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.skill-card code {
  background: transparent;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* =============================================================
   Work list
   ============================================================= */

.work-list {
  display: grid;
  gap: var(--space-10);
}

.work-item h3 {
  margin-bottom: var(--space-2);
  font-weight: var(--weight-semibold);
}

.work-item p {
  color: var(--color-muted);
  max-width: 65ch;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.tag {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--color-subtle);
  padding: 0.18rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  letter-spacing: 0.02em;
}

/* =============================================================
   Timeline
   ============================================================= */

.timeline {
  display: grid;
  gap: var(--space-6);
}

.timeline li {
  border-left: 2px solid var(--color-border);
  padding-left: var(--space-5);
}

.timeline .role {
  margin: 0 0 var(--space-1);
  font-weight: var(--weight-medium);
  color: var(--color-fg);
}

.timeline .org {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-subtle);
}

/* =============================================================
   Skill cluster
   ============================================================= */

.skill-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.skill-cluster li {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--color-muted);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

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

.cta {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  padding: var(--space-3) var(--space-5);
  background: var(--color-accent);
  color: var(--color-accent-fg);
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out);
  box-shadow: var(--shadow-sm);
}

.cta:hover {
  color: var(--color-accent-fg);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.cta.is-copied::after {
  content: " ✓ copied";
  font-size: var(--text-sm);
  opacity: 0.85;
}

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

.site-footer {
  max-width: var(--content-width);
  margin: var(--space-16) auto var(--space-8);
  padding: var(--space-6) var(--gutter);
  border-top: 1px solid var(--color-border);
  color: var(--color-subtle);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

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

@media (max-width: 540px) {
  :root {
    --text-5xl: 2.75rem;
    --text-4xl: 2.25rem;
    --text-xl: 1.2rem;
  }

  .site-header nav {
    gap: var(--space-4);
  }

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

  .hero {
    padding-block: var(--space-12) var(--space-8);
  }
}

/* =============================================================
   Visual chrome — dots & glow
   ============================================================= */

/* Hero — dot grid that fades from top-left + soft accent glow */
.hero {
  position: relative;
  isolation: isolate;
}

.hero::before {
  content: "";
  position: absolute;
  inset: calc(var(--space-4) * -1) 0 0 0;
  background-image: radial-gradient(
    circle at 1px 1px,
    color-mix(in oklab, var(--color-fg) 10%, transparent) 1px,
    transparent 0
  );
  background-size: 28px 28px;
  -webkit-mask-image: radial-gradient(
    ellipse 70% 70% at 20% 30%,
    #000 0%,
    transparent 75%
  );
  mask-image: radial-gradient(
    ellipse 70% 70% at 20% 30%,
    #000 0%,
    transparent 75%
  );
  z-index: -1;
  pointer-events: none;
}

.hero::after {
  content: "";
  position: absolute;
  top: 0;
  left: -12%;
  width: 55%;
  height: 80%;
  background: radial-gradient(
    circle at center,
    color-mix(in oklab, var(--color-accent) 22%, transparent) 0%,
    transparent 65%
  );
  filter: blur(40px);
  opacity: 0.85;
  z-index: -1;
  pointer-events: none;
}

/* Section heading — small accent dot */
section h2::before {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-accent);
  margin-right: var(--space-3);
  vertical-align: 0.18em;
  box-shadow: 0 0 10px
    color-mix(in oklab, var(--color-accent) 55%, transparent);
}

/* Brand — slow pulsing status dot */
.brand {
  position: relative;
  padding-right: var(--space-4);
}

.brand::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-accent);
  transform: translateY(-50%);
  box-shadow: 0 0 10px
    color-mix(in oklab, var(--color-accent) 60%, transparent);
  animation: pulse 2.8s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.65;
    transform: translateY(-50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-50%) scale(1.25);
  }
}

/* CTA — accent glow on hover */
.cta:hover {
  box-shadow: var(--shadow-md),
    0 0 32px color-mix(in oklab, var(--color-accent) 35%, transparent);
}

/* Theme toggle — tactile press response */
.theme-toggle:active {
  transform: scale(0.92);
}

/* =============================================================
   Fluid theme switch — View Transitions radial reveal
   ============================================================= */

@supports (view-transition-name: none) {
  /* Root — page-wide radial reveal */
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
  }

  ::view-transition-old(root) {
    z-index: 1;
  }

  ::view-transition-new(root) {
    z-index: 2;
    animation: theme-reveal 920ms cubic-bezier(0.65, 0, 0.35, 1) forwards;
  }

  @keyframes theme-reveal {
    from {
      clip-path: circle(0 at var(--vt-x, 50%) var(--vt-y, 50%));
    }
    to {
      clip-path: circle(
        var(--vt-r, 150vmax) at var(--vt-x, 50%) var(--vt-y, 50%)
      );
    }
  }

  /* Toggle — independent rotation lane, with a springy curve.
     The view transition takes a snapshot of the old icon and a snapshot of
     the new icon; we cross-rotate them so the eye reads it as one continuous
     spin. */
  .theme-toggle {
    view-transition-name: theme-toggle;
  }

  ::view-transition-old(theme-toggle),
  ::view-transition-new(theme-toggle) {
    animation: none;
    mix-blend-mode: normal;
    transform-origin: 50% 50%;
  }

  ::view-transition-old(theme-toggle) {
    animation: toggle-spin-out 820ms cubic-bezier(0.34, 1.36, 0.5, 1)
      forwards;
  }

  ::view-transition-new(theme-toggle) {
    animation: toggle-spin-in 820ms cubic-bezier(0.34, 1.36, 0.5, 1)
      forwards;
  }

  @keyframes toggle-spin-out {
    0% {
      transform: rotate(0deg) scale(1);
      opacity: 1;
    }
    60% {
      opacity: 0;
    }
    100% {
      transform: rotate(180deg) scale(0.85);
      opacity: 0;
    }
  }

  @keyframes toggle-spin-in {
    0% {
      transform: rotate(-180deg) scale(0.85);
      opacity: 0;
    }
    40% {
      opacity: 0;
    }
    100% {
      transform: rotate(0deg) scale(1);
      opacity: 1;
    }
  }
}

/* Honor reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .brand::after {
    animation: none;
  }
}
