/* diorama-player.css — full-screen paper-theatre story scenes. */

.diorama {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  background: #120e0a;
  opacity: 0;
  transition: opacity 0.6s ease;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  /* Invisible while the layers load, so the title underneath stays usable. */
  pointer-events: none;
}

.diorama.is-playing {
  opacity: 1;
  pointer-events: auto;
}

/* Portrait screens: the scene is landscape, so the whole player is laid out in
 * the swapped (landscape) box and turned 90° to fill the screen. Centring the
 * box means the rotation covers the screen exactly, and the player turns the
 * device to watch — the scene, subtitles and skip control stay together. */
.diorama.is-turned {
  inset: auto;
  left: 50%;
  top: 50%;
  width: var(--diorama-box-width, 100vh);
  height: var(--diorama-box-height, 100vw);
  transform: translate(-50%, -50%) rotate(90deg);
}

/* The scene itself: one canvas, painted at device resolution by the player.
 * Everything the theatre is made of — layers, contact shadows, the lighting
 * rig, the paper sheet and the vignette — is drawn into it (see the module
 * comment in diorama-player.js for why it is not a stack of DOM layers). */
.diorama__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.diorama__subtitle {
  position: absolute;
  left: 50%;
  bottom: max(5%, calc(env(safe-area-inset-bottom) + 12px));
  width: min(82%, 1100px);
  margin: 0;
  padding: 0.55em 1.1em 0.65em;
  transform: translate(-50%, 8px);
  box-sizing: border-box;
  /* A torn parchment strip pinned over the scene. */
  background:
    linear-gradient(180deg, rgba(255, 246, 222, 0.96), rgba(236, 219, 182, 0.96));
  color: #2b1a0c;
  border-radius: 3px 6px 4px 7px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45), inset 0 0 22px rgba(140, 95, 40, 0.35);
  font-family: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  font-size: clamp(16px, calc(var(--diorama-text-box, 100vw) * 0.026), 30px);
  line-height: 1.35;
  text-align: center;
  /* The cards carry the whole story now (there is no voice-over), so a card
   * holds up to three short sentences. Authored line breaks show, lines are
   * balanced so a card never ends on one orphaned word, and a long German
   * compound may break rather than push past the card's edge. The card's
   * rendered height is measured at the smallest boxes by tools/measure-cards.py. */
  white-space: pre-line;
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: manual;
  opacity: 0;
  transition: opacity 0.45s ease, transform 0.45s ease;
  z-index: 10;
}

.diorama__subtitle.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.diorama__subtitle:empty { display: none; }

/* Spellbook lines (**…** in scene.json). */
.diorama__subtitle strong {
  font-weight: 700;
  font-style: italic;
}

/* The heading card of a scene ("Act II: The Long Country · Levels 11–20"). */
.diorama__subtitle.is-title {
  font-weight: 700;
  letter-spacing: 0.03em;
}

/* Landscape phones — and a turned portrait screen, which is the same short
 * landscape box — get a slimmer strip so it covers less of the scene. The
 * class comes from the player (COMPACT_BOX_HEIGHT), so it follows the box
 * rather than the screen. */
.diorama.is-compact .diorama__subtitle {
  bottom: max(3%, calc(env(safe-area-inset-bottom) + 8px));
  width: min(88%, 1100px);
  padding: 0.35em 1em 0.45em;
  font-size: clamp(14px, calc(var(--diorama-text-box, 100vw) * 0.0205), 20px);
  line-height: 1.3;
}

.diorama__controls {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  display: flex;
  gap: 10px;
  z-index: 11;
}

.diorama__btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid rgba(255, 236, 200, 0.75);
  border-radius: 6px;
  background: rgba(30, 20, 10, 0.55);
  color: #fff3dc;
  font: 600 16px/1 Georgia, serif;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.diorama__btn:hover,
.diorama__btn:focus-visible {
  background: rgba(60, 38, 16, 0.8);
  outline: 2px solid #ffd27a;
  outline-offset: 2px;
}

.diorama__btn[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .diorama,
  .diorama__subtitle { transition: none; }
}


/* Reduce Motion must not move the scene. styles.css switches animation off for
 * people who ask for it with `* { transform: none !important }`, which also
 * strips the turn that fits the landscape scene to a portrait phone and the
 * centring of the subtitle strip: the scene then sat at the screen centre with
 * its Skip button off-screen, as a hard-edged picture over the lower right of
 * the title menu. These are layout, not motion (the player's own reduced-motion
 * handling is the diorama--reduced class), so they are restated with a higher
 * specificity. */
.diorama.is-turned {
  transform: translate(-50%, -50%) rotate(90deg) !important;
}

.diorama .diorama__subtitle {
  transform: translate(-50%, 8px) !important;
}

.diorama .diorama__subtitle.is-visible {
  transform: translate(-50%, 0) !important;
}

/* Inside the web's desktop phone frame (game/phone-frame.js) the portrait screen cannot be
 * turned, so the scene is not rotated: it is a 16:9 band across the full width, centred,
 * with the subtitle strip below it and Skip in the screen's own top-right corner. The band
 * height comes from the player (--diorama-band-height). Placed with top/left, not
 * transform, so the reduced-motion reset above cannot move it. */
.diorama.is-letterboxed .diorama__canvas {
  position: absolute;
  left: 0;
  top: calc(50% - var(--diorama-band-height, 56.25vw) / 2);
}

.diorama.is-letterboxed .diorama__subtitle {
  top: calc(50% + var(--diorama-band-height, 56.25vw) / 2 + 20px);
  bottom: auto;
  width: 90%;
  font-size: 18px;
}
