* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1); /* strong ease-out for entrances/exits */
  --font-body: "Archivo", -apple-system, "Helvetica Neue", Arial, sans-serif;
}


html, body {
  background: #050505;
  color: #eae6de;
  font-family: var(--font-body);
  overflow-x: hidden;
}

.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #050505; /* Build 35: dark loader, no light flash before the dark room (was #f5f5f5) */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s var(--ease-out);
}

.loading-percent {
  font-family: var(--font-body);
  font-size: 15px;
  letter-spacing: 0.12em;
  color: #eae6de; /* Build 35: light counter on the dark loader */
}

.loading-screen.is-hidden {
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .loading-screen { transition: opacity 0.2s ease; }
}

.brand-logo {
  position: fixed;
  top: 5%;
  left: 2%;
  width: 9%;
  z-index: 40;
  filter: brightness(0) invert(1);
  mix-blend-mode: screen;
  pointer-events: none;
}

/* 9% of a phone-width viewport renders too small to read comfortably (a percentage tuned for much
   wider desktop viewports) — scoped to body.is-mobile (set in script.js) rather than a width media
   query, so it can never affect a narrow-but-still-desktop window. */
body.is-mobile .brand-logo {
  width: 32%;
  max-width: 150px;
}

.scene { position: relative; }

.gallery-spacer { height: 100vh; }

.stage {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.room {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ambient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 45% at 50% 46%, rgba(70, 90, 130, 0.16), transparent 70%),
    radial-gradient(ellipse 90% 60% at 50% 100%, rgba(20, 20, 24, 0.9), transparent 70%);
  pointer-events: none;
}

/* ---------- FRAME (the curved screen) ---------- */

.frame {
  position: fixed;
  overflow: hidden;
  background: #0c0c0e;
  pointer-events: auto;
  will-change: clip-path, left, top, width, height;
  /* Neither .frame nor .reflect had a z-index, so they stacked by DOM order — reflectTop (which
     comes BEFORE .frame in the markup) was painted UNDER .frame's own opaque rectangular
     background. reflectTop's own box deliberately extends a bit into .frame's own box (so its
     near edge has room for the bow's peak — see reflectGeometry()), so that overlap silently ate
     the bottom slice of the top reflection, right where it's most visible. reflectBottom comes
     AFTER .frame in the markup, so it was never affected — this is why only the top looked cut
     off no matter what changed in the reflection's own drawing code. Giving .frame an explicit
     z-index below .reflect's fixes this regardless of DOM order. */
  z-index: 1;
}

#glcanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
}

.edge-blur-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.flat-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* cover + centered, matching computeCoverFit() exactly (see script.js) — the same centered-crop
     math the WebGL gallery already uses. This element takes over from the WebGL canvas mid-frame
     (see openProject/settleToCenter) and hands back to it on close, so its very first (and very
     last) rendered frame must be pixel-identical to what the canvas was just showing — canvas
     always renders cover-style (computeCoverFit), so this has to as well, or the handoff pops.
     The box stays centered with constant width throughout the whole open/close tween (gallery
     rect and full rect share the same center — see computeGalleryRect/computeFullRect), so cover
     scales smoothly outward/inward from that shared center rather than sliding the crop around. */
  object-fit: cover;
  object-position: 50% 50%;
  display: none;
  user-select: none;
  -webkit-user-drag: none;
}

.track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  display: flex;
  pointer-events: none;
}

.detail-slide {
  position: relative;
  height: 100%;
  flex-shrink: 0;
  overflow: hidden;
}

.detail-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- REFLECTIONS ---------- */

/* The container itself carries no blur/opacity/mask — just a solid, fully-opaque background.
   Wherever the canvas's own curved clip doesn't reach (the gap between the frame's real edge and
   the reflection band), this background shows through, reading as a crisp, consistently dark
   bezel — not "whatever's behind, at whatever brightness it happens to be". Only the reflection
   CONTENT (the canvas) gets dimmed/blurred/faded, via the rules below. */
.reflect {
  position: fixed;
  overflow: hidden;
  pointer-events: none;
  background: #050505;
  /* Must stack above .frame (z-index: 1) — see the note there. */
  z-index: 2;
}

.reflect-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: blur(3px) saturate(0.85) brightness(0.8);
}

/* Top's fade is baked directly into the canvas's own pixels in drawReflections() (destination-in),
   not a CSS mask — confirmed against real Chrome and Safari (not just a sandboxed test browser)
   that neither `to top` nor `to bottom` + `transform: scaleY(-1)` fades this canvas reliably.
   Canvas 2D's own alpha compositing has no such ambiguity. Bottom has no such issue and keeps its
   CSS mask unchanged. */
.reflect-bottom .reflect-canvas { mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent 88%); -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,0.9), transparent 88%); }

/* On mobile, reflectTop/reflectBottom's own CONTAINER gets rolled 90° by CSS transform (see
   applyRectMobile in script.js) to move the whole band from above/below to the side — this mask,
   defined in the container's own local (pre-roll) space, rolls right along with it, so a
   top-to-bottom local fade correctly reads as a side-to-side fade on screen. No override needed. */

/* rot90 wraps ONLY the live WebGL canvas pair (glcanvas/edgeBlurCanvas). It is rendered internally
   exactly like desktop (horizontal sweep, top/bottom bow) and then rolled 90° here in CSS so it
   reads as vertical/left-right on screen — purely a DISPLAY rotation of an already-rendered raster
   canvas. The photo content itself is kept upright by pre-rotating -90° into the source material
   this rolled canvas renders (see buildAtlasMobile in script.js) — the two rotations cancel out.
   flatCover/track are NOT inside it — they display already screen-orientated content of their
   own and must never be rolled. */
.rot90 { position: absolute; }

/* ---------- CLOSE BUTTON ---------- */

.close-btn {
  position: fixed;
  top: 28px;
  right: 32px;
  z-index: 60;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: #f4f1ea;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.25s var(--ease-out), transform 0.25s var(--ease-out), background 0.2s ease;
}
@media (hover: hover) and (pointer: fine) {
  .close-btn:hover { background: rgba(255,255,255,0.14); }
}
body.state-detail .close-btn { opacity: 1; transform: translateY(0); pointer-events: auto; }
/* Build 33 (critique-affordance): 44px hit area and a visible keyboard focus ring */
.close-btn::before { content: ""; position: absolute; inset: -5px; } /* from the padding box: 34px + 10px = 44px */
.close-btn:focus-visible { outline: 1px solid #eae6de; outline-offset: 4px; }
body.state-detail .close-btn:active { transform: scale(0.97); transition-duration: 0.12s; } /* Build 32: press feedback */

@media (prefers-reduced-motion: reduce) {
  .close-btn, body.state-detail .close-btn:active { transition: opacity 0.2s ease, background 0.2s ease; transform: none; }
}

/* ---------- DETAIL (fullscreen) STATE ---------- */

body.state-detail,
body.state-opening,
body.state-closing {
  overflow: hidden;
  height: 100vh;
}

/* Composite each text group against the projected surface, like the OPEN cursor. */
body.blend-type :is(.brand-logo, .loading-percent, .p2-label, .p2-credits, .p2-reel,
  .p2-title, .p3-toggle, .p3-index, .p4-cursor, .p5-hint, .p5-count, .close-btn) {
  mix-blend-mode: difference;
}

body.blend-type .brand-logo {
  filter: brightness(0) invert(0.94);
}

body.blend-type .loading-percent,
body.blend-type .p4-cursor {
  color: #efeee9;
}

/* Build 34: accessible heading and no-JavaScript fallback */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.noscript { position: fixed; inset: 0; z-index: 200; background: #050505; color: #eae6de; padding: 12vh 8vw;
  font-family: var(--font-body); font-size: 15px; line-height: 1.6; max-width: 46em; }
.noscript ul { list-style: none; padding: 0; margin: 2em 0; letter-spacing: 0.12em; text-transform: uppercase; font-size: 12px; }
.noscript li { padding: 0.35em 0; }

/* Deploy: Archivo Expanded stands in for ABC Diatype Extended until it is licensed */
html { font-stretch: 125%; }
