/* ── Base Styles, Reset, Cursor & Utilities ─────────────── */

/* ── Reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}



/* ── Base ─────────────────────────────────────────────────── */
html {
  scroll-behavior: smooth;
  background: var(--bg);
  overflow-x: clip;
}

body {
  background: transparent;
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 1.0625rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

::selection {
  background: var(--accent-a12);
  color: var(--heading);
}

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

button,
summary,
input,
textarea,
select {
  font: inherit;
}

a,
button,
summary,
input,
textarea,
select {
  transition: color 0.2s ease,
              border-color 0.2s ease,
              background-color 0.2s ease,
              box-shadow 0.2s ease,
              transform 0.2s ease,
              opacity 0.2s ease;
}

button,
summary {
  cursor: pointer;
}

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

@media (pointer: fine) {
  body {
    cursor: none;
  }
}

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

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Grain overlay — dark mode performance optimization */
html:not([data-theme="light"]) body::before {
  content: "";
  position: fixed;
  inset: -100px;
  z-index: 9998;
  pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px;
}

/* Background canvases — only present on index.html */
#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  opacity: 0.55;
}

#pcb-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
}

/* ── Custom cursor ────────────────────────────────────────── */
.cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99999;
  pointer-events: none;
  display: none;
}

@media (pointer: fine) {
  .cursor {
    display: block;
  }
}

.cursor-dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  transform: translate(-50%, -50%);
  transition: transform 0.1s;
}

.cursor-ring {
  width: 32px;
  height: 32px;
  border: 1px solid var(--accent-a45);
  border-radius: 50%;
  position: absolute;
  transform: translate(-50%, -50%);
  transition:
    transform 0.18s ease,
    width 0.2s,
    height 0.2s,
    opacity 0.2s;
}

body:has(a:hover) .cursor-ring,
body:has(button:hover) .cursor-ring {
  width: 48px;
  height: 48px;
  border-color: var(--accent-a80);
}

/* ── Skip link ────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.6rem 1.2rem;
  border-radius: 2px;
  text-decoration: none;
  z-index: 10000;
  transition: top 0.2s;
}

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



/* ── Scroll progress bar ──────────────────────────────────── */
.scroll-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--glow-gold, #d4a85a));
  box-shadow: 0 0 8px var(--accent), 0 0 14px var(--accent-a40);
  z-index: 10000;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left;
  will-change: transform;
  border-radius: 0 2px 2px 0;
}

/* ── Back-to-top + scroll % ───────────────────────────────── */
.back-top {
  position: fixed;
  bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  right: calc(2rem + env(safe-area-inset-right, 0px));
  z-index: 200;
  width: 42px;
  height: 42px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.3s,
    transform 0.3s,
    border-color 0.2s,
    color 0.2s;
}

.back-top.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.audio-toggle {
  bottom: calc(9rem + env(safe-area-inset-bottom, 0px));
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

.audio-icon-off {
  display: none;
}

.audio-toggle.is-active {
  border-color: var(--accent);
  color: var(--accent);
}

.audio-toggle.is-active .audio-icon-on {
  display: block;
}

.audio-toggle:not(.is-active) .audio-icon-on {
  display: none;
}

.audio-toggle:not(.is-active) .audio-icon-off {
  display: block;
}

.back-top:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.back-top svg {
  width: 14px;
  height: 14px;
  pointer-events: none;
}

.scroll-pct {
  position: fixed;
  bottom: calc(2.9rem + env(safe-area-inset-bottom, 0px));
  right: calc(2rem + env(safe-area-inset-right, 0px));
  z-index: 200;
  width: 42px;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.56rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.scroll-pct.visible {
  opacity: 0.7;
  transform: translateY(0);
}



/* ── Section base ─────────────────────────────────────────── */
section {
  padding: 7rem 3rem;
  position: relative;
}

.section-header {
  margin-bottom: 4rem;
}

.section-num {
  font-family: var(--mono);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.section-title {
  font-family: var(--serif);
  font-size: clamp(2rem, 3.5vw, 3.2rem);
  font-weight: 300;
  color: var(--heading);
  line-height: 1.1;
  position: relative;
  display: inline-block;
}

.section-title::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), transparent);
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1) 0.2s;
  border-radius: 2px;
}

.reveal.visible .section-title::after {
  width: 100%;
}

.section-title em {
  font-style: italic;
  color: var(--accent);
}

html[data-theme="light"] .section-num {
  color: var(--accent);
  opacity: 1;
}



/* ── Dividers ─────────────────────────────────────────────── */
.divider-wrap {
  position: relative;
  display: flex;
  align-items: center;
  padding: 1.5rem 3rem;
  gap: 0;
  background: transparent;
  z-index: 1;
}

.divider-edge {
  flex-shrink: 0;
  width: 3rem;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line));
}

.divider-edge--right {
  background: linear-gradient(90deg, var(--line), transparent);
}

.divider-node {
  flex-shrink: 0;
  width: 5px;
  height: 5px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: var(--bg);
  position: relative;
  z-index: 1;
  box-shadow: 0 0 6px var(--accent-a35);
  animation: divider-node-pulse 4s ease-in-out infinite;
  will-change: transform, opacity;
}

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

.divider-wrap .divider {
  margin: 0;
  flex: 1;
  width: auto;
}

.divider {
  position: relative;
  flex: 1;
  width: auto;
  height: 1px;
  background: var(--line);
  overflow: hidden;
}

.divider::before {
  content: "";
  position: absolute;
  top: -1.5px;
  left: 0;
  width: 15%;
  height: 4px;
  background: transparent;
  border-top: 2.5px solid var(--accent);
  filter: drop-shadow(0 0 5px var(--accent)) drop-shadow(0 0 2px var(--accent));
  border-radius: 2px;
  transform: translateX(-110%);
  animation: arc-sweep-cw 5s linear infinite;
  opacity: 0.9;
}

.divider::after {
  content: "";
  position: absolute;
  top: -1px;
  right: 0;
  width: 10%;
  height: 3px;
  background: transparent;
  border-top: 1.5px solid var(--accent2);
  filter: drop-shadow(0 0 4px var(--accent2));
  border-radius: 2px;
  transform: translateX(1100%);
  animation: arc-sweep-ccw 7s linear infinite;
  opacity: 0.6;
}

@keyframes arc-sweep-cw {
  0% {
    transform: translateX(-110%);
    opacity: 0;
  }

  5% {
    opacity: 0.85;
  }

  95% {
    opacity: 0.85;
  }

  100% {
    transform: translateX(767%);
    opacity: 0;
  }
}

@keyframes arc-sweep-ccw {
  0% {
    transform: translateX(1100%);
    opacity: 0;
  }

  5% {
    opacity: 0.55;
  }

  95% {
    opacity: 0.55;
  }

  100% {
    transform: translateX(-1100%);
    opacity: 0;
  }
}

/* Stagger per divider position */
.divider-wrap:nth-of-type(1) .divider::before {
  animation-delay: 0s;
}

.divider-wrap:nth-of-type(2) .divider::before {
  animation-delay: -0.7s;
}

.divider-wrap:nth-of-type(3) .divider::before {
  animation-delay: -1.4s;
}

.divider-wrap:nth-of-type(4) .divider::before {
  animation-delay: -2.1s;
}

.divider-wrap:nth-of-type(5) .divider::before {
  animation-delay: -2.8s;
}

.divider-wrap:nth-of-type(1) .divider::after {
  animation-delay: -2s;
}

.divider-wrap:nth-of-type(2) .divider::after {
  animation-delay: -3s;
}

.divider-wrap:nth-of-type(3) .divider::after {
  animation-delay: -4s;
}

.divider-wrap:nth-of-type(4) .divider::after {
  animation-delay: -5s;
}

.divider-wrap:nth-of-type(5) .divider::after {
  animation-delay: -1s;
}

html[data-theme="light"] .divider::before {
  border-top-color: var(--glow-gold);
  filter: drop-shadow(0 0 5px var(--glow-gold)) drop-shadow(0 0 2px var(--glow-gold));
}

html[data-theme="light"] .divider::after {
  border-top-color: var(--glow-teal);
  filter: drop-shadow(0 0 4px var(--glow-teal));
}

html[data-theme="light"] .divider-node {
  border-color: var(--glow-gold);
  box-shadow: 0 0 6px var(--glow-gold-a35);
}



/* ── Reveal on scroll ─────────────────────────────────────── */
.reveal {
  opacity: 0;
  transform: translateY(18px) scale(0.975);
  transition:
    opacity 0.48s cubic-bezier(0.16, 1, 0.3, 1),
    transform 0.48s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.reveal-stagger-1 { transition-delay: 0.05s; }
.reveal-stagger-2 { transition-delay: 0.10s; }
.reveal-stagger-3 { transition-delay: 0.15s; }
.reveal-stagger-4 { transition-delay: 0.20s; }
.reveal-stagger-5 { transition-delay: 0.25s; }
.reveal-stagger-6 { transition-delay: 0.30s; }
.reveal-stagger-7 { transition-delay: 0.35s; }
.reveal-stagger-8 { transition-delay: 0.40s; }



/* ── Focus & pointer reset ────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 6px var(--accent);
  border-radius: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

@media (pointer: coarse) {
  body {
    cursor: auto;
  }
}

/* ── Reduced motion ───────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  body {
    cursor: auto !important;
  }
  .cursor {
    display: none !important;
  }

  @view-transition {
    navigation: none;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

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

  html {
    scroll-behavior: auto;
  }
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 1100px) {
  section {
    padding: 5.5rem 2rem;
  }
}

@media (max-width: 900px) {
  :root {
    --nav-h: 68px;
  }

  section {
    padding: 3.5rem 1.25rem;
  }

  .divider-wrap {
    padding: 0;
    margin: 0 1.25rem;
  }

  .back-top {
    bottom: calc(4.2rem + env(safe-area-inset-bottom, 0px));
    right: calc(1.25rem + env(safe-area-inset-right, 0px));
  }

  .audio-toggle {
    bottom: calc(7.6rem + env(safe-area-inset-bottom, 0px));
    right: calc(1.25rem + env(safe-area-inset-right, 0px));
  }

  .scroll-pct {
    bottom: calc(2.2rem + env(safe-area-inset-bottom, 0px));
    right: calc(1.25rem + env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 480px) {
  :root {
    --nav-h: 60px;
  }

  section {
    padding: 2.75rem 0.85rem;
  }

  .divider-wrap {
    margin: 0 0.85rem;
  }

  .back-top {
    bottom: calc(3.8rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
    width: 36px;
    height: 36px;
  }

  .audio-toggle {
    bottom: calc(6.8rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
    width: 36px;
    height: 36px;
  }

  .scroll-pct {
    bottom: calc(1.8rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
    width: 36px;
    font-size: 0.52rem;
  }

  .section-title {
    font-size: clamp(1.6rem, 7vw, 2.2rem);
  }
}

@media (max-width: 360px) {
  :root {
    --nav-h: 56px;
  }

  section {
    padding: 2.25rem 0.65rem;
  }

  .divider-wrap {
    margin: 0 0.65rem;
  }

  .back-top {
    bottom: calc(3.4rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.6rem + env(safe-area-inset-right, 0px));
    width: 32px;
    height: 32px;
  }

  .audio-toggle {
    bottom: calc(6.1rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.6rem + env(safe-area-inset-right, 0px));
    width: 32px;
    height: 32px;
  }

  .scroll-pct {
    bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.6rem + env(safe-area-inset-right, 0px));
    width: 32px;
    font-size: 0.48rem;
  }
}

/* ── Content Visibility & Rendering Optimization ───────────── */
.content-visibility-auto,
.cv-auto {
  content-visibility: auto;
  contain-intrinsic-size: auto 500px;
}

.cv-card {
  content-visibility: auto;
  contain-intrinsic-size: auto 280px;
}
