:root {
  --bg: #000000;
  --fg: #e8e8e8;
  --fg-dim: rgba(232, 232, 232, 0.4);
  --line: rgba(232, 232, 232, 0.15);
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --outer-col-width: 64px;
  /* --slot-w-0, --slot-w-1, … are NOT declared here — the number of
     projects (and so the number of slots) isn't fixed, so script.js's
     boot() sets one per project directly on the root element, and also
     sets .layout's grid-template-columns to match, before the first
     paint. See placeCategorySlots()/setActiveSlotWidth() in script.js. */
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-mono);
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.5), 0 0 16px rgba(255, 255, 255, 0.22);
}

button {
  font-family: var(--font-mono);
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

a {
  color: var(--fg);
}

a:focus {
  outline: none;
}

a:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

/* Intro gate — the first thing a visitor sees, sitting above everything
   else (including mobile-nav's z-index:10) until dismissed. The rest of
   the site boots up normally underneath it regardless; this is purely a
   visual overlay, not something the rest of the boot sequence waits on.
   Only .intro-text itself is interactive (see below) — the backdrop is
   just a static background, not a click target. */
.intro-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
  color: inherit;
  transition: opacity 2500ms ease-out;
}

.intro-gate[hidden] {
  display: none;
}

.intro-gate.is-dismissing {
  opacity: 0;
  pointer-events: none;
}

.intro-logo {
  position: absolute;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 100px;
  height: auto;
  pointer-events: none;
  /* Same fade+blur reveal as .intro-text, reusing the same keyframes. */
  animation: intro-reveal 2500ms ease-out forwards;
}

/* The only clickable/focusable part of the gate — not a native <button>
   (see script.js for why), so keyboard support and focus-visible styling
   don't come free and are restated here explicitly. */
.intro-text {
  font-family: var(--font-mono);
  font-size: clamp(1.1rem, 4.2vw, 1.5rem);
  font-weight: 300;
  letter-spacing: 0.15em;
  /* Fallback only — intro-glow-pulse below drives the real value whenever
     it's running (an active animation always outranks a plain
     declaration), which is always, except under reduced motion. */
  color: rgba(232, 232, 232, 0.8);
  text-align: center;
  cursor: pointer;
  /* Multiplies every blur-radius/alpha in intro-glow-pulse below — plain
     :hover bumping this to 1.5 scales the glow up in place, live, without
     restarting the animation (only a change to animation-name itself does
     that) or needing any JS class-toggle to drive it. --color-floor works
     the same way for the color pulse: collapsing it to 1 on hover means
     the 0%/50%/100% keyframe stops all resolve to the same full-bright
     value, i.e. a constant color rather than a pulsing one, without a
     separate :hover color rule that an active animation would just
     override anyway (same reasoning as the fallback comment above). */
  --glow-intensity: 1;
  --color-floor: 0.8;
  animation: intro-reveal 2500ms ease-out forwards, intro-glow-pulse 2000ms ease-in-out infinite;
  transition: color 150ms ease-out, font-weight 150ms ease-out;
}

.intro-text:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 6px;
}

.intro-text:hover {
  font-weight: 400;
  --glow-intensity: 1.5;
  --color-floor: 1;
}

/* Runs continuously from page load, not just on hover — tempo matches the
   radar-wind sound's own 0.5Hz tremolo (script.js) so the glow visually
   breathes in the same rhythm as the drone underneath it while hovering.
   Color pulses between --color-floor and full brightness at rest; on
   hover --color-floor itself becomes 1, so every stop below resolves to
   the same value — full brightness held constant instead of pulsing. */
@keyframes intro-glow-pulse {
  0%, 100% {
    color: rgb(232 232 232 / var(--color-floor));
    text-shadow:
      0 0 calc(5px * var(--glow-intensity)) rgb(255 255 255 / calc(0.375 * var(--glow-intensity))),
      0 0 calc(13px * var(--glow-intensity)) rgb(255 255 255 / calc(0.225 * var(--glow-intensity))),
      0 0 calc(23px * var(--glow-intensity)) rgb(255 255 255 / calc(0.1 * var(--glow-intensity)));
  }
  50% {
    color: rgb(232 232 232 / 1);
    text-shadow:
      0 0 calc(10px * var(--glow-intensity)) rgb(255 255 255 / calc(0.75 * var(--glow-intensity))),
      0 0 calc(26px * var(--glow-intensity)) rgb(255 255 255 / calc(0.45 * var(--glow-intensity))),
      0 0 calc(46px * var(--glow-intensity)) rgb(255 255 255 / calc(0.2 * var(--glow-intensity)));
  }
}

/* No transition is ever declared for .intro-text's opacity (only for
   transform, above) — so this takes effect instantly the moment
   is-dismissing is added, rather than fading like the backdrop does.
   animation: none is required too — the reveal animation's forwards fill
   mode otherwise keeps pinning opacity at its own end value (1),
   overriding a plain opacity:0 declared here for that same property. */
.intro-gate.is-dismissing .intro-text {
  animation: none;
  opacity: 0;
}

/* Same instant (no transition) disappearance as .intro-text above — logo
   and text vanish together the moment the gate is dismissed, well before
   the backdrop itself finishes its own separate, slower fade.
   animation: none is required — the reveal animation's forwards fill
   otherwise keeps pinning opacity at 1, silently overriding this rule
   (same issue as .intro-text's own dismiss rule below). */
.intro-gate.is-dismissing .intro-logo {
  animation: none;
  opacity: 0;
}

/* Typed in via typeElement() (see script.js) once .intro-text's reveal
   animation finishes — starts empty, so nothing shows until then. Same
   font and glow as the rest of the page (text-shadow is inherited from
   the html/body rule, not redeclared here), just smaller, dim by default,
   and pinned to the bottom center.
   Centered as a whole block (left:50% + translateX(-50%)) rather than via
   text-align:center on its own text — script.js pins its width to the
   full "CONTACT" string's rendered size *before* typing starts, so the
   box itself doesn't grow (and re-center) as each character is added.
   text-align:left inside that fixed box is what makes the reveal read
   left-to-right from a fixed point, matching how the project system text
   types, instead of visually expanding outward from the center. */
.intro-contact {
  position: absolute;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  color: var(--fg-dim);
  text-align: left;
  white-space: nowrap;
  text-decoration: none;
  transition: color 150ms ease-out;
}

.intro-contact:hover {
  color: var(--fg);
}

.intro-gate.is-dismissing .intro-contact {
  opacity: 0;
}

@keyframes intro-reveal {
  from {
    opacity: 0;
    filter: blur(10px);
  }
  to {
    opacity: 1;
    filter: blur(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .intro-gate {
    transition: none;
  }

  .intro-logo {
    animation: none;
    opacity: 1;
    filter: none;
  }

  .intro-text {
    animation: none;
    opacity: 1;
    filter: none;
    transition: none;
    /* Static, not pulsing — the same --glow-intensity var still scales it
       up on hover below, just without the keyframe animation driving it. */
    text-shadow:
      0 0 calc(7px * var(--glow-intensity)) rgb(255 255 255 / calc(0.5 * var(--glow-intensity))),
      0 0 calc(18px * var(--glow-intensity)) rgb(255 255 255 / calc(0.3 * var(--glow-intensity))),
      0 0 calc(32px * var(--glow-intensity)) rgb(255 255 255 / calc(0.13 * var(--glow-intensity)));
  }

  .intro-text:hover {
    color: var(--fg);
    font-weight: 400;
  }
}

/* Layout */

/* grid-template-columns is NOT set here — the track count depends on how
   many projects there are, so script.js's boot() sets it directly as an
   inline style once it knows that number (see the --slot-w-N comment in
   :root above). */
.layout {
  display: grid;
  /* dvh accounts for Safari's collapsing address bar — plain vh is always
     the full-screen height even when the bar is showing and eating into
     the actually-visible area, which on mobile Safari specifically pushed
     content (the work-selector menu) below the visible, unscrollable
     (overflow:hidden) viewport and made cover-fit media read as zoomed in.
     The vh line stays first as a fallback for browsers without dvh
     support. */
  min-height: 100vh;
  min-height: 100dvh;
}

/* Only animated while a category switch is actually in flight (see
   beginSlotSwitchTransition() in script.js) — never left on permanently,
   since an always-on transition here previously made ordinary window
   resizing feel laggy (every resize-driven width recalc got animated too). */
.layout.is-switching {
  transition: grid-template-columns 500ms ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
  .layout.is-switching {
    transition: none;
  }
}

/* Equal slots, one per category (CATEGORY_ORDER in script.js) in fixed
   left-to-right order. Each holds either a small rotated category button,
   or — when that category is active — the #content-bundle (moved there by
   JS). Whichever slot is active gets a wide --slot-w-N (see
   fitActiveSlotWidth() in script.js); the rest stay at the narrow default.
   This is what lets the active category "open" wherever it was clicked,
   not always in a fixed center. */
.category-slot {
  display: flex;
  position: relative;
  overflow: hidden;
  border-right: 1px solid var(--line);
  transition: border-color 800ms ease-out;
}

.category-slot:last-of-type {
  border-right: none;
}

/* The first slot has no left neighbor to supply its left edge (every
   border lives on a slot's right side), so on its own it has nothing
   there to highlight on hover — give it an invisible one to light up. */
.category-slot:first-of-type {
  border-left: 1px solid transparent;
}

/* Hovering a column highlights both edges framing it — its own right
   border, and the previous slot's right border, which is what forms this
   column's left edge (slots only ever declare a border on their right
   side, never their left). The exclusion here is keyed on which slot is
   actually being *hovered*, not on which slot's border-right is being
   colored — hovering the open project (.is-active) itself shows no
   highlight anywhere, but hovering an inactive neighbor still highlights
   both of its edges normally, even the one it shares with the open
   project (that edge belongs to whichever slot is being invited to open,
   not to the one already open). The moment a project opens, it stops
   matching the first rule below and its border-color falls back to the
   dim default, fading there over the transition set above. */
.category-slot:hover:not(.is-active),
.category-slot:active:not(.is-active),
.category-slot:has(+ .category-slot:hover:not(.is-active)),
.category-slot:has(+ .category-slot:active:not(.is-active)) {
  border-right-color: var(--fg);
}

.category-slot:first-of-type:not(.is-active):hover,
.category-slot:first-of-type:not(.is-active):active {
  border-left-color: var(--fg);
}

#content-bundle {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Category buttons */

.cat-btn {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 0.8rem;
  width: 100%;
  padding: 12px 8px;
  color: rgba(255, 255, 255, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms ease-out, color 150ms ease-out;
}

.cat-btn[aria-current="true"] {
  color: #ffffff;
  opacity: 1;
  border-bottom: 1px solid #ffffff;
}

.cat-btn:hover,
.cat-btn:active {
  color: #ffffff;
}

/* Main panel content */

.viewer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.viewer-placeholder {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
}

.viewer-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@media (min-width: 850px) {
  .viewer-media {
    object-fit: contain;
  }
}

.canvas-header {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  max-width: 70%;
  padding: 24px 28px;
  text-align: left;
}

.active-label {
  font-size: 0.7rem;
  letter-spacing: 0.15em;
  opacity: 0.6;
  margin: 0;
  cursor: pointer;
  transition: opacity 150ms ease-out;
}

.active-label:hover {
  opacity: 1;
}

.active-label::before {
  content: "> ";
}

.work-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.work-title {
  font-size: 1.1rem;
  font-weight: normal;
  letter-spacing: 0.05em;
  margin: 0;
}

.work-text {
  font-size: 0.85rem;
  color: var(--fg-dim);
  margin: 0;
}

/* A link typed into the systemtekst — brighter than the surrounding dim
   text is affordance enough (matches the no-underline links used
   elsewhere on the site, e.g. CONTACT on the intro screen). */
.work-text a {
  color: var(--fg);
  text-decoration: none;
  transition: opacity 150ms ease-out;
}

.work-text a:hover {
  opacity: 0.7;
}

.cursor {
  display: inline-block;
  width: 0.4em;
  height: 0.85em;
  margin-left: 2px;
  background: var(--fg-dim);
  vertical-align: text-bottom;
  opacity: 1;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Only shown when the active work's media actually has an audio track (see
   updateAudioToggle() in script.js). A pure CSS icon — five bars, matching
   the reference: gray when off, bright when on — the bars pulse either
   way, only the color marks the actual on/off state. align-items:center
   is what gives it the mirrored look (each bar's own vertical center
   lands on the shared midline, so it extends symmetrically up and down)
   — align-items:flex-end instead would only ever show the top half,
   growing from a bottom baseline. Positioned with the same inset as
   .canvas-header's padding (24px/28px, 20px on mobile) so the two sit
   symmetrically in their respective corners. */
.audio-toggle {
  position: absolute;
  top: 24px;
  right: 28px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  color: var(--fg-dim);
  transition: color 150ms ease-out, transform 150ms ease-out;
}

.audio-toggle[hidden] {
  display: none;
}

/* Hover enlarges but does not brighten — the color highlight is reserved
   for an actual press/click, unlike most other interactive elements on
   the page. Separate from, and layered on top of, the lasting highlight
   set by aria-pressed below. */
.audio-toggle:hover {
  transform: scale(1.15);
}

.audio-toggle:active {
  color: var(--fg);
  transform: scale(1.15);
}

.audio-bar {
  display: block;
  width: 4.5px;
  border-radius: 2px;
  background: currentColor;
  animation: audio-pulse 900ms ease-in-out infinite;
}

.audio-bar:nth-child(1) {
  height: 10.5px;
  animation-delay: -0.1s;
}

.audio-bar:nth-child(2) {
  height: 19.5px;
  animation-delay: -0.5s;
}

.audio-bar:nth-child(3) {
  height: 30px;
  animation-delay: -0.3s;
}

.audio-bar:nth-child(4) {
  height: 19.5px;
  animation-delay: -0.7s;
}

.audio-bar:nth-child(5) {
  height: 10.5px;
  animation-delay: -0.2s;
}

.audio-toggle[aria-pressed="true"] {
  color: var(--fg);
}

@keyframes audio-pulse {
  0%,
  100% {
    transform: scaleY(0.4);
  }
  50% {
    transform: scaleY(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .audio-bar {
    animation: none;
  }
}

.work-selector {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  padding: 0 20px 16px;
}

.work-selector button {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-dim);
  font-size: 0.8rem;
  transition: color 150ms ease-out;
}

.work-selector button:hover,
.work-selector button:active {
  color: var(--fg);
}

.work-selector button[aria-current="true"] {
  color: var(--fg);
  border-bottom: 1px solid var(--fg);
}

.work-head[hidden],
.viewer[hidden],
.work-selector[hidden] {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .cursor {
    display: none;
  }

  .cat-btn {
    transition: none;
  }
}

/* Fade transitions */

.fade-target {
  transition: opacity 220ms ease-out;
}

.fade-target.is-fading {
  opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
  .fade-target {
    transition: none;
  }
}

/* Mobile edge nav (hidden on desktop) */

#mobile-nav-left,
#mobile-nav-right {
  display: none;
}

.edge-scrim {
  display: none;
  pointer-events: none;
}

/* Mobile layout */

@media (max-width: 849px) {
  /* All of .layout's children are either display:none (.category-slot) or
     position:fixed (.edge-scrim, mobile nav) at this width, so none of them
     contribute to its height in normal flow — it must collapse to 0 here,
     or it sits as an invisible full-viewport-height spacer that pushes its
     next sibling, #content-bundle, one whole screen down and off-screen. */
  .layout {
    display: block;
    min-height: 0;
  }

  .category-slot {
    display: none;
  }

  #content-bundle {
    height: 100vh;
    height: 100dvh;
  }

  .canvas-header {
    max-width: 85%;
    padding: 20px;
  }

  .audio-toggle {
    top: 20px;
    right: 20px;
  }

  .work-selector {
    padding: 0 12px 14px;
  }

  #mobile-nav-left,
  #mobile-nav-right {
    display: flex;
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    min-width: 44px;
  }

  #mobile-nav-left {
    left: 0;
  }

  #mobile-nav-right {
    right: 0;
  }

  #mobile-nav-left .cat-btn,
  #mobile-nav-right .cat-btn {
    min-height: 44px;
  }

  #mobile-nav-left .cat-btn:hover,
  #mobile-nav-right .cat-btn:hover,
  #mobile-nav-left .cat-btn:active,
  #mobile-nav-right .cat-btn:active {
    transform: rotate(180deg) scale(1.05);
  }

  .edge-scrim {
    display: block;
    position: fixed;
    top: 0;
    bottom: 0;
    width: 50px;
    /* Sits above the video (z-index 1) but below all real UI content
       (z-index 2) and the nav buttons (z-index 10) — it should only ever
       darken the video, never paint over text. */
    z-index: 1;
  }

  .edge-scrim-left {
    left: 0;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  }

  .edge-scrim-right {
    right: 0;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  }

  /* Closed state: with nothing open there's no single project to fill the
     screen and no neighbors to page between, so this replaces the "one
     project full-screen + edge nav" layout above with all the projects
     stacked as equal-height rows instead. */
  .layout.is-closed {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .layout.is-closed .category-slot {
    display: flex;
    flex: 1 1 0;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .layout.is-closed .category-slot:last-of-type {
    border-bottom: none;
  }

  /* Same highlight as desktop, just on the horizontal edges between
     stacked rows instead of the vertical edges between columns. Also
     replaces the desktop first-slot rule (an invisible border on its
     *left* edge) with one on its *top* edge instead, for the same reason:
     the first row has no previous sibling to supply its top edge. */
  .layout.is-closed .category-slot:first-of-type {
    border-left: none;
    border-top: 1px solid transparent;
  }

  .layout.is-closed .category-slot:hover:not(.is-active),
  .layout.is-closed .category-slot:active:not(.is-active),
  .layout.is-closed .category-slot:has(+ .category-slot:hover:not(.is-active)),
  .layout.is-closed .category-slot:has(+ .category-slot:active:not(.is-active)) {
    border-bottom-color: var(--fg);
  }

  .layout.is-closed .category-slot:first-of-type:not(.is-active):hover,
  .layout.is-closed .category-slot:first-of-type:not(.is-active):active {
    border-top-color: var(--fg);
  }

  .layout.is-closed #mobile-nav-left,
  .layout.is-closed #mobile-nav-right,
  .layout.is-closed .edge-scrim {
    display: none;
  }

  /* Rotated vertical text suits a narrow column, not a wide-short row. */
  .layout.is-closed .cat-btn {
    writing-mode: horizontal-tb;
    transform: none;
    font-size: 0.9rem;
  }
}
