/* Keep content readable when a scene no longer has room for its desktop layout. */
#viewport { width: 100%; }
.domain-entry > div, .quick-links > *, .edition-card, .paper-feature-slot,
.paper-feature-intro, .paper-tools-grid > *, .paper-about > * { min-width: 0; }
.domain-entry, .site-colophon, .gallery-contact > a, .journey-email,
.edition-card-copy { overflow-wrap: anywhere; }
.toast { max-width: calc(100% - 32px); text-align: center; }
.paper-menu { overflow-y: auto; }
.paper-masthead { font-size: 16.5vw; }
.edition-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.os-popup { max-height: calc(100% - 100px); overflow-y: auto; }
.desktop-icons { bottom: 110px; overflow-y: auto; scrollbar-width: thin; }
.desktop-icons .app-icon { flex-shrink: 0; }
.os-window { max-width: calc(100% - 24px); min-height: 0; }
.os-welcome-links { flex-wrap: wrap; }
.os-welcome, .settings-body, .os-domains { overflow-wrap: anywhere; }
.os-dock { min-width: 0; }
.os-taskbar { max-width: 100%; }

/* Static reading remains an explicit motion preference, never a size fallback. */
.reading-pages .folio-face {
  position: relative; min-width: 0; min-height: 510px; height: auto;
  padding: 30px; transform: none; backface-visibility: visible; overflow: visible;
  display: flex; flex-direction: column;
}
.reading-pages .page-folio { position: static; margin-top: auto; padding-top: 12px; gap: 10px; }
.reading-pages .book-domain-list { margin-bottom: 24px; }
.reading-pages .folio-face > p { font-size: 14px; line-height: 1.8; }
.reading-pages .book-domain-list .domain-entry p { font-size: 13px; }
.reading-pages .book-domain-list .domain-entry b { font-size: 17px; }
.reading-pages .book-domain-list .domain-entry small,
.reading-pages .book-utilities small, .reading-pages .book-colophon { font-size: 11px; }
.reading-pages .inside-toc button, .reading-pages .book-utilities > a { min-height: 44px; }
.reading-pages .book-work-link { margin-bottom: 24px; }

/* Lay out text at its displayed resolution before applying the page-turn transforms.
   Scaling the 730px composited scene magnifies its cached text texture on 2K screens. */
@supports (zoom: 1) {
  .book-desk {
    width: calc(730px * var(--book-scale, 1));
    height: calc(465px * var(--book-scale, 1));
    transform: translate(-50%, -50%);
    perspective: calc(2000px * var(--book-scale, 1));
  }
  .bound-book { width: 730px; height: 465px; zoom: var(--book-scale, 1); }
}

/* Cover lettering needs sturdy strokes at every book size. */
.book-cloth { color: #24251f; padding: 28px 28px 26px; }
.book-cloth > span, .book-cloth > small {
  font: 600 10px/1.5 var(--sans); letter-spacing: 1px;
}
.book-cloth h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 64px; font-weight: 700; line-height: .95;
  letter-spacing: -3px; margin: 26px 0 12px;
}
.book-cloth p { font-size: 14px; font-weight: 500; line-height: 1.8; margin-top: 12px; }
.book-cloth h2 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 20px; font-weight: 600; line-height: 1.2; margin-bottom: 16px;
}
.book-cloth h2 i { font-size: 22px; }
.book-ornament { font-size: 32px; margin: 10px 0 8px; }
.back-emblem { font-family: Georgia, 'Times New Roman', serif; font-weight: 700; }
.back-cloth h2 { font-size: 28px; margin-top: 28px; }

/* All book action rows share the technical chapter's interaction feedback. */
body[data-mode=book] :is(.book-domain-list .domain-entry, .book-utilities > a, .folio-face .quick-links > a, .folio-face .quick-links > button) {
  transition: background-color .16s ease, color .16s ease;
}
body[data-mode=book] :is(.book-domain-list .domain-entry, .book-utilities > a, .folio-face .quick-links > a, .folio-face .quick-links > button):is(:hover, :focus-visible) {
  background-color: #2423210a; color: #923c2c;
}
@media (prefers-reduced-motion: reduce) {
  body[data-mode=book] :is(.book-domain-list .domain-entry, .book-utilities > a, .folio-face .quick-links > a, .folio-face .quick-links > button) { transition: none; }
}

@media (max-width: 759px) {
  .edition-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reading-pages, .reduced-motion .reading-pages { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 20px; }
  .reading-pages .folio-face, .reduced-motion .reading-pages .folio-face { padding: 24px; }
  .reading-edition { padding-right: 0; }
  .paper-feature-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .paper-feature-intro { grid-column: 1 / -1; grid-row: 1; border: 0; padding: 10px 0 24px; }
  .paper-tools-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .paper-header { height: auto; min-height: 65px; gap: 12px; flex-wrap: wrap; padding: 12px 0; }
  .paper-header > b { font-size: clamp(14px, 3vw, 19px); }
  .paper-header-actions { margin-left: auto; gap: 10px; }
  .paper-menu > [data-paper-jump] { font-size: clamp(18px, 5vw, 30px); }
  .gallery-index nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .gallery-panel { padding: 40px 24px; }
  .gallery-intro { padding-top: 100px; }
  .gallery-panel h2 { font-size: clamp(32px, 9vw, 46px); }
  .gallery-intro h1 { font-size: clamp(36px, 11vw, 54px); }
  .gallery-toolbox > div > a { flex-wrap: wrap; }
  .gallery-toolbox small { flex-basis: 100%; }
  .os-window { left: 8px !important; top: 160px !important; width: calc(100% - 16px) !important; height: calc(100% - 255px) !important; min-height: 0; max-width: none; }
  .desktop-icons { top: 82px; bottom: auto; left: 8px; right: 8px; flex-direction: row; gap: 8px; overflow-x: auto; overflow-y: hidden; }
  .desktop-icons .app-icon { min-height: 68px; width: 70px; }
  .desktop-personalize { max-width: calc(100% - 24px); }
  .os-taskbar .os-dock { overflow-x: auto; overflow-y: hidden; }
  .os-taskbar .app-icon { flex-shrink: 0; }
  .os-taskbar .app-icon span { display: none; }
  .os-taskbar > button, .task-tray { flex-shrink: 0; }
  [data-os=windows] .task-tray { position: static; margin-left: auto; }
  .desktop-legal { flex-wrap: wrap; padding: 0 8px; gap: 3px 10px; bottom: 74px; }
  [data-os=windows] .desktop-legal { bottom: 56px; }
  .os-welcome > h1 { font-size: clamp(24px, 7vw, 32px); }
  .os-welcome > img { float: none; margin-bottom: 16px; }
  .os-popup { max-height: calc(100% - 100px); }
  .journey-email { font-size: clamp(17px, 5.5vw, 22px); }
}

@media (max-width: 480px) {
  .paper-about, .paper-tools-grid, .paper-domain-grid { grid-template-columns: minmax(0, 1fr); }
  .paper-profile { border-right: 0; padding-right: 0; }
  .paper-domain-grid .domain-entry:nth-child(n) { border-right: 0; }
  .paper-profile h2 { font-size: 10vw; }
  .paper-profile h2 strong { font-size: 15vw; }
  .paper-tools > header { flex-wrap: wrap; gap: 12px; }
  .paper-tools h2 { font-size: 10vw; }
  .paper-contact .quick-links > * { width: 80px; height: 80px; }
  .edition-picker-panel > header { gap: 10px; }
}

@media (max-height: 600px) {
  .desktop-status { display: none; }
  .desktop-icons { bottom: 90px; }
  .os-window { top: 85px !important; height: calc(100% - 180px) !important; min-height: 0; }
  .os-window.maximized { top: 34px !important; }
}
@media (max-height: 600px) and (max-width: 759px) {
  .desktop-icons { bottom: auto; }
  .os-window { top: 160px !important; height: calc(100% - 255px) !important; }
}
@media (pointer: coarse) {
  .edition-entry, .edition-close, .dialog-close, .book-pagination button,
  .paper-header-actions button, .journey-header button { min-height: 44px; min-width: 44px; }
}

/* Preserve the book spread and page turns on phones, tablets and short screens. */
@media (max-width: 1100px), (max-height: 650px) {
  .library-header { top: 14px; left: 16px; right: 16px; font-size: 10px; align-items: center; }
  .library-header .entry-book { margin-top: -14px; padding: 12px 14px 20px; }
  .library-header .edition-entry span { display: inline; }
  .book-index { top: 68px; left: 16px; right: 16px; width: auto; transform: none; }
  .book-index h2, .book-index > p { display: none; }
  .book-index > .literary-toc { display: flex; overflow-x: auto; gap: 16px; }
  .book-index .literary-toc button { width: auto; min-height: 44px; flex-shrink: 0; padding: 8px 0; font-size: 12px; }
  .book-index .literary-toc button span { font-size: 0; }
  .book-index .literary-toc button span::after { content: attr(data-short); font: 12px var(--sans); }
  .book-index .literary-toc i { display: none; }
  .book-desk, .book-pagination, .book-scroll-hint { left: 50%; }
  .book-pagination { bottom: 22px; gap: 16px; font-size: 11px; }
  .book-pagination button { min-width: 48px; min-height: 44px; font-size: 22px; }
  .book-scroll-hint { bottom: 4px; font-size: 10px; }
  .page-grab { width: calc(44px / var(--book-scale, 1)); height: calc(44px / var(--book-scale, 1)); }
}

/* Narrow galleries retain a horizontal rail with native touch scrolling. */
@media (max-width: 1024px), (max-height: 650px) {
  body:not(.reduced-motion) .gallery-track { height: auto !important; }
  body:not(.reduced-motion) .gallery-scene { height: 100dvh; position: relative; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) 54px; overflow: hidden; }
  body:not(.reduced-motion) .gallery-scene > * { min-width: 0; }
  body:not(.reduced-motion) .gallery-index { position: relative; inset: auto; width: 100%; height: auto; padding: 12px 16px; border-right: 0; border-bottom: 1px solid #c5c1b8; }
  body:not(.reduced-motion) .gallery-mark { font-size: 28px; }
  body:not(.reduced-motion) .gallery-index > p,
  body:not(.reduced-motion) .gallery-index > small,
  body:not(.reduced-motion) .gallery-direction { display: none; }
  body:not(.reduced-motion) .gallery-index nav { display: flex; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; gap: 16px; margin: 8px 0 0; }
  body:not(.reduced-motion) .gallery-index nav button { flex-shrink: 0; min-height: 44px; font-size: 12px; }
  body:not(.reduced-motion) .gallery-window { position: relative; inset: auto; min-height: 0; overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; overscroll-behavior-x: contain; }
  body:not(.reduced-motion) .gallery-rail { display: flex; align-items: stretch; height: 100%; width: max-content; transform: none !important; }
  body:not(.reduced-motion) .gallery-panel { width: var(--gallery-panel-width, 100vw); height: 100%; min-height: 0; margin: 0; padding: 32px 24px; overflow-y: auto; overflow-x: hidden; scroll-snap-align: start; border-right: 1px solid #c5c1b8; border-bottom: 0; }
  body:not(.reduced-motion) .gallery-intro { padding-top: 92px; }
  body:not(.reduced-motion) .gallery-intro-art { position: relative; width: min(75%, 440px); right: auto; bottom: auto; margin: 40px auto 15px; }
  body:not(.reduced-motion) .gallery-work { display: block; padding-top: 56px; }
  body:not(.reduced-motion) .gallery-work-label, body:not(.reduced-motion) .gallery-work-bottom { display: block; }
  body:not(.reduced-motion) .gallery-work-bottom p { max-width: none; }
  body:not(.reduced-motion) .gallery-work-bottom a { display: inline-flex; margin-top: 24px; }
  body:not(.reduced-motion) .gallery-toolbox > img { position: static; width: min(45%, 200px); height: auto; margin: 20px 0 35px auto; }
  body:not(.reduced-motion) .gallery-contact .site-colophon { margin-top: 36px; }
  body:not(.reduced-motion) .gallery-ruler { display: flex; position: relative; inset: auto; height: 54px; padding: 0 16px; gap: 16px; }
  body:not(.reduced-motion) .gallery-position { width: auto; flex-shrink: 0; font-size: 12px; }
  body:not(.reduced-motion) .gallery-ruler > div { gap: 8px; }
  body:not(.reduced-motion) .gallery-ruler button { min-height: 44px; }
  body:not(.reduced-motion) .gallery-ruler button span { display: none; }
}

/* Use CSS viewport dimensions so OS/browser scaling remains respected. */
@media (min-width: 1700px) and (min-height: 900px) {
  :root { --text-body: clamp(18px, .8vw, 20px); --text-caption: 14px; }
  .edition-entry, .journey-header button, .gallery-index nav button { font-size: 17px; min-height: 48px; }
  .site-colophon { font-size: 15px; }
  .registration, .book-pagination, .gallery-index nav button span, .gallery-ruler > div > button { font-size: 14px; }
  .book-pagination button { font-size: 24px; min-width: 48px; min-height: 48px; }
  .gallery-intro-art span, .journey-row > span, .voyage-label { font-size: 14px; }
  .edition-picker-panel { max-width: 1600px; }
  .edition-card-copy > b { font-size: 22px; }
  .edition-card-copy > span, .edition-picker-panel > header > span,
  .edition-picker-panel > footer, .edition-picker-panel > footer button { font-size: 14px; }

  .os-window { width: clamp(960px, 52vw, 1320px); height: min(850px, calc(100% - 230px)); }
  .window-body, .finder { font-size: 18px; }
  .os-welcome { padding: 44px 52px; }
  .os-welcome > h1 { font-size: clamp(54px, 2.65vw, 68px); }
  .os-welcome > p, .os-domains > p, .settings-body p { font-size: 20px; line-height: 1.8; }
  .os-welcome > img { width: 88px; height: 88px; }
  .os-welcome > small, .os-welcome > h3, .os-welcome .registration,
  .finder > aside > small, .finder > section > footer, .notes-status { font-size: 14px; }
  .os-welcome-links button, .os-primary, .os-welcome .quick-links > *,
  .os-welcome .site-colophon { font-size: 16px; }
  .os-welcome-links button, .os-primary { padding: 14px 20px; }
  .os-domains .domain-entry { padding: 20px 0; }
  .os-domains .domain-entry b { font-size: 24px; }
  .notes-body textarea { font-size: 20px; line-height: 1.8; }
  .finder > aside { width: 230px; }
  .finder > aside > button, .finder-toolbar span, .finder-toolbar input,
  .finder-file small { font-size: 16px; }
  .finder > aside > button { padding: 14px 10px; }
  .finder-toolbar { min-height: 68px; }
  .finder-toolbar input { width: 200px; padding: 10px; }
  .finder-file b { font-size: 18px; }
  .finder-file > i { width: 60px; height: 60px; font-size: 34px; }
  .finder-items { gap: 24px; padding: 28px; }

  .desktop-icons { left: 32px; top: 80px; gap: 20px; bottom: 150px; }
  .desktop-icons .app-icon { width: 126px; min-height: 112px; padding: 10px 6px; }
  .desktop-icons .app-icon i { width: 60px; height: 60px; font-size: 36px; }
  .desktop-icons .app-icon span, .desktop-personalize .os-switch button { font-size: 16px; }
  .desktop-personalize { top: 60px; }
  .desktop-personalize .os-switch button { padding: 10px 20px; }
  .desktop-status { font-size: 14px; bottom: 140px; }
  .desktop-legal { font-size: 13px; bottom: 108px; }
  .window-titlebar, [data-os=windows] .window-titlebar { height: 48px; min-height: 48px; }
  .window-titlebar > b, [data-os=windows] .window-titlebar > b { font-size: 16px; }
  .window-controls button { width: 16px; height: 16px; }
  [data-os=windows] .window-controls { height: 48px; }
  [data-os=windows] .window-controls button { width: 58px; height: 48px; font-size: 20px; }
  .os-menubar { height: 40px; font-size: 14px; }
  .os-menubar button { font-size: 14px; }
  .os-taskbar { height: 88px; }
  .os-taskbar .app-icon { min-width: 66px; }
  .os-taskbar .app-icon i { width: 54px; height: 54px; font-size: 32px; }
  [data-os=windows] .os-taskbar { height: 72px; }
  [data-os=windows] .os-taskbar .app-icon { width: 60px; min-width: 60px; height: 58px; padding: 8px; }
  [data-os=windows] .os-taskbar .app-icon i { width: 40px; height: 40px; font-size: 28px; }
  [data-os=windows] :is(.start-button, .task-search, .task-view-button) { width: 58px; height: 58px; }
  .windows-mark { width: 28px; height: 28px; }
  [data-os=windows] .task-tray > button { height: 58px; }
  [data-os=windows] .task-clock { font-size: 15px; min-width: 115px; }
  [data-os=windows] .desktop-legal { bottom: 85px; }
  .os-window.maximized { top: 44px !important; bottom: 104px !important; }
  [data-os=windows] .os-window.maximized,
  .os-window.snap-left, .os-window.snap-right { bottom: 72px !important; }
  .os-task-view { bottom: 72px; }
  .popup-start, .popup-search { width: 700px; bottom: 110px !important; padding: 36px; }
  [data-os=windows] :is(.popup-start, .popup-search) { bottom: 86px !important; }
  .start-apps .app-icon { min-height: 100px; }
  .start-apps .app-icon i { width: 52px; height: 52px; font-size: 30px; }
  .start-apps .app-icon span, .app-search, .start-footer,
  .start-footer button, .popup-start > small, .menu-item { font-size: 16px; }
  .start-header { font-size: 18px; }
  .popup-calendar { width: 420px; top: 48px; }
  .popup-quick, [data-os=windows] .popup-calendar { bottom: 86px; }
  .popup-quick { width: 380px; }
  .calendar-grid, .os-calendar > button { font-size: 16px; }
}
