/* ---------- Intro loader: ASCII donut + counter + split-screen reveal ---------- */
html.loading,
html.loading body {
  overflow: hidden;
}
html.no-intro #loader {
  display: none;
}
#loader {
  /* Same tokens as the site (base.css / theme.css), so the intro follows dark + light mode */
  --ld-bg: var(--bg, #05030d);
  --ld-fg: var(--fg, #f2f0ff);
  --ld-dim: var(--dim, #a99fd0);
  --ld-accent: var(--ascii, #fd400c);
  --ld-violet: 176, 120, 255; /* nav-glow purple */
  --ld-blue: 90, 140, 255;
  position: fixed;
  inset: 0;
  z-index: 10000;
  color: var(--ld-fg);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  touch-action: none;
  user-select: none;
}
.ld-half {
  position: absolute;
  left: 0;
  right: 0;
  height: 50.2%;
  background: var(--ld-bg);
  transition: transform 1.05s cubic-bezier(0.76, 0, 0.24, 1);
  will-change: transform;
}
.ld-half::after {
  /* faint scanlines */
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    rgba(127, 120, 170, 0.07) 0 1px,
    transparent 1px 3px
  );
}
.ld-top {
  top: 0;
}
.ld-bot {
  bottom: 0;
}
.ld-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: var(--ld-accent);
  box-shadow: 0 0 18px 2px color-mix(in srgb, var(--ld-accent) 75%, transparent);
  transform: scaleX(0);
  transition:
    transform 0.55s cubic-bezier(0.7, 0, 0.2, 1) 0.4s,
    opacity 0.3s;
}
.ld-ui {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) clamp(16px, 3vw, 32px)
    calc(20px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(
    circle at 50% 50%,
    color-mix(in srgb, var(--ld-accent) 13%, transparent),
    transparent 55%
  );
}
.ld-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ld-dim);
  transition: opacity 0.4s;
}
.ld-tl {
  top: calc(22px + env(safe-area-inset-top, 0px));
  left: clamp(16px, 3vw, 32px);
}
.ld-tr {
  top: calc(22px + env(safe-area-inset-top, 0px));
  right: clamp(16px, 3vw, 32px);
  text-align: right;
}
.ld-bl {
  bottom: calc(26px + env(safe-area-inset-bottom, 0px));
  left: clamp(16px, 3vw, 32px);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ld-accent);
}
#ld-donut {
  margin: 0;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: clamp(6px, 1.25vw, 13px);
  line-height: 1.2;
  color: var(--ld-accent);
  text-shadow: 0 0 12px color-mix(in srgb, var(--ld-accent) 55%, transparent);
  white-space: pre;
  transform-origin: 50% 50%;
  transition:
    transform 1.1s cubic-bezier(0.7, 0, 0.2, 1),
    opacity 0.7s 0.35s;
}
.ld-count {
  position: absolute;
  right: clamp(16px, 3vw, 32px);
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: flex-start;
  line-height: 0.85;
  font-size: clamp(40px, 7vw, 104px);
  font-weight: 500;
  letter-spacing: -0.05em;
  font-variant-numeric: tabular-nums;
  text-shadow:
    -2px 0 rgba(var(--ld-violet), 0.55),
    2px 0 rgba(var(--ld-blue), 0.55); /* subtle split in the nav-glow purple/blue */
  transition: opacity 0.4s;
}
.ld-count i {
  font-style: normal;
  font-size: 0.22em;
  letter-spacing: 0;
  margin: 0.25em 0 0 0.2em;
  color: var(--ld-accent);
}

/* ----- exit: donut zooms through the screen, a red line draws, the halves split ----- */
#loader.is-exit #ld-donut {
  transform: scale(14);
  opacity: 0;
  animation: ldGlitch 0.5s steps(1) 1;
}
#loader.is-exit .ld-count,
#loader.is-exit .ld-corner {
  opacity: 0;
}
#loader.is-exit .ld-line {
  transform: scaleX(1);
}
#loader.is-split .ld-top {
  transform: translateY(-101%);
}
#loader.is-split .ld-bot {
  transform: translateY(101%);
}
#loader.is-split .ld-line {
  opacity: 0;
}
#loader.is-split .ld-ui {
  display: none;
}
@keyframes ldGlitch {
  0% {
    text-shadow:
      -8px 0 rgb(176, 120, 255),
      8px 0 rgb(90, 140, 255);
  }
  25% {
    text-shadow:
      6px 3px rgb(176, 120, 255),
      -6px -3px rgb(90, 140, 255);
  }
  50% {
    text-shadow:
      -10px -2px rgb(176, 120, 255),
      10px 2px rgb(90, 140, 255);
  }
  75% {
    text-shadow:
      4px 0 rgb(176, 120, 255),
      -4px 0 rgb(90, 140, 255);
  }
  100% {
    text-shadow: 0 0 12px color-mix(in srgb, var(--ld-accent) 55%, transparent);
  }
}

/* ----- the site itself arrives after the reveal ----- */
body:not(.loaded) header > * {
  opacity: 0;
}
body.loaded header > * {
  animation: ldDrop 0.95s cubic-bezier(0.2, 0.8, 0.2, 1) backwards;
}
body.loaded header > *:nth-child(2) {
  animation-delay: 0.08s;
}
body.loaded header > *:nth-child(3) {
  animation-delay: 0.16s;
}
body.loaded #gl {
  animation: ldRise 1.7s cubic-bezier(0.2, 0.8, 0.2, 1) 0.15s backwards;
}
body.loaded footer {
  animation: ldFade 1s 0.7s backwards;
}
@keyframes ldDrop {
  from {
    opacity: 0;
    transform: translateY(-26px);
  }
}
@keyframes ldRise {
  from {
    opacity: 0;
    transform: scale(1.18);
  }
}
@keyframes ldFade {
  from {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  #ld-donut {
    font-size: min(2.6vw, 12px);
  }
  .ld-corner {
    font-size: 10px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .ld-half,
  #ld-donut,
  .ld-line {
    transition-duration: 0.01s !important;
    animation: none !important;
  }
  body.loaded header > *,
  body.loaded #gl,
  body.loaded footer {
    animation: none;
  }
}
