/*
 * The reader (Pages/Index.cshtml): reader bar (contents, context row, tools), the book stage, the
 * fixed navigation bar and the dialogs.
 *
 * Layout rules (doel.md §4):
 *  - The book is sized from the viewport height: header, reader bar and navigation bar have fixed
 *    heights (custom properties below), the stage gets the rest and the book fits inside it. A whole
 *    spread is visible without scrolling, and nothing on the page can move it while paging.
 *  - The facing layout comes from body.reading-mode / body[data-book] and the 760 px query, which
 *    js/boot.js sets before the first paint (no layout shift). JS-only classes (is-book, is-spread,
 *    is-pair, is-current) only add frame-specific details.
 *  - Breakpoints: 760 (two leaves, doel.md §4), 1200 (one-row reader bar), height 500 (phone landscape),
 *    and portrait tablets (760–1199 px, portrait: js/reader/env.js PORTRAIT_MEDIA).
 *  - The chrome heights below are also summed in the `sizes` of the A4 previews (Pages/Index.cshtml,
 *    previewSizes): change both together.
 */
@layer reader {
  :root {
    --edge: 24px;
    --header-h: 64px;
    --bar-h: 64px;
    --context-h: 64px;
    --tools-h: 40px;
    --gap: 12px;
    --nav-h: 60px;
    --nav-bottom: 10px;
    --vh: 100vh;
    --stage-min: 300px;
    --stage-h: max(
      var(--stage-min),
      calc(var(--vh) - var(--header-h) - var(--bar-h) - var(--nav-h) - var(--nav-bottom) - 3 * var(--gap))
    );
    /* When the width limits the book (portrait windows), the stage keeps its height and the free space
       stays below the book: the reader bar sits right under the header (constant while paging).
       Width of two facing A4 leaves (420 × 297 mm) and of one leaf at the stage height. */
    --book-w: calc(var(--stage-h) * 420 / 297);
    --leaf-w: calc(var(--stage-h) * 210 / 297);
  }
  @supports (height: 100svh) {
    :root {
      /* The small viewport height never changes while a mobile address bar shows or hides. */
      --vh: 100svh;
    }
  }
  @media (max-width: 1199.98px) {
    :root {
      --context-h: 56px;
      --bar-h: calc(var(--tools-h) + 6px + var(--context-h));
    }
  }
  @media (max-width: 759.98px) {
    :root {
      --edge: 13px;
      --header-h: 82px;
      --context-h: 52px;
      --gap: 8px;
      --nav-h: 56px;
      --nav-bottom: 8px;
    }
  }
  /* Phone landscape and other short windows: one slim row each. */
  @media (max-height: 500px) {
    :root {
      --stage-min: 160px;
      --header-h: 44px;
      --tools-h: 44px;
      --context-h: 44px;
      --bar-h: 44px;
      --gap: 6px;
      --nav-h: 48px;
      --nav-bottom: 6px;
    }
  }

  body:has(.reader-navigation) {
    padding-bottom: calc(var(--nav-h) + var(--nav-bottom) + 16px);
  }
  /* In the magazine view the footer starts below the fold, not next to the navigation bar. */
  body:not(.reading-mode) .workspace ~ .site-footer {
    margin-top: calc(var(--nav-h) + var(--nav-bottom) + 3 * var(--gap));
  }
  html:has(.reader-navigation) {
    scroll-padding-bottom: calc(var(--nav-h) + var(--nav-bottom) + 16px);
  }

  /* --- Reader bar ------------------------------------------------------------------------------- */
  .reader {
    outline: 0;
  }
  .reader-bar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: 'contents context tools';
    align-items: center;
    gap: 10px;
    height: var(--bar-h);
    /* The contents button and the tools flank the context row, which stays about as wide as the book. */
    width: min(100%, max(calc(var(--book-w) + 320px), 860px));
    margin: var(--gap) auto 0;
  }
  .reading-mode .reader-bar {
    width: min(100%, 890px);
  }
  .contents-button {
    grid-area: contents;
  }
  .contents-button .label-short {
    display: none;
  }
  .reader-context {
    grid-area: context;
  }
  .reader-tools {
    grid-area: tools;
    display: flex;
    gap: 2px;
    justify-content: flex-end;
  }
  .tool-button {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 11px;
    border-radius: 20px;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
  }
  .tool-icon {
    font-size: 17px;
    line-height: 1;
  }
  @media (hover: hover) {
    .tool-button:hover {
      background: var(--tint);
    }
  }
  #reading-toggle[aria-pressed='true'] {
    background: var(--lime);
    color: var(--green);
  }
  /* The toggle names the way back while Lees & doe is on (body.reading-mode is set before the first paint). */
  #reading-toggle .when-reading,
  #reading-toggle .label-short,
  .reading-mode #reading-toggle .when-book {
    display: none;
  }
  .reading-mode #reading-toggle .when-reading {
    display: inline;
  }
  #save-page[aria-pressed='true'] .tool-icon {
    color: var(--focus);
  }

  /* Context row: fixed height, single lines that truncate, so it never pushes the book. */
  .reader-context {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--context-h);
    min-width: 0;
    padding: 0 10px 0 16px;
    background: var(--paper);
    border-left: 3px solid var(--green);
    border-radius: 0 8px 8px 0;
    box-shadow: 0 1px 2px var(--shade);
  }
  .context-text {
    flex: 1;
    min-width: 0;
  }
  .context-eyebrow {
    margin: 0;
    display: flex;
    gap: 8px;
    align-items: baseline;
    font-size: 11px;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    color: var(--muted);
  }
  .context-eyebrow .eyebrow {
    font-size: 10.5px;
    color: var(--ink);
  }
  .spread-heading {
    display: inline-flex;
    gap: 5px;
    align-items: baseline;
    padding: 1px 7px;
    border-radius: 4px;
    background: var(--green);
    color: var(--lime);
    font-size: 10.5px;
    font-weight: 800;
  }
  .spread-heading .eyebrow {
    color: inherit;
  }
  .context-title {
    display: block;
    font: 750 17px/1.3 var(--display);
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .article-route {
    flex: none;
  }
  .article-leaves {
    display: flex;
    gap: 4px;
  }
  .article-leaves button {
    min-width: 34px;
    height: 34px;
    padding: 0 4px;
    border: 1px solid var(--rule);
    border-radius: 6px;
    background: var(--paper);
    font-size: 12px;
    font-weight: 800;
  }
  .article-leaves button[aria-current] {
    background: var(--green);
    color: var(--lime);
    border-color: var(--green);
  }
  .page-action {
    flex: none;
  }
  .action-button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    border-radius: 18px;
    background: var(--lime);
    color: var(--green);
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--green) 25%, transparent);
  }

  /* --- Book stage ------------------------------------------------------------------------------- */
  .reader-stage {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    height: var(--stage-h);
    margin-top: var(--gap);
  }
  .pages {
    position: relative;
    width: min(100%, var(--leaf-w));
    touch-action: pan-y pinch-zoom;
  }
  .magazine-page {
    position: relative;
    background: var(--paper);
  }
  .magazine-page[hidden] {
    display: none;
  }
  /*
   * The magazine view shows the A4 images; screen readers get the text of the visible leaves instead (the
   * same HTML as Lees & doe, visually hidden). Its controls stay out of the keyboard order (sighted keyboard
   * users would land on invisible buttons) while their text stays readable; images and figures are not loaded.
   */
  /*
   * In the magazine view the visually hidden page text stays in the body face: the reading faces of Lees & doe
   * (serif voices, handwriting, display titles) are only downloaded when Lees & doe opens.
   */
  body:not(.reading-mode) .page-live,
  body:not(.reading-mode) .page-live * {
    font-family: var(--body) !important;
  }
  body:not(.reading-mode) .page-live {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    pointer-events: none;
  }
  body:not(.reading-mode)
    .page-live
    :is(button, input, select, textarea, a, summary, [tabindex]:not([tabindex='-1'])) {
    visibility: hidden;
  }
  body:not(.reading-mode) .page-live :is(button, summary) > * {
    visibility: visible;
  }
  body:not(.reading-mode) .page-live :is(img, .fig-canvas, .comic-art, .spread-panorama, .simulation-chart) {
    display: none;
  }
  .reading-mode .page-print {
    display: none;
  }
  body:not(.reading-mode) .magazine-page {
    box-shadow:
      0 1px 3px var(--shade),
      0 12px 32px -8px var(--shade);
  }
  .page-print {
    position: relative;
    aspect-ratio: 210 / 297;
    width: 100%;
    overflow: hidden;
    background: var(--paper);
    cursor: zoom-in;
  }
  .page-print > img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    object-fit: fill;
  }
  /* Placeholder while a preview loads: paper with the page number and title (covered by the image). */
  .page-print::before {
    content: attr(data-number) '\A' attr(data-title);
    white-space: pre-line;
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18%;
    text-align: center;
    font: 750 clamp(13px, 1.6vw, 22px) / 1.3 var(--display);
    color: color-mix(in srgb, var(--ink) 40%, var(--paper));
  }
  .book-placeholder {
    display: none;
    aspect-ratio: 210 / 297;
    background: color-mix(in srgb, var(--paper) 72%, var(--bg));
  }

  @media (min-width: 760px) {
    body:not(.reading-mode):not([data-book='off']) .pages {
      display: grid;
      grid-template-columns: repeat(2, minmax(0, 1fr));
      align-items: start;
      width: min(100%, var(--book-w));
      box-shadow:
        0 1px 3px var(--shade),
        0 14px 36px -10px var(--shade);
    }
    body:not(.reading-mode):not([data-book='off']) .magazine-page {
      box-shadow: none;
      min-width: 0;
    }
    body:not(.reading-mode):not([data-book='off']) .leaf-left {
      grid-column: 1;
    }
    body:not(.reading-mode):not([data-book='off']) .leaf-right {
      grid-column: 2;
    }
    body:not(.reading-mode):not([data-book='off']) .book-placeholder:not([hidden]) {
      display: block;
    }
    body:not(.reading-mode):not([data-book='off']) .book-placeholder[data-side='left'] {
      grid-column: 1;
      grid-row: 1;
    }
    body:not(.reading-mode):not([data-book='off']) .book-placeholder[data-side='right'] {
      grid-column: 2;
      grid-row: 1;
    }
    /* The fold: a soft shadow where the two leaves meet. */
    body:not(.reading-mode):not([data-book='off']) .pages::after {
      content: '';
      position: absolute;
      inset: 0 auto 0 calc(50% - 18px);
      width: 36px;
      pointer-events: none;
      background: linear-gradient(
        90deg,
        transparent,
        rgb(0 0 0 / 0.07) 42%,
        rgb(0 0 0 / 0.16) 50%,
        rgb(0 0 0 / 0.05) 58%,
        transparent
      );
    }
    .pages.is-spread::after {
      opacity: 0.55;
    }
    /* The selected leaf of an open pair (target of Bewaren, Lees & doe and the deep link). */
    .pages.is-pair .magazine-page:not(.is-current) .page-print {
      cursor: pointer;
    }
    .pages.is-pair .magazine-page.is-current .page-print::after {
      content: '';
      position: absolute;
      inset: 0 0 auto;
      height: 4px;
      background: var(--green);
    }
  }

  /* Small screens and portrait tablets: one tap away from readable text (doel.md §4–5). */
  .read-page-button {
    display: none;
    position: absolute;
    z-index: 2;
    left: 50%;
    bottom: 14px;
    transform: translateX(-50%);
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 18px;
    border-radius: 22px;
    background: var(--lime);
    color: var(--green);
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: 0 4px 16px var(--shade);
  }
  @media (max-width: 759.98px), (max-height: 500px) {
    body:not(.reading-mode) .read-page-button {
      display: inline-flex;
    }
    body:not(.reading-mode) .page-print {
      cursor: pointer;
    }
  }
  /* Portrait tablets: two narrow leaves; a tap enlarges the leaf (Vergroot), the button opens Lees & doe. */
  @media (min-width: 760px) and (max-width: 1199.98px) and (orientation: portrait) {
    body:not(.reading-mode) .read-page-button {
      display: inline-flex;
    }
    body:not(.reading-mode) .pages.is-pair .magazine-page .page-print {
      cursor: zoom-in;
    }
  }

  /* Lees & doe: the selected page as flowing HTML, as wide as a comfortable reading column. */
  .reading-mode .reader-stage {
    display: block;
    height: auto;
    max-width: 890px;
    margin-inline: auto;
  }
  .reading-mode .pages {
    width: 100%;
    touch-action: auto;
  }
  .reading-mode #book-toggle {
    display: none;
  }

  /* --- Navigation bar (fixed at the bottom, doel.md §4) ------------------------------------------ */
  .reader-navigation {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: calc(var(--nav-bottom) + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(560px, calc(100% - 24px));
    height: var(--nav-h);
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 12px;
    align-items: center;
    padding: 0 10px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 16px;
    box-shadow: 0 6px 26px var(--shade);
  }
  .page-turn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--paper);
    border: 1px solid var(--rule);
    font-size: 28px;
    line-height: 1;
    padding: 0 0 3px;
  }
  @media (hover: hover) {
    .page-turn:hover:enabled {
      background: var(--lime);
    }
  }
  .reader-position {
    min-width: 0;
    text-align: center;
  }
  #page-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    line-height: 1.4;
    font-weight: 750;
  }
  .page-position {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
  }
  .page-position select {
    border: 0;
    background: transparent;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    padding: 2px;
    max-width: 52px;
  }
  @media (pointer: coarse) {
    /* iOS zooms into form controls below 16 px. */
    .page-position select {
      font-size: 16px;
    }
  }
  .progress-track {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 0;
    height: 3px;
    border-radius: 3px;
    overflow: hidden;
    background: color-mix(in srgb, var(--ink) 10%, var(--paper));
  }
  .progress-track span {
    display: block;
    height: 100%;
    background: var(--green);
    transition: width 0.2s;
  }

  /* --- Narrow desktop and tablet: tools above the context row ------------------------------------ */
  @media (max-width: 1199.98px) {
    .reader-bar {
      grid-template-columns: auto minmax(0, 1fr);
      grid-template-rows: var(--tools-h) var(--context-h);
      grid-template-areas:
        'contents tools'
        'context context';
      row-gap: 6px;
      width: min(100%, max(var(--book-w), 700px));
    }
    .context-title {
      font-size: 16px;
    }
  }

  /* --- Phones -------------------------------------------------------------------------------------- */
  @media (max-width: 759.98px) {
    .reader-bar {
      width: 100%;
      column-gap: 4px;
    }
    .tool-button {
      padding: 0 8px;
      gap: 5px;
      font-size: 13px;
    }
    #book-toggle {
      display: none;
    }
    .contents-button .label-long,
    #reading-toggle .label-long {
      display: none;
    }
    .contents-button .label-short,
    #reading-toggle .label-short {
      display: inline;
    }
    #save-page .tool-label,
    #zoom-page .tool-label {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
    .reader-context {
      padding: 0 8px 0 12px;
      gap: 6px;
    }
    .context-title {
      font-size: 15px;
    }
    .article-leaves {
      gap: 3px;
    }
    .article-leaves button {
      min-width: 30px;
      height: 32px;
    }
    /* The "Lees deze pagina" button on the page opens the activity of this page. */
    .page-action {
      display: none;
    }
    .reader-navigation {
      grid-template-columns: 44px minmax(0, 1fr) 44px;
      gap: 8px;
      border-radius: 14px;
    }
  }

  /* --- Short windows (phone landscape) --------------------------------------------------------------- */
  @media (max-height: 500px) {
    .reader-bar {
      grid-template-columns: auto minmax(0, 1fr) auto;
      grid-template-rows: var(--bar-h);
      grid-template-areas: 'contents context tools';
      width: 100%;
    }
    .tool-button {
      height: 36px;
    }
    .reader-bar .tool-label {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
    }
    .contents-button .label-short {
      display: none;
    }
    .contents-button .label-long {
      display: inline;
    }
    .context-eyebrow {
      display: none;
    }
    .context-title {
      font-size: 14px;
    }
    .read-page-button {
      bottom: 8px;
      height: 38px;
      font-size: 14px;
    }
    .page-turn {
      width: 38px;
      height: 38px;
    }
    .reader-navigation {
      grid-template-columns: 38px minmax(0, 1fr) 38px;
    }
    #page-name {
      font-size: 12px;
    }
  }

  /* --- Dialogs ----------------------------------------------------------------------------------------- */
  dialog {
    color: var(--ink);
    border: 1px solid var(--rule);
    border-radius: 12px;
    padding: 28px;
    max-width: 560px;
    width: calc(100% - 30px);
    max-height: 88vh;
    /* The visible height while a mobile toolbar shows (vh is the tallest viewport). */
    max-height: 88dvh;
    background: var(--paper);
    box-shadow: 0 20px 70px var(--shade);
  }
  dialog::backdrop {
    background: color-mix(in srgb, var(--ink) 65%, transparent);
    backdrop-filter: blur(4px);
  }
  .dialog-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 18px;
  }
  .dialog-header h2 {
    font: 800 29px/1.2 var(--display);
    letter-spacing: -0.8px;
    margin: 6px 0;
  }
  .close-dialog {
    font-size: 30px;
    background: color-mix(in srgb, var(--ink) 8%, var(--paper));
    border-radius: 50%;
    width: 40px;
    height: 40px;
    line-height: 1;
    flex-shrink: 0;
  }
  .dialog-subheading {
    margin: 22px 0 8px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
  }

  /* Contents: saved pages, spotlights and the mascot question, then every page. */
  .contents-dialog {
    max-width: 820px;
  }
  .contents-dialog .dialog-header {
    position: sticky;
    z-index: 1;
    top: -28px;
    margin: -28px -28px 10px;
    padding: 22px 28px 12px;
    background: var(--paper);
    border-bottom: 1px solid var(--rule);
  }
  .saved-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .saved-list button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 8px;
    border-radius: 18px;
    background: var(--tint);
    font-size: 13px;
    text-align: left;
  }
  .saved-list .contents-number {
    font: 800 15px var(--display);
    color: var(--green);
  }
  .spotlight-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
  }
  .teaser {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg) 55%, var(--paper));
    text-align: left;
  }
  .teaser > img {
    width: 64px;
    height: 76px;
    object-fit: cover;
    border-radius: 4px;
    flex: none;
  }
  .teaser-number {
    flex: none;
    display: grid;
    place-items: center;
    width: 64px;
    height: 76px;
    border-radius: 4px;
    background: var(--green);
    color: var(--lime);
    font: 800 26px var(--display);
  }
  .teaser-text {
    min-width: 0;
  }
  .teaser small {
    display: block;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    color: var(--muted);
  }
  .teaser strong {
    display: block;
    margin: 3px 0;
    font: 700 16px/1.2 var(--display);
  }
  .teaser em {
    font-size: 12px;
    font-style: normal;
    color: var(--muted);
  }
  .mascot-note {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: 8px;
    background: var(--tint);
  }
  .mascot-note img {
    width: 64px;
    height: 88px;
    object-fit: contain;
    flex: none;
  }
  .mascot-note small {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.07em;
  }
  .mascot-note p {
    font-size: 14px;
    line-height: 1.5;
    margin: 4px 0 6px;
  }
  .mascot-note button {
    background: transparent;
    padding: 4px 0;
    font-size: 13px;
    font-weight: 800;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 3px;
  }
  .contents-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 24px;
  }
  .contents-list button {
    display: flex;
    gap: 14px;
    align-items: center;
    background: none;
    border-bottom: 1px solid var(--rule);
    padding: 13px 6px;
    text-align: left;
  }
  .contents-list .contents-number {
    font: 800 23px var(--display);
    color: var(--green);
    min-width: 31px;
  }
  .contents-text {
    flex: 1;
    min-width: 0;
  }
  .contents-list small {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
  }
  .contents-list strong {
    display: block;
    margin-top: 3px;
    font: 700 16px/1.25 var(--display);
  }
  .contents-list button > b {
    font-size: 16px;
    color: var(--muted);
  }
  .contents-list button.is-visible {
    background: color-mix(in srgb, var(--lime) 18%, var(--paper));
  }
  .contents-list button[aria-current='page'] {
    background: var(--tint);
    box-shadow: inset 3px 0 0 var(--green);
  }
  .contents-list button.bookmarked strong::after {
    content: ' ★';
    color: var(--focus);
  }

  #print-dialog > .button {
    width: 100%;
    margin: 7px 0;
  }
  .print-file {
    margin: 0 0 4px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
  }
  .edition-card {
    display: flex;
    gap: 21px;
    border: 1px solid var(--rule);
    padding: 15px;
    border-radius: 6px;
    text-decoration: none;
  }
  .edition-card img {
    flex: none;
    width: 100px;
    height: 130px;
    object-fit: cover;
  }
  .edition-card span {
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  .edition-card small {
    font-size: 11px;
  }
  .edition-card strong {
    font: 750 23px var(--display);
    margin: 10px 0;
  }
  .edition-card em {
    font-size: 12px;
    font-style: normal;
  }

  /* Vergroot: a large viewer with zoom steps and page turning (js/reader/zoom.js). */
  .zoom-dialog {
    width: calc(100vw - 24px);
    max-width: 1600px;
    height: calc(100vh - 24px);
    height: calc(100dvh - 24px);
    max-height: none;
    padding: 14px 16px 16px;
    flex-direction: column;
  }
  .zoom-dialog[open] {
    display: flex;
  }
  .zoom-header {
    margin-bottom: 10px;
    gap: 12px;
  }
  .zoom-title h2 {
    font-size: 22px;
    margin: 2px 0;
  }
  .zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
  }
  .zoom-button {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    border-radius: 20px;
    background: color-mix(in srgb, var(--ink) 7%, var(--paper));
    font-size: 20px;
    font-weight: 700;
    line-height: 1;
  }
  .zoom-fit {
    font-size: 13px;
  }
  .zoom-level {
    min-width: 64px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
  }
  .zoom-viewport {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    background: color-mix(in srgb, var(--ink) 14%, var(--bg));
    border-radius: 8px;
    touch-action: pan-x pan-y pinch-zoom;
  }
  .zoom-leaves {
    display: flex;
    justify-content: center;
    width: max-content;
    min-width: 100%;
    margin: 0 auto;
  }
  .zoom-leaves img {
    display: block;
    max-width: none;
    height: auto;
    aspect-ratio: 210 / 297;
    background: var(--paper);
  }
  .zoom-viewport.is-spread .zoom-leaves img {
    aspect-ratio: 420 / 297;
  }
  /* "Hele dubbele pagina": floats over the bottom of the view while one leaf of a spread is shown. */
  .zoom-spread {
    position: absolute;
    z-index: 1;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 44px;
    padding: 0 18px;
    border-radius: 22px;
    background: var(--paper);
    color: var(--ink);
    font-size: 14px;
    font-weight: 800;
    white-space: nowrap;
    box-shadow: 0 4px 16px var(--shade);
  }
  .zoom-spread[aria-pressed='true'] {
    background: var(--lime);
    color: var(--green);
  }

  /* --- Status message ---------------------------------------------------------------------------------- */
  .notification {
    position: fixed;
    bottom: calc(var(--nav-h) + var(--nav-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    max-width: 90vw;
    padding: 14px 25px;
    border-radius: 8px;
    background: var(--green);
    color: white;
    font-size: 14px;
    box-shadow: 0 4px 20px var(--shade);
    opacity: 0;
    visibility: hidden;
    transition:
      opacity 0.2s,
      visibility 0.2s;
  }
  .notification.is-visible {
    opacity: 1;
    visibility: visible;
  }

  @media (max-width: 759.98px) {
    dialog {
      padding: 20px;
    }
    .contents-dialog .dialog-header {
      top: -20px;
      margin: -20px -20px 10px;
      padding: 16px 20px 10px;
    }
    .dialog-header h2 {
      font-size: 24px;
    }
    .contents-list {
      grid-template-columns: 1fr;
    }
    .zoom-dialog {
      width: 100vw;
      height: 100vh;
      height: 100dvh;
      max-width: none;
      border-radius: 0;
      padding: 10px;
    }
    .zoom-dialog .zoom-title .eyebrow,
    .zoom-fit {
      display: none;
    }
    /* One line for "Pagina 4" next to the controls. */
    .zoom-header {
      gap: 6px;
    }
    .zoom-title h2 {
      font-size: 18px;
      letter-spacing: -0.3px;
      white-space: nowrap;
    }
    .zoom-controls {
      gap: 4px;
    }
    .zoom-button {
      min-width: 36px;
      height: 36px;
    }
    .zoom-level {
      min-width: 52px;
    }
  }
  @media (max-width: 400px) {
    .zoom-controls {
      gap: 2px;
    }
    .zoom-button {
      min-width: 32px;
      padding: 0 6px;
    }
    .zoom-level {
      min-width: 44px;
    }
    .zoom-title h2 {
      font-size: 16px;
    }
    .zoom-dialog .close-dialog {
      width: 36px;
      height: 36px;
    }
  }
}
