/* Studio: the film chrome, the end card, the kept stamp, the replay frame and the Undo chip (ST4; studio DESIGN §2.2,
   §2.3, §2.4, §8). Every class root carries the st- prefix; colours, motion and layers come from the core tokens.
   Layers: the set's view at --z-view; this chrome above its HUD and below the sheets (--z-sheet), the break and toasts. */

/* While a film, the end card or the instant replay is up: no UI glyph over the picture, no scaffold control. */
.st-set[data-st-filming] .st-glyphs,
.st-set[data-st-filming] .st-live-glyphs,
.st-set[data-st-filming] .st-scaffold { visibility: hidden; }

/* ── the film chrome: a tap anywhere shows the close button for 3 s (§2.2) */
.st-movie-layer { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.st-film-close {
  position: absolute; left: calc(12px + env(safe-area-inset-left)); top: calc(12px + env(safe-area-inset-top));
  width: 60px; height: 60px; min-height: 60px; padding: 0; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--card); color: var(--ink); box-shadow: var(--shadow), var(--press); display: grid; place-items: center;
  opacity: 0; visibility: hidden; pointer-events: none; touch-action: none;
}
.st-film-close .ico { width: 30px; height: 30px; }
.st-film-close.is-on { visibility: visible; pointer-events: auto; animation: st-close-show 3s linear forwards; }
.st-film-close:active { transform: scale(.92); transition: transform 80ms; }
@keyframes st-close-show { 0% { opacity: 0; transform: scale(.8); } 6% { opacity: 1; transform: scale(1); } 88% { opacity: 1; } 100% { opacity: 0; } }

/* the REC dot of a top-up (§4.8, §2.1 glyphs) */
.st-rec {
  position: absolute; left: 50%; top: calc(96px + env(safe-area-inset-top)); width: 16px; height: 16px; margin-left: -8px;
  border-radius: 50%; background: var(--coral); box-shadow: 0 0 0 3px var(--card); animation: st-rec 1s ease-in-out infinite alternate;
}
.st-rec[hidden] { display: none; }
@keyframes st-rec { from { opacity: .5; } to { opacity: 1; } }

/* the scaffold's Movie! pill (until the HUD draws its own): the §4.8 glow */
[data-st-movie][data-st-glow="on"] { box-shadow: 0 0 0 4px var(--signal), var(--shadow); animation: st-glow 1.6s ease-in-out infinite; }
[data-st-movie][data-st-glow="soft"] { box-shadow: 0 0 0 4px color-mix(in srgb, var(--signal) 50%, transparent), var(--shadow); animation: st-glow-soft 1.6s ease-in-out infinite; }
[data-st-movie][data-st-glow="pulse"] { animation: st-glow 1.2s ease-in-out 1; box-shadow: 0 0 0 4px var(--signal), var(--shadow); }
@keyframes st-glow { 0%, 100% { box-shadow: 0 0 0 2px var(--signal), var(--shadow); } 50% { box-shadow: 0 0 0 7px var(--signal), var(--shadow); } }
@keyframes st-glow-soft { 0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--signal) 50%, transparent), var(--shadow); } 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--signal) 50%, transparent), var(--shadow); } }

/* ── the instant replay (§2.4): a coral frame and the badge, no controls */
.st-replay { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
.st-replay-frame { position: absolute; inset: 0; box-shadow: inset 0 0 0 4px var(--coral); }
.st-replay-badge {
  position: absolute; left: calc(12px + env(safe-area-inset-left)); top: calc(12px + env(safe-area-inset-top));
  width: 72px; height: 72px; animation: st-wobble 1.4s ease-in-out infinite alternate; transform-origin: 50% 60%;
}
.st-replay-badge img { width: 72px; height: 72px; display: block; filter: drop-shadow(0 4px 8px rgba(93, 63, 26, .25)); }
.st-replay-badge .ico {
  position: absolute; right: -4px; bottom: -4px; width: 28px; height: 28px; padding: 4px; border-radius: 50%;
  background: var(--card); color: var(--ink); box-shadow: 0 0 0 2px var(--ink);
}
@keyframes st-wobble { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }

/* ── the end card (§2.3) */
.st-end { position: fixed; inset: 0; z-index: 26; pointer-events: none; }
.st-end > * { pointer-events: auto; }
.st-end-live { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.st-end-panel {
  position: absolute; left: 0; right: 0; bottom: 0; box-sizing: border-box;
  padding: 18px calc(12px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--card); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lift);
  transform: translateY(110%); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.st-end.is-in .st-end-panel { transform: none; transition: transform var(--t-card) var(--spring); }
.st-end.is-out .st-end-panel { transform: translateY(110%); transition: transform 200ms ease-in; }
.st-end-slot { width: 100%; display: flex; justify-content: center; }
.st-end-slot[hidden] { display: none; }
.st-end-main { display: flex; align-items: center; justify-content: center; gap: 16px; }
.st-end button { font: inherit; color: var(--ink); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.st-end button:active { transform: scale(.92); transition: transform 80ms; }
.st-end button:focus-visible { outline: 4px solid var(--signal); outline-offset: 2px; }
.st-end-again {
  width: 96px; height: 96px; min-height: 96px; padding: 0; border-radius: 50%; border: 3px solid var(--ink);
  background: var(--card); box-shadow: var(--shadow), var(--press); display: grid; place-items: center;
}
.st-end-again .ico { width: 40px; height: 40px; }
.st-end-back {
  width: 208px; height: 96px; min-height: 96px; padding: 0 16px; border-radius: 48px; border: 3px solid var(--ink);
  background: var(--signal); box-shadow: var(--shadow), var(--press); display: flex; align-items: center; justify-content: center; gap: 10px;
}
/* the label: 22 px weight 800 (§2.3); after `.st-end button { font: inherit }`, so it needs the same weight of selector */
.st-end .st-end-back { font-size: 22px; font-weight: 800; line-height: 1.05; text-align: left; letter-spacing: -.01em; }
.st-end-back span { min-width: 0; text-wrap: balance; }
.st-end-back .ico { width: 36px; height: 36px; flex: none; }
.st-end-tiles { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.st-end-tile {
  width: 88px; height: 88px; min-height: 88px; padding: 3px 2px; box-sizing: border-box; border-radius: 20px; border: 3px solid var(--line);
  background: var(--card); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.st-end-pic { display: grid; place-items: center; width: 40px; height: 40px; flex: none; }
.st-end-pic .ico { width: 40px; height: 40px; }
/* a label for the grown-ups: 15 px, at most two lines inside the tile */
.st-end-lab { font-size: 15px; font-weight: 700; line-height: 15px; max-height: 30px; text-align: center; color: var(--muted); width: 80px; overflow: hidden;
  letter-spacing: -.01em; overflow-wrap: anywhere; hyphens: auto; }
.st-end-notthis { color: var(--muted); }
.st-end-notthis .st-lid-open { display: none; }
.st-end-notthis.is-armed { border-color: var(--coral); }
.st-end-notthis.is-armed .st-lid-shut { display: none; }
.st-end-notthis.is-armed .st-lid-open { display: grid; color: var(--coral-deep); animation: st-lid 600ms ease-in-out infinite; }
@keyframes st-lid { 0%, 100% { transform: rotate(-5deg); } 50% { transform: rotate(5deg); } }
.st-end-tile.nope { animation: st-nope 260ms ease-in-out; }
@keyframes st-nope { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
/* the grown-ups' video: top right, outside the panel */
.st-end-video {
  position: absolute; right: calc(12px + env(safe-area-inset-right)); top: calc(12px + env(safe-area-inset-top));
  height: 60px; min-height: 60px; min-width: 60px; padding: 0 12px; border-radius: 30px; border: 3px solid var(--line);
  background: var(--card); box-shadow: var(--shadow); display: flex; align-items: center; gap: 2px;
}
.st-end-video .ico { width: 28px; height: 28px; }
/* the kept stamp, over the frame centre */
.st-end-stamp {
  position: absolute; left: 50%; top: 38%; width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center;
  background: var(--signal); color: var(--ink); box-shadow: 0 0 0 3px var(--ink), var(--shadow-lift); transform: translate(-50%, -50%) scale(.5); opacity: 0;
  pointer-events: none;
}
.st-end-stamp .ico { width: 40px; height: 40px; stroke-width: 3; }
.st-end-cover {
  position: absolute; left: 50%; top: 38%; width: min(64vw, 420px); aspect-ratio: 16 / 9; object-fit: cover; border-radius: 16px;
  box-shadow: 0 0 0 3px var(--ink), var(--shadow-lift); transform: translate(-50%, -50%); pointer-events: none;
}
/* the Undo chip after Not this one (6-8): 72 px, icon only, bottom centre over the set for 6 s */
.st-undo-chip {
  position: fixed; z-index: 26; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom) + 12px); width: 72px; height: 72px; min-height: 72px;
  margin-left: -36px; padding: 0; border-radius: 50%; border: 3px solid var(--ink); background: var(--card); color: var(--ink);
  box-shadow: var(--shadow-lift), var(--press); display: grid; place-items: center; animation: st-pop-in var(--t-pop) var(--spring) both;
}
.st-undo-chip .ico { width: 36px; height: 36px; }
.st-undo-chip:active { transform: scale(.92); }
@keyframes st-pop-in { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* phone landscape: the panel is a right-side column 340 px wide */
@media (orientation: landscape) and (max-height: 599px) {
  .st-end-panel {
    left: auto; top: 0; width: calc(340px + env(safe-area-inset-right)); border-radius: 24px 0 0 24px; justify-content: center; gap: 12px;
    padding: calc(12px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) 16px;
    transform: translateX(110%);
  }
  .st-end.is-out .st-end-panel { transform: translateX(110%); }
  .st-end-again { width: 88px; height: 88px; min-height: 88px; }
  .st-end-back { width: 196px; height: 88px; min-height: 88px; }
  .st-end .st-end-back { font-size: 20px; }
  .st-end-video { right: calc(352px + env(safe-area-inset-right)); }
  .st-end-stamp, .st-end-cover { left: calc((100% - 340px) / 2); top: 50%; }
  .st-film-close, .st-replay-badge { top: calc(8px + env(safe-area-inset-top)); }
}
/* tablets: a centred bottom panel */
@media (min-width: 600px) and (min-height: 600px) {
  .st-end-panel { left: 50%; right: auto; width: min(720px, 100%); margin-left: max(-360px, -50%); }
}

@media (prefers-reduced-motion: reduce) {
  .st-replay-badge, .st-rec, .st-end-notthis.is-armed .st-lid-open, [data-st-movie][data-st-glow] { animation: none; }
  .st-end.is-in .st-end-panel, .st-end.is-out .st-end-panel { transition: transform var(--t-calm) linear; }
}
