/* =====================================================================
   css/scenes/card.css · scene 6 `card` (his cue cards) and the content of
   the read-it-all letter overlay. Package cue-cards-and-letter (WP5).
   Prefixes: card-, letter-. Values: tokens, runtime variables, and the
   scene-local --card-* / --letter-* variables declared on our own roots.
   ===================================================================== */

/* ---------- scene-local geometry (the only literals in this file) ---------- */
.scene--card{overflow:hidden;              /* fallen cards rotate past the edges: never a horizontal scroll */
  --card-lift:4px;                         /* each card beneath the top one sits this much lower */
  --card-fall-y:70vh;                      /* a card falls this far: onto the floor, behind the dock */
  --card-shade:.86;                        /* the floor is outside the spot: a fallen card's top edge is dim paper, */
  --card-floor:1.1em;                      /* ...and this far below it the card is lost in the dark of the floor */
  --card-edge:inset 0 1px 0 rgba(var(--rgb-wick), .34);   /* its very edge still catches the spot */
  --card-dock-w:min(40%, 340px);           /* the landscape dock column (base.css) */
  --card-land-w:min(54vw, 440px);          /* card width beside that column */
  --card-pad-y:clamp(22px,5.5vw,40px);     /* base.css .cue-card vertical padding (the scrolling card's fade) */
  --card-fall-x:0px;--card-fall-r:0deg}    /* per card, set inline at mount */
@supports (height:1dvh){ .scene--card{--card-fall-y:70dvh} }
/* the scrolling card's bottom fade ends in the stock's warm bottom edge */
.scene--card{--card-fade:linear-gradient(rgba(var(--rgb-wick), 0), rgba(var(--rgb-wick), .92))}
@supports (color:color-mix(in srgb, currentColor, transparent)){
  .scene--card{--card-fade:linear-gradient(rgba(var(--rgb-wick), 0),
    color-mix(in srgb, color-mix(in srgb, var(--c-wick) 88%, var(--c-tungsten)) 94%, var(--c-midnight)))}
}

/* ---------- the deck: every card rendered once, stacked in one grid cell ---------- */
.scene--card .card-deck{position:absolute;left:0;right:0;
  top:calc(var(--chrome-h) + env(safe-area-inset-top) + var(--sp-2));
  bottom:calc(var(--dock-h) + env(safe-area-inset-bottom));
  display:grid;place-items:center;pointer-events:none;padding-bottom:var(--card-raise, 0px)}   /* raised over the sign: card.js */
.scene--card .cue-card{grid-area:1 / 1;translate:0 0;rotate:0deg;
  -webkit-user-select:none;user-select:none;-webkit-touch-callout:none;
  transition:translate calc(300ms * var(--t-scale)) var(--ease-out), rotate calc(300ms * var(--t-scale)) var(--ease-out),
    opacity calc(300ms * var(--t-scale)) var(--ease-out)}
/* the shade a card takes on when it leaves the light (opacity only, so it may move) */
.scene--card .cue-card::before{content:"";position:absolute;inset:0;z-index:1;border-radius:inherit;
  background:linear-gradient(rgba(var(--rgb-midnight), var(--card-shade)), var(--c-midnight) var(--card-floor));
  box-shadow:var(--card-edge);opacity:0;pointer-events:none;transition:opacity calc(450ms * var(--t-scale)) var(--ease-in)}

/* below her name (card.js decides it per viewport): the deck starts under the sign and every card is
   one height, from 46 dvh down to what its words need; otherwise the deck stands in front of the sign */
.scene--card .card-deck.card-below{top:var(--card-top);padding-bottom:var(--card-gap, 0px)}   /* clear of the last card's counter */
.scene--card .card-deck.card-below .cue-card{min-height:var(--card-h);max-height:var(--card-h)}
/* a short laptop screen: the card below her name is a little wider (fewer wrapped lines) and keeps a
   slimmer margin, so its longest cards still fit at the largest step they can */
.scene--card .card-deck.card-low{--card-pad-y:var(--sp-5)}
.scene--card .card-deck.card-low .cue-card{width:clamp(520px, 48vw, 640px);padding-top:var(--card-pad-y);padding-bottom:var(--card-pad-y)}
.scene--card .card-deck.card-low .cue-card.card-scroll{padding-bottom:0}
/* in front of the sign on a desktop: wide enough to hide her whole name, never just its middle */
.scene--card .card-deck.card-cover .cue-card{width:max(min(86vw, 520px), min(var(--card-cover-w), 92vw))}

/* positions: top, the two cards beneath (4 px lower each), the rest of the stack, the pile */
.scene--card .cue-card[data-pos="top"]{z-index:7;pointer-events:auto;cursor:pointer;touch-action:pan-y}
.scene--card .card-deck.card-at-end .cue-card[data-pos="top"]{cursor:default}   /* the last card: a tap does nothing */
.scene--card .cue-card[data-pos="under"]{z-index:6;translate:0 var(--card-lift)}
.scene--card .cue-card[data-pos="under2"]{z-index:5;translate:0 calc(var(--card-lift) * 2)}
.scene--card .cue-card[data-pos="deep"]{z-index:4;translate:0 calc(var(--card-lift) * 2);visibility:hidden}
.scene--card .cue-card[data-pos^="pile"],
.scene--card .cue-card[data-pos="gone"]{translate:var(--card-fall-x) var(--card-fall-y);rotate:var(--card-fall-r)}
.scene--card .cue-card[data-pos="pile-1"]{z-index:3}
.scene--card .cue-card[data-pos="pile-2"]{z-index:2}
.scene--card .cue-card[data-pos="pile-3"]{z-index:1}
.scene--card .cue-card[data-pos="gone"]{z-index:0;opacity:0;visibility:hidden;
  transition:opacity calc(450ms * var(--t-scale)) var(--ease-out), visibility 0s linear calc(450ms * var(--t-scale))}
.scene--card .cue-card[data-pos^="pile"]::before,
.scene--card .cue-card[data-pos="gone"]::before{opacity:1}

/* moves: the fall (450 ms, ease-in, in front of everything) and the rise back (ease-out) */
.scene--card .cue-card[data-move]{transition-duration:calc(450ms * var(--t-scale))}
.scene--card .cue-card[data-move="fall"]{z-index:8;transition-timing-function:var(--ease-in)}
.scene--card .cue-card[data-move="rise"]{transition-timing-function:var(--ease-out)}
.scene--card .card-deck.card-instant .cue-card,
.scene--card .card-deck.card-instant .cue-card::before{transition:none}

/* fit: measured with plain word wrapping and top alignment, so overflow is never hidden */
.scene--card .card-deck.card-measure .cue-card{justify-content:flex-start}
.scene--card .card-deck.card-measure .cue-card p{overflow-wrap:normal}
.scene--card .card-deck.card-measure .cue-card.card-breaks p{overflow-wrap:anywhere}   /* its long word breaks at any step */
/* the last resort: the card scrolls inside, with a soft fade at its bottom edge. Sticky offsets count
   from the content box, so the card's bottom padding moves into the fade (--card-pad-y mirrors base.css) */
.scene--card .cue-card.card-scroll{justify-content:flex-start;overscroll-behavior:contain;padding-bottom:0}
.scene--card .cue-card.card-scroll::after{content:"";position:sticky;z-index:1;bottom:0;flex:none;height:calc(1.6em + var(--card-pad-y));margin-top:-.32em;pointer-events:none;
  background:var(--card-fade)}
/* the fade paints over the card's own ink ring (-8 px): redraw the ring's bottom edge on it */
.scene--card .cue-card.card-scroll:focus-visible::after{background:linear-gradient(var(--c-ink), var(--c-ink)) 0 calc(100% - 6px) / 100% 2px no-repeat, var(--card-fade)}

/* ---------- the dock: counter, then the tape centred with Back hanging to its right ---------- */
.scene-ui--card .card-row{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;column-gap:var(--sp-3);width:100%}
.scene-ui--card .card-row .tape{grid-column:2;grid-row:1}
.scene-ui--card .card-row .ghost{grid-column:3;grid-row:1;justify-self:start}

/* ---------- landscape phones: the dock is a right-hand column, the card takes the left ---------- */
@media (orientation:landscape) and (max-height:500px){
  .scene--card .card-deck{right:var(--card-dock-w);bottom:calc(var(--sp-3) + env(safe-area-inset-bottom))}
  .scene--card .cue-card{width:var(--card-land-w)}
  .scene-ui--card .card-row{grid-template-columns:auto;justify-content:center;row-gap:var(--sp-1)}
  .scene-ui--card .card-row .tape{grid-column:1}
  .scene-ui--card .card-row .ghost{grid-column:1;grid-row:2;justify-self:center}
}

/* ---------- reduced motion: cards crossfade, the pile just updates ---------- */
@media (prefers-reduced-motion:reduce){
  .scene--card .cue-card{transition:opacity calc(200ms * var(--t-scale)) linear}
  .scene--card .cue-card[data-move]{transition-duration:calc(200ms * var(--t-scale));transition-timing-function:linear}
  .scene--card .cue-card::before{transition:none}
  .scene--card .cue-card[data-move="fall"]{translate:0 0;rotate:0deg;opacity:0}
  .scene--card .cue-card[data-move="fall"]::before{opacity:0}
  .scene--card .cue-card[data-move="rise"]{animation:card-fade-in calc(200ms * var(--t-scale)) linear both}
}
@keyframes card-fade-in{from{opacity:0}}

/* =====================================================================
   The letter overlay content (the .overlay frame itself is ui.js + base.css)
   ===================================================================== */
.overlay .letter-page{--letter-w:min(86vw, 560px);
  --letter-pad:clamp(24px, 7vw, 56px) clamp(22px, 6.5vw, 56px);
  --letter-gap:1.1em;                      /* between stanzas */
  --letter-top:calc(var(--chrome-h) + env(safe-area-inset-top));   /* the overlay's own top padding (base.css) */
  --letter-edge:calc((100% - var(--letter-w)) / 2 + var(--gutter));  /* the sheet's side edge, seen from the overlay */
  --letter-paper:linear-gradient(90deg, rgba(var(--rgb-midnight), .04), rgba(var(--rgb-midnight), 0) 8%, rgba(var(--rgb-midnight), 0) 92%, rgba(var(--rgb-midnight), .04)),
    radial-gradient(130% 480px at 50% 0, var(--c-wick), rgba(var(--rgb-wick), 0)),
    linear-gradient(rgba(var(--rgb-tungsten), .07), rgba(var(--rgb-tungsten), .13)), var(--c-wick);
  display:flex;flex-direction:column;align-items:center;gap:var(--sp-6)}
/* an opaque room behind the sheet: the frame's 97 % Midnight would let the tapes of the dock
   behind it ghost through under "Save it as a picture" (it fades in with the frame) */
.overlay .letter-page::before{content:"";position:fixed;inset:0;z-index:-1;background:var(--c-midnight);pointer-events:none}

/* the sticky row, in the chrome's place: the heading over the sheet's left edge, Close over its right.
   Sticky insets are measured inside the overlay's padding, hence the negative top. */
.overlay .letter-head{position:sticky;z-index:1;top:calc(-1 * var(--letter-top));align-self:stretch;
  display:flex;align-items:center;justify-content:space-between;gap:var(--sp-3);min-height:var(--letter-top);
  margin:calc(-1 * var(--letter-top)) calc(-1 * (var(--gutter) + env(safe-area-inset-right))) calc(-1 * var(--sp-2)) calc(-1 * (var(--gutter) + env(safe-area-inset-left)));
  padding:env(safe-area-inset-top) max(calc(var(--gutter) + env(safe-area-inset-right)), var(--letter-edge)) 0 max(calc(var(--gutter) + env(safe-area-inset-left)), var(--letter-edge));
  background:var(--c-midnight)}
.overlay .letter-head .label{min-width:0;overflow-wrap:anywhere}
.overlay .letter-head .ghost{flex:none;margin-right:calc(-1 * var(--sp-3))}

/* one long sheet of the same card stock, in his hand */
.overlay .letter-sheet{width:var(--letter-w);padding:var(--letter-pad);border-radius:var(--r-card);background:var(--letter-paper);box-shadow:var(--sh-card);
  color:var(--c-ink);font:700 var(--step-2)/var(--lh-snug) var(--font-hand);font-variation-settings:var(--hand-axes);text-align:start;overflow-wrap:anywhere}
/* one of his lines that wraps hangs, so his own line breaks stay readable (the PNG does the same) */
.overlay .letter-stanza p{text-wrap:pretty;padding-inline-start:.8em;text-indent:-.8em}
.overlay .letter-stanza + .letter-stanza{margin-top:var(--letter-gap)}
.overlay .letter-stanza--last{font-size:var(--step-3)}
.overlay .letter-signoff{margin-top:var(--letter-gap)}
.overlay .letter-stamp{margin-top:var(--sp-5);font:italic 400 var(--step--1)/var(--lh-body) var(--font-script);font-variation-settings:normal}

/* after a save on iOS and in in-app browsers: the PNG, to press and hold */
.overlay .letter-image{width:var(--letter-w);height:auto;border-radius:var(--r-card);box-shadow:var(--sh-card);-webkit-touch-callout:default}

.overlay .letter-foot{display:flex;flex-direction:column;align-items:center;gap:var(--sp-3);max-width:var(--measure);text-align:center}
.overlay .letter-foot .note{text-wrap:balance}

@media (forced-colors:active){ .overlay .letter-sheet{forced-color-adjust:none} }
