/* Round 2 (T9): the room kit. Shared by every round 2 page; a page joins by
   loading this file and assets/js/room.js, and keeps its own layout in its
   own file (the home page: room-home.css). Nothing here knows about a page.

   What the kit gives a page:
   - Words that switch on (.room__word, made by TettpaRoom.split / ignite in
     room.js): an outline until lit. Sentence lines (.room__sentence).
   - The red light: six layers a page puts inside its stage, all hidden until
     the stage carries .room-live (room.js or the page script adds it once
     motion has started, so no script and Reduce Motion never see them):
       .room__wash   red multiplied over what is under it: red stage light
       .room__dark   black, for dimming
       .room__light  red at the edges, black at the rim
       .room__beam   a cone of light from above, swept by TettpaRoom.sweep
       .room__lamp   a lamp out of frame, added light
       .room__grain  film grain
     Each layer is position:absolute, inset:0, z-index:1, opacity 0: the page
     script fades them in. The stage needs position:relative (or absolute).

   Red is light here, never paint: it arrives as gradients that behave like
   lamps (a source off the edge, falling off into black). */

:root {
  --room-ember: #2a0003;
}

.room__sentence {
  display: block;
}

/* Only transform and color move on the words; inline-block so a transform has
   a box to act on, and the space after each word stays a real space. */
.room__word {
  display: inline-block;
}

/* Unlit, a word is dark glass: only its outline shows. Words exist only once
   room.js has split them (motion allowed), and it is room.js that turns their
   fill off, so with no script or Reduce Motion this never shows. */
.room__word {
  -webkit-text-stroke: 1.5px rgba(244, 244, 244, 0.55);
}

/* ---- The light layers ------------------------------------------------------
   Hidden on the plain page: without .room-live a stage looks as it always did. */
.room__wash,
.room__dark,
.room__light,
.room__beam,
.room__lamp,
.room__grain {
  display: none;
}

.room-live .room__wash,
.room-live .room__dark,
.room-live .room__light,
.room-live .room__beam,
.room-live .room__lamp,
.room-live .room__grain {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  will-change: opacity;
}

/* Red light on the room: the clip multiplied by red keeps only its red
   channel, so what was bright (smoke, faces, haze) glows red and what was
   green goes to black. One flat layer, so it costs one blend, not a filter. */
.room-live .room__wash {
  background: var(--red-hot);
  mix-blend-mode: multiply;
}

.room-live .room__dark {
  background: var(--bg);
}

/* A moving head: a cone of light from a fixture above the frame, hard-edged,
   swept across each line of the statement as its words switch on (room.js
   moves it; the light is what lights them). Plain see-through red, not a
   screen blend: a blended layer makes the browser composite the area under
   its box apart from the rest, and the box's edge showed as a hairline down
   the whole room. Over this much dark the two look the same. */
.room-live .room__beam {
  inset: -6% auto -4% 0;
  width: 24vw;
  min-width: 11rem;
  clip-path: polygon(44% 0, 56% 0, 100% 100%, 0 100%);
  background: linear-gradient(to bottom, rgba(255, 110, 116, 0.62), rgba(255, 26, 40, 0.32) 55%, rgba(255, 26, 40, 0.08));
}

/* The edges of the room going red: black at the very rim, red light inside
   it, the middle left to the clip. */
.room-live .room__light {
  background:
    radial-gradient(125% 100% at 50% 50%, transparent 46%, rgba(227, 6, 19, 0.14) 62%, rgba(150, 0, 8, 0.5) 76%, var(--room-ember) 88%, #000 100%);
}

/* A lamp above the floor, out of frame: added light, so it brightens what it
   falls on instead of covering it. */
.room-live .room__lamp {
  background:
    radial-gradient(55% 50% at 22% -10%, rgba(255, 26, 40, 0.42), transparent 70%),
    radial-gradient(40% 36% at 94% 110%, rgba(227, 6, 19, 0.28), transparent 70%);
  mix-blend-mode: screen;
}

/* Film grain, the room's texture. A tiny tile, still on phones, stepping on a
   computer (a few positions a second, like grain on a projected film). */
.room-live .room__grain {
  inset: -180px;
  background-size: 180px 180px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.07;
  mix-blend-mode: overlay;
}

@media (hover: hover) and (pointer: fine) {
  .room-live .room__grain {
    animation: room-grain 0.6s steps(4) infinite;
  }
}

@keyframes room-grain {
  /* Whole pixels, and whole tiles' worth of nothing in between: a grain tile
     shifted by a fraction of a pixel is resampled, and its edge shows as a
     hairline down the whole room. */
  0% { transform: translate(0, 0); }
  25% { transform: translate(-97px, 53px); }
  50% { transform: translate(71px, -88px); }
  75% { transform: translate(-41px, -127px); }
  100% { transform: translate(0, 0); }
}

/* ---- The curtain between pages (TettpaRoom.curtain) -------------------------
   Two layers, red then black, like a red stage curtain with the dark of the
   wings behind it: the red leads up over the page, its top edge throwing
   light onto what it is about to cover; on the next page the black lifts
   first, then the red. Only transform moves. */
.room-curtain {
  position: fixed;
  inset: 0;
  z-index: 10001;
  background: #000;
  pointer-events: none;
  visibility: hidden;
  will-change: transform;
}

/* The red is lit, not painted: brightest where it leads, deepening behind,
   with the room's grain on it. */
.room-curtain--red {
  z-index: 10000;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E") 0 0 / 180px 180px,
    linear-gradient(to bottom, #ff1a28 0%, #c4000f 30%, #8a0009 70%, #c4000f 100%);
}

.room-curtain--red::before,
.room-curtain--red::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 26vh;
}

.room-curtain--red::before {
  bottom: 100%;
  background: linear-gradient(to top, rgba(255, 26, 40, 0.62), rgba(227, 6, 19, 0.2) 35%, rgba(227, 6, 19, 0.05) 70%, transparent);
}

.room-curtain--red::after {
  top: 100%;
  background: linear-gradient(to bottom, rgba(196, 0, 15, 0.62), rgba(227, 6, 19, 0.2) 35%, rgba(227, 6, 19, 0.05) 70%, transparent);
}

/* The next page, covered from its first frame until room.js lifts the real
   curtain off it (the line in each page's <head>). If the kit never runs, the
   cover goes by itself after a moment. */
html.curtain-closed::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10002;
  background: #000;
  animation: room-curtain-failsafe 0.3s ease 1.6s forwards;
}

@keyframes room-curtain-failsafe {
  to { opacity: 0; visibility: hidden; }
}
