/* MT-189: every portrait rule of the app (PosterScroller) is here and nowhere else; tests/portrait.test.js is the guard.
   Every screen has its upright layout below (MT-195), so the app never asks for the phone to be turned. */

/* MT-191: the Info deck's own parts are shown only upright; sideways Info keeps its tab strip. MT-195: so is Help's
   upright map. MT-438: so are the Screen player's clip info (MT-411) and its eye button. */
.deck-head, .map-upright { display: none; }
.clip-info, .clip-info-btn { display: none; }
/* The deck stepping forward one card: the next card, and the edges behind it, move into the place of the one in front. */
@keyframes deck-step {
  0%, 30% { transform: translate(6px, -6px); }
  70%, 100% { transform: none; }
}
/* The front card going round to the back: peeled off up-right over the deck, then, once off the screen, slipped in
   behind it from there to the last edge's place. Played backwards it is the back card coming round to the front. */
@keyframes deck-round {
  0% { transform: none; z-index: 3; }
  40% { transform: translate(140%, -40%) rotate(8deg); z-index: 3; }
  45% { transform: translate(140%, -40%) rotate(8deg); z-index: 0; }
  100% { transform: translate(30px, -30px); z-index: 0; }
}
@keyframes deck-rise {
  from { transform: translateY(100%); clip-path: inset(0 0 100% 0); }
  to { transform: none; clip-path: inset(0); }
}

@media (orientation: portrait) and (max-width: 900px) {

  /* MT-190: the main screen upright. The header wraps rather than running past the width, Subscribed / Show all on a
     line of its own; Movies sits above Series; the lists grid takes as many tiles across as fit. */
  .main-head { flex-wrap: wrap; row-gap: 8px; }
  .main-head h1 { min-width: 0; overflow-wrap: anywhere; }
  #main:not([data-pick]) #main-title, #main[data-pick=""] #main-title { font-size: 16px; letter-spacing: .04em; }
  .tab-pick { gap: 8px; }
  .tab-pick button { letter-spacing: 0; }
  .tab-pick [aria-pressed="true"] { font-size: 13px; }
  .tab-pick [aria-pressed="false"] { font-size: 11px; }
  #main[data-pick=""] .main-head { flex-wrap: nowrap; gap: 8px; }
  #main[data-pick=""] #main-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #main[data-pick=""] #unseen-only { display: none; }
  .list-view:not([hidden]) { order: 1; }
  #unseen-only { order: 2; margin-left: auto; }
  #main:not([data-pick=""]) .install { order: 3; }
  .halves { flex-direction: column; }
  .lists { grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); }
  .list { padding: 10px 8px; height: clamp(112px, 22vh, 180px); }

  /* MT-191: Info is a deck of framed cards. The front card is the selected tab, the poster on Details; the other four
     tabs show only as edges stepped up and right behind it, the pile's shadows. The page keeps clear of the heart and ×
     above. Each card's head is its way through the deck: ◀ and ▶ either side of its title, a dot per card under it. */
  .details {
    --deck-t: calc(102px + var(--safe-t)); --deck-r: calc(44px + var(--safe-r)); --deck-b: calc(16px + var(--safe-b)); --deck-l: calc(14px + var(--safe-l));
    align-items: stretch; padding: var(--deck-t) var(--deck-r) var(--deck-b) var(--deck-l);
  }
  .details-panel {
    z-index: 2; flex-direction: column; gap: 10px; padding: 12px 14px;
    border: 2px solid rgba(255,255,255,.85); border-radius: 16px; background: #121218;
  }
  /* The poster's card is framed half as thick again in the wordmark's blue, in front, going round and as an edge in the
     pile (`data-poster`, details.js: which edge it is), so it can be followed through the deck. */
  .details { --poster-edge: #0090ff; }
  .details-panel[data-tab="info"] { border: 3px solid var(--poster-edge); }
  .details[data-poster="1"] { --w1: 1px; --c1: var(--poster-edge); }
  .details[data-poster="2"] { --w2: 1px; --c2: var(--poster-edge); }
  .details[data-poster="3"] { --w3: 1px; --c3: var(--poster-edge); }
  .details[data-poster="4"] { --w4: 1px; --c4: var(--poster-edge); }
  .details[data-poster="5"] { --w5: 1px; --c5: var(--poster-edge); }
  .details::before {
    content: ""; position: absolute; inset: var(--deck-t) var(--deck-r) var(--deck-b) var(--deck-l); z-index: 1; border-radius: 16px; pointer-events: none;
    box-shadow:
      6px -6px 0 -2px #121218, 6px -6px 0 var(--w1, 0) var(--c1, rgba(255,255,255,.6)),
      12px -12px 0 -2px #121218, 12px -12px 0 var(--w2, 0) var(--c2, rgba(255,255,255,.45)),
      18px -18px 0 -2px #121218, 18px -18px 0 var(--w3, 0) var(--c3, rgba(255,255,255,.3)),
      24px -24px 0 -2px #121218, 24px -24px 0 var(--w4, 0) var(--c4, rgba(255,255,255,.18)),
      30px -30px 0 -2px #121218, 30px -30px 0 var(--w5, 0) var(--c5, rgba(255,255,255,.1));
  }
  .deck-head {
    display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; gap: 6px; position: relative; z-index: 1; flex: none;
    padding: 4px; border: 1px solid rgba(255,255,255,.16); border-radius: 12px; background: rgba(255,255,255,.06);
  }
  .deck-btn { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 9px; background: rgba(255,255,255,.1); }
  .deck-btn:active { background: rgba(255,255,255,.24); }
  .deck-btn svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
  .deck-name { display: grid; justify-items: center; gap: 6px; min-width: 0; }
  .deck-title { display: block; max-width: 100%; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
  .deck-dots { display: flex; gap: 5px; }
  .deck-dots i { width: 6px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.3); }
  .deck-dots .on { width: 14px; background: var(--accent); }
  .details-poster { height: 34%; align-self: center; }
  .details-panel[data-tab]:not([data-tab="info"]) .details-poster { display: none; }
  .details-body { position: relative; padding-right: 0; }
  .details-body > .tabs { display: none; }
  .links { min-height: 100%; }

  /* A turn (details.js). ▶: the pile and the new front card step forward while the copy of the old one goes round to
     the back; ◀ plays it backwards. During it the pile draws three edges, the fourth being the card going round. */
  .deck-copy { position: absolute; margin: 0; pointer-events: none; }
  .turn-ahead::before, .turn-back::before {
    box-shadow:
      6px -6px 0 -2px #121218, 6px -6px 0 var(--w1, 0) var(--c1, rgba(255,255,255,.6)),
      12px -12px 0 -2px #121218, 12px -12px 0 var(--w2, 0) var(--c2, rgba(255,255,255,.45)),
      18px -18px 0 -2px #121218, 18px -18px 0 var(--w3, 0) var(--c3, rgba(255,255,255,.3));
  }
  .turn-ahead::before, .turn-ahead > .details-panel { animation: deck-step .8s ease-in-out both; }
  .turn-ahead > .deck-copy { animation: deck-round .8s ease-in-out both; }
  .turn-back::before, .turn-back > .deck-copy { animation: deck-step .8s ease-in-out reverse both; }
  .turn-back > .details-panel:not(.deck-copy) { animation: deck-round .8s ease-in-out reverse both; }

  /* MT-194: Mini and Trailer upright. The video plays in a 16:9 band across the width, centred, the film's poster
     dimmed behind it; the timeline and the film's name sit under the band, and the up/down slide-in and the poster
     panel within it. Turning the phone hands over to the landscape rules with the same video playing on. */
  #player { --band: calc((100vw - 2 * var(--pad)) * 9 / 16); }
  .player-bg {
    display: block; position: absolute; inset: -40px; pointer-events: none; will-change: transform;
    background: var(--poster) center / cover no-repeat; filter: blur(18px) brightness(.35) saturate(1.2);
  }
  #player[data-view="info"] .player-bg { display: none; }
  #player.scrolling .stage { overflow: visible; z-index: 1; }
  #player.scrolling .peek { top: 0; height: 100%; }
  #player.scrolling .mini-frame { visibility: hidden; }
  #player.scrolling .peek[data-state="under"] { z-index: 0; }
  #player.scrolling .peek[data-state="under"] .peek-poster, #player.scrolling .peek[data-state="under"] .peek-text { display: none; }
  .stage { top: calc(50% - var(--band) / 2); bottom: auto; height: var(--band); overflow: hidden; }
  .mini-frame { box-sizing: border-box; top: calc(50% - var(--band) / 2 - var(--pad) + var(--frame)); bottom: auto; height: calc(var(--band) + 2 * (var(--pad) - var(--frame))); }
  .timeline { bottom: auto; top: calc(50% + var(--band) / 2 + var(--pad) - var(--frame) + 6px); }
  .caption { bottom: auto; top: calc(50% + var(--band) / 2 + var(--pad) - var(--frame) + 46px); flex-direction: column; }
  .clip-above { top: auto; bottom: calc(50% + var(--band) / 2 + var(--pad) - var(--frame) + 8px); left: calc(var(--pad) + var(--safe-l)); right: calc(var(--pad) + var(--safe-r)); }
  .clip-info { display: block; }
  .clip-info-btn { display: grid; }
  .unavailable-box { width: min(400px, 100%); }
  .unavailable img { filter: brightness(.85); }
  .peek { top: calc(50% - var(--band) / 2); bottom: auto; height: var(--band); }
  .paused svg { width: 18vw; height: 18vw; padding: 4vw; }

  /* MT-195: the remaining screens upright. About puts its text over the mini; How to use it shows the upright map, its
     gestures under it; the help pages' nav puts its box over Back, Skip and the way on; the quiz stacks the poster over its answers; each scrolls down when it
     runs past the screen and never sideways. The sheets, the dial, the intro and My viewing already fit a narrow screen. */
  #about, #help, #help-dial, #quiz { overflow-x: hidden; overflow-y: auto; justify-content: flex-start; }
  #quiz { align-items: flex-start; }
  .about-panel { flex-direction: column; align-items: stretch; gap: 2vh; }
  .about-text h1 { overflow-wrap: anywhere; }
  .about-mini video { max-height: 32vh; }
  .help-panel { height: auto; justify-content: flex-start; }
  .help-body { flex-direction: column; align-items: stretch; gap: 2vh; }
  .map { display: none; }
  .map-upright { display: block; width: 100%; height: auto; max-height: 50vh; }
  .map-upright text { font-size: 15px; fill: var(--muted); text-anchor: middle; }
  .upright-heads text { font-size: 13px; font-weight: 800; fill: var(--text); }
  .upright-says text { fill: var(--accent); font-weight: 800; font-size: 14px; }
  .upright-deck rect { fill: #121218; stroke: rgba(255,255,255,.35); stroke-width: 1.5; }
  .upright-deck .upright-card { stroke: #fff; stroke-width: 2; }
  .upright-buttons circle { fill: #121218; stroke: #fff; stroke-width: 1.5; }
  .upright-buttons path { fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .help-side { display: contents; }
  #help .help-title { order: -1; }
  .help-more { width: 100%; }
  .help-dial-body { align-items: center; }
  .help-dial-show { width: min(70vw, 34vh); }
  .help-dial-text { flex: none; width: 100%; }
  #about, #help, #help-dial { padding-bottom: calc(112px + var(--safe-b)); }
  .help-nav { grid-template-columns: auto 1fr; grid-template-areas: "box box" "left on"; row-gap: 8px; }
  .skip-help { justify-self: center; }
  .help-on { min-width: 0; padding: 0 18px; }
  .quiz-panel { height: auto; min-height: 100%; }
  .quiz-body { flex-direction: column; align-items: stretch; }
  .quiz-card { height: 36vh; align-self: center; }
  #intro-offer .report-actions { flex-direction: column-reverse; align-items: stretch; }

  /* MT-193: the Details card is the poster, filling the frame, with Details over its lower part (Craig's pick on MT-192).
     `rising` (details.js) opens it: the poster alone for a second, then Details rises smoothly all the way in one run.
     Only the part above the card's foot is shown, so it never runs past the frame. */
  .details-panel[data-tab="info"] .details-poster { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 14px; box-shadow: none; }
  .details-panel[data-tab="info"] .deck-head { background: rgba(18,18,24,.72); }  .details-panel[data-tab="info"] .details-franchise-badge { top: 72px; left: 14px; }
  .details-panel[data-tab="info"] .details-body {
    flex: 0 1 auto; margin-top: auto; max-height: 58%; padding: 28px 10px 6px; border-radius: 0 0 14px 14px;
    background: linear-gradient(rgba(18,18,24,0), rgba(18,18,24,.94) 24px);
  }
  .details-panel[data-tab="info"] .details-body.rising { animation: deck-rise 1.8s ease-in-out 1s both; }
}
