/* Hidden navigation controls must never escape their Library state on any device. */
html body > .iphone-library-zoom-controls[hidden] { display: none !important; }

/* KRONIKARZ — mobilna Biblioteka oparta wyłącznie na zatwierdzonej panoramie V3.
   Desktop pozostaje nietknięty. Poziom: cała panorama jest widoczna; hotspoty odpowiadają pozycjom grzbietów.
   Pion: ta sama panorama staje się poziomo przewijaną sceną o wysokości całego viewportu. */

/* Touch landscape Library: reuse the existing open-road button.
   Desk feather measured in the V3 panorama (1672×941). Follow the same
   zoom/pan variables as the artwork; preserve action, layers and desktop. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html body.archiwum-aktywne .wejscie.otwarty .droga-do-redakcji {
    left: calc(50vw + var(--iphone-library-bg-width, 100vw) * 0.1 + var(--iphone-library-bg-offset, 0px)) !important;
    top: calc(50dvh + var(--iphone-library-bg-height, 100dvh) * 0.29) !important;
    width: max(44px, calc(var(--iphone-library-bg-width, 100vw) * 0.13)) !important;
    height: max(44px, calc(var(--iphone-library-bg-height, 100dvh) * 0.2)) !important;
  }
}

@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html,
  body,
  #app,
  body.archiwum-aktywne .wejscie {
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
  }

  html body.archiwum-aktywne .archiwum-scena {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    background-image: url("./assets/redakcja/KRONIKARZ_biblioteka_montaz_13_tomow_v3.png") !important;
    background-size: 100% 100% !important;
    background-position: center center !important;
    background-repeat: no-repeat !important;
    background-color: #000 !important;
    z-index: 90 !important;
    pointer-events: none !important;
  }

  html body.archiwum-aktywne :is(
    .tom1-archiwum,
    .tom2-archiwum,
    .tom3-archiwum,
    .tom4-archiwum,
    .tom5-archiwum,
    .tom6-archiwum,
    .tom7-archiwum,
    .tom8-archiwum,
    .tom9-archiwum,
    .tom10-archiwum,
    .tom11-archiwum,
    .tom12-archiwum
  ) {
    display: block !important;
    position: fixed !important;
    top: 44.95dvh !important;
    width: 2.71vw !important;
    height: 24.65dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: translate(-50%, -50%) !important;
    border: 0 !important;
    background: transparent !important;
    z-index: 30020 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  html body.archiwum-aktywne .tom1-archiwum  { left: 33.41vw !important; }
  html body.archiwum-aktywne .tom2-archiwum  { left: 36.27vw !important; }
  html body.archiwum-aktywne .tom3-archiwum  { left: 39.14vw !important; }
  html body.archiwum-aktywne .tom4-archiwum  { left: 42.07vw !important; }
  html body.archiwum-aktywne .tom5-archiwum  { left: 44.99vw !important; }
  html body.archiwum-aktywne .tom6-archiwum  { left: 47.91vw !important; }
  html body.archiwum-aktywne .tom7-archiwum  { left: 50.84vw !important; }
  html body.archiwum-aktywne .tom8-archiwum  { left: 53.76vw !important; }
  html body.archiwum-aktywne .tom9-archiwum  { left: 56.68vw !important; }
  html body.archiwum-aktywne .tom10-archiwum { left: 59.61vw !important; }
  html body.archiwum-aktywne .tom11-archiwum { left: 62.53vw !important; }
  html body.archiwum-aktywne .tom12-archiwum { left: 65.45vw !important; }

  html body.archiwum-aktywne .pusta-ksiega-archiwum {
    display: block !important;
    position: fixed !important;
    left: 68.38vw !important;
    top: 44.95dvh !important;
    width: 2.71vw !important;
    height: 24.65dvh !important;
    transform: translate(-50%, -50%) !important;
    border: 0 !important;
    background: transparent !important;
    pointer-events: none !important;
  }
}

@media (orientation: portrait) and (max-width: 600px) and (hover: none) and (pointer: coarse) {
  body.archiwum-aktywne {
    overflow: hidden !important;
    background: #000 !important;
  }

  body.archiwum-aktywne .wejscie {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    overscroll-behavior-x: contain !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth;
    background: #000 !important;
  }

  html body.archiwum-aktywne .archiwum-scena {
    display: block !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    right: auto !important;
    bottom: auto !important;
    width: 216.784dvh !important;
    height: 100dvh !important;
    background-image: url("./assets/redakcja/KRONIKARZ_biblioteka_montaz_13_tomow_v3.png") !important;
    background-size: 100% 100% !important;
    background-position: left top !important;
    background-repeat: no-repeat !important;
    background-color: #000 !important;
    z-index: 90 !important;
    pointer-events: none !important;
  }

  html body.archiwum-aktywne :is(
    .tom1-archiwum,
    .tom2-archiwum,
    .tom3-archiwum,
    .tom4-archiwum,
    .tom5-archiwum,
    .tom6-archiwum,
    .tom7-archiwum,
    .tom8-archiwum,
    .tom9-archiwum,
    .tom10-archiwum,
    .tom11-archiwum,
    .tom12-archiwum
  ) {
    display: block !important;
    position: absolute !important;
    top: 44.95dvh !important;
    width: 5.87dvh !important;
    min-width: 44px !important;
    height: 24.65dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: translate(-50%, -50%) !important;
    border: 0 !important;
    background: transparent !important;
    z-index: 30020 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  html body.archiwum-aktywne .tom1-archiwum  { left: 72.42dvh !important; }
  html body.archiwum-aktywne .tom2-archiwum  { left: 78.64dvh !important; }
  html body.archiwum-aktywne .tom3-archiwum  { left: 84.86dvh !important; }
  html body.archiwum-aktywne .tom4-archiwum  { left: 91.20dvh !important; }
  html body.archiwum-aktywne .tom5-archiwum  { left: 97.54dvh !important; }
  html body.archiwum-aktywne .tom6-archiwum  { left: 103.87dvh !important; }
  html body.archiwum-aktywne .tom7-archiwum  { left: 110.21dvh !important; }
  html body.archiwum-aktywne .tom8-archiwum  { left: 116.55dvh !important; }
  html body.archiwum-aktywne .tom9-archiwum  { left: 122.89dvh !important; }
  html body.archiwum-aktywne .tom10-archiwum { left: 129.23dvh !important; }
  html body.archiwum-aktywne .tom11-archiwum { left: 135.56dvh !important; }
  html body.archiwum-aktywne .tom12-archiwum { left: 141.90dvh !important; }

  html body.archiwum-aktywne .pusta-ksiega-archiwum {
    display: block !important;
    position: absolute !important;
    left: 148.24dvh !important;
    top: 44.95dvh !important;
    width: 5.87dvh !important;
    min-width: 44px !important;
    height: 24.65dvh !important;
    transform: translate(-50%, -50%) !important;
    border: 0 !important;
    background: transparent !important;
    pointer-events: none !important;
  }
}

@media (hover: none) and (pointer: coarse) {
  html body.archiwum-aktywne .powrot-z-archiwum {
    display: block !important;
    position: fixed !important;
    left: 14px !important;
    top: auto !important;
    right: auto !important;
    bottom: 14px !important;
    width: 62px !important;
    height: 44px !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid rgba(210, 175, 115, 0.72) !important;
    border-radius: 6px !important;
    background: rgba(18, 11, 7, 0.78) !important;
    z-index: 40000 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  html body.archiwum-aktywne .powrot-z-archiwum::after {
    content: "← LAS";
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: #d8b878;
    font: 700 11px/1 Georgia, "Times New Roman", serif;
    letter-spacing: 0.08em;
  }
}

/* Landscape phone only: the artwork and clickable spines use identical zoom/pan. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html body.archiwum-aktywne .archiwum-scena {
    background-size: var(--iphone-library-bg-width, 100vw) var(--iphone-library-bg-height, 100dvh) !important;
    background-position: calc(50% + var(--iphone-library-bg-offset, 0px)) center !important;
  }
  html body.archiwum-aktywne :is(
    .tom1-archiwum, .tom2-archiwum, .tom3-archiwum, .tom4-archiwum,
    .tom5-archiwum, .tom6-archiwum, .tom7-archiwum, .tom8-archiwum,
    .tom9-archiwum, .tom10-archiwum, .tom11-archiwum, .tom12-archiwum,
    .pusta-ksiega-archiwum
  ) {
    left: var(--book-x, 50vw) !important;
    top: var(--iphone-library-book-top, 44.95dvh) !important;
    width: var(--iphone-library-book-width, 2.71vw) !important;
    height: var(--iphone-library-book-height, 24.65dvh) !important;
  }
  html body.archiwum-aktywne .iphone-library-selected {
    outline: 2px solid rgba(239, 199, 112, .9) !important;
    outline-offset: 1px !important;
    box-shadow: 0 0 13px rgba(239, 199, 112, .65) !important;
  }
  .iphone-library-zoom-controls { display: none; }
  body.archiwum-aktywne .iphone-library-zoom-controls {
    display: flex;
    position: fixed;
    top: 10px;
    right: 12px;
    z-index: 45000;
    gap: 6px;
  }
  body.archiwum-aktywne .iphone-library-zoom-controls button {
    min-width: 40px;
    min-height: 40px;
    border: 1px solid #c9a76e;
    border-radius: 6px;
    color: #e8cb91;
    background: rgba(21, 13, 9, .88);
    font: bold 22px Georgia, serif;
    touch-action: manipulation;
  }
}

/* iPhone Library only: keep Safari's native touch gestures from moving the
   page independently of the panorama and its clickable book spines. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html:has(body.archiwum-aktywne),
  html body.archiwum-aktywne,
  html body.archiwum-aktywne .wejscie,
  html body.archiwum-aktywne .archiwum-scena {
    touch-action: none !important;
    overscroll-behavior: none !important;
  }
  html body.archiwum-aktywne .iphone-library-zoom-controls,
  html body.archiwum-aktywne .iphone-library-zoom-controls button,
  html body.archiwum-aktywne .powrot-z-archiwum {
    touch-action: manipulation !important;
  }
}

/* iPhone landscape only: a book must cover the entrance scene when opened.
   Preserve each volume's existing artwork and all desktop rules. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  body.otwarty-tom .wejscie > .desktop-entrance-artwork,
  body.otwarty-tom .wejscie > .tytul {
    display: none !important;
  }
  body.otwarty-tom .tom-panel.aktywny {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: 500 !important;
    background-color: #000 !important;
  }
}

/* iPhone landscape MASTER V2: neutralize legacy book and parchment layers.
   Scope strictly to touch landscape; desktop and portrait are unchanged. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny {
    position: fixed !important;
    inset: 0 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
    overflow: hidden !important;
    background: #070a08 !important;
    isolation: isolate;
  }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > :not(.mac-master-book):not(.desktop-master-book-background) {
    display: none !important;
  }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > .desktop-master-book-background {
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: cover !important;
    object-position: center !important;
    z-index: 0 !important;
    pointer-events: none !important;
  }
  /* MASTER host geometry belongs to mac-master-books.css for this profile. */
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .mac-master-book__room { background: none !important; }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .mac-master-book__illustration { display: none !important; }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .mac-master-book__header { z-index: 4 !important; }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .mac-master-book__entry { position: absolute !important; }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .mac-master-book__entry-title { position: relative; }
  html body.mac-master-books-enabled.otwarty-zapis
  .tom-panel[data-panel-tom].aktywny > :not(.pergamin) { display: none !important; }
  html body.mac-master-books-enabled.otwarty-zapis
  .tom-panel[data-panel-tom].aktywny > .pergamin.aktywny {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: 10 !important;
  }
}

/* Keep every zoom/pan/reset control in the visible iPhone viewport,
   above the archive panorama even after the image has been enlarged. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html body.archiwum-aktywne > .iphone-library-zoom-controls {
    position: fixed !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    top: max(6px, env(safe-area-inset-top)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    left: auto !important;
    bottom: auto !important;
    width: max-content !important;
    max-width: calc(100vw - 16px) !important;
    height: auto !important;
    transform: none !important;
    z-index: 2147483000 !important;
    pointer-events: auto !important;
    gap: 4px !important;
  }
  html body.archiwum-aktywne > .iphone-library-zoom-controls > button {
    position: relative !important;
    display: block !important;
    flex: 0 0 auto !important;
    width: 38px !important;
    min-width: 38px !important;
    height: 38px !important;
    min-height: 38px !important;
    margin: 0 !important;
    padding: 0 !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }
}


/* Three Library feathers share the phone panorama's zoom and pan. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html body.archiwum-aktywne .wejscie.otwarty .droga-do-redakcji { display: none !important; }
  html body.archiwum-aktywne .powrot-z-archiwum {
    left: calc(50vw + var(--iphone-library-bg-width, 100vw) * .105 + var(--iphone-library-bg-offset, 0px)) !important;
    top: calc(50dvh + var(--iphone-library-bg-height, 100dvh) * .29) !important;
    bottom: auto !important;
    width: calc(var(--iphone-library-bg-width, 100vw) * .13) !important;
    height: max(44px, calc(var(--iphone-library-bg-height, 100dvh) * .20)) !important;
    transform: translate(-50%, -50%) !important;
    border: 0 !important; border-radius: 0 !important; background: transparent !important;
  }
  html body.archiwum-aktywne .powrot-z-archiwum::after { content: none !important; }
  html body.archiwum-aktywne .desktop-library-standing-quill:not([hidden]),
  html body.archiwum-aktywne .desktop-library-door-feather:not([hidden]) {
    min-width: 44px; min-height: 44px; touch-action: manipulation;
  }
}

