/* GT exam — phone layout fix (v=mob1)
   ---------------------------------------------------------------------------
   Why this file exists.

   gtc-tcs.css loads AFTER mv-gt-exam.css and its rule
       #exam .palette { position:fixed; top:0; right:-300px; bottom:0; width:290px }
   outranks mv-gt-exam's `.mid > .palette` bottom-sheet rule on specificity
   (1,1,0 vs 0,2,0). The computed style on a phone was therefore a mix:

       position:fixed  top:0  bottom:0  right:-300px  transform:translateY(540px)

   top:0 + translateY(540) pinned a 540px panel into the MIDDLE of an 844px
   screen, so the palette legend and question grid covered the question and
   could not be dismissed. The palette must be a bottom sheet on phones.

   This file wins by specificity (#exam is kept) and by load order (loaded
   last), so it does not need !important on layout - only where the vendor
   rule would otherwise win.

   Desktop is untouched: every rule here is inside max-width:900px.
   The frozen GT visual design is respected - this file sets NO colour, font
   or shadow, only geometry.
   --------------------------------------------------------------------------- */

@media (max-width: 900px) {

  /* --- the palette becomes a true bottom sheet ---------------------------- */
  #exam .mid > .palette,
  #exam .palette {
    /* kill the desktop right-rail geometry completely */
    top: auto !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 0 !important;

    width: auto !important;
    max-width: none !important;
    flex: 0 0 auto !important;

    /* sheet height is bounded by the viewport, never by content */
    height: auto;
    max-height: min(64dvh, 560px) !important;
    min-height: 0;

    border-left: 0;
    border-top: 1px solid #e0e0e0;   /* edges only - this is not a colour change */
    box-shadow: 0 -6px 22px rgba(12, 18, 28, .18);

    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* above the scrim (59) so the open sheet is never dimmed over */
    z-index: 60 !important;

    /* closed: pushed fully below the viewport bottom */
    transform: translateY(100%);
    transition: transform .24s cubic-bezier(.23, 1, .32, 1);
    will-change: transform;
  }

  /* open: sits flush on the bottom edge */
  #exam .mid > .palette.open,
  #exam .palette.open {
    transform: translateY(0);
  }

  /* the sheet's inner scrollers must not grow it past max-height */
  #exam .palette > * { min-height: 0 }
  #exam .palette [id="palGrid"],
  #exam .palette .pal-grid,
  #exam .palette .pal-legend {
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  #exam .palette .pal-grid {
    flex: 1 1 auto;
    max-height: none;
  }

  /* a closed sheet must never intercept taps meant for the question */
  #exam .palette:not(.open) { pointer-events: none; }

  /* --- scrim over the question, below the sheet -------------------------- */
  #palScrim {
    position: fixed !important;
    inset: 0 !important;
    z-index: 59 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    background: rgba(12, 18, 28, .38);
  }
  #palScrim.show {
    opacity: 1;
    pointer-events: auto;
  }
  #palScrim[hidden],
  #palScrim.hide { display: none !important }

  /* --- the floating "Q Index" button sits above the sheet ----------------- */
  /* gtc-tcs.css hides the floating pill because on desktop the palette rail is
     always visible. On a phone the rail IS the bottom sheet, so the pill is the
     only way to open it - reveal it here, and only here.
     #exam .qf-pal (1,1,0) is what hides it, so match that specificity. */
  #exam .qf-pal {
    display: block !important;
    position: fixed;
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    z-index: 61;
    margin: 0;
    padding: 0;
  }
  #exam .qf-pal #palFab {
    display: flex !important;
    align-items: center;
    gap: 7px;
    min-height: 44px;                  /* comfortable tap target */
    padding: 0 16px;
  }
  /* never let the pill float over an open sheet.
     togglePalette() puts `pal-open` on <body>, so that is the hook.
     This must out-specify the reveal rule above (#exam .qf-pal), hence body. */
  body.pal-open #exam .qf-pal,
  body.pal-open .qf-pal { display: none !important }

  /* --- question pane: the page scrolls, not a trapped sub-pane ------------ */
  #exam {
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
  }
  #exam > .mid { overflow: visible }
  #exam .mid > .qwrap { border-right: 0 }
  #exam .mid > .qwrap .qbody {
    overflow-y: visible;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* --- phone chrome: keep the question readable, not cramped -------------- */
  #exam .qbody {
    /* 16px stops iOS from zooming the page when an input is focused */
    font-size: 16px;
    line-height: 1.6;
    padding-left: 14px;
    padding-right: 14px;
  }
  #exam .qbody img {
    max-width: 100%;
    height: auto;
  }

  /* options become full-width tap targets, min 44px per Apple HIG */
  #exam .opt,
  #exam .option,
  #exam .opt-row {
    min-height: 44px;
    padding: 10px 12px;
    touch-action: manipulation;
  }

  /* topbar / titlebar: shrink, but stay readable and clear of the notch */
  #exam > .topbar,
  #exam > .titlebar {
    padding-top: calc(6px + env(safe-area-inset-top, 0px));
    padding-bottom: 6px;
  }

  /* the bottom strip of the sheet must clear the home indicator */
  #exam .palette { padding-bottom: env(safe-area-inset-bottom, 0px) }

  /* native-feeling touch behaviour on the controls we own */
  #exam button,
  #exam [role="button"],
  #palFab {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
  }
}

/* very short landscape phones: give the question more room */
@media (max-width: 900px) and (max-height: 430px) {
  #exam .mid > .palette,
  #exam .palette { max-height: 80dvh !important }
  #exam > .topbar,
  #exam > .titlebar { padding-top: 4px; padding-bottom: 4px }
}
