/* poster.css — owner track: C5. The poster screen (tasks B11 and C5.3): the poster img, the one element a long press or
   a selection may reach, in its frame (printing, ready, or failed with its retry), the in-app browser banner, the
   actions (SHARE or COPY IMAGE, COPY HEADLINE, SAVE PNG, SWAP SCENE, SIGN IT, ENCORE and WARDROBE), SIGN IT's name box,
   the clipboard's select-all box and the next show's line; and the scene polaroid over the stage, which shrinks in from
   the freeze and stamps its tissue packets one by one (each one's --i staggers it), its photo beside the caption when
   the stage is short for the text size. Cut paper as everywhere: cream card stock with a hard offset shadow. Under .e2e
   (app.css) nothing animates, and html.reduced-motion keeps the polaroid still. */

/* The poster: app.css turns the long-press menu and selection off app-wide, and this img turns them back on, so a long
   press offers Save Image. */
img.poster {
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
}

/* — The poster screen: over the whole column, scrolling when the phone is short — */

.poster-screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 20px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(ellipse 90% 55% at 50% 0%, rgba(255, 211, 138, 0.16), rgba(255, 211, 138, 0) 70%),
    linear-gradient(var(--sky-mid), var(--sky-dark) 60%);
  outline: none;
}

.poster-banner {
  flex: none;
  width: min(100%, 420px);
  padding: 9px 14px 10px;
  border-radius: 10px 13px 9px 14px;
  background: var(--cards);
  box-shadow: var(--paper-shadow);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.9375rem;
  line-height: 1.3;
  text-align: center;
}

/* The frame keeps the poster's 1080:1350 shape before the img arrives, so nothing jumps when it does. */
.poster-frame {
  position: relative;
  flex: none;
  width: min(100%, 420px);
  aspect-ratio: 1080 / 1350;
  border-radius: 3px;
  background: var(--cards);
  box-shadow: 5px 6px 0 rgba(0, 0, 0, 0.45);
  transform: rotate(-1deg);
}

.poster-frame > .poster {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
}

.poster-frame[data-state="printing"] {
  background:
    repeating-linear-gradient(0deg, rgba(91, 42, 94, 0.07) 0 2px, rgba(91, 42, 94, 0) 2px 9px),
    var(--cards);
  animation: poster-printing 1.4s ease-in-out infinite alternate;
}

@keyframes poster-printing {
  from { background-position: 0 0; }
  to { background-position: 0 36px; }
}

.poster-printing {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 24px;
  color: var(--plum);
  font: 800 1.25rem/1.2 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.03em;
  text-align: center;
}

/* A poster that did not print: its line and TRY AGAIN, in the frame. */
.poster-frame[data-state="failed"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
}

.poster-failed {
  margin: 0;
  color: var(--plum);
  font: 800 1.25rem/1.2 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.03em;
  text-align: center;
  text-wrap: balance;
}

/* — The actions: the first is the one to take, a gold card across the row, and the rest share rows by their width;
   ENCORE is the velvet ticket; every target is 48 px+ — */

.poster-actions {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: min(100%, 420px);
}

.poster-action {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 52px;
  margin: 0;
  padding: 10px 20px 9px;
  border: 0;
  border-radius: 22px 18px 21px 19px;
  background: var(--cards);
  color: var(--ink);
  font: 800 1.0625rem/1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.05em;
  text-align: center;
  text-decoration: none;
  box-shadow: var(--paper-shadow);
  cursor: pointer;
  transition: transform 90ms ease-out, box-shadow 90ms ease-out, opacity 120ms ease-out;
}

.poster-actions > .poster-action {
  flex: 1 1 auto;
}

.poster-actions > .poster-action:first-child {
  flex-basis: 100%;
}

.poster-action:first-child,
.poster-retry,
.poster-sign-submit {
  background: var(--tone-fabulous);
}

.poster-action:active {
  transform: translate(2px, 2px) scale(0.97);
  box-shadow: var(--paper-press);
}

/* SHARE, COPY IMAGE and SAVE, until the current poster's File is ready. */
.poster-action[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* SIGN IT while its name box is open: pressed in, in plum. */
.poster-sign[aria-expanded="true"] {
  background: var(--plum);
  color: var(--cards);
  box-shadow: var(--paper-press);
  transform: translate(2px, 2px);
}

.poster-encore,
.poster-action.poster-encore:first-child {
  border: 2.5px solid var(--tone-callback);
  background: radial-gradient(ellipse 80% 90% at 50% 25%, #A8253E, var(--velvet) 62%, var(--velvet-deep));
  color: var(--tone-fabulous);
  text-shadow: 2px 2px 0 var(--velvet-deep);
}

/* SIGN IT's name box: a cream card with a dashed signature line, under "Conducted by" as the poster's footer prints it. */
.poster-sign-box {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px 12px;
  width: min(100%, 420px);
  padding: 12px 14px;
  border-radius: 12px 9px 14px 10px;
  background: var(--cards);
  box-shadow: var(--paper-shadow);
  color: var(--ink);
}

.poster-sign-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.poster-sign-by {
  color: var(--plum);
  font: 800 0.875rem/1.2 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.04em;
}

/* Its text is 16px or more: iOS zooms into a focused field set any smaller. */
.poster-sign-name {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  margin: 0;
  padding: 6px 4px 2px;
  border: 0;
  border-bottom: 2.5px dashed var(--plum);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 800 1.25rem/1.2 "Baloo 2", system-ui, sans-serif;
}

.poster-sign-hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--plum);
  font-size: 0.8125rem;
  line-height: 1.3;
}

/* On cream card the warm focus ring would vanish, so it turns plum. */
.poster-frame :focus-visible,
.poster-sign-box :focus-visible {
  outline-color: var(--plum);
}

/* The clipboard's last resort: the headline, selected, ready for the phone's own Copy. */
.select-box {
  -webkit-appearance: none;
  appearance: none;
  flex: none;
  width: min(100%, 420px);
  margin: 0;
  padding: 10px 12px;
  border: 2px dashed var(--window-warm);
  border-radius: 10px;
  background: var(--cards);
  color: var(--ink);
  font: 600 0.9375rem/1.35 Nunito, system-ui, sans-serif;
  resize: none;
}

/* execCommand's hidden textarea: in the page, so it can be selected, but out of sight. Every COPY HEADLINE tap selects
   it, so its text is 16px: iOS zooms into a focused field set any smaller. */
.copy-buffer {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
  font-size: 16px;
}

.poster-next {
  flex: none;
  margin: 2px 0 0;
  color: var(--window-warm);
  font-weight: 800;
  font-size: 0.9375rem;
  line-height: 1.3;
  text-align: center;
}

/* — The poster full size (I38): while it shows the poster, on a window that would show it larger than the preview
   (never a phone layout: posterScreen.js opensLarger reads this padding as ENLARGED_PAD), the preview is a button that
   opens the poster over the whole page, as large as the window allows, never past its own 1,080 x 1,350, on the dimmed
   page; a click anywhere on it, Esc or the 48 px close button takes it down — */

.poster-frame[role="button"] {
  cursor: zoom-in;
}

.poster-enlarged {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px 72px;
  background: rgba(20, 10, 28, 0.86);
  cursor: zoom-out;
  outline: none;
}

.poster-enlarged-img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 1080px);
  max-height: min(100vh - 32px, 1350px);
  max-height: min(100dvh - 32px, 1350px);
  border-radius: 3px;
  box-shadow: 6px 8px 0 rgba(0, 0, 0, 0.5);
}

.poster-enlarged-close {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--cards);
  color: var(--ink);
  box-shadow: var(--paper-shadow);
  cursor: pointer;
}

.poster-enlarged-cross {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
}

/* — The scene polaroid: centred over the stage, sized to whatever the stage leaves — */

.polaroid-layer {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  container-type: size;
  pointer-events: none;
}

/* While it is up, the HUD's YOU tag rests, hidden in its place, and the pause button stays: the tag hangs from the HUD,
   which paints over the stage, and lay over the card, so that CAN LAH read YOU LAH. The tag is for play, and the
   polaroid ends the scene. */
#app:has(.polaroid-layer) .hud-you {
  visibility: hidden;
}

.polaroid {
  --polaroid-in: 520ms;
  --polaroid-gap: 280ms;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(272px, calc(100cqw - 24px));
  margin: 0;
  padding: 12px 12px 14px;
  border-radius: 2px;
  background: #FFFFFF;
  box-shadow: 4px 5px 0 rgba(0, 0, 0, 0.4);
  color: var(--ink);
  transform: rotate(-3deg);
  animation: polaroid-in var(--polaroid-in) cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}

/* The freeze shrinks into the polaroid. */
@keyframes polaroid-in {
  from { transform: scale(2.2) rotate(0deg); }
  to { transform: scale(1) rotate(-3deg); }
}

.polaroid-frame {
  position: relative;
}

.polaroid-photo {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  background: var(--sky-dark);
}

/* NEW ROLE sits above the photo, at its right: over the photo's top-right corner it covered the first line of a raised
   WELL DONE, {NAME} board (the Phase D gate: all of SHARON's WELL on the Lunch Break's polaroid). */
.polaroid-new {
  position: absolute;
  top: auto;
  bottom: calc(100% + 6px);
  right: -12px;
  padding: 4px 9px 2px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--tone-callback);
  color: var(--ink);
  font: 800 0.875rem/1.1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.06em;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  transform: rotate(8deg);
}

/* The column's shortest stages at 100% text keep NEW ROLE at the photo's top-right corner, over a raised board's WELL,
   as before. The card is centred, so a sticker standing about 21 px over its top needs about 42 px more stage than the
   card: on the column's stages 401 to 431 px tall it would leave the stage (to 430 px in Chromium, 431 in WebKit, by
   0.3 px). From 115% text the column starts at 461 px and always has room. */
@container (min-height: 25.0001rem) and (max-height: 431px) {
  .polaroid-new {
    top: -10px;
    bottom: auto;
  }
}

/* A role, reason or label that wraps breaks into even lines, never one word alone on the last. */
.polaroid-caption {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-wrap: balance;
}

.polaroid-role {
  color: var(--plum);
  font: 800 1rem/1.1 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
}

.polaroid-packets {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.polaroid-packet,
.polaroid-label {
  animation: polaroid-stamp 240ms cubic-bezier(0.3, 1.4, 0.5, 1) both;
  animation-delay: calc(var(--polaroid-in) + var(--i, 0) * var(--polaroid-gap));
}

/* NEW ROLE is slapped on as the polaroid lands, a beat before its first packet: the stamps' own punch. It animates
   scale alone, so the sticker keeps its place and its rotate(8deg); held still in Reduced motion, as the stamps are. */
.polaroid-new {
  animation: polaroid-stamp 240ms cubic-bezier(0.3, 1.4, 0.5, 1) both;
  animation-delay: calc(var(--polaroid-in) - var(--polaroid-gap) / 2);
}

.polaroid-packet {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 0.8125rem;
  line-height: 1.25;
  letter-spacing: 0.02em;
}

/* Each packet stamps down, and the label last. It animates scale alone, so the label keeps its tilt. */
@keyframes polaroid-stamp {
  from { opacity: 0; scale: 1.8; }
  60% { opacity: 1; scale: 0.94; }
  to { opacity: 1; scale: 1; }
}

.polaroid-packet-icon {
  flex: none;
  width: 24px;
  height: 18px;
}

.polaroid-packet-body,
.polaroid-packet-puff {
  fill: #FFFFFF;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linejoin: round;
}

.polaroid-packet-band {
  fill: var(--accent-star);
}

.polaroid-packet-slit {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
}

.polaroid-label {
  margin-top: 2px;
  padding: 3px 12px 1px;
  border: 2.5px solid var(--plum);
  border-radius: 8px;
  color: var(--plum);
  font: 800 1.125rem/1.15 "Baloo 2", system-ui, sans-serif;
  letter-spacing: 0.04em;
  text-align: center;
  transform: rotate(-2deg);
}

/* A stage short for the text size (a phone lying down, or the 130% text): the photo sits beside a tighter caption. The
   switch is in rem, so it follows --text-scale: 25rem is B11's 400 px at 100%, 460 px at 115% and 520 px at 130%, above
   what the column needs at each (390, 402 and 420 px with 4 or 5 packets and NEW ROLE at the photo's corner, where
   .polaroid-new's band keeps it on the stages too short for it above the photo). The photo never outgrows the
   stage (100cqh). The rules after this one shrink the photo, or the text, only where the card would otherwise spill out
   of the stage or its caption out of the card: measured in both engines on stages 360 to 480 px wide, from 240 px tall
   up, at every text size. */
@container (max-height: 25rem) {
  .polaroid {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    width: auto;
    max-width: calc(100cqw - 16px);
    padding: 8px;
  }

  .polaroid-frame {
    flex: none;
    width: min(200px, calc((100cqh - 40px) * 4 / 3));
  }

  /* NEW ROLE shrinks with the smaller photo and sits above it, at its right as in the column: off the photo, and so off
     its boards, its faces and a photobomb at its left. */
  .polaroid-new {
    top: auto;
    bottom: calc(100% + 6px);
    right: -8px;
    padding: 3px 7px 1px;
    font-size: min(0.75rem, 12px);
  }

  .polaroid-caption {
    gap: 2px;
  }

  .polaroid-role {
    line-height: 1.05;
  }

  .polaroid-packets {
    gap: 1px;
  }

  .polaroid-packet {
    gap: 5px;
    line-height: 1.1;
  }

  .polaroid-label {
    margin-top: 1px;
    padding: 2px 10px 0;
  }
}

/* The photo yields width to its caption (36cqw) where the caption cannot fit beside a 200 px photo. On a stage 370 px
   wide or less, or one narrow for the text size (21rem: 386 px at 115%, 437 px at 130%), the label's longest word does
   not fit beside it at any height. On a stage short for the text size (17rem: 272, 313 and 354 px), the wrapped caption
   would stand taller than the stage. */
@container (max-height: 25rem) and (max-width: 21rem) {
  .polaroid-frame {
    width: min(200px, 36cqw, calc((100cqh - 40px) * 4 / 3));
  }
}

@container (max-height: 25rem) and (max-width: 370px) {
  .polaroid-frame {
    width: min(200px, 36cqw, calc((100cqh - 40px) * 4 / 3));
  }
}

@container (max-height: 17rem) {
  .polaroid-frame {
    width: min(200px, 36cqw, calc((100cqh - 40px) * 4 / 3));
  }
}

/* At 130%, on a stage both short and narrow (16rem by 20rem: 333 by 416 px), that caption still stands taller than the
   stage, so its text is capped. Below 130%, 1rem is at most 18.4 px, which only the label's cap reaches (by 0.2 px). */
@container (max-height: 16rem) and (max-width: 20rem) {
  .polaroid-role {
    font-size: min(1rem, 18.5px);
  }

  .polaroid-packet {
    font-size: min(0.8125rem, 15px);
  }

  .polaroid-label {
    font-size: min(1.125rem, 20.5px);
  }
}

html.reduced-motion .polaroid,
html.reduced-motion .polaroid-packet,
html.reduced-motion .polaroid-label,
html.reduced-motion .polaroid-new,
html.reduced-motion .poster-frame[data-state="printing"] {
  animation: none;
}

html.reduced-motion .poster-action:active {
  transform: none;
}
