/* One engraved surround brings the separate Stories windows into a single opening. */
@media(min-width:681px){
  [data-chapter=juwe-stories] #station > .stories-collage{
    box-sizing:border-box;
    border:solid transparent;
    border-width:clamp(18px,2.4dvh,33px) clamp(14px,1.3vw,25px) clamp(13px,2dvh,24px);
    border-image:url('assets/interface/frame-5.avif') 96 90 63 fill / 1 / 0 stretch;
    opacity:var(--visual-progress,1);
  }
  [data-chapter=program] #station .framed-print::after,
  [data-chapter=dla-sponsorow] #station .framed-print::after{
    border-width:8px 9px 8px;
    inset:-3px -4px;
  }
}
@media(min-width:1000px) and (min-aspect-ratio:1/1){
  [data-chapter=dla-sponsorow] #station .layout-gallery{
    --bx:66vw;--by:max(13.5dvh,65px);--bw:30.5vw;--bh:min(74dvh,calc(100dvh - var(--by) - 66px));
  }
  [data-chapter=partnerzy] #station .photo-wing{
    --bx:67vw;--by:max(15.5dvh,68px);--bw:26vw;--bh:51dvh;
  }
  [data-chapter=juwe-stories] #station > .stories-collage{
    --bx:64.8vw;--by:max(9.8dvh,69px);--bw:32vw;--bh:min(79.7dvh,calc(100dvh - var(--by) - 65px));
    container-type:size;
    align-content:center;
    gap:clamp(3px,.55vw,9px);
  }
  [data-chapter=juwe-stories] #station > .stories-collage .story-window{
    width:min(100%,calc((100cqh - clamp(3px,.55vw,9px) * 2) * .225));
  }
}
@media(min-width:681px) and (max-width:999px), (min-width:681px) and (max-aspect-ratio:1/1){
  [data-chapter=program] #station .layout-gallery{
    --bx:4.8vw;--by:61dvh;--bw:92.5vw;--bh:min(31.5dvh,calc(100dvh - var(--by) - 67px));
    display:grid;grid-template-columns:repeat(6,minmax(0,1fr));grid-template-rows:repeat(2,minmax(0,1fr));
    gap:clamp(4px,1dvh,12px);
  }
  [data-chapter=program] #station .layout-gallery button{grid-column:span 2}
  [data-chapter=program] #station .layout-gallery button:nth-child(4):nth-last-child(2){grid-column:2 / span 2}
  [data-chapter=promocja] #station .photo-wing{
    --bx:18vw;--by:58dvh;--bw:53vw;--bh:min(32dvh,calc(100dvh - var(--by) - 70px));
  }
  [data-chapter=dla-sponsorow] #station .layout-gallery{
    --bx:61.8vw;--by:55.5dvh;--bw:35vw;--bh:min(35dvh,calc(100dvh - var(--by) - 67px));
    gap:8px;
  }
  body[data-chapter=partnerzy] #station .photo-wing{
    --by:max(12dvh,72px);--bw:43vw;--bh:41dvh;
    left:auto;right:5vw;transform:translateX(var(--wing-x,0px));
  }
  [data-chapter=juwe-stories] #station > .stories-collage{
    --by:max(10dvh,69px);--bh:min(80dvh,calc(100dvh - var(--by) - 66px));
    /* Fade only the scrolling strip, preserving the engraved outer edge. */
    mask-image:linear-gradient(to bottom,#000 0 3%,#0003 3.2%,#000 12% 88%,#0003 96.7%,#000 97%),
      linear-gradient(to right,#000 0 5%,transparent 7% 93%,#000 95%);
    padding:clamp(9px,2dvh,25px) 0;
    scrollbar-width:thin;scrollbar-color:#758579 transparent;
  }
}
@media(min-width:681px) and (max-width:999px) and (min-height:551px) and (orientation:landscape){
  [data-chapter=program] #station .layout-gallery{
    --by:68dvh;--bh:min(22dvh,calc(100dvh - var(--by) - 66px));
    display:flex;
  }
  body:is([data-chapter=partnerzy],[data-chapter=promocja]) #station .photo-wing{
    --bx:70vw;--bw:26vw;--bh:51dvh;
    top:49%;left:var(--bx);right:auto;transform:translate(var(--wing-x,0px),-50%);
  }
}
@media(min-width:681px) and (max-height:550px) and (orientation:landscape){
  [data-chapter=program] #station .layout-gallery{
    --bx:68vw;--bw:29vw;--by:63px;--bh:calc(100dvh - 125px);
    display:grid;grid-template-columns:repeat(4,minmax(0,1fr));grid-template-rows:repeat(3,minmax(0,1fr));gap:5px;
  }
  [data-chapter=program] #station .layout-gallery button,
  [data-chapter=program] #station .layout-gallery button:nth-child(4):nth-last-child(2){grid-column:span 2}
  [data-chapter=program] #station .layout-gallery button:nth-child(5){grid-column:2 / span 2}
  [data-chapter=dla-sponsorow] #station .layout-gallery,
  [data-chapter=juwe-stories] #station > .stories-collage{
    --bx:68vw;--bw:29vw;--by:63px;--bh:calc(100dvh - 125px);
  }
  body:is([data-chapter=edycje],[data-chapter=promocja],[data-chapter=partnerzy]) #station .photo-wing{
    --bx:69vw;--bw:27vw;--bh:calc(100dvh - 140px);
    left:var(--bx);right:auto;top:50%;transform:translate(var(--wing-x,0px),-50%);
  }
}

@media(min-width:681px) and (max-height:550px) and (orientation:landscape){
  [data-chapter=juwe-stories] #station > .stories-collage .story-window{
    width:min(94%,calc((var(--bh) - 65px) * .675));
  }
}

/* Open the festival photographs at reading size in the centre of the viewport. */
body:is([data-chapter=festiwal],[data-chapter=program],[data-chapter=liczby]) #folio[open][data-mode=album]{
  --edge-x:max(clamp(6px,calc(6vw - 20px),64px),env(safe-area-inset-left),env(safe-area-inset-right));
  --edge-y:max(clamp(8px,3dvh,40px),env(safe-area-inset-top),env(safe-area-inset-bottom));
  --bw:min(1200px,calc(100vw - 2 * var(--edge-x)));
  --bh:min(980px,calc(100dvh - 2 * var(--edge-y)));
  inset:0;
  margin:auto;
  width:var(--album-w);
  height:fit-content;
  max-width:var(--bw);
  max-height:var(--bh);
}

/* The festival album leaves “Dalej” live. A centred print can clear the
   button either horizontally or vertically, whichever makes it larger. */
body[data-chapter=festiwal] #folio[open][data-mode=album]{
  --beside-controls:calc(100vw - 2 * (max(var(--gutter),env(safe-area-inset-right)) + 102px));
  --footer-space:max(77px,calc(3.5dvh + 55px),calc(env(safe-area-inset-bottom) + 55px));
  --above-controls:calc((100dvh - 2 * var(--footer-space) - var(--cap) - var(--band) - var(--sill)) * var(--print-ratio,1.5) + 2 * var(--jamb));
  --bw:min(1200px,calc(100vw - 2 * var(--edge-x)),max(var(--beside-controls),var(--above-controls)));
}

@media (max-width:680px) {
  body[data-chapter] #folio[open][data-mode="album"] {
    --band:52px;--cap:12px;--jamb:10px;--sill:11px;
    --bh:calc(100dvh - max(14px,env(safe-area-inset-top)) - max(14px,env(safe-area-inset-bottom)));
    --bw:calc(100vw - 16px);
    position:fixed;inset:50% 0 auto;margin:0 auto;translate:0 -50%;
    width:min(var(--bw),max(min(230px,80vw),var(--album-w)));
    height:auto;max-width:var(--bw);max-height:var(--bh);
  }
  body[data-chapter] #folio[open][data-mode="album"] :is(#folio-inner,#folio-content) {
    height:auto;max-height:none;overflow:visible;
  }
  body[data-chapter] #folio[open][data-mode="album"] #folio-content {
    grid-template:auto auto / minmax(0,1fr) auto;
  }
  body[data-chapter] #folio[open][data-mode="album"] .album-main {grid-area:1 / 1 / 2 / 3}
  body[data-chapter] #folio[open][data-mode="album"] .album-print {
    height:auto;aspect-ratio:auto;
  }
  body[data-chapter] #folio[open][data-mode="album"] .album-print img {
    width:100%;height:auto;max-height:calc(var(--bh) - var(--band) - var(--cap) - var(--sill));
    object-fit:contain;
  }
  body[data-chapter] #folio[open][data-mode="album"] .dialog-title {
    grid-area:2 / 1;text-align:left;margin:0;padding:4px 0;font-size:13px;min-height:0;overflow-wrap:anywhere;
  }
  body[data-chapter] #folio[open][data-mode="album"] .album-foot {
    grid-area:2 / 2;margin:0 48px 0 0;min-height:var(--band);
  }
  body[data-chapter=festiwal] #folio[open][data-mode=album] {
    --bh:calc(100dvh - 2 * var(--footer-space));
  }
}
