/* Theme tokens */
:root,
[data-theme="light"] {
  --bg: #f4f1ea;
  --bg-elevated: #fffdf8;
  --bg-muted: #ebe6dc;
  --text: #1a1f1c;
  --text-muted: #5a635c;
  --border: #d5cfc3;
  --accent: #1f3d2b;
  --accent-soft: #e4ebe6;
  --accent-contrast: #f4f1ea;
  --shadow: 0 1px 0 rgba(26, 31, 28, 0.06);
  --header-h: 4rem;
  --radius: 0.75rem;
  --font-sans: "Figtree", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
  --content: 72rem;
  --space: clamp(0.75rem, 2vw, 1rem);
  --section-y: clamp(2.25rem, 5vw, 3.5rem);
  --text-halo: 0 0 16px var(--bg), 0 0 28px color-mix(in srgb, var(--bg) 80%, transparent);
  --field-wash: transparent;
}

[data-theme="dark"] {
  --bg: #121614;
  --bg-elevated: #1a201c;
  --bg-muted: #232a26;
  --text: #eceae4;
  --text-muted: #a3aba5;
  --border: #2f3832;
  --accent: #8fbf9b;
  --accent-soft: #243028;
  --accent-contrast: #121614;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  --text-halo: 0 0 16px var(--bg), 0 0 28px color-mix(in srgb, var(--bg) 85%, transparent);
}

html[data-bg="ocean"][data-theme="light"] {
  --text-muted: #24332e;
  --accent: #163226;
  --border: color-mix(in srgb, #1a1f1c 20%, transparent);
  --text-halo: none;
  --field-wash: transparent;
}

html[data-bg="ocean"][data-theme="dark"] {
  --text-muted: #d2d8d0;
  --border: color-mix(in srgb, #eceae4 16%, transparent);
  --text-halo:
    0 0 8px var(--bg),
    0 0 20px var(--bg),
    0 0 32px color-mix(in srgb, var(--bg) 85%, transparent);
  --field-wash: color-mix(in srgb, var(--bg) 18%, transparent);
}

html[data-bg="code"][data-theme="light"] {
  --text-muted: #3a433e;
  --field-wash: transparent;
}

html[data-bg="code"][data-theme="dark"] {
  --text-muted: #c5cdc6;
  --field-wash: color-mix(in srgb, var(--bg) 12%, transparent);
}

html[data-bg="gravity"][data-theme="light"] {
  --text-muted: #24322c;
  --accent: #163226;
  --border: color-mix(in srgb, #1a1f1c 20%, transparent);
  --text-halo: none;
  --field-wash: transparent;
}

html[data-bg="gravity"][data-theme="dark"] {
  --text-muted: #d2d8d0;
  --border: color-mix(in srgb, #eceae4 16%, transparent);
  --text-halo:
    0 0 8px var(--bg),
    0 0 20px var(--bg),
    0 0 32px color-mix(in srgb, var(--bg) 85%, transparent);
  --field-wash: color-mix(in srgb, var(--bg) 22%, transparent);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h) + 0.75rem);
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.bg-field {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
  transform: translateZ(0);
  contain: strict;
}

.bg-field[hidden] {
  display: none;
}

#app {
  position: relative;
  z-index: 1;
}

#app::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: var(--field-wash);
}

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

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-thickness: 2px;
}

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

.skip-link {
  position: absolute;
  left: var(--space);
  top: -100px;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: 0.4rem;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
}

.hero__title,
.section-title,
.hero__lead,
.lead,
.prose p,
.hero__role,
.kicker,
.site-footer,
.contact-links a:not(.btn) {
  text-shadow: var(--text-halo);
}

.wrap {
  width: min(100% - var(--space) * 2, var(--content));
  margin-inline: auto;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  height: var(--header-h);
  min-width: 0;
}

.brand {
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
}

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

.nav-desktop {
  display: none;
  flex: 1;
  justify-content: center;
  gap: 0.15rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-desktop a {
  display: block;
  padding: 0.4rem 0.55rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: 0.4rem;
}

.nav-desktop a:hover {
  color: var(--text);
  background: var(--bg-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
  flex-shrink: 0;
}

.header-links {
  display: none;
  align-items: center;
  gap: 0.25rem;
}

.header-links a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.35rem 0.45rem;
  border-radius: 0.4rem;
}

.header-links a:hover {
  color: var(--text);
  background: var(--bg-muted);
}

.icon-btn,
.lang-toggle,
.menu-toggle {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 0.45rem;
  padding: 0.35rem 0.55rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.2;
}

.icon-btn:hover,
.lang-toggle:hover,
.menu-toggle:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--accent-soft);
}

.theme-toggle {
  --pad: 2px;
  --d: 20px;
  appearance: none;
  position: relative;
  display: grid;
  grid-template-columns: var(--d) var(--d);
  align-items: center;
  width: calc(var(--d) * 2 + var(--pad) * 2 + 2px);
  height: calc(var(--d) + var(--pad) * 2 + 2px);
  padding: var(--pad);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-muted);
  cursor: pointer;
  flex-shrink: 0;
  line-height: 0;
}

.theme-toggle:hover {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.theme-toggle__thumb {
  position: absolute;
  top: var(--pad);
  left: var(--pad);
  width: var(--d);
  height: var(--d);
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg-elevated) 55%, #fff);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.28);
  transition: transform 0.22s ease;
}

[data-theme="dark"] .theme-toggle__thumb {
  transform: translateX(var(--d));
}

.theme-toggle__slot {
  display: grid;
  place-items: center;
  width: var(--d);
  height: var(--d);
}

.theme-toggle__icon {
  position: relative;
  z-index: 1;
  display: block;
  width: 12px;
  height: 12px;
  color: #e8b40a;
  fill: currentColor;
  pointer-events: none;
  opacity: 0.45;
}

[data-theme="light"] .theme-toggle__icon--sun,
[data-theme="dark"] .theme-toggle__icon--moon {
  opacity: 1;
}

.lang-toggle[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.lang-pair {
  display: inline-flex;
  gap: 0.2rem;
}

.cv-chip {
  display: none;
  text-decoration: none;
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
  padding: 0.35rem 0.65rem;
  border-radius: 0.45rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.cv-chip:hover {
  filter: brightness(1.05);
  text-decoration: none;
}

.menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.menu-toggle[aria-expanded="true"] {
  background: var(--accent-soft);
}

.nav-mobile {
  display: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.nav-mobile.is-open {
  display: block;
}

.nav-mobile__list {
  list-style: none;
  margin: 0;
  padding: 0.5rem var(--space) 0.75rem;
  display: grid;
  gap: 0.15rem;
}

.nav-mobile a {
  display: block;
  padding: 0.7rem 0.75rem;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  border-radius: 0.45rem;
}

.nav-mobile a:hover {
  background: var(--bg-muted);
}

.nav-mobile__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  margin-top: 0.25rem;
  padding-top: 0.85rem;
}

.nav-mobile__meta a {
  font-size: 0.9rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
}

/* Main layout */
main {
  min-height: 60vh;
}

.section,
.hero {
  scroll-margin-top: calc(var(--header-h) + 0.5rem);
}

.section {
  padding-block: var(--section-y);
  border-bottom: 1px solid var(--border);
}

.section:last-of-type {
  border-bottom: none;
}

.kicker {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.section-title {
  margin: 0 0 0.7rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.6rem, 3.2vw, 2.15rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
  max-width: 28ch;
}

.lead,
.prose p {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
  max-width: 62ch;
}

html[data-bg] .hero__role,
html[data-bg] .hero__lead,
html[data-bg] .lead,
html[data-bg] .prose p,
html[data-bg] .site-footer {
  font-weight: 500;
}

html[data-bg="ocean"] .site-header,
html[data-bg="gravity"] .site-header {
  background: color-mix(in srgb, var(--bg) 80%, transparent);
}

html[data-bg="ocean"][data-theme="light"] .stack-card,
html[data-bg="ocean"][data-theme="light"] .service-card,
html[data-bg="ocean"][data-theme="light"] .project-card,
html[data-bg="ocean"][data-theme="light"] .empty-slot,
html[data-bg="ocean"][data-theme="light"] .note-card,
html[data-bg="gravity"][data-theme="light"] .stack-card,
html[data-bg="gravity"][data-theme="light"] .service-card,
html[data-bg="gravity"][data-theme="light"] .project-card,
html[data-bg="gravity"][data-theme="light"] .empty-slot,
html[data-bg="gravity"][data-theme="light"] .note-card {
  box-shadow: 0 1px 0 rgba(26, 31, 28, 0.04), 0 10px 28px rgba(26, 31, 28, 0.08);
}

.prose p {
  margin-bottom: 0.7rem;
}

.prose p:last-child {
  margin-bottom: 0;
}

/* Hero */
.hero {
  padding-block: clamp(1.9rem, 5.5vw, 3.5rem) var(--section-y);
}

.hero__role {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-weight: 500;
}

.hero__title {
  margin: 0 0 0.65rem;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.hero__lead {
  margin: 0 0 1rem;
  font-size: 1.125rem;
  line-height: 1.6;
  color: var(--text-muted);
  max-width: 42rem;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.15rem;
  border-radius: 0.55rem;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn--primary:hover {
  filter: brightness(1.06);
  text-decoration: none;
}

.btn--ghost {
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  color: var(--text);
  border-color: color-mix(in srgb, var(--text) 22%, var(--border));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.btn--ghost:hover {
  background: var(--bg-muted);
  text-decoration: none;
}

/* Stack grid */
.stack-grid {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
  grid-template-columns: 1fr;
}

.stack-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.7rem 0.75rem;
}

.stack-card h3 {
  margin: 0 0 0.45rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Services */
.service-grid {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.service-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.service-card h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.3;
}

.service-card p {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.6;
}

.service-notes {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.9rem;
}

.note-card {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 0.65rem 0.75rem;
}

.note-card h3 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
}

.note-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.98rem;
  line-height: 1.6;
}

/* Projects */
.project-grid {
  display: grid;
  gap: 0.55rem;
  margin-top: 1rem;
}

.project-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.project-card__top {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.project-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.project-card__problem,
.project-card__role {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
}

.project-card__role span {
  color: var(--text);
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}

.stat {
  padding: 0.75rem 0.85rem;
  background: var(--bg-muted);
  border-radius: 0.55rem;
}

.stat__value {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
}

.stat__label {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.empty-slot {
  margin-top: 1rem;
  padding: 0.8rem 0.7rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-muted);
}

.empty-slot p {
  margin: 0;
  max-width: 52ch;
  line-height: 1.6;
}

/* Contact */
.contact-panel {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.contact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.55rem;
  align-items: center;
}

.contact-links a:not(.btn) {
  color: var(--text);
  font-weight: 500;
}

.site-footer {
  padding: 1rem 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
}

.site-footer p {
  margin: 0;
}

.bg-switch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin: 1.25rem auto 0;
}

.bg-switch__caption {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.bg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  appearance: none;
  height: 2.25rem;
  padding: 0 0.8rem 0 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-elevated) 88%, transparent);
  color: var(--text-muted);
  cursor: pointer;
}

.bg-toggle:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

.bg-toggle__name {
  font-size: 0.85rem;
  font-weight: 500;
  color: inherit;
}

.bg-toggle__icon {
  width: 1.2rem;
  height: 1.2rem;
  flex-shrink: 0;
  fill: currentColor;
}

.bg-toggle__icon--line {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.loading,
.error {
  padding: 4rem var(--space);
  text-align: center;
  color: var(--text-muted);
}

.error {
  color: #a33;
}

/* Breakpoints */
@media (max-width: 639px) {
  .site-header__inner {
    gap: 0.4rem;
  }

  .header-actions {
    gap: 0.22rem;
  }
}

@media (min-width: 640px) {
  .stack-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .service-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .service-notes {
    grid-template-columns: repeat(2, 1fr);
  }

  .header-links {
    display: flex;
  }

  .cv-chip {
    display: inline-flex;
  }
}

@media (min-width: 900px) {
  .nav-desktop {
    display: flex;
  }

  .menu-toggle {
    display: none;
  }

  .stack-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .service-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .project-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1100px) {
  .project-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .theme-toggle__thumb {
    transition: none;
  }
}
