:root {
  color-scheme: dark;
  font: 15px Arial, sans-serif;
  --canvas: #212226;
  --bar: #191a1d;
  --line: #414247;
  --strong: #f5f5f5;
  --muted: #cccdd1;
}
* { box-sizing: border-box; }
body { margin: 0; height: 100vh; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; color: var(--strong); background: var(--canvas); }
header, footer { background: var(--bar); display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px clamp(12px, 3vw, 36px); position: relative; z-index: 3; }
header { flex-direction: row-reverse; border-bottom: 1px solid var(--line); }
.header-actions { display: flex; gap: 8px; align-items: center; }
#landscape { padding-inline: 10px; white-space: nowrap; }
footer { direction: ltr; border-top: 1px solid var(--line); padding-bottom: max(10px, env(safe-area-inset-bottom)); }
h1 { margin: 0; font-size: 19px; font-weight: 850; letter-spacing: .12em; white-space: nowrap; }
h1 span { font-weight: 500; font-size: 11px; color: var(--muted); letter-spacing: .11em; margin-left: 8px; }
button, summary { border: 1px solid var(--line); background: #25262b; color: var(--strong); border-radius: 8px; padding: 0; cursor: pointer; min-width: 44px; min-height: 44px; display: grid; place-items: center; font: inherit; }
button:disabled { color: #818188; cursor: default; }
button:hover:not(:disabled), summary:hover { background: #37383d; }
button:focus-visible, summary:focus-visible, a:focus-visible, .nav-link:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
summary { list-style: none; padding-inline: 14px; }
summary::-webkit-details-marker { display: none; }
nav { position: absolute; inset-inline-start: clamp(12px, 3vw, 36px); top: calc(100% + 8px); width: min(320px, calc(100vw - 24px)); max-height: min(65dvh, 530px); overflow: auto; background: #242529; border: 1px solid var(--line); padding: 6px; border-radius: 10px; box-shadow: 0 12px 32px #0006; }
.nav-link { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; padding: 0 10px; direction: ltr; border: 0; background: transparent; }
.nav-link small { color: #bcbec5; padding-left: 8px; }
main, #viewport { min-width: 0; min-height: 0; position: relative; }
#viewport { height: 100%; overflow: auto; direction: ltr; overscroll-behavior: contain; touch-action: pan-y pinch-zoom; }
#viewport.zoomed { touch-action: pan-x pan-y pinch-zoom; }
#surface { min-width: 100%; min-height: 100%; width: max-content; display: flex; align-items: center; justify-content: center; padding: 10px; }
#book { width: min(calc(100vw - 20px), 1250px); aspect-ratio: 2048 / 1365; flex: none; position: relative; perspective: 1800px; box-shadow: 0 8px 38px #0009; background: #fff; }
.leaf { position: absolute; inset: 0; margin: 0; background: #fff; overflow: hidden; backface-visibility: hidden; }
.leaf img { display: block; width: 100%; height: 100%; object-fit: contain; user-select: none; }
.hotspot { position: absolute; display: block; border-radius: 4px; }
.hotspot:hover { background: #1617190d; }
.hotspot:focus-visible { outline: 2px solid #26282e; }
.turns, .zoom { display: flex; align-items: center; gap: 7px; }
.turns button, .zoom button { font-size: 24px; }
#zoom-reset { font-size: 13px; padding: 0 7px; min-width: 50px; }
output { font-variant-numeric: tabular-nums; min-width: 67px; text-align: center; color: var(--muted); }
#notice { position: absolute; bottom: 7px; left: 50%; translate: -50% 0; margin: 0; padding: 10px; background: #202125; color: #fff; border-radius: 8px; z-index: 2; }
@media (max-width: 390px) {
  h1 { font-size: 16px; }
  h1 span { font-size: 9px; margin-left: 3px; }
  footer { padding-inline: 8px; gap: 8px; }
  .turns, .zoom { gap: 4px; }
  output { min-width: 60px; }
}
@media (max-width: 350px) { h1 span { letter-spacing: 0; font-size: 8px; } .header-actions { gap: 4px; } #landscape, summary { padding-inline: 6px; font-size: 12px; } }
@media (orientation: landscape) and (max-height: 620px) {
  body { grid-template: "header header" auto "stage controls" minmax(0, 1fr) / minmax(0, 1fr) 62px; direction: ltr; }
  header { grid-area: header; padding-block: 4px; direction: rtl; }
  main { grid-area: stage; }
  footer { grid-area: controls; flex-direction: column; justify-content: center; padding: 4px 5px; gap: 10px; border-top: 0; border-left: 1px solid var(--line); }
  .turns, .zoom { flex-direction: column; gap: 3px; }
  output { min-width: 0; font-size: 12px; }
  footer button { min-height: 42px; }
}

