/* telefon: opis rozdziału chowa się za ekranem, wystaje tylko uchwyt. W pionie wysuwa się spod dolnej krawędzi, w poziomie zza lewej.
   Wysokość bierze z treści, dolna krawędź jest wspólna */
.sz-uchwyt, .sz-obrys { display: none; }
@media (max-width: 760px) and (orientation: portrait) {
  .chapter.mod, .chapter.garden-card, .room-controls.mod {
    --glass-x: 0px; --glass-y: 0px;
    left: 10px !important; right: 10px !important; top: auto !important; bottom: calc(10px + env(safe-area-inset-bottom) + var(--pod)) !important;
    width: auto; max-width: none; max-height: none; box-sizing: border-box; margin: 0;
    display: flex; flex-direction: column; padding: 24px 18px 18px; touch-action: none;
    translate: 0 calc(100% + 10px + env(safe-area-inset-bottom));
  }

  .sz-uchwyt { display: block; position: absolute; left: 50%; bottom: 100%; z-index: 2; width: 104px; height: 48px; margin: 0 0 0 -52px; padding: 0; border: 0; background: none; color: inherit; cursor: grab; touch-action: none; pointer-events: auto; -webkit-tap-highlight-color: transparent; }
  .room-controls > .sz-uchwyt { opacity: clamp(0, calc((var(--pz-in, 1) - .5) * 2), 1); transform: none; }
  .chapter::before, .room-controls::before, .sz-obrys { inset: -24px 0 0; }
  .sz-uchwyt::after { content: ""; position: absolute; left: 50%; bottom: 8px; width: 30px; height: 4px; margin-left: -15px; border-radius: 4px; background: currentColor; transition: transform .16s cubic-bezier(.23, 1, .32, 1); }

  /* przy wysuniętej planszy reszta pulpitu schodzi z drogi */
  .levels, .og-dots, .zacheta, .st-look { transition: opacity .25s ease, visibility 0s; }
  html.sz-otwarta :is(.levels, .og-dots, .zacheta, .st-look) { opacity: 0 !important; visibility: hidden; pointer-events: none; }
  .zacheta { bottom: calc(50px + env(safe-area-inset-bottom)); }
  html:has(.station.on) .zacheta { bottom: calc(126px + env(safe-area-inset-bottom)); }
  .st-look { bottom: calc(50px + var(--pod)); }
  .st-side .chapter.on { opacity: 1; translate: 0 calc(100% + 10px + env(safe-area-inset-bottom)); pointer-events: auto; }
}

/* wspólne dla pionu i poziomu */
@media (max-width: 760px) and (orientation: portrait), (max-height: 500px) and (orientation: landscape) {
  .chapter.garden-card.compact { display: flex; }
  .chapter.garden-card .mod-foot { display: flex; }
  .chapter.garden-card .mod-recs { display: grid; }
  .chapter.on, .room-controls { pointer-events: auto; }
  /* tekst stoi na szkle nad ruchomym obrazem: szkło gęstsze niż na dużym ekranie */
  .chapter::before, .room-controls::before { background: rgba(22,20,28,.5); -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%); }
  .chapter.ink-dark::before { background: rgba(250,247,240,.6); -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%); }
  /* szkło i uchwyt to jeden kształt: szuflada.js wycina go z tafli i prowadzi po nim jedną krawędź */
  .chapter::before, .room-controls::before { border: 0; border-radius: 0; box-shadow: none; clip-path: var(--sz-ksztalt); }
  .sz-obrys { display: block; position: absolute; z-index: -1; overflow: visible; fill: none; stroke: rgba(255,255,255,.42); stroke-width: 1; pointer-events: none; }
  .ink-dark > .sz-obrys { stroke: rgba(255,255,255,.75); }
  .chapter > .sz-obrys, .room-controls > .sz-obrys { transform: none; }
  .room-controls > .sz-obrys { opacity: var(--pz-in, 1); }
  .sz-uchwyt:active::after { transform: scaleX(1.25); }
  .sz-uchwyt:focus-visible { outline: 2px solid currentColor; outline-offset: -4px; border-radius: 14px; }
  .mod .label > span:not(.rule):not(.pill) { white-space: nowrap; }
  .mod .label .rule { flex-basis: 20px; }
  .sz-zamk > :not(.sz-uchwyt, .sz-obrys) { visibility: hidden; }
  .sz-zamk { pointer-events: none !important; }
}

/* telefon w poziomie: lewa krawędź planszy stoi w osi logo, dolna ma ten sam odstęp od ekranu.
   Prawa krawędź razem z uchwytem nie wychodzi za 33% kadru, pierwszy obraz w pokoju zaczyna się na 34,6% */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --siatka: 26px; --sz-safe: env(safe-area-inset-left, 0px); --sz-lewa: calc(var(--siatka) + var(--sz-safe)); --sz-dol: max(var(--siatka), env(safe-area-inset-bottom)); }
  .bar { padding: 0 calc(var(--siatka) + env(safe-area-inset-right)) 0 var(--sz-lewa); }
  .chapter.mod, .chapter.garden-card, .room-controls.mod {
    --glass-x: 0px; --glass-y: 0px;
    left: var(--sz-lewa) !important; right: auto !important; top: auto !important; bottom: calc(var(--sz-dol) + var(--pod)) !important;
    width: calc((33vw - 10px) * .9 - var(--sz-safe) * .9); max-width: none; max-height: none; box-sizing: border-box; margin: 0;
    display: flex; flex-direction: column; padding: 12px 15px 13px; touch-action: none;
    translate: calc(-100% - var(--sz-lewa) - 1px) 0;
  }
  .chapter.garden-card .mod-foot { display: none; }
  .chapter::before, .room-controls::before, .sz-obrys { inset: 0 -18px 0 0; }
  /* drobniejszy skład: plansza zajmuje jedną trzecią ekranu */
  .mod:not(.arch-head) .label { gap: 7px; margin: 0 0 7px; font-size: 8.5px; letter-spacing: .07em; }
  .chapter .label .dots, .room-controls .label .dots { display: none; }
  :is(.chapter, .room-controls) { font-size: 10.5px; }
  :is(.chapter, .room-controls) .mod-title-play { font-size: 26px; }
  :is(.chapter, .room-controls) .mod-twin { width: 15px; height: 25px; }
  :is(.chapter, .room-controls) .mod-kick { margin-top: 6px; font-size: 8.5px; }
  :is(.chapter, .room-controls) .mod-quote { display: block; margin-top: 6px; font-size: 10.5px; line-height: 1.34; }
  :is(.chapter, .room-controls) :is(.mod-tags, .pz-tags, .mod-foot) { display: none; }
  :is(.chapter, .room-controls) .mod-cols { column-gap: 10px; margin-top: 7px; }
  :is(.chapter, .room-controls) :is(.mod-music, .mod-recs, .mod-live) { margin-top: 8px; padding-top: 7px; }
  :is(.chapter, .room-controls) .mod-cols dt { font-size: 8px; }
  :is(.chapter, .room-controls) .mod-cols dd { margin-top: 2px; font-size: 10px; }
  :is(.chapter, .room-controls) .mod-recs { display: grid; grid-template-columns: 1fr 1fr; }
  :is(.chapter, .room-controls) .mod-recs small { font-size: 9px; margin-top: 1px; }
  :is(.chapter, .room-controls) .room-modes { margin-top: 8px; gap: 3px; }
  :is(.chapter, .room-controls) .room-modes button { gap: 3px; font-size: 9.5px; }
  .room-controls .mod-timer { width: 18px; }
  .room-status:empty { display: none; }
  /* niski ekran: kolejno ustępują dopiski, potem książka i film, nazwy trybów, na końcu hasło */
  .sz-c1 .mod-recs small, .sz-c1 .mod-kick { display: none !important; }
  .sz-c2 .mod-recs { display: none !important; }
  .sz-c3 .mod-cols:not(.mod-music):not(.mod-recs) { display: none !important; }
  .sz-c4 .mod-quote { display: none !important; }

  /* uchwyt: wypustka tej samej tafli w połowie prawego boku; po schowaniu planszy tylko ona zostaje na ekranie */
  .sz-uchwyt { display: block; position: absolute; left: calc(100% - 18px); top: max(50%, calc(100% - 58px - max(0px, 1000px - var(--sz-safe) * 1000))); z-index: 2; width: 48px; height: 96px; margin: -48px 0 0; padding: 0; border: 0; background: none; color: inherit; cursor: grab; touch-action: none; pointer-events: auto; -webkit-tap-highlight-color: transparent; }
  .room-controls > .sz-uchwyt { opacity: clamp(0, calc((var(--pz-in, 1) - .5) * 2), 1); transform: none; }
  .chapter > .sz-uchwyt { transform: none; }
  .sz-uchwyt::after { content: ""; position: absolute; left: 24px; top: 50%; width: 3px; height: 26px; margin-top: -13px; border-radius: 3px; background: currentColor; transition: transform .16s cubic-bezier(.23, 1, .32, 1); }
  .sz-uchwyt:active::after { transform: scaleY(1.25); }
  .sz-uchwyt:focus-visible { outline-offset: -8px; }

  .st-side .chapter.on { opacity: 1; translate: calc(-100% - var(--sz-lewa) - 1px) 0; pointer-events: auto; }
  /* podgląd pracy: strzałki na dole, na krawędziach siatki, z dala od próbek */
  .viewer-prev, .viewer-next { top: auto; bottom: calc(var(--sz-dol) - 12px); width: 64px; height: 48px; translate: none; opacity: .9; }
  .viewer-prev { left: var(--sz-lewa); text-align: left; } .viewer-next { right: calc(var(--siatka) + env(safe-area-inset-right)); text-align: right; }
  .viewer-info { width: calc(206px + var(--sz-lewa)); padding: 20px 0 0 var(--sz-lewa); }
  .viewer-close { top: 7px; right: calc(var(--siatka) + env(safe-area-inset-right)); } .viewer-close kbd { display: none; }
  .archive { padding: calc(var(--bar) + 16px) calc(var(--siatka) + env(safe-area-inset-right)) 0 var(--sz-lewa); }
  .arch-head.mod { padding-bottom: 14px; }
  .arch-index { padding-top: 14px; }
  .levels { top: calc(50% + 18px); right: calc(var(--siatka) + env(safe-area-inset-right)); }
  .levels ol { gap: 0; }
  .levels a { min-height: min(24px, calc((100dvh - 56px - var(--sz-dol)) / 12)); }
  .levels a span { display: none; }
  .st-look { bottom: calc(var(--sz-dol) + var(--pod)); gap: 2px; padding: 4px; }
  .st-places button { padding: 0 9px; letter-spacing: .08em; }
  .st-arrow { width: 36px; height: 36px; }
  .zacheta { bottom: var(--sz-dol); }
  html:has(.station.on) .zacheta { bottom: calc(var(--sz-dol) + 60px); }
  .og-dots { display: none; }   /* światy ogrodu zmienia się w planszy */
  .st-places button { white-space: nowrap; }
}

/* najmniejsze telefony w poziomie */
@media (max-height: 500px) and (max-width: 740px) and (orientation: landscape) {
  .chapter.mod, .chapter.garden-card, .room-controls.mod { padding: 9px 13px 10px 12px; }
  :is(.chapter, .room-controls) .mod-title-play { font-size: 22px; }
  :is(.chapter, .room-controls) .mod-quote { margin-top: 5px; font-size: 10px; line-height: 1.3; }
  :is(.chapter, .room-controls) .mod-cols dd { font-size: 9.5px; }
  .st-places button { padding: 0 6px; font-size: 9.5px; letter-spacing: .04em; }
  .st-arrow { width: 32px; height: 32px; }
}
@media (max-height: 500px) and (max-width: 760px) and (orientation: landscape) { :root { --siatka: 16px; } }

/* zachęta do obrócenia telefonu: w pionie najpierw plakietka na środku, potem sama ikona w rogu */
.obrot { display: none; }
@media (max-width: 760px) and (orientation: portrait) {
  .obrot { position: fixed; z-index: 70; left: 50%; top: 50%; display: grid; justify-items: center; gap: 12px; width: 216px; padding: 22px 18px 10px; box-sizing: border-box; border-radius: 22px; color: #fff; text-align: center; translate: -50% -50%;
    background: rgba(22,20,28,.62); border: 1px solid rgba(255,255,255,.26); -webkit-backdrop-filter: blur(18px) saturate(160%); backdrop-filter: blur(18px) saturate(160%); box-shadow: 0 20px 50px rgba(0,0,0,.3);
    opacity: 1; transition: opacity .25s cubic-bezier(.23, 1, .32, 1), scale .25s cubic-bezier(.23, 1, .32, 1), visibility 0s; }
  .obrot.off { opacity: 0; scale: .96; visibility: hidden; pointer-events: none; transition-delay: 0s, 0s, .25s; }
  .obrot button { color: inherit; border: 0; background: none; font: 500 11px/1.2 var(--grot); cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .16s cubic-bezier(.23, 1, .32, 1); }
  .obrot button:active, .obrot-ikona:active { transform: scale(.97); }
  .obrot-tak { display: grid; justify-items: center; gap: 14px; padding: 0; min-height: 44px; }
  .obrot-tak b { text-wrap: balance; font: 400 24px/1.05 var(--serif); letter-spacing: -.01em; }
  .obrot-tak span { font: 400 12px/1.4 var(--cond); opacity: .85; text-wrap: balance; }
  .obrot-nie { min-height: 44px; padding: 0 16px; opacity: .8; text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
  .obrot svg { width: 72px; height: 72px; }
  .obrot svg, .obrot-ikona svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
  .ob-tel { transform-origin: 20px 20px; }
  .obrot:not(.off) .ob-tel { animation: obrot 3.2s cubic-bezier(.77, 0, .175, 1) infinite; }
  .ob-luk { opacity: .55; }
  @keyframes obrot { 0%, 18% { transform: rotate(0); } 48%, 82% { transform: rotate(90deg); } 100% { transform: rotate(0); } }
  .obrot-ikona { position: fixed; z-index: 45; left: 8px; bottom: calc(2px + env(safe-area-inset-bottom)); display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: 0; background: none; color: #fff; filter: drop-shadow(0 0 5px rgba(0,0,0,.45)); cursor: pointer; transition: opacity .25s ease, transform .16s cubic-bezier(.23, 1, .32, 1); }
  .obrot-ikona svg { width: 26px; height: 26px; stroke-width: 2.4; }
  .obrot-ikona:not(.in), .obrot-ikona.arch, html.sz-otwarta .obrot-ikona { opacity: 0; visibility: hidden; pointer-events: none; }
  :is(.obrot button, .obrot-ikona):focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 12px; }
}
@media (min-width: 761px), (orientation: landscape) { .obrot-ikona { display: none; } }
@media (prefers-reduced-motion: reduce) { .obrot:not(.off) .ob-tel { animation: none; transform: rotate(90deg); } .obrot { transition-duration: .01s; } }
@media (prefers-reduced-transparency: reduce) { .obrot { background: rgb(22,20,28); -webkit-backdrop-filter: none; backdrop-filter: none; } }
