/* ============================================================
   Maestro on the iPhone Duo (Ali, 2026-10-25: "optimize everything for
   the iPhone Duo, folded or unfolded, landscape or portrait").

   Everything Maestro does differently for compact or wide-short screens
   lives in this one file, loaded after style.css so a tie goes to the
   rule here. It is the method the staff app settled on in
   src/styles/duo.css: shape, input and installed display mode, never the
   user agent. tests/duo-css.test.mjs evaluates every query here against
   the measured Duo matrix and against ordinary phones, tablets and
   desktop windows.

   Jarvis's Safari 27.1 measurements, 2026-10-25 (available CSS px; the
   first height is with Safari's bars showing, the second with them
   collapsed). They replaced the 3x estimates this file was first built
   on, which were all wrong:

     outer, closed, upright     382 x 580 or 618   OUTER PORTRAIT
     outer, closed, on its side 594 x 368 or 406   OUTER LANDSCAPE
     inner, open, upright       669 x 867 or 902   INNER PORTRAIT
     inner, open, on its side   951 x 585 or 620   INNER LANDSCAPE
     one pane of split view     385 x 571 or 609   SPLIT-VIEW PANE

   What each shape gets, decided with the staff app on 2026-10-25:
     outer portrait and a split-view pane: a short, narrow phone. A web
       app cannot tell them from any other short phone, so the compact
       rule below helps every short narrow phone instead of guessing.
     outer landscape: the normal phone layout from style.css, inside a
       screen-height scrolling region. Nothing is squeezed below the 44 px
       tap floor to force the whole game into a short viewport.
     inner portrait: the normal phone layout from style.css, nothing here.
       The old estimated rules for it (605 to 655 px wide upright) never
       matched the real screen and are gone.
     inner landscape: wide but short on a touch-first device, the shape
       and input rule below, which the real 951 x 585 and 951 x 620 both
       fall inside. A fine-pointer desktop window at the same dimensions
       keeps the ordinary desktop layout.
   ============================================================ */

/* ---------- short, narrow phone: the outer screen upright, a split-view pane ---------- */
/* Ali, 2026-10-25: all four answers on screen without a scroll. The
   outer screen gives a question 580 px in Safari with its bars showing,
   and a split-view pane 571. Counted from style.css at 580: wrap top
   padding 10, hud 44 plus 4, the disc area (80 px record, 6 and 11 for
   the timer, 4 and 48 for Hear it again, 4 and 4 around it), "Worth 40
   points" 17, the prompt 27 with 4 and 6 around it, four 56 px answers
   with 5 px between and around them 249: about 560 of 580, so a few px
   to spare in a 571 pane and in the 618 and 609 viewports once the bars
   collapse. Any other phone this short and narrow (an SE or 8 in Safari,
   a 360 x 640 Android) gets the same help on purpose; it needed it too. */
@media (max-width: 430px) and (max-height: 640px) and (orientation: portrait) {
  .wrap{ padding-top:calc(env(safe-area-inset-top) + 10px); }
  .hud{ margin-bottom:4px; }
  .disc{ width:80px; height:80px; }
  .disc-area{ margin:4px 0 4px; }
  .timerbar{ margin-top:6px; }
  .replay{ margin-top:4px; }
  .onoffer{ margin-top:0; }
  .qprompt{ margin:4px 0 6px; }
  .ans{ margin:5px 0; }
}

/* ---------- short landscape phone: scroll instead of shrinking controls ---------- */
/* The outer screen is only 368 or 406 px tall on its side. Ordinary iPhones
   and Android phones can be just as short. Give the active screen its own
   viewport-height scrolling region, while leaving every control at its full
   size. showScreen() resets this region whenever navigation changes screens. */
@media (max-height: 500px) and (orientation: landscape) {
  .screen.show{
    height:100dvh;
    overflow-y:auto;
    overscroll-behavior-y:contain;
    -webkit-overflow-scrolling:touch;
  }
}

/* ---------- installed Duo side column ---------- */
/* A Live Activity can extend the system status cluster roughly 260 px down
   the top-right edge. A fixed corner box is therefore unsafe. The explicit
   Duo launch identity reserves the entire right column on every supplied
   outer and inner shape. Maestro has no navigation bar to put there, so the
   column stays empty. Browser tabs and ordinary installed phones never get
   both classes and keep their existing full width. */
@media (min-width: 382px) and (max-width: 478px) and (min-height: 650px) and (max-height: 900px) and (orientation: portrait),
       (min-width: 650px) and (max-width: 900px) and (min-height: 350px) and (max-height: 500px) and (orientation: landscape),
       (min-width: 820px) and (max-width: 1000px) and (min-height: 500px) and (max-height: 700px) and (min-aspect-ratio: 4/3) and (max-aspect-ratio: 7/4),
       (min-width: 650px) and (max-width: 700px) and (min-height: 900px) and (max-height: 980px) and (orientation: portrait) {
  html.is-standalone.is-duo{
    --duo-safe-right:env(safe-area-inset-right, 0px);
    --duo-side-rail:max(80px, var(--duo-safe-right));
  }
  html.is-standalone.is-duo body{ padding-right:var(--duo-side-rail); }
  /* The reported right safe inset is the status column itself. The body has
     already reserved max(80px, inset), so adding the inset to .wrap would
     create a second empty column. Keep only Maestro's ordinary content pad. */
  html.is-standalone.is-duo .wrap{ padding-right:var(--pad); }
  html.is-standalone.is-duo :is(.nowplaying, .voice-recovery, #asksheet){ right:var(--duo-side-rail); }
  html.is-standalone.is-duo .nowplaying{ padding-right:14px; }
  html.is-standalone.is-duo .voice-recovery{ padding-right:20px; }
  html.is-standalone.is-duo #toast{
    left:calc((100vw - var(--duo-side-rail)) / 2);
    max-width:calc(100vw - var(--duo-side-rail) - 24px);
  }
}

/* Outer upright keeps the approved smaller disc and tight vertical rhythm.
   Piece titles can wrap to three lines in the narrow content column. Keep the
   complete title readable while all four choices retain their 56 px target. */
@media (min-width: 382px) and (max-width: 478px) and (min-height: 650px) and (max-height: 900px) and (orientation: portrait) {
  html.is-standalone.is-duo .wrap{ padding-top:calc(env(safe-area-inset-top) + 10px); }
  html.is-standalone.is-duo .hud{ margin-bottom:4px; }
  html.is-standalone.is-duo #s-play .disc{ width:80px; height:80px; }
  html.is-standalone.is-duo .disc-area{ margin:4px 0; }
  html.is-standalone.is-duo .timerbar{ margin-top:6px; }
  html.is-standalone.is-duo .replay{ margin-top:4px; }
  html.is-standalone.is-duo .buzzrow:empty{ display:none; }
  html.is-standalone.is-duo .onoffer{ margin-top:0; }
  html.is-standalone.is-duo .qprompt{ margin:4px 0 6px; }
  html.is-standalone.is-duo .ans{ margin:5px 0; }
  html.is-standalone.is-duo body:not(.hands-free) #s-play .ans{
    min-height:var(--tap);
    padding:4px 10px;
    font-size:16px;
    line-height:1.15;
  }
}

/* An installed Duo keeps the same inner layout if a paired pointer changes
   pointer/hover media features. Without reported viewport segments, the 12 px
   answer gutter is centered on the physical midpoint: the left page owns the
   first 50vw and the right page gives the reserved system column back. */
@media (min-width: 820px) and (max-width: 1000px) and (min-height: 500px) and (max-height: 700px) and (min-aspect-ratio: 4/3) and (max-aspect-ratio: 7/4) {
  html.is-standalone.is-duo .play-wrap{ max-width:none; }
  html.is-standalone.is-duo #s-play2 .wrap{ max-width:none; }
  html.is-standalone.is-duo .buzzrow:empty{ display:none; }
  html.is-standalone.is-duo .answers{
    display:grid;
    grid-template-columns:
      calc(50vw - env(safe-area-inset-left) - var(--pad) - 6px)
      calc(50vw - var(--duo-side-rail) - var(--pad) - 6px);
    column-gap:12px;
  }
  html.is-standalone.is-duo .answers .ans{ margin:0; }
  html.is-standalone.is-duo #s-home .wrap{
    min-height:100dvh;
    display:flex;
    flex-direction:column;
    justify-content:center;
    max-width:680px;
  }
  html.is-standalone.is-duo #s-home .home-foot{ flex-wrap:nowrap; }
}

/* ---------- wide, short screen: the inner screen on its side ---------- */
/* 820 to 1000 px wide, 500 to 700 px tall, between 4:3 and 7:4, with a
   coarse pointer and no hover. An iPhone on its side is under 500 px tall,
   an iPad on its side at least 744 px tall, and a 13" iPad Split View pane
   at most 678 px wide. A desktop window dragged to the same dimensions
   keeps the ordinary desktop layout because its pointer is fine and it can
   hover. */
@media (min-width: 820px) and (max-width: 1000px) and (min-height: 500px) and (max-height: 700px) and (min-aspect-ratio: 4/3) and (max-aspect-ratio: 7/4) and (pointer: coarse) and (hover: none) {
  /* The 900 px rule from style.css, which the real 951 px screen does
     reach, but the card width there is sized for an iPad: 820 px keeps
     the question in the middle. The answers pair up so no button spans
     the screen. Measured in the browser at 951 x 585 (2026-10-26): the
     card's top padding is 18, hud 44 plus 6, the disc area with the 160
     px record 281 plus 6 and 14, "Worth 40 points" 20 plus 4, the prompt
     30 plus 4 and 14, two rows of answers 124. That came to 585.7, so the
     bottom row lost its last pixel on the 585 px screen, because the
     empty two-player buzz row between the record and the question still
     spent its 20 px of margin. An empty row takes no room now, and the
     answers end at about 562 of 585. A buzz race fills the row, and then
     it shows as before. */
  .wrap{ max-width:820px; }
  .buzzrow:empty{ display:none; }
  .answers{ display:grid; grid-template-columns:1fr 1fr; gap:12px; }
  .answers .ans{ margin:0; }

  /* The 900 x 640 rule's centered Home, which 585 and 620 px of height
     both miss. The 76 px title is left out: with it, Home would not fit
     in 585 px. */
  #s-home .wrap{ min-height:100dvh; display:flex; flex-direction:column; justify-content:center; max-width:680px; }
  #s-home .home-foot{ flex-wrap:nowrap; }
}

/* ---------- the fold itself ---------- */
/* Only where the browser reports the fold (the Viewport Segments API:
   Chrome and Edge 138 and later; Safari on the Duo has it behind a flag
   at most, so on a Duo today this block usually does nothing and the
   paired answers above, which already split in the middle, are what keeps
   a button off the hinge). Here the two answer columns are the two
   screens exactly, and the gap between them is the hinge. */
@media (min-width: 820px) and (max-width: 1000px) and (min-height: 500px) and (max-height: 700px) and (min-aspect-ratio: 4/3) and (max-aspect-ratio: 7/4) and (pointer: coarse) and (hover: none) and (horizontal-viewport-segments: 2) {
  /* Player Two's answers sit in #s-play2 .wrap, which the wide rule above
     caps at 820 px. Two segment-wide columns need the full width
     (review 2026-10-27). */
  .play-wrap, #s-play2 .wrap{ max-width:none; }
  .answers{
    grid-template-columns:
      calc(env(viewport-segment-width 0 0) - env(safe-area-inset-left) - var(--pad))
      calc(env(viewport-segment-width 1 0) - env(safe-area-inset-right) - var(--pad));
    column-gap:calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
  }
  html.is-standalone.is-duo .answers{
    grid-template-columns:
      calc(env(viewport-segment-width 0 0) - env(safe-area-inset-left) - var(--pad))
      calc(env(viewport-segment-width 1 0) - var(--pad) - var(--duo-side-rail));
  }
}

/* Keep the real segment geometry when it is exposed, even while a paired
   pointer is primary. These selectors stay behind explicit installed-Duo
   identity, so an ordinary 951 x 585 desktop remains unchanged. */
@media (min-width: 820px) and (max-width: 1000px) and (min-height: 500px) and (max-height: 700px) and (min-aspect-ratio: 4/3) and (max-aspect-ratio: 7/4) and (horizontal-viewport-segments: 2) {
  html.is-standalone.is-duo .play-wrap{ max-width:none; }
  html.is-standalone.is-duo .answers{
    grid-template-columns:
      calc(env(viewport-segment-width 0 0) - env(safe-area-inset-left) - var(--pad))
      calc(env(viewport-segment-width 1 0) - var(--pad) - var(--duo-side-rail));
    column-gap:calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
  }
}
