.novel-theater {
  padding-top: clamp(1.5rem, 3.7vw, 3.25rem);
}
.theater-housing { position: relative; }
.novel-theater .theater-housing {
  container-type: inline-size;
  overflow: hidden;
  border: 1px solid #a7835a;
  border-radius: 5px;
  background: #24172b;
  box-shadow: 0 4px 14px #68462c20;
}
.theater-poster {
  --screen-left: 19.40%;
  --screen-width: 65.88%;
  --screen-center: calc(var(--screen-left) + var(--screen-width) / 2);
  /* Wide banners need enough room for the teacups below the screen. */
  --poster-height: max(calc(var(--theater-banner-height, var(--home-sign-min-height)) - 2px), 30.5cqw);
  /* On the widest sign, keep the tips of the sconces just inside the upper edge. */
  --scene-offset: max(0px, calc(15.45cqw - var(--poster-height) / 2 + 3px));
  position: relative;
  display: grid;
  isolation: isolate;
  container-type: inline-size;
  overflow: hidden;
  height: var(--poster-height);
  cursor: pointer;
  text-decoration: none;
  color: #fff5d9;
  font-family: var(--serif);
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.theater-poster::-webkit-details-marker { display: none; }
.theater-poster:focus-visible { outline: 3px solid #fff4cc; outline-offset: -5px; }
/* The screen, wheels and audience share the original room's 1600 × 616 coordinates.
   The painting adds 220 pixels above and below for taller, narrow displays. */
.theater-stage {
  display: block;
  position: absolute;
  top: calc(50% + var(--scene-offset));
  left: 0;
  /* Keep the painted frame and projected film centered on the lettering. */
  transform-origin: var(--screen-center) 37%;
  transform: translateY(-50%) scale(min(var(--screen-zoom, 1), 1.32), var(--screen-zoom, 1));
  width: 100%;
  aspect-ratio: 1600 / 616;
  pointer-events: none;
}
.theater-art {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 100%;
  height: auto;
}
.theater-flame {
  /* One painting pixel at the rendered scale of the room. */
  --unit: .0625cqw;
  position: absolute;
  left: calc((var(--wick-x) - 22) * var(--unit));
  top: calc((var(--wick-y) - 220 - 42) * var(--unit));
  width: calc(44 * var(--unit));
  height: calc(48 * var(--unit));
  pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
  .theater-flame::before,
  .theater-flame::after {
    content: "";
    position: absolute;
    animation-duration: var(--period);
    animation-delay: var(--phase);
    animation-timing-function: ease-in-out;
    animation-iteration-count: infinite;
    animation-play-state: paused;
  }
  .theater-flame::before {
    inset: 0;
    /* Bend the painted flame about its own wick; the mask fades into the wall. */
    background-image: var(--room-art);
    background-size: 100cqw 66cqw;
    background-position: calc((22 - var(--wick-x)) * var(--unit)) calc((42 - var(--wick-y)) * var(--unit));
    background-repeat: no-repeat;
    -webkit-mask-image: radial-gradient(ellipse 28% 49% at 50% 58%, #000 61%, transparent 100%);
    mask-image: radial-gradient(ellipse 28% 49% at 50% 58%, #000 61%, transparent 100%);
    transform-origin: 50% 87.5%;
    animation-name: theater-candle-sway;
  }
  .theater-flame::after {
    inset: -30% -45%;
    background: radial-gradient(ellipse closest-side, #ffba5f2b 6%, #ffb35413 55%, transparent);
    animation-name: theater-candle-glow;
  }
  .is-projecting .theater-flame::before,
  .is-projecting .theater-flame::after { animation-play-state: running; }
}
@keyframes theater-candle-sway {
  0%, 100% { transform: skewX(-.3deg) scaleY(1); }
  34% { transform: skewX(1.4deg) scaleY(1.007); }
  72% { transform: skewX(-1.2deg) scaleY(.994); }
}
@keyframes theater-candle-glow {
  0%, 100% { opacity: .23; }
  38% { opacity: .28; }
  76% { opacity: .20; }
}
.theater-film {
  position: absolute;
  left: var(--screen-left);
  top: 8.12%;
  width: var(--screen-width);
  height: 58.12%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  /* The pulled-back curtains overlap the upper corners of the canvas. */
  clip-path: polygon(5.4% 0, 94.3% 0, 95.8% 14%, 97.7% 28%, 100% 41%, 100% 100%, 0 100%, 0 39.5%, 1.75% 28%, 3.8% 14%);
}
.novel-theater.has-film .theater-film { opacity: 1; }
.theater-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 37% 42% at var(--screen-center) 37%, #15152bbd 10%, #1d1a3d88 58%, transparent);
}
.theater-poster:active { filter: brightness(.82); }

/* The two halves of the steam texture share the painting's pixel scale. */
.theater-steam {
  position: absolute;
  left: calc(var(--cup-x) * .0625cqw);
  top: calc((var(--cup-y) - 216) * .0625cqw);
  width: 6%;
  aspect-ratio: 4 / 5;
  transform: translate(-50%, -100%);
  background-image: var(--steam-still);
  background-repeat: no-repeat;
  background-size: 200% 100%;
  pointer-events: none;
}
.theater-steam-left {
  --cup-x: 446;
  --cup-y: 719;
  background-position: left top;
}
.theater-steam-right {
  --cup-x: 1179;
  --cup-y: 712;
  background-position: right top;
}
@media (prefers-reduced-motion: no-preference) {
  .theater-steam { background-image: var(--steam-art); }
}
.theater-titles {
  position: absolute;
  top: 37%;
  /* 37% of the original room, now centered inside the banner. */
  top: calc(50% - 5.005cqw + var(--scene-offset));
  left: var(--screen-center);
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  width: max-content;
  max-width: 96%;
  text-shadow: 0 1px 3px #282235, 0 2px 9px #292039;
}
.theater-imprint {
  display: flex;
  align-items: center;
  gap: .7em;
  color: #ffedc0;
  font-size: clamp(.875rem, 1.55vw, 1.2rem);
  font-weight: 600;
  letter-spacing: .12em;
}
.theater-imprint::before, .theater-imprint::after {
  content: "";
  width: 1.8em;
  height: 1px;
  background: linear-gradient(90deg, transparent, #f0ce91);
}
.theater-imprint::after { transform: scaleX(-1); }
.theater-title {
  margin-block: .08em .13em;
  color: #fff7e5;
  font-size: clamp(1.5rem, 4.8vw, 4.1rem);
  line-height: 1.24;
  font-weight: 600;
  letter-spacing: .045em;
}
.theater-note {
  color: #fff1d5;
  font: 600 clamp(.875rem, 1.5vw, 1.1rem)/1.45 var(--serif);
  letter-spacing: .03em;
}
.theater-ticket {
  position: absolute;
  place-self: end center;
  bottom: 8%;
  display: flex;
  align-items: center;
  gap: .75em;
  border: 1px solid #d4af70;
  padding: .26em 1.1em;
  color: #ffedc7;
  background: linear-gradient(#512b39, #351d2b);
  box-shadow: 0 0 0 2px #3b2127, 0 2px 6px #24171a;
  font-size: clamp(.875rem, 1.45vw, 1.1rem);
  letter-spacing: .06em;
  font-weight: 600;
}
.theater-toggle {
  position: relative;
  width: .7em;
  height: .7em;
}
.theater-toggle::before, .theater-toggle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  border-top: 1px solid currentColor;
}
.theater-toggle::after { transform: rotate(90deg); }
.novel-theater details[open] .theater-toggle::after { display: none; }
@media (hover: hover) {
  .theater-poster:hover .theater-ticket { color: #fff; border-color: #fff0c3; background: #642e42; }
}
.theater-program {
  display: flex;
  align-items: center;
  gap: clamp(1rem, 3vw, 2.25rem);
  padding: clamp(1.15rem, 3vw, 2.25rem);
  border-top: 1px solid #ac895b;
  background: #faf4e9;
  color: #462c38;
}
.theater-program img {
  align-self: flex-start;
  width: clamp(3.5rem, 10vw, 6rem);
  height: auto;
  box-shadow: 0 2px 6px #3b26353b;
}
.theater-program h2 { margin: 0; font: 600 clamp(1.06rem, 2vw, 1.5rem)/1.55 var(--serif); }
.theater-program p { margin: .55rem 0; }
.theater-program a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: #7e2941;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: .24em;
}

@media (max-width: 620px) {
  .theater-note > span { display: block; }
}
@media (max-width: 480px) {
  .theater-stage { --screen-zoom: 1.3; }
  .theater-imprint {
    font-size: clamp(.78rem, 3.5vw, .875rem);
    line-height: 1.3;
  }
  .theater-title { font-size: clamp(1.25rem, 6.4vw, 1.55rem); }
  .theater-ticket { line-height: 1.35; padding-block: .18em; bottom: 6%; }
}

.theater-reel,
.theater-beam,
.theater-lens {
  position: absolute;
  display: block;
  pointer-events: none;
}
.theater-reel {
  background-repeat: no-repeat;
  background-size: 6100% 100%;
  background-position: 0% 0%;
  animation: theater-reel-spin var(--turn) steps(60, end) infinite paused;
}
.theater-reel-supply {
  left: 2.125%;
  top: 33.766234%;
  width: 3.625%;
  height: 13.149351%;
  --turn: 2.9s;
  background-image: var(--supply-art);
}
.theater-reel-takeup {
  left: 0;
  top: 46.428571%;
  width: 2.875%;
  height: 9.902597%;
  --turn: 2.15s;
  background-image: var(--takeup-art);
}
@keyframes theater-reel-spin { to { background-position: 100% 0%; } }
.theater-beam {
  /* The light's alpha follows the viewer's silhouette in the room painting. */
  left: 6.5%;
  top: 13.798701%;
  width: 34%;
  height: auto;
  opacity: 0;
}
.theater-lens {
  left: 5.9%;
  top: 50.7%;
  width: 1.6%;
  height: 4.6%;
  border-radius: 50%;
  background: radial-gradient(ellipse, #fffdeb 8%, #fff0bdd9 22%, #ffcd7d63 44%, transparent 72%);
  opacity: 0;
}
.novel-theater.is-projecting .theater-reel { animation-play-state: running; }
.novel-theater.is-projecting .theater-beam { animation: theater-projector-light 2.8s ease-in-out infinite; }
.novel-theater.is-projecting .theater-lens { opacity: .77; }
@keyframes theater-projector-light {
  0%, 100% { opacity: .86; }
  38% { opacity: .94; }
  63% { opacity: .89; }
}

/* The completed serial leads the homepage; the film, flames and projector
   keep their original shared stage and follow the reader's motion setting. */
.novel-theater--featured { padding-top: clamp(1.1rem, 3.2vw, 2.6rem); }
.novel-theater--featured .theater-housing {
  border-color: #aa824c;
  box-shadow: 0 4px 18px #5d35472b;
}
.novel-theater--featured .theater-ticket::after {
  content: "";
  width: .4em;
  height: .4em;
  border-right: 1px solid currentColor;
  border-top: 1px solid currentColor;
  transform: rotate(45deg);
}
