/* KRONIKARZ — MAC ONLY — one MASTER book system for TOM I–XII.
   The approved book art is shared by every volume. Legacy per-TOM book geometry
   remains untouched for mobile/tablet and is hidden only in desktop-pointer mode. */
@media (hover: hover) and (pointer: fine), (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    overflow: hidden !important;
    /* Site-colored letterbox bands only; the room layer owns the scene. */
    background: #070a08 !important;
    z-index: 120 !important;
  }

  body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > :not(.mac-master-book):not(.pergamin):not(.desktop-master-book-background) {
    display: none !important;
  }

  .mac-master-book {
    display: none;
  }

  body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > .mac-master-book {
    display: block !important;
    position: fixed;
    inset: 0;
    /* Portrait Redakcja composition from ksiega-tom-ii(3).png. */
    width: min(100%, calc(100vh * 1161 / 1354));
    height: min(100vh, calc(100vw * 1354 / 1161));
    margin: auto;
    overflow: hidden;
    isolation: isolate;
    font-family: Georgia, 'Times New Roman', serif;
    text-align: left;
  }

  body.mac-master-books-enabled.otwarty-zapis .mac-master-book {
    display: none !important;
  }

  .mac-master-book__room {
    position: absolute;
    inset: 0;
    background: url('/src/assets/redakcja/mac-redakcja-room.png') center / contain no-repeat;
    /* Tone only the room, leaving foreground parchment and ink unchanged. */
    filter: brightness(0.83) contrast(0.92) saturate(0.85);
    z-index: 0;
    pointer-events: none;
  }

  .mac-master-book__frame {
    /* Book art and entries share this independent frame on the tabletop. */
    position: absolute;
    top: 66%;
    left: 50%;
    width: 85.8%;
    height: auto;
    aspect-ratio: 1443 / 1090;
    transform: translate(-50%, -50%);
    overflow: visible;
    z-index: 1;
    filter: none;
    container-type: inline-size;
  }

  .mac-master-book__art {
    position: absolute;
    inset: 0;
    background: url('/src/assets/redakcja/ksiega-master-mac-parchment.png') center / contain no-repeat;
    filter: saturate(0.55) sepia(0.12);
    /* Reuse only the approved foreground alpha, preserving its exact outline
       and scene integration. None of the old painted winettes is displayed. */
    mask: url('/src/assets/redakcja/ksiega-master-mac-foreground.png') center / contain no-repeat;
    -webkit-mask: url('/src/assets/redakcja/ksiega-master-mac-foreground.png') center / contain no-repeat;
    z-index: 0;
    pointer-events: none;
  }

  .mac-master-book__header {
    position: absolute;
    left: 50%;
    top: 6%;
    width: 88%;
    height: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateX(-50%);
    z-index: 4;
    text-align: center;
    color: #e7c692;
  }

  .mac-master-book__header::before {
    content: '';
    position: absolute;
    left: -5%;
    right: -5%;
    top: 1%;
    bottom: 0;
    background: none;
    z-index: -1;
    pointer-events: none;
  }

  .mac-master-book__tom {
    margin: 0;
    font-size: clamp(25px, 3vh, 47px);
    line-height: 1;
    letter-spacing: 0.08em;
    text-shadow: 0 2px 6px #000;
  }

  .mac-master-book__title {
    margin: 10px auto 0;
    max-width: 96%;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(28px, 3.7vh, 50px);
    font-weight: 700;
    line-height: 1.08;
    letter-spacing: 0;
    text-transform: none;
    color: #eee4d2;
    text-shadow: 0 2px 5px #000;
  }

  /* TOM VIII's legacy all-button reset must not erase the MASTER return art. */
  .mac-master-book__archive,
  body.mac-master-books-enabled.otwarty-tom
  .tom-panel[data-panel-tom="8"].aktywny .mac-master-book__archive {
    position: relative;
    width: 38%;
    height: auto;
    aspect-ratio: 386 / 78;
    margin: 14px auto 0;
    padding: 0;
    flex: none;
    transform: none;
    border: 0;
    border-radius: 0;
    outline: none;
    /* Reuse the approved printed return frame, without repainting its label. */
    background: url('/src/assets/redakcja/mac-tom-header-reference.png')
      44.3871% 17.0846% / 300.7772% 1735.8974% no-repeat !important;
    color: transparent !important;
    font: 600 clamp(10px, 1.25vh, 17px)/1.15 Georgia, 'Times New Roman', serif !important;
    letter-spacing: 0;
    cursor: pointer;
    text-shadow: none;
    box-shadow: none !important;
  }

  .mac-master-book__archive:hover,
  .mac-master-book__archive:focus-visible {
    opacity: 0.9;
    color: transparent !important;
    outline: none;
  }

  .mac-master-book__divider {
    width: 35%;
    aspect-ratio: 350 / 42;
    margin: 10px auto 0;
    background: url('/src/assets/redakcja/mac-tom-header-reference.png')
      44.3896% 23.1707% / 331.7143% 3223.8095% no-repeat;
    mix-blend-mode: lighten;
    pointer-events: none;
  }

  .mac-master-book__tagline {
    margin: 8px auto 0;
    color: #b9a67f;
    font: 400 clamp(9px, 0.95vh, 14px)/1.35 Georgia, 'Times New Roman', serif;
    letter-spacing: 0.12em;
    text-align: center;
  }

  .mac-master-book__entries {
    position: absolute;
    inset: 0;
    z-index: 2;
  }

  .mac-master-book__entry {
    position: absolute;
    top: var(--entry-top);
    /* Open parchment columns beside the vignettes; these are invisible
       positioning/click regions, independent of the retired writing frames. */
    width: 20.0%;
    height: 12.0%;
    box-sizing: border-box;
    margin: 0;
    padding: 0.35% 0.45%;
    border: 0;
    border-radius: 0;
    outline: none;
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    background: transparent !important;
    color: #2b1a0f;
    text-align: left;
    font-family: "Noteworthy", "Bradley Hand", "Apple Chancery", "Segoe Print", cursive;
    font-weight: 400;
    text-transform: none;
    text-shadow: none;
    line-height: 1.12;
    cursor: pointer;
    box-shadow: none !important;
    overflow: visible;
  }

  .mac-master-book__entry[data-page-side="left"] {
    left: 23.0%;
  }

  .mac-master-book__entry[data-page-side="right"] {
    left: 55.0%;
  }

  /* TOM VI's longer live titles need taller targets within the three-row spread.
     Keep the approved fonts and illustration scale unchanged. */
  .mac-master-book[data-master-tom="6"] .mac-master-book__entry {
    height: 16%;
  }

  .mac-master-book[data-master-tom="6"] .mac-master-book__illustration {
    height: 101.25%;
  }

  .mac-master-book__illustration {
    position: absolute;
    top: -5%;
    width: 72%;
    height: 135%;
    max-width: none;
    object-fit: contain;
    /* Grow into the outer parchment margin; keep the title-side edge fixed. */
    transform: scale(var(--mac-illustration-scale, 1.10));
    pointer-events: none;
    user-select: none;
    mix-blend-mode: multiply;
    opacity: 0.83;
    filter: sepia(1) saturate(0.55) contrast(0.87);
    mask-image: radial-gradient(ellipse, #000 42%, rgba(0,0,0,.72) 65%, transparent 94%);
    -webkit-mask-image: radial-gradient(ellipse, #000 42%, rgba(0,0,0,.72) 65%, transparent 94%);
  }

  .mac-master-book__entry[data-page-side="left"] .mac-master-book__illustration {
    right: 103%;
    transform-origin: right center;
  }

  .mac-master-book__entry[data-page-side="right"] .mac-master-book__illustration {
    left: 106%;
    transform-origin: left center;
  }

  /* Airier 4–5-entry volumes have room for stronger artwork presence. */
  .mac-master-book[data-master-tom="4"],
  .mac-master-book[data-master-tom="5"],
  .mac-master-book[data-master-tom="8"],
  .mac-master-book[data-master-tom="9"],
  .mac-master-book[data-master-tom="10"],
  .mac-master-book[data-master-tom="11"],
  .mac-master-book[data-master-tom="12"] {
    --mac-illustration-scale: 1.18;
  }

  button.mac-master-book__entry:hover:not(:disabled),
  button.mac-master-book__entry:focus-visible:not(:disabled) {
    background: transparent !important;
    transform: none;
    box-shadow: none !important;
    outline: none;
    color: #3b2112;
  }

  .mac-master-book__entry-number {
    display: block;
    margin: 0 0 0.1em;
    font-family: inherit;
    font-size: 3.0cqw;
    line-height: 1.05;
    font-weight: 400;
    letter-spacing: 0;
    color: #25160c;
    -webkit-text-stroke: 0.06px currentColor;
  }

  .mac-master-book .mac-master-book__entry-title {
    display: block;
    width: 94%;
    margin: 0 auto;
    font-family: inherit;
    font-size: 2.05cqw;
    line-height: 1.18;
    font-weight: 700;
    letter-spacing: 0;
    color: #1e1008;
    -webkit-text-stroke: 0.38px currentColor;
    overflow-wrap: break-word;
    text-wrap: pretty;
    text-align: center;
  }

  .mac-master-book .mac-master-book__entry--short .mac-master-book__entry-title {
    font-size: 2.35cqw;
    line-height: 1.16;
  }

  .mac-master-book .mac-master-book__entry--long .mac-master-book__entry-title {
    font-size: 1.75cqw;
    line-height: 1.20;
  }

  .mac-master-book__entry[disabled] {
    cursor: default;
    color: #342015;
    background: transparent !important;
  }

  .mac-master-book__entry[disabled]::after {
    content: '';
    position: absolute;
    right: -5%;
    bottom: -9%;
    width: 18%;
    aspect-ratio: 1;
    background: url('/src/assets/redakcja/mac-seal-burgundy.svg') center / contain no-repeat;
    pointer-events: none;
  }

  .mac-master-book__page {
    position: absolute;
    top: 93.8%;
    z-index: 8;
    width: 7.5%;
    height: 3.7%;
    border: 1px solid rgba(92, 53, 24, 0.50);
    border-radius: 999px;
    background: rgba(219, 183, 126, 0.84);
    color: #3c2414;
    font: 700 clamp(12px, 1.7vh, 22px)/1 Georgia, serif;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(61, 35, 15, 0.18);
  }

  .mac-master-book__page--previous { left: 35.0%; }
  .mac-master-book__page--next { right: 35.0%; }

  .mac-master-book__page:hover,
  .mac-master-book__page:focus-visible {
    background: rgba(239, 210, 160, 0.95);
  }

  .mac-master-book__page-indicator {
    position: absolute;
    left: 50%;
    top: 95.65%;
    transform: translate(-50%, -50%);
    z-index: 8;
    min-width: 7%;
    text-align: center;
    color: #51331c;
    font: 700 clamp(8px, 1.0vh, 13px)/1 Georgia, serif;
    letter-spacing: 0.08em;
    text-shadow: 0 1px 0 rgba(255, 238, 201, 0.40);
  }
}

/* TOM XIII has no entry illustrations yet. Keep the MASTER rows, giving its
   approved full titles the available parchment width only in this book. */
@media (hover: hover) and (pointer: fine), (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  .mac-master-book[data-master-tom="13"] .mac-master-book__entry {
    width: 32%;
    height: 21%;
  }
  .mac-master-book[data-master-tom="13"] .mac-master-book__entry[data-page-side="left"] {
    left: 12%;
  }
  .mac-master-book[data-master-tom="13"] .mac-master-book__entry[data-page-side="right"] {
    left: 55%;
  }
}

/* Preserve the approved header composition instead of wrapping its fixed-size
   controls over the first entry row in a narrow Mac window. */
@media (max-width: 600px) and (hover: hover) and (pointer: fine) {
  body.mac-master-books-enabled .mac-master-book__header {
    width: calc(88% / var(--master-book-header-scale, 1));
    transform: translateX(-50%) scale(var(--master-book-header-scale, 1));
    transform-origin: top center;
  }
}

/* A touch profile must never display a retained desktop MASTER node. */
@media (orientation: portrait) and (hover: none), (orientation: portrait) and (pointer: coarse) {
  .mac-master-book,
  .desktop-master-book-background {
    display: none !important;
  }
}

/* MASTER title margins measured on the 1443 × 1090 parchment artwork.
   At the occupied rows the outer rules reach x≈146 (left) and x≈1274
   (right); the spine ornaments reach x≈693/732. Keep an ink gutter:
   left title zone x=158.73..663.78, right x=764.79..1262.625.
   cqw measures the unchanged book frame, never the hotspot column.
   Higher specificity overrides only the later title-layout text layer. */
@media (hover: hover) and (pointer: fine) {
  body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry .mac-master-book__entry-title {
    width: 35cqw;
    max-width: none;
    margin: 0;
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    -webkit-hyphens: none;
  }

  body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry[data-page-side="left"] .mac-master-book__entry-title {
    left: -12cqw; /* entry x=23cqw; title x=11cqw */
  }

  body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry[data-page-side="right"] .mac-master-book__entry-title {
    left: -2cqw; /* entry x=55cqw; title x=53cqw */
    width: 34.5cqw;
  }

  body.mac-master-books-enabled .mac-master-book[data-master-tom="13"]
  .mac-master-book__entry[data-page-side="left"] .mac-master-book__entry-title {
    left: -1cqw; /* TOM XIII entry x=12cqw; same title x=11cqw */
  }
}

/* Public TOM X (Polczat) is technical MASTER 1.
   Anchor its title directly below the unchanged 3.45cqw number line.
   Absolute placement prevents a relative/in-flow offset being added twice.
   Keep the measured horizontal margins, fonts, hotspots and rows intact. */
@media (hover: hover) and (pointer: fine) {
  body.mac-master-books-enabled .mac-master-book[data-master-tom="1"]
  .mac-master-book__entry .mac-master-book__entry-title {
    position: absolute !important;
    top: 3.45cqw;
  }
}

/* TOM IX's approved renderer sets titles to relative positioning inline.
   Place only the title below the existing number line; otherwise its normal
   flow position and top offset add together. Preserve labels and row anchors. */
@media (hover: hover) and (pointer: fine) {
  body.mac-master-books-enabled .mac-master-book[data-master-tom="9"]
  .mac-master-book__entry .mac-master-book__entry-title {
    position: absolute !important;
    top: 3.45cqw;
  }
}

/* iPhone landscape MASTER: same approved artwork and hotspots, scaled to
   the short landscape viewport. Does not change desktop-pointer rendering. */
@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 {
    z-index: 2147480000 !important;
    overflow: hidden !important;
  }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > .mac-master-book {
    display: block !important;
    position: absolute !important;
    padding: 0 !important;
    z-index: 2 !important;
    width: min(100vw, calc(100dvh * 1161 / 1354)) !important;
    height: min(100dvh, calc(100vw * 1354 / 1161)) !important;
    inset: 0 !important;
    margin: auto !important;
    transform: none !important;
    overflow: hidden !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;
  }
  html body.mac-master-books-enabled.otwarty-tom:not(.otwarty-zapis)
  .tom-panel[data-panel-tom].aktywny > :not(.mac-master-book):not(.pergamin):not(.desktop-master-book-background) {
    display: none !important;
  }
  html body.mac-master-books-enabled .mac-master-book__entry {
    touch-action: manipulation;
  }
  html body.mac-master-books-enabled .mac-master-book__archive {
    touch-action: manipulation;
    min-height: 22px;
  }
  html body.mac-master-books-enabled .mac-master-book__page {
    touch-action: manipulation;
    min-height: 22px;
  }
  html body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry .mac-master-book__entry-title {
    width: 35cqw;
    max-width: none;
    margin: 0;
    word-break: normal;
    overflow-wrap: normal;
    hyphens: none;
    -webkit-hyphens: none;
  }
  html body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry[data-page-side="left"] .mac-master-book__entry-title {
    left: -12cqw;
  }
  html body.mac-master-books-enabled .mac-master-book[data-master-tom]
  .mac-master-book__entry[data-page-side="right"] .mac-master-book__entry-title {
    left: -2cqw;
    width: 34.5cqw;
  }
  html body.mac-master-books-enabled .mac-master-book[data-master-tom="13"]
  .mac-master-book__entry[data-page-side="left"] .mac-master-book__entry-title {
    left: -1cqw;
  }
  html body.mac-master-books-enabled .mac-master-book[data-master-tom="1"]
  .mac-master-book__entry .mac-master-book__entry-title,
  html body.mac-master-books-enabled .mac-master-book[data-master-tom="9"]
  .mac-master-book__entry .mac-master-book__entry-title {
    position: absolute !important;
    top: 3.45cqw;
  }
}

/* Share the existing tagline typography for approved book subtitles. Reclaim
   header gaps only, keeping every book frame and entry coordinate unchanged. */
@media (hover: hover) and (pointer: fine) {
  .mac-master-book__header:has(.mac-master-book__subtitle) .mac-master-book__archive {
    margin-top: 8px !important;
  }
  .mac-master-book__header:has(.mac-master-book__subtitle) .mac-master-book__divider {
    margin-top: 8px;
  }
  .mac-master-book__header:has(.mac-master-book__subtitle) > .mac-master-book__tagline:last-child {
    margin-top: 6px;
  }
  .mac-master-book__subtitle {
    max-width: 96%;
    text-wrap: pretty;
  }
}

/* iPhone: keep public TOM X's pagination clear of Safari's bottom safe area.
   Move only its controls; the book, entry slots and typography stay anchored. */
@media (orientation: landscape) and (max-height: 600px) and (hover: none) and (pointer: coarse) {
  html[data-mobile-raven-door="true"] body.mac-master-books-enabled
  .mac-master-book[data-master-tom="1"] .mac-master-book__page {
    top: calc(93.8% - 18px - env(safe-area-inset-bottom, 0px));
  }
  html[data-mobile-raven-door="true"] body.mac-master-books-enabled
  .mac-master-book[data-master-tom="1"] .mac-master-book__page--previous { left: 0; }
  html[data-mobile-raven-door="true"] body.mac-master-books-enabled
  .mac-master-book[data-master-tom="1"] .mac-master-book__page--next { right: 0; }
  html[data-mobile-raven-door="true"] body.mac-master-books-enabled
  .mac-master-book[data-master-tom="1"] .mac-master-book__page-indicator {
    top: calc(95.65% - 18px - env(safe-area-inset-bottom, 0px));
  }
}
