/* Mobile runtime v18
   Cel: jedna, stabilna geometria dla realnych telefonow.
   W pionie szerokosc maty jest zawsze wyliczana od szerokosci strony,
   nigdy od chwilowej wysokosci viewportu/paska Safari/Chrome.
*/

@media (max-width:820px) and (orientation:portrait){
  body.pz-game-page.pz-classic-layout-v2.pz-retro-ui-v1.pz-retro-ui-v2.pz-retro-ui-v3.pz-retro-ui-v4.pz-retro-ui-v5.pz-retro-ui-v6{
    --pz-mobile-stage-aspect:.72;
    --pz-mobile-safe-x:max(0px,env(safe-area-inset-left));
    --pz-mobile-safe-r:max(0px,env(safe-area-inset-right));
  }

  /* Nie probujemy juz wciskac calej konsoli w wysokosc visual viewportu.
     To wlasnie powodowalo mikroskopijna mate na realnych telefonach. */
  body.pz-game-page.pz-classic-layout-v2.pz-retro-ui-v1.pz-retro-ui-v2.pz-retro-ui-v3.pz-retro-ui-v4.pz-retro-ui-v5.pz-retro-ui-v6 .pz-game-shell{
    width:100%!important;
    height:auto!important;
    min-height:0!important;
    overflow:visible!important;
    contain:none!important;
  }

  body.pz-game-page.pz-classic-layout-v2.pz-retro-ui-v1.pz-retro-ui-v2.pz-retro-ui-v3.pz-retro-ui-v4.pz-retro-ui-v5.pz-retro-ui-v6 :is(.pz-uk-layout,.pz-od-layout,.pz-mem-layout,.pz-demontaz-layout,.pz-sp-layout){
    width:100%!important;
    height:auto!important;
    min-height:0!important;
    grid-template-rows:auto auto auto!important;
    align-content:start!important;
    overflow:visible!important;
  }

  /* Pelna szerokosc. Aspect ratio daje boardWrapowi stabilna wysokosc jeszcze
     zanim silnik gry wpisze width/height na samym stage. */
  body.pz-game-page.pz-classic-layout-v2.pz-retro-ui-v1.pz-retro-ui-v2.pz-retro-ui-v3.pz-retro-ui-v4.pz-retro-ui-v5.pz-retro-ui-v6 :is(.pz-uk-board-wrap,.pz-od-board-wrap,.pz-mem-board-wrap,.pz-demontaz-board-wrap,.pz-sp-board-wrap){
    box-sizing:border-box!important;
    width:100%!important;
    max-width:100%!important;
    height:auto!important;
    min-height:0!important;
    max-height:none!important;
    aspect-ratio:var(--pz-mobile-stage-aspect)!important;
    margin:0!important;
    padding:0!important;
    overflow:visible!important;
  }

  body.pz-game-page.pz-classic-layout-v2.pz-retro-ui-v1.pz-retro-ui-v2.pz-retro-ui-v3.pz-retro-ui-v4.pz-retro-ui-v5.pz-retro-ui-v6 :is(.pz-uk-stage,.pz-od-stage,.pz-mem-stage,.pz-demontaz-stage,.pz-sp-stage){
    max-width:100%!important;
    max-height:none!important;
    margin:0!important;
    flex:0 0 auto!important;
  }

  /* Przejscia i statusy zawsze siedza wewnatrz maty. */
  body.pz-game-page :is(.pz-uk32-challenge-overlay,.pz-demontaz-complete,.pz-od-complete,.pz-mem-phase-overlay,.pz-mem-complete,.pz-sp-phase-overlay,.pz-sp-complete){
    box-sizing:border-box!important;
    max-width:100%!important;
    max-height:100%!important;
    overflow:hidden!important;
  }

  /* ---------- ODKRYWACZ ---------- */
  body.pz-od-page .pz-od-complete.pz-od12-level-card-overlay,
  body.pz-od-page .pz-od-complete.pz-od16-transition-overlay{
    padding:6px!important;
  }
  body.pz-od-page .pz-od12-level-card,
  body.pz-od-page .pz-od16-transition-card{
    width:calc(100% - 12px)!important;
    max-width:460px!important;
    max-height:calc(100% - 12px)!important;
    min-height:0!important;
    overflow:hidden!important;
    padding:8px 9px!important;
    gap:4px!important;
    border-radius:15px!important;
  }
  body.pz-od-page .pz-od12-level-art--large{max-height:70px!important;width:min(62%,240px)!important;}
  body.pz-od-page .pz-od14-before-label,
  body.pz-od-page .pz-od15-done-label,
  body.pz-od-page .pz-od15-next-label{min-height:18px!important;padding:2px 7px!important;font-size:7px!important;}
  body.pz-od-page .pz-od14-objective,
  body.pz-od-page .pz-od16-objective{width:min(92%,320px)!important;padding:3px 7px!important;}
  body.pz-od-page .pz-od14-objective small{font-size:6px!important;}
  body.pz-od-page .pz-od14-objective b{font-size:10px!important;}
  body.pz-od-page .pz-od14-level-tip,
  body.pz-od-page .pz-od16-level-tip{
    max-width:94%!important;
    margin:0 auto!important;
    font-size:9px!important;
    line-height:1.18!important;
    display:-webkit-box!important;
    -webkit-box-orient:vertical!important;
    -webkit-line-clamp:2!important;
    overflow:hidden!important;
  }
  body.pz-od-page .pz-od14-start-level,
  body.pz-od-page .pz-od16-start-level{
    min-width:170px!important;
    min-height:32px!important;
    padding:4px 10px!important;
    font-size:11px!important;
  }
  body.pz-od-page .pz-od16-done-head{min-height:20px!important;gap:6px!important;}
  body.pz-od-page .pz-od16-done-stars{min-height:18px!important;}
  body.pz-od-page .pz-od16-done-stars img{width:17px!important;height:17px!important;}
  body.pz-od-page .pz-od16-done-summary{gap:5px!important;}
  body.pz-od-page .pz-od16-done-level{width:64px!important;max-height:26px!important;}
  body.pz-od-page .pz-od16-done-stats{gap:3px!important;}
  body.pz-od-page .pz-od16-done-stats>span{min-width:0!important;padding:2px 4px!important;}
  body.pz-od-page .pz-od16-done-stats small{font-size:5.5px!important;}
  body.pz-od-page .pz-od16-done-stats b{font-size:10px!important;}
  body.pz-od-page .pz-od16-done-reward{display:none!important;}
  body.pz-od-page .pz-od16-next-block{gap:2px!important;}
  body.pz-od-page .pz-od16-next-level{width:min(42%,150px)!important;max-height:48px!important;}
  body.pz-od-page .pz-od16-next-block>strong{font-size:18px!important;line-height:1!important;}
  body.pz-od-page .pz-od16-time-limit{min-height:22px!important;}
  body.pz-od-page .pz-od16-anywhere-note,
  body.pz-od-page .pz-od14-wait-note{display:none!important;}

  /* ---------- SPRINT ---------- */
  body.pz-sp-page .pz-sp-phase-overlay{padding:6px!important;}
  body.pz-sp-page .pz-sp-gate-card,
  body.pz-sp-page .pz-sp-phase-card{
    width:calc(100% - 12px)!important;
    max-width:470px!important;
    max-height:calc(100% - 12px)!important;
    min-height:0!important;
    overflow:hidden!important;
    padding:8px 10px!important;
    gap:4px!important;
    border-radius:15px!important;
  }
  body.pz-sp-page .pz-sp-phase-card{grid-template-columns:1fr!important;}
  body.pz-sp-page .pz-sp-phase-done{
    min-height:0!important;
    padding:5px 7px!important;
    gap:4px 6px!important;
    border-radius:10px!important;
  }
  body.pz-sp-page .pz-sp-phase-done>span{font-size:8px!important;white-space:normal!important;}
  body.pz-sp-page .pz-sp-phase-mini{gap:3px!important;}
  body.pz-sp-page .pz-sp-phase-mini b{font-size:8px!important;padding:3px 5px!important;}
  body.pz-sp-page .pz-sp-phase-reward{height:26px!important;max-height:26px!important;max-width:66px!important;}
  body.pz-sp-page .pz-sp-phase-next{gap:2px!important;}
  body.pz-sp-page .pz-sp-phase-next>img{height:42px!important;max-height:42px!important;max-width:130px!important;}
  body.pz-sp-page .pz-sp-phase-next>span{font-size:7px!important;}
  body.pz-sp-page .pz-sp-phase-next h2{font-size:18px!important;line-height:1!important;}
  body.pz-sp-page .pz-sp-phase-next p{
    max-width:94%!important;
    font-size:9px!important;
    line-height:1.18!important;
    display:-webkit-box!important;
    -webkit-box-orient:vertical!important;
    -webkit-line-clamp:2!important;
    overflow:hidden!important;
  }
  body.pz-sp-page .pz-sp-phase-next .pz-sp-gate-start{
    min-width:170px!important;
    min-height:32px!important;
    padding:4px 10px!important;
    font-size:10px!important;
  }
  body.pz-sp-page .pz-sp-phase-next small{display:none!important;}
  body.pz-sp-page .pz-sp-welcome-card{padding:9px 11px!important;gap:4px!important;}
  body.pz-sp-page .pz-sp-welcome-card .pz-sp-gate-state{max-height:54px!important;}
  body.pz-sp-page .pz-sp-gate-card h2{font-size:18px!important;}
  body.pz-sp-page .pz-sp-gate-card p{font-size:9px!important;line-height:1.2!important;}
  body.pz-sp-page .pz-sp-gate-card small{display:none!important;}

  /* ---------- PAMIECIOWKA ---------- */
  body.pz-mem-page .pz-mem-phase-overlay{padding:6px!important;}
  body.pz-mem-page .pz-mem-flow-card,
  body.pz-mem-page .pz-mem-result-card--new{
    width:calc(100% - 12px)!important;
    max-width:470px!important;
    max-height:calc(100% - 12px)!important;
    min-height:0!important;
    overflow:hidden!important;
    padding:8px 10px!important;
    gap:4px!important;
    border-radius:15px!important;
  }
  body.pz-mem-page .pz-mem-flow-card h2{font-size:18px!important;line-height:1.05!important;}
  body.pz-mem-page .pz-mem-flow-card p{
    font-size:9px!important;
    line-height:1.2!important;
    max-width:95%!important;
  }
  body.pz-mem-page .pz-mem-flow-card__eyebrow{font-size:6.5px!important;}
  body.pz-mem-page .pz-mem-flow-card img{max-height:58px!important;object-fit:contain!important;}
  body.pz-mem-page .pz-mem-flow-button{min-height:32px!important;padding:4px 10px!important;font-size:10px!important;}
  body.pz-mem-page .pz-mem-click-note{display:none!important;}

  /* ---------- UKLADANIE ---------- */
  body.pz-uk-page .pz-uk32-challenge-overlay{padding:6px!important;}
  body.pz-uk-page .pz-uk32-level-card,
  body.pz-uk-page .pz-uk32-timeup-card{
    width:calc(100% - 12px)!important;
    max-width:460px!important;
    max-height:calc(100% - 12px)!important;
    min-height:0!important;
    overflow:hidden!important;
    padding:7px 8px!important;
    gap:4px!important;
  }
  body.pz-uk-page .pz-uk32-level-art{width:min(76%,300px)!important;max-height:86px!important;}
  body.pz-uk-page .pz-uk32-time-art{width:min(50%,180px)!important;max-height:48px!important;}
  body.pz-uk-page .pz-uk32-level-card strong{font-size:22px!important;}
  body.pz-uk-page .pz-uk32-level-card p{padding:4px 8px!important;font-size:10px!important;}
  body.pz-uk-page .pz-uk32-level-card small{font-size:8px!important;}
  body.pz-uk-page .pz-uk32-timeup-card>img{max-height:92px!important;}
  body.pz-uk-page .pz-uk32-timeup-card>button:first-of-type img{max-height:76px!important;}

  /* ---------- DEMONTAZ ---------- */
  body.pz-demontaz-page .pz-dem23-level-card{gap:5px!important;padding:6px!important;overflow:hidden!important;}
  body.pz-demontaz-page .pz-dem23-level-art{width:min(78%,300px)!important;max-height:82px!important;}
  body.pz-demontaz-page .pz-dem23-limit{gap:6px!important;}
  body.pz-demontaz-page .pz-dem23-limit img{width:min(42%,150px)!important;max-height:46px!important;}
  body.pz-demontaz-page .pz-dem23-limit b{font-size:20px!important;border-width:2px!important;padding:.25em .4em!important;}
  body.pz-demontaz-page .pz-dem23-fail-card{max-width:calc(100% - 12px)!important;max-height:calc(100% - 12px)!important;overflow:hidden!important;padding:8px!important;}

  /* Stanowe grafiki: nigdy crop. */
  body.pz-game-page :is(.pz-uk32-level-art,.pz-uk32-time-art,.pz-dem23-level-art,.pz-od12-level-art,.pz-od15-done-level,.pz-od15-next-level,.pz-mem-flow-card img,.pz-sp-gate-state,.pz-sp-phase-next>img,.pz-sp-phase-reward){
    object-fit:contain!important;
    object-position:center!important;
  }
}

/* Bardzo waskie urzadzenia 320-359 CSS px. Mniej dekoracji, ta sama funkcja. */
@media (max-width:359px) and (orientation:portrait){
  body.pz-od-page .pz-od16-done-level{display:none!important;}
  body.pz-od-page .pz-od16-done-summary{grid-template-columns:1fr!important;}
  body.pz-od-page .pz-od16-next-level{max-height:42px!important;}
  body.pz-od-page .pz-od16-next-block>strong{font-size:16px!important;}
  body.pz-sp-page .pz-sp-phase-reward{display:none!important;}
  body.pz-sp-page .pz-sp-phase-next>img{height:36px!important;max-height:36px!important;}
  body.pz-sp-page .pz-sp-phase-next h2{font-size:16px!important;}
  body.pz-mem-page .pz-mem-flow-card p:nth-of-type(n+2){display:none!important;}
}
