:root {
  --bg: #fcf8f8;
  --bg-soft: #f8efef;
  --surface: rgba(255, 255, 255, 0.7);
  --surface-strong: #fffdfd;
  --text: #1e1818;
  --muted: #6f5f62;
  --line: rgba(52, 36, 41, 0.16);
  --accent: #8b5962;
  --accent-soft: rgba(139, 89, 98, 0.14);
  --shadow: 0 20px 46px -28px rgba(45, 20, 29, 0.33);
  --radius-xl: 22px;
  --radius-lg: 14px;
}

html[data-theme="dark"] {
  --bg: #181417;
  --bg-soft: #231d21;
  --surface: rgba(36, 30, 34, 0.8);
  --surface-strong: #262026;
  --text: #f4eff1;
  --muted: #bcaeb3;
  --line: rgba(255, 232, 238, 0.14);
  --accent: #d2a8b2;
  --accent-soft: rgba(210, 168, 178, 0.18);
  --shadow: 0 22px 52px -34px rgba(0, 0, 0, 0.72);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  background: radial-gradient(1100px 620px at 12% 4%, var(--bg-soft), var(--bg));
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

a {
  color: inherit;
}

.page {
  width: min(1100px, calc(100% - 2.2rem));
  margin: 0 auto;
  padding: 1.1rem 0 2.2rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.3rem;
  min-height: 2.8rem;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.site-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.94rem;
  letter-spacing: 0.01em;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: color 180ms ease, border-color 180ms ease;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.site-nav a[aria-current="page"] {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  outline: none;
}

.theme-toggle {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.48rem 0.86rem;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.01em;
  transition: background-color 180ms ease, transform 180ms ease, border-color 180ms ease;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
  background: var(--surface-strong);
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  transform: translateY(-1px);
  outline: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(5px);
  transition: transform 220ms ease, border-color 220ms ease, background-color 220ms ease;
}

.panel:hover {
  border-color: color-mix(in srgb, var(--accent) 33%, var(--line));
  transform: translateY(-2px);
}

.footer {
  margin-top: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  display: grid;
  gap: 0.2rem;
}

.footer p {
  margin: 0;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(62px);
  opacity: 0.25;
  animation: drift var(--dur, 16s) ease-in-out infinite alternate;
}

.orb-a {
  width: 28rem;
  height: 28rem;
  top: -10rem;
  left: -8rem;
  background: #f8dbe2;
  --dur: 14s;
}

.orb-b {
  width: 24rem;
  height: 24rem;
  bottom: -11rem;
  right: -7rem;
  background: #efd6dd;
  --dur: 16s;
}

.orb-c {
  width: 18rem;
  height: 18rem;
  top: 40%;
  left: 58%;
  background: #f3e8ee;
  --dur: 18s;
}

html[data-theme="dark"] .orb-a {
  background: #5d4d5c;
}

html[data-theme="dark"] .orb-b {
  background: #6d5a67;
}

html[data-theme="dark"] .orb-c {
  background: #5d4f58;
}

.ambient-particle {
  position: absolute;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  opacity: 0.22;
  transform: translate3d(0, 0, 0);
  animation: floatParticle var(--time) linear infinite;
}

.reveal {
  opacity: 0;
  transform: translateY(12px);
}

.ready .reveal {
  animation: revealIn 780ms ease forwards;
}

.ready .reveal.delay-1 {
  animation-delay: 70ms;
}

.ready .reveal.delay-2 {
  animation-delay: 130ms;
}

@keyframes revealIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  from {
    transform: translateY(0) translateX(0) scale(1);
  }
  to {
    transform: translateY(18px) translateX(12px) scale(1.05);
  }
}

@keyframes floatParticle {
  0% {
    transform: translate3d(0, 0, 0);
  }
  50% {
    transform: translate3d(var(--dx), -22px, 0);
  }
  100% {
    transform: translate3d(0, -45px, 0);
  }
}

/* Gallery archive */
.page-gallery-archive {
  width: min(980px, calc(100% - 2rem));
  padding-bottom: 2.6rem;
}

.gallery-hero {
  padding: clamp(1.15rem, 2.3vw, 1.6rem);
  margin-bottom: 0.9rem;
}

.gallery-hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4.1vw, 2.9rem);
  line-height: 1.18;
  letter-spacing: -0.02em;
  font-weight: 600;
}

.gallery-subtitle {
  margin: 0.76rem 0 0;
  color: var(--text);
  font-size: clamp(1rem, 1.4vw, 1.1rem);
  line-height: 1.72;
}

.gallery-note {
  margin: 0.5rem 0 0;
  color: var(--muted);
  max-width: 62ch;
  font-size: 0.98rem;
  line-height: 1.7;
}

.gallery-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.05rem 0 0.95rem;
}

.gallery-filter {
  border: 1px solid var(--line);
  color: var(--muted);
  background: color-mix(in srgb, var(--surface-strong) 80%, transparent);
  border-radius: 999px;
  padding: 0.32rem 0.72rem;
  font: inherit;
  font-size: 0.87rem;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background-color 180ms ease;
}

.gallery-filter:hover,
.gallery-filter:focus-visible {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  outline: none;
}

.gallery-filter.is-active,
.gallery-filter[aria-pressed="true"] {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 60%, var(--surface-strong));
}

.gallery-list {
  border-top: 1px solid var(--line);
}

.gallery-loading,
.gallery-empty {
  margin: 1rem 0 0;
  padding: 1rem 0.2rem;
  color: var(--muted);
}

.gallery-item {
  display: grid;
  grid-template-columns: minmax(130px, 200px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
  padding: 1rem 0.15rem;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 88%, transparent);
}

.gallery-thumb {
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-strong) 92%, transparent);
  cursor: zoom-in;
  transition: border-color 180ms ease, transform 180ms ease;
}

.gallery-thumb:hover,
.gallery-thumb:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  transform: translateY(-1px);
  outline: none;
}

.gallery-thumb-portrait {
  aspect-ratio: 3 / 4;
}

.gallery-thumb-landscape {
  aspect-ratio: 4 / 3;
}

.gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-meta {
  min-width: 0;
}

.gallery-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  letter-spacing: 0.01em;
}

.gallery-title {
  margin: 0.2rem 0 0;
  font-size: 1.2rem;
  line-height: 1.35;
  font-weight: 600;
}

.gallery-series {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.gallery-description {
  margin: 0.48rem 0 0;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.66;
  max-width: 66ch;
}

.gallery-view {
  margin-top: 0.68rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface-strong) 80%, transparent);
  color: var(--text);
  border-radius: 999px;
  padding: 0.38rem 0.78rem;
  font: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.gallery-view:hover,
.gallery-view:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 58%, var(--surface-strong));
  outline: none;
}

.gallery-lightbox {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 30;
}

.gallery-lightbox[hidden] {
  display: none;
}

.gallery-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 6, 9, 0.8);
  backdrop-filter: blur(4px);
}

.gallery-lightbox-content {
  position: relative;
  margin: 0;
  width: min(980px, 100%);
  max-height: calc(100vh - 2rem);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: 12px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-strong) 78%, #111);
  box-shadow: var(--shadow);
}

.gallery-lightbox-content img {
  display: block;
  width: 100%;
  max-height: min(66vh, 720px);
  object-fit: contain;
  background: color-mix(in srgb, var(--bg) 70%, #111);
}

.gallery-lightbox-content figcaption {
  padding: 0.88rem 1rem 0.72rem;
  border-top: 1px solid var(--line);
}

.gallery-lightbox-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 600;
}

.gallery-lightbox-meta {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.gallery-lightbox-description {
  margin: 0.45rem 0 0;
  font-size: 0.95rem;
  line-height: 1.58;
}

.gallery-lightbox-controls {
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem 1rem;
}

.gallery-lightbox-controls button,
.gallery-lightbox-close {
  border: 1px solid var(--line);
  color: var(--text);
  background: color-mix(in srgb, var(--surface-strong) 80%, transparent);
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.gallery-lightbox-controls button {
  padding: 0.36rem 0.76rem;
  font-size: 0.85rem;
}

.gallery-lightbox-controls button:hover,
.gallery-lightbox-controls button:focus-visible,
.gallery-lightbox-close:hover,
.gallery-lightbox-close:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 56%, var(--surface-strong));
  outline: none;
}

.gallery-lightbox-close {
  position: absolute;
  top: 0.58rem;
  right: 0.58rem;
  width: 2rem;
  height: 2rem;
  font-size: 1.1rem;
  line-height: 1;
}

/* Lab */
.page-lab {
  width: min(900px, calc(100% - 3rem));
  padding-bottom: 2.5rem;
}

.lab-hero {
  padding: clamp(1.35rem, 3vw, 2rem);
}

.lab-hero {
  margin-bottom: 1.65rem;
}

.lab-hero h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4.1vw, 2.9rem);
  line-height: 1.18;
  letter-spacing: -0.02em;
  font-weight: 600;
}

.lab-subtitle {
  margin: 0.76rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.4vw, 1.08rem);
  line-height: 1.78;
}

.lab-projects {
  display: grid;
  gap: 1.55rem;
}

.lab-project {
  display: block;
}

.panel.lab-project {
  padding: clamp(1.75rem, 3.4vw, 2rem);
}

.lab-project h2 {
  margin: 0 0 0.75rem;
  font-size: 1.12rem;
  line-height: 1.35;
  letter-spacing: 0.01em;
  font-weight: 600;
}

.lab-project p {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.78;
}

.lab-project h2 + p {
  color: var(--text);
}

.lab-project p.lab-project-note {
  margin-top: 0.75rem;
  color: var(--muted);
  font-size: 0.91rem;
  line-height: 1.62;
}

.lab-project-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  margin-top: 1.25rem;
  min-height: 2.38rem;
  padding: 0 1rem;
  border: 1px solid color-mix(in srgb, var(--accent) 44%, var(--line));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-soft) 58%, var(--surface-strong));
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.lab-project-link:hover,
.lab-project-link:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 62%, var(--line));
  background: color-mix(in srgb, var(--accent-soft) 84%, var(--surface-strong));
  transform: translateY(-1px);
  outline: none;
}

@media (max-width: 920px) {
  .topbar {
    margin-bottom: 0.9rem;
  }

  .gallery-item {
    grid-template-columns: minmax(120px, 170px) minmax(0, 1fr);
    gap: 0.82rem;
  }
}

@media (max-width: 620px) {
  .page {
    width: min(1100px, calc(100% - 1.25rem));
  }

  .site-nav {
    font-size: 0.91rem;
  }

  .page-gallery-archive,
  .page-lab {
    width: min(980px, calc(100% - 2.25rem));
  }

  .gallery-item {
    grid-template-columns: 1fr;
  }

  .gallery-thumb {
    width: min(100%, 240px);
  }

  .gallery-lightbox-content img {
    max-height: 54vh;
  }

  .lab-project {
    display: block;
  }

  .panel.lab-project {
    padding: 1.38rem 1.25rem;
  }

  .lab-project-link {
    width: fit-content;
    max-width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }

  .reveal {
    opacity: 1;
    transform: none;
  }
}
