/* B98: compact result and studio for a phone held horizontally. R70 still
   owns the actions and commentary; desktop keeps its existing result layout. */
#r70-result-screen .b98-result-tabs { display: none; }
@media (orientation: landscape) and (pointer: coarse) and (hover: none) and (max-width: 1150px) and (max-height: 650px) {
  html[data-sejm-interface] body #r70-result-screen.r70-result-stage {
    display: grid !important;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    max-height: 100dvh;
    overflow: hidden !important;
    grid-template-columns: clamp(84px, 14vw, 132px) minmax(0, 1fr) minmax(220px, 32%);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 6px clamp(10px, 1.6vw, 18px);
    padding: max(8px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)) !important;
  }
  /* Native result actions hide the panel before changing scenes. An !important
     grid on the same panel must never paint it after the hidden flag is set. */
  html[data-sejm-interface] body #r70-result-screen.r70-result-stage[hidden] {
    display: none !important;
  }
  #r70-result-screen .r70-result-intro {
    grid-column: 1 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 12px;
    align-items: end;
    align-self: start;
    min-width: 0;
    padding: 0 0 6px;
  }
  #r70-result-screen .r70-result-intro .r70-eyebrow { grid-column: 1; grid-row: 1; margin: 0; font-size: 10px; }
  html[data-sejm-interface] body #r70-result-screen .r70-result-intro h1 {
    grid-column: 1; grid-row: 2; min-width: 0;
    margin: 0 !important; font-size: clamp(22px, 3.5vh, 31px) !important;
    line-height: 1.08 !important; overflow-wrap: anywhere;
  }
  #r70-result-screen .r70-result-matchup { grid-column: 2; grid-row: 1; min-width: 0; margin: 0; font-size: 12px; line-height: 1.3; }
  #r70-result-screen .r70-result-rules { grid-column: 2; grid-row: 2; min-width: 0; margin: 0; font-size: 11px; line-height: 1.25; }
  #r70-result-screen .r70-result-center {
    grid-column: 1; grid-row: 2; align-self: start;
    justify-content: flex-start; align-items: center;
    min-height: 0; min-width: 0; max-height: 100%;
    overflow: hidden; gap: 2px;
  }
  html[data-sejm-interface] body #r70-result-screen .r70-result-portrait {
    width: 100%; height: clamp(62px, 20vh, 118px) !important;
    min-height: 0; max-height: 100%; flex: 0 1 auto;
    object-fit: contain; object-position: center bottom;
  }
  #r70-result-screen .r70-result-score { font-size: clamp(12px, 1.65vw, 17px); text-align: center; overflow-wrap: anywhere; }
  #r70-result-screen .r70-result-detail { margin: 2px 0 0; font-size: 11px; line-height: 1.3; text-align: center; }
  #r70-result-screen .r70-result-advice {
    grid-column: 2; grid-row: 2; align-self: stretch;
    min-height: 0; min-width: 0; max-height: 100%;
    margin: 0; padding: 0 8px 0 12px;
    border-left-width: 1px; overflow-y: auto;
    overscroll-behavior: contain; touch-action: pan-y;
    scrollbar-width: thin; scrollbar-color: #8e7444 transparent;
  }
  html[data-sejm-interface] body #r70-result-screen .r70-result-advice h2 {
    margin: 1px 0 3px; font-size: clamp(16px, 2.1vw, 22px) !important;
  }
  #r70-result-screen .r70-result-advice > p { margin: 3px 0 6px; font-size: max(14px, calc(12px * var(--sk-r45-text-scale, 1.25))); line-height: 1.38; }
  #r70-result-screen .r70-result-advice > .r70-eyebrow { font-size: 10px; }
  #r70-result-screen .r70-result-commentary {
    display: grid; grid-template-columns: clamp(52px, 20%, 80px) minmax(0, 1fr);
    gap: 3px 9px; margin: 8px 0 0; padding: 7px 0 0;
  }
  #r70-result-screen .r73-studio-caption { grid-column: 2; grid-row: 1; gap: 1px; min-width: 0; }
  #r70-result-screen .r73-studio-label { font-size: 10px; }
  #r70-result-screen .r73-studio-speaker { font-size: clamp(14px, 1.9vw, 18px); line-height: 1.18; }
  #r70-result-screen .r73-studio-portrait {
    grid-column: 1; grid-row: 1 / span 3; align-self: start;
    width: 100%; max-height: 78px; object-fit: contain;
  }
  html[data-sejm-interface] body #r70-result-screen .r70-result-commentary blockquote {
    grid-column: 2; grid-row: 2; margin: 0;
    font-size: max(15px, calc(13px * var(--sk-r45-text-scale, 1.25))) !important;
    line-height: 1.38 !important;
  }
  #r70-result-screen .r70-result-commentary button { grid-column: 2; grid-row: 3; min-height: 44px !important; }
  #r70-result-screen .r73-studio-no-art .r73-studio-caption,
  #r70-result-screen .r73-studio-no-art blockquote,
  #r70-result-screen .r73-studio-no-art button { grid-column: 1 / -1; }
  #r70-result-screen .r70-result-actions,
  #r70-result-screen.r75-result-has-story .r70-result-actions {
    grid-column: 3; grid-row: 2; align-self: start;
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start; gap: 6px; min-height: 0;
    max-height: 100%; margin: 0; overflow-y: auto;
    overscroll-behavior: contain; scrollbar-width: thin;
  }
  html[data-sejm-interface] body #r70-result-screen .r70-result-actions button,
  #r70-result-screen .b98-share-result-action > button {
    width: 100%; min-width: 0; min-height: 44px !important;
    padding: 7px 8px !important; text-align: center;
    font-size: 13px !important; line-height: 1.18;
    white-space: normal; overflow-wrap: anywhere;
  }
  #r70-result-screen .r70-result-actions .r70-primary { padding-left: 8px; }
  #r70-result-screen .r70-result-actions .r70-primary::after { display: none; }
  #r70-result-screen .b98-share-result-action { grid-column: 1 / -1; padding-top: 4px; }
  /* Quick-result continuation remains directly under the main content; its
     two possible offers use one short row without pushing actions below view. */
  #r70-result-screen .b98-next-match {
    grid-column: 1 / 3; grid-row: 3;
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(125px, 30%);
    gap: 2px 8px; align-self: stretch;
    max-width: none; max-height: min(28vh, 104px);
    min-height: 0; margin: 0; padding: 5px 0 0;
    overflow-y: auto; overscroll-behavior: contain;
  }
  #r70-result-screen .b98-next-match .b98-next-eyebrow { grid-column: 1 / -1; margin: 0; font-size: 10px; }
  #r70-result-screen .b98-next-row { grid-column: 1; grid-row: 2 / span 2; gap: 6px; }
  #r70-result-screen .b98-next-row img { width: 42px; height: 50px; }
  #r70-result-screen .b98-next-content h2 { font-size: 16px; }
  #r70-result-screen .b98-next-content p { margin: 1px 0 3px; font-size: 11px; line-height: 1.24; }
  #r70-result-screen .b98-next-match button { min-height: 44px !important; padding: 5px 7px !important; font-size: 12px !important; }
  #r70-result-screen .b98-next-match [data-b98-next-action="campaign"] {
    grid-column: 2; grid-row: 2 / span 2; align-self: start;
    margin: 0; min-height: 44px !important;
  }
  #r70-result-screen .b98-next-status { grid-column: 1 / -1; }
  #r70-result-screen .r70-result-hint { display: none; }

  /* Campaign: a wide reading pane and a fixed action rail. The three sections
     share the same pane; Studio is shown first and the others stay one tap away.
     Match the stage selector's specificity so the old three-column grid cannot
     win the cascade (it caused the narrow vertical text on actual phones). */
  html[data-sejm-interface] body #r70-result-screen.r70-result-stage.r75-result-has-story {
    grid-template-columns: minmax(0, 1fr) clamp(180px, 27vw, 238px);
    grid-template-rows: auto 44px minmax(0, 1fr);
    column-gap: clamp(10px, 1.6vw, 18px);
  }
  #r70-result-screen.r75-result-has-story .r70-result-intro {
    grid-column: 1; grid-row: 1; grid-template-columns: minmax(0, 1fr);
    padding-bottom: 3px;
  }
  #r70-result-screen.r75-result-has-story .r70-result-intro :is(.r70-eyebrow,h1,.r70-result-matchup) {
    grid-column: 1; min-width: 0;
  }
  #r70-result-screen.r75-result-has-story .r70-result-intro h1 {
    grid-column: 1 / -1; grid-row: 2; overflow-wrap: normal; word-break: normal;
  }
  #r70-result-screen.r75-result-has-story .r70-result-matchup { grid-row: 3; font-size: 11px; }
  #r70-result-screen.r75-result-has-story .r70-result-center {
    grid-column: 2; grid-row: 1; align-self: center;
    flex-direction: row; justify-content: center; gap: 8px;
    overflow: hidden; height: 100%;
  }
  #r70-result-screen.r75-result-has-story .r70-result-portrait {
    width: clamp(42px, 8vw, 68px); height: clamp(44px, 12vh, 62px) !important;
    max-height: 100%; min-height: 0;
  }
  #r70-result-screen.r75-result-has-story .r70-result-score { max-width: 104px; font-size: 13px; }
  #r70-result-screen.r75-result-has-story .b98-result-tabs {
    grid-column: 1; grid-row: 2; display: grid;
    grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
    gap: 2px; min-width: 0; min-height: 44px;
    border-bottom: 1px solid #9a784778;
  }
  #r70-result-screen.r75-result-has-story .b98-result-tab {
    min-width: 0; min-height: 44px; padding: 7px 10px;
    border: 0; border-bottom: 2px solid transparent;
    background: #1b1c1ac9; color: #d4c8b1;
    font: 650 14px/1.2 var(--sk-r70-body,Arial,sans-serif);
    touch-action: manipulation;
  }
  #r70-result-screen.r75-result-has-story .b98-result-tab[aria-pressed="true"] {
    border-bottom-color: #e5c788; color: #fff0d2;
    background: linear-gradient(#41301ec9,#241e18d9);
  }
  #r70-result-screen.r75-result-has-story .b98-result-tab:focus-visible {
    outline: 2px solid #f4d899; outline-offset: -2px;
  }
  #r70-result-screen.r75-result-has-story .r75-result-story {
    grid-column: 1; grid-row: 3; align-self: stretch;
    min-height: 0; min-width: 0; max-height: 100%;
    padding: 10px 14px 6px; overflow-y: auto;
    overscroll-behavior: contain; touch-action: pan-y;
  }
  html[data-sejm-interface] body #r70-result-screen.r75-result-has-story .r75-result-story h2 {
    margin: 2px 0 5px; font-size: 18px !important; line-height: 1.14 !important;
  }
  #r70-result-screen.r75-result-has-story .r75-result-story p {
    margin: 4px 0;
    font-size: max(15px, calc(13px * var(--sk-r45-text-scale, 1.25))) !important;
    line-height: 1.42;
  }
  #r70-result-screen.r75-result-has-story .r75-result-next { margin-top: 7px; padding-top: 5px; }
  #r70-result-screen.r75-result-has-story .r70-result-advice {
    grid-column: 1; grid-row: 3; align-self: stretch;
    min-height: 0; max-height: 100%;
    padding: 10px 14px 6px; border: 0; overflow-y: auto;
    overscroll-behavior: contain; touch-action: pan-y;
  }
  #r70-result-screen.r75-result-has-story[data-b98-result-tab="story"] .r70-result-advice,
  #r70-result-screen.r75-result-has-story:is([data-b98-result-tab="studio"],[data-b98-result-tab="coach"]) .r75-result-story {
    display: none;
  }
  #r70-result-screen.r75-result-has-story[data-b98-result-tab="studio"] .r70-result-advice > :not(.r70-result-commentary),
  #r70-result-screen.r75-result-has-story[data-b98-result-tab="coach"] .r70-result-commentary {
    display: none;
  }
  #r70-result-screen.r75-result-has-story[data-b98-result-tab="studio"] .r70-result-commentary {
    margin: 0; padding: 0; border: 0;
    grid-template-columns: clamp(76px, 17%, 112px) minmax(0, 1fr);
    gap: 8px 14px;
  }
  #r70-result-screen.r75-result-has-story[data-b98-result-tab="studio"] .r73-studio-portrait {
    width: 100%; max-height: clamp(72px, 25vh, 138px);
  }
  #r70-result-screen.r75-result-has-story .r70-result-actions {
    grid-column: 2; grid-row: 2 / span 2;
    display: grid; grid-template-columns: minmax(0, 1fr);
    align-content: start; min-height: 0; overflow-y: auto;
  }
}

/* Tiny landscape phones keep the same content order and 44px targets. Each
   long region may scroll locally instead of forcing a whole-screen pan. */
@media (orientation: landscape) and (pointer: coarse) and (hover: none) and (max-width: 680px) and (max-height: 410px) {
  #r70-result-screen .r70-result-intro .r70-result-rules { font-size: 10px; }
  #r70-result-screen .r70-result-commentary { grid-template-columns: 48px minmax(0, 1fr); }
  #r70-result-screen .r73-studio-portrait { max-height: 60px; }
  #r70-result-screen .b98-next-match { max-height: min(26vh, 88px); }
  #r70-result-screen .b98-next-row img { width: 34px; height: 42px; }
}
