/* Night office hero scene. Owned by public/scene/scene.js.
   All stage geometry is a 1600x900 space; percentages below are generated from
   public/scene/constants.json (stageRects.hotspots, portrait.reaper) and checked
   by tests/scene-runtime.test.js. Palette from the approved hero mock. */

.night-office {
  --no-ink: #e9e4da;
  --no-dim: #a8a398;
  --no-brass: #c9a46a;
  --no-brass-hi: #f1d29b;
  --no-bg: #070504;
  --no-brown: #1a110c;
  --no-font: var(--sans, 'Segoe UI', Arial, sans-serif);
  position: relative;
  display: block;
  height: 100vh;
  height: 100svh;
  min-height: 22rem;
  overflow: hidden;
  isolation: isolate;
  background: var(--no-bg);
  color: var(--no-ink);
  font-family: var(--no-font);
}
.night-office [hidden] { display: none !important; }

/* Visually hidden page heading (the nameplate is in the render). */
.night-office__title {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  font-size: 1rem;
  letter-spacing: 0;
}

/* Gradient bridge: the scene's bottom edge melts into the section below (same near-black). */
@media (orientation: landscape) {
  .night-office::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 9%;
    z-index: 4;
    pointer-events: none;
    background: linear-gradient(180deg, rgba(7, 5, 4, 0), rgba(7, 5, 4, .55) 55%, var(--no-bg));
  }
}

/* ---------- viewport and stage (cover, capped so letterbox stays small) ---------- */
.night-office__view {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 70% at 50% 38%, #24170f 0, #120b08 48%, var(--no-bg) 100%);
}
.night-office__stage {
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  aspect-ratio: 16 / 9;
  transform: translateY(-50%);
  overflow: hidden;
  container-type: inline-size;
  background:
    radial-gradient(ellipse 60% 55% at 50% 40%, rgba(255, 196, 120, .07), transparent 70%),
    /* Placeholder before the flattened still decodes: its mean row colours, so first paint is the same
       exposure as the still and the live stack (no black-to-lit jump). */
    linear-gradient(180deg, #2e261f 0, #28272b 17%, #1d1d22 28%, #151418 39%, #1c1717 50%, #191210 61%, #1b130d 72%, #21150c 83%, #160701 100%);
}
@supports (width: 1cqw) {
  .night-office__view { container-type: size; }
  .night-office__stage {
    /* Landscape: cover the view, but never crop more than 1.25x a contain fit. */
    --no-sw: min(max(100cqw, 177.7778cqh), min(100cqw, 177.7778cqh) * 1.25);
    left: calc(50cqw - var(--no-sw) / 2);
    top: calc(50cqh - var(--no-sw) * .28125);
    width: var(--no-sw);
    height: calc(var(--no-sw) * .5625);
    aspect-ratio: auto;
    transform: none;
  }
}

.night-office__layers { position: absolute; inset: 0; pointer-events: none; }
/* Film look: one subtle vignette over the whole composited stage (never per layer, so layers keep matching).
   Sits above the layers, below hotspots (z-index 3) and nav. */
.night-office__layers::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse 75% 70% at 50% 48%, transparent 58%, rgba(6, 4, 3, .16) 82%, rgba(6, 4, 3, .34) 100%);
}
.night-office__still,
.night-office__layer {
  position: absolute;
  display: block;
  max-width: none;
  margin: 0;
  border: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
.night-office__still { left: 0; top: 0; width: 100%; height: 100%; object-fit: fill; }
img.night-office__layer, video.night-office__layer, canvas.night-office__layer { object-fit: fill; }
.night-office__layer { will-change: auto; }
.night-office.is-live .night-office__layer.is-parallax { will-change: transform; }
.night-office__canvas { left: 0; top: 0; width: 100%; height: 100%; }
.night-office__figure-slot { background: transparent; }
.night-office__alpha > canvas,
.night-office__alpha > img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.night-office__alpha > video {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none;
}
.night-office__feather {
  -webkit-mask-image:
    linear-gradient(to right, transparent, #000 var(--no-fx, 3%), #000 calc(100% - var(--no-fx, 3%)), transparent),
    linear-gradient(to bottom, transparent, #000 var(--no-fy, 2%), #000 calc(100% - var(--no-fy, 2%)), transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent, #000 var(--no-fx, 3%), #000 calc(100% - var(--no-fx, 3%)), transparent),
    linear-gradient(to bottom, transparent, #000 var(--no-fy, 2%), #000 calc(100% - var(--no-fy, 2%)), transparent);
  mask-composite: intersect;
}

/* Still mode (reduced motion or animations off): only the flattened still plus lit states. */
.night-office.is-still .night-office__layer:not(.is-static) { display: none; }
.night-office.is-still .night-office__reaper-dark { visibility: hidden; }

/* Live mode first paint: the flattened still shows alone until exterior, bridge and room have all
   decoded (runtime adds .is-stack-ready), then the live stack replaces it in one frame. No fade: the stack's
   first frame matches the still, so the swap is invisible. */
.night-office.is-live .night-office__layer:not(.is-static) { opacity: 0; }
.night-office.is-live.is-stack-ready .night-office__layer:not(.is-static) { opacity: 1; }
.night-office.is-live:not(.is-stack-ready) .night-office__reaper-dark { opacity: 0; }

/* Lit overlays cross-fade in over the dark scene (full opacity when on). */
.night-office__lit,
.night-office__pubstack,
.night-office__reaper-lit,
.night-office__reaper-dark {
  opacity: 0;
  transition: opacity .35s ease;
}
.night-office__reaper-dark { opacity: 1; }
.night-office__lit.is-on,
.night-office__pubstack.is-shown,
.night-office__reaper.is-on .night-office__reaper-lit { opacity: 1; }
.night-office__reaper.is-on .night-office__reaper-dark { opacity: 0; }
/* The sprite fills its own rect; nothing here may scale it down. */
.night-office__reaper > img {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block; max-width: none;
  object-fit: fill; transform: none;
}
/* The model hangs on two cables from the ceiling at the top edge of its rect (sprite x 27.9% and 53.7%). It sways
   in the window draught about the ceiling line, pivot midway between the cables, so the cable ends stay put.
   live.js uses the same pivot (REAPER_PIVOT_X) for the propeller, lights and room light. */
.night-office__reaper { transform-origin: 40.8% 0; will-change: transform; }

/* Paper on the manuscript stack: the sheet is rendered lit, so settle it to the lamp-lit desk
   (warm off-white rather than flat white) and keep the pen readable. */
.night-office__pubstack { filter: sepia(.22) saturate(1.08) brightness(.86) contrast(1.06); }

/* Soft warm glow behind each lit object (sits under the lit layer, scoped to its rect). */
.night-office__glow {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s ease;
  background: radial-gradient(closest-side, rgba(255, 196, 128, .26), rgba(255, 176, 104, .1) 55%, transparent);
  mix-blend-mode: screen;
  transform: scale(1.7);
}
.night-office__glow.is-on { opacity: 1; }
.night-office__glow--trophy { transform: scale(1.5, 1.25); }
.night-office__glow--phone { transform: scale(1.8, 1.6); }
.night-office__glow--reaper {
  transform: scale(1.25, 1.6);
  background: radial-gradient(closest-side, rgba(255, 214, 160, .2), rgba(255, 190, 130, .07) 60%, transparent);
}
/* Manuscript: a contact shadow under the stack plus a faint warm lift. */
.night-office__glow--manuscript {
  transform: none;
  mix-blend-mode: normal;
  background:
    radial-gradient(ellipse 46% 9% at 50% 91%, rgba(8, 5, 3, .55), transparent),
    radial-gradient(closest-side, rgba(255, 190, 120, .1), transparent);
}

/* ---------- hotspots (links, clickable from the first frame) ---------- */
.night-office__hot {
  position: absolute;
  z-index: 3;
  display: block;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
/* Reaper: the 3.3 m model hung inside the room, top right; top edge at y 72 so the name row (y 25-61) and its
   focus ring stay clear. */
.night-office__hot--reaper     { left: 61.875%; top: 8%;       width: 35%;     height: 19.2222%; }
.night-office__hot--arm        { left: 3.6%;    top: 6%;       width: 17.4%;   height: 57%; }
.night-office__hot--manuscript { left: 61.25%;  top: 66.6667%; width: 11.875%; height: 13.3333%; }
.night-office__hot--trophy     { left: 19.6875%; top: 54.4444%; width: 6.875%; height: 23.5556%; }
.night-office__hot--phone      { left: 28.2%;   top: 69.2%;    width: 7.2%;    height: 9.6%; }
/* Teaching: the generated rect above starts at y 54, inside the top-bar name row (y 25-61). Inset the top edge
   to y 76.5 (same bottom edge) so the name row stays clear and its focus ring (about 8 px) never clips a label.
   tests/scene-runtime.test.js documents and checks this inset. */
.night-office .night-office__hot--arm { top: 8.5%; height: 54.5%; }

/* Arm: no beam or cone, only a faint warm pool hugging the arm's base and shoulder. */
.night-office__hot::before {
  content: "";
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transition: opacity .35s ease;
}
.night-office__hot:not(.night-office__hot--arm)::before { content: none; }
.night-office__hot--arm::before {
  left: 10%; right: 10%; top: 30%; bottom: 0;
  background: radial-gradient(ellipse 50% 55% at 50% 70%, rgba(255, 190, 120, .12), transparent 70%);
  mix-blend-mode: screen;
}
.night-office__hot-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translate(-50%, 6px);
  opacity: 0;
  /* 13.6px at a 1600 px stage, scales with the stage; never below 13px. */
  font-size: clamp(13px, .85cqw, 16px);
  font-weight: 600;
  letter-spacing: .26em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--no-brass-hi);
  /* Dark backing keeps the brass at AA contrast over any part of the render. */
  padding: .38em .6em .38em .86em;
  border-radius: 2px;
  background: rgba(10, 7, 5, .78);
  box-shadow: 0 0 0 1px rgba(201, 164, 106, .28);
  text-shadow: 0 1px 2px rgba(0, 0, 0, .9);
  transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
}
.night-office__hot-label::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 100%;
  width: 1px;
  height: 14px;
  background: linear-gradient(transparent, var(--no-brass));
}
.night-office__hot-label { margin-top: 14px; }
.night-office__hot:hover::before,
.night-office__hot:focus-visible::before,
.night-office__hot.is-on::before { opacity: 1; }
.night-office__hot:hover .night-office__hot-label,
.night-office__hot:focus-visible .night-office__hot-label,
.night-office__hot.is-on .night-office__hot-label { opacity: 1; transform: translate(-50%, 0); }
.night-office__hot--reaper .night-office__hot-label { top: 104%; }

/* ---------- top bar: five names spread evenly ---------- */
.night-office__nav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  padding: max(10px, 1.6vw) 6vw 0;
  font-size: clamp(11px, .82vw, 14px);
  letter-spacing: .3em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(233, 228, 218, .82);
}
.night-office__name {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: .4em .2em .4em .5em;
  color: inherit;
  text-decoration: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, .85);
  transition: color .35s ease, text-shadow .35s ease;
}
.night-office__name:hover,
.night-office__name:focus-visible,
.night-office__name.is-on {
  color: var(--no-brass-hi);
  text-shadow: 0 0 14px rgba(241, 210, 155, .35), 0 1px 4px rgba(0, 0, 0, .85);
}

/* ---------- scene controls: pause/play and sound ---------- */
.night-office__controls {
  position: absolute;
  right: 3%;
  bottom: 4.6%;
  z-index: 6;
  display: flex;
  gap: 8px;
}
/* Nothing moves in still mode (reduced motion or the site's animation switch), so there is nothing to pause. */
.night-office.is-still .night-office__motion { display: none; }
.night-office__motion,
.night-office__sound {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid #3d362f;
  border-radius: 3px;
  background: rgba(7, 5, 4, .55);
  color: var(--no-ink);
  font: inherit;
  font-size: clamp(11px, .75vw, 12px);
  letter-spacing: .18em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color .3s ease, color .3s ease;
}
.night-office__motion svg,
.night-office__sound svg { width: 16px; height: 16px; flex: none; }
.night-office__sound .night-office__wave { opacity: .35; transition: opacity .3s ease; }
.night-office__motion:hover,
.night-office__sound:hover { border-color: var(--no-brass); color: var(--no-brass-hi); }
.night-office__sound[aria-pressed="true"] { border-color: var(--no-brass); color: var(--no-brass-hi); }
.night-office__sound[aria-pressed="true"] .night-office__wave { opacity: 1; }

/* ---------- focus rings (visible on dark and light parts of the render) ---------- */
.night-office a:focus-visible,
.night-office button:focus-visible {
  outline: 2px solid var(--no-brass-hi);
  outline-offset: 3px;
  box-shadow: 0 0 0 5px rgba(7, 5, 4, .85);
}
.night-office a:focus:not(:focus-visible),
.night-office button:focus:not(:focus-visible) { outline: none; }

/* ---------- portrait: crop window, Reaper moves top right, label row beneath ---------- */
@media (orientation: portrait) {
  /* The app's host wrapper reserves a full screen; in portrait the scene is only as tall as its content. */
  div.home-scene { min-height: 0; }
  .night-office {
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }
  .night-office__view {
    position: relative;
    inset: auto;
    flex: none;
    width: 100%;
    /* A 900 px window (stage x 280..1180: whole trophy, lantern, phone, chair, nameplate, manuscript),
       scaled to fit the width. The view is exactly the scene band (square), so there are no empty bands:
       the page starts with the scene, the label row follows directly and the sections after it.
       The Sound button docks inside the band's bottom-left corner. */
    aspect-ratio: 1 / 1;
    max-height: calc(100vh - 7.5rem);
    max-height: calc(100svh - 7.5rem);
    background: linear-gradient(180deg, #0a0706 0, #271e17 100%);
  }
  @supports (width: 1cqw) {
    .night-office__view {
      /* Stage is 100cqw tall here, so the scene band is 50% -/+ 50cqw; the gradient hits the render's top
         and bottom edge colours exactly at the band edges. */
      background: linear-gradient(180deg, #0a0706 0, #271e17 calc(50% - 50cqw), #0f0805 calc(50% + 50cqw), #070504 100%);
    }
    .night-office__stage {
      --no-sw: min(177.7778cqw, 177.7778cqh);
      left: calc(50cqw - var(--no-sw) * .45625);
    }
  }
  .night-office__nav {
    position: static;
    order: 2;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0 4px;
    padding: 10px 12px 14px;
    font-size: 11px;
    letter-spacing: .16em;
    background: var(--no-bg);
  }
  .night-office__name { min-height: 44px; padding: 0 10px; }
  .night-office__hot--arm,
  .night-office__hot--trophy { visibility: hidden; }
  .night-office.is-reaper-moved .night-office__hot--reaper {
    left: 50.625%; top: 0%; width: 18.75%; height: 13.3333%;
  }
  .night-office__hot-label { display: none; }
  .night-office__controls {
    /* Bottom-left of the scene (the view is the scene band): clear of every hotspot, which all end above
       the desk edge, and of the Reaper at the top right. */
    left: 8px; right: auto; top: auto; bottom: 8px;
  }
  .night-office__controls button { min-width: 44px; min-height: 44px; padding: 6px 12px; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  .night-office__lit,
  .night-office__pubstack,
  .night-office__reaper-lit,
  .night-office__reaper-dark,
  .night-office__glow,
  .night-office__layer,
  .night-office__hot::before,
  .night-office__hot-label,
  .night-office__name { transition: none; }
}

/* ---------- the short section after the scene (filled by another step) ---------- */
.night-office-after {
  position: relative;
  padding: clamp(56px, 9vw, 120px) clamp(20px, 6vw, 96px);
  background: linear-gradient(180deg, var(--no-bg, #070504) 0, #120c08 45%, #17100b 100%);
  color: #e9e4da;
  font-family: var(--sans, 'Segoe UI', Arial, sans-serif);
}
.night-office-after > * { max-width: 72rem; margin-left: auto; margin-right: auto; }
.night-office-after h2 {
  margin-top: 0;
  margin-bottom: 18px;
  font-family: var(--serif, Georgia, 'Times New Roman', serif);
  font-weight: 400;
  font-size: clamp(30px, 4.4vw, 56px);
  line-height: 1.08;
  letter-spacing: -.02em;
  color: #f3eee4;
}
.night-office-after p {
  max-width: 44rem;
  margin-left: 0;
  color: #c3bcaf;
  font-size: clamp(16px, 1.3vw, 19px);
  line-height: 1.6;
}
.night-office-after > p { margin-left: auto; margin-right: auto; }
.night-office-after a { color: #f1d29b; text-decoration: underline; text-underline-offset: .2em; }
.night-office-after a:hover { color: #fff1d6; }
.night-office-after a:focus-visible { outline: 2px solid #f1d29b; outline-offset: 3px; }
.night-office-after__links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-top: 28px;
  margin-bottom: 0;
  padding: 0;
  list-style: none;
}
.night-office-after__links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid rgba(201, 164, 106, .5);
  border-radius: 3px;
  font-size: 13px;
  letter-spacing: .18em;
  text-transform: uppercase;
  text-decoration: none;
  transition: border-color .3s ease, background-color .3s ease;
}
.night-office-after__links a:hover { border-color: #f1d29b; background: rgba(201, 164, 106, .08); }
/* The latest notice, when one is published: one quiet line under the links. */
.night-office-after .night-office-after__notice {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-top: 36px;
  margin-bottom: 0;
  padding-top: 20px;
  border-top: 1px solid rgba(201, 164, 106, .2);
  font-size: 16px;
}
.night-office-after__notice span {
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: #a8997f;
}
