:root {
  --wine: #7b131b;
  --paper: #fffaf1;
  --ink: #211615;
  --muted: #766a68;
  --line: #e4d8ce;
}

* { box-sizing: border-box; }

.menu-language { display: flex; flex-shrink: 0; gap: 2px; }
.menu-language button { min-width: 36px; min-height: 44px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: #fffaf1ed; color: var(--wine); font: 600 12px system-ui; cursor: pointer; }
.menu-language button[aria-pressed="true"] { background: var(--wine); color: white; }
.menu-language button:focus-visible { outline: 3px solid #e3aa45; outline-offset: 2px; }

/* The final reader layout is defined below the image/gesture styles. */

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  width: 100%;
  margin: auto;
  /* Keep the last page clear of the fixed bottom bar. */
  padding: 0 0 calc(90px + env(safe-area-inset-bottom));
}

.menu-head {
  position: sticky;
  top: 0;
  background: var(--paper);
  padding: 10px max(16px, env(safe-area-inset-left)) 8px;
  z-index: 3;
  box-shadow: 0 6px 12px -10px #0006;
}
.menu-head h1 { margin: 0; font-size: 22px; letter-spacing: .04em; }
.menu-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.section-nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 0 2px;
  scrollbar-width: none;
}
.section-nav::-webkit-scrollbar { display: none; }
.section-nav button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  background: #fff;
  color: var(--wine);
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
}

.menu-section { margin: 0; }
.menu-section[hidden], .page[hidden] { display: none; }
.section-title {
  padding-inline: 16px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.page { position: relative; margin: 0; overflow: clip; }
.page-frame {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0;
  overflow: hidden;
  /* Guests pinch-zoom the page and can long-press anywhere to save a position. */
  touch-action: pan-y pinch-zoom;
}
.page-frame img { display: block; width: 100%; height: auto; }
.page-frame.failed { min-height: 180px; display: grid; place-items: center; }
.page-frame.failed img { display: none; }

.page figcaption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 16px;
  font-size: 12px;
  color: var(--muted);
}

.alc-saved-marker {
  position: absolute;
  z-index: 2;
  left: clamp(34px, var(--alc-saved-left), calc(100% - 34px));
  top: clamp(34px, var(--alc-saved-top), calc(100% - 34px));
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.alc-saved-marker svg {
  position: absolute;
  left: 9px;
  top: 9px;
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 50%;
  background: var(--wine);
  fill: #fff;
  box-shadow: 0 3px 10px #0004;
}
.alc-saved-marker::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
  width: 56px;
  height: 56px;
  left: -6px;
  top: -6px;
  border: 2px solid rgba(123, 19, 27, .45);
  border-radius: 50%;
  animation: alc-saved-pulse .7s ease-out both;
}
.alc-saved-marker-flash svg {
  animation: alc-saved-flash .55s ease-out;
}
@keyframes alc-saved-pulse {
  from { transform: scale(.55); opacity: 1; }
  to { transform: scale(1.2); opacity: 0; }
}
@keyframes alc-saved-flash {
  50% { transform: scale(1.3); }
}

.alc-retry {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--wine);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
}

.alc-saved-nav {
  position: fixed;
  z-index: 5;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(44px, 1fr) minmax(112px, auto) minmax(44px, 1fr);
  gap: 6px;
  padding: 6px;
  border-radius: 14px;
  background: #38442F;
  color: #fff;
  box-shadow: 0 6px 22px #0005;
}
.alc-saved-nav[hidden] { display: none; }
.alc-saved-nav button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  font-weight: 700;
}
.alc-saved-nav button:disabled { opacity: .35; }
.alc-saved-nav [data-saved-previous] { text-align: left; }
.alc-saved-nav [data-saved-next] { text-align: right; }
.alc-saved-center {
  display: grid;
  gap: 2px;
  justify-items: center;
}
.alc-saved-nav .alc-clear {
  width: 100%;
  padding-inline: 12px;
  border: 1px solid rgba(255, 255, 255, .72);
  background: rgba(255, 255, 255, .10);
}
.alc-saved-nav [data-saved-status] { padding-inline: 10px; }

.alc-status {
  position: fixed;
  z-index: 7;
  left: 16px;
  right: 16px;
  bottom: calc(218px + env(safe-area-inset-bottom));
  padding: 11px 14px;
  border-radius: 10px;
  background: #211615;
  color: #fff;
  text-align: center;
  box-shadow: 0 5px 18px #0004;
  pointer-events: none;
}
.alc-status[hidden] { display: none; }

.alc-toast {
  position: fixed;
  z-index: 7;
  left: 16px;
  right: 16px;
  bottom: calc(190px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  background: #211615;
  color: #fff;
  box-shadow: 0 5px 18px #0004;
}
.alc-toast[hidden] { display: none; }
.alc-toast button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--wine);
  font-weight: 700;
}

.alc-saved-overview {
  position: fixed;
  z-index: 8;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 70vh;
  overflow-y: auto;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: #fff;
  box-shadow: 0 -8px 30px #0003;
}
.alc-saved-overview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.alc-saved-overview-head h2 { margin: 0; font-size: 18px; }
.alc-saved-overview-head button,
.alc-saved-overview-row {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--wine);
  font-weight: 700;
}
.alc-saved-overview-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}
.alc-saved-overview-row {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
}
.alc-empty { color: var(--muted); }

.alc-clear {
  width: 100%;
  margin-top: 14px;
  border: 1px solid var(--wine);
  background: #fff;
  color: var(--wine);
  border-radius: 10px;
  padding: 12px;
  font-weight: 700;
}

.page-frame:focus-visible,
.alc-saved-marker:focus-visible,
.alc-saved-nav button:focus-visible,
.alc-saved-overview button:focus-visible {
  outline: 3px solid #e3aa45;
  outline-offset: 3px;
}

.empty { padding: 30px 4px; color: var(--muted); }
.alc-offline {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(192px + env(safe-area-inset-bottom));
  background: #211615;
  color: #fff;
  font-size: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  z-index: 6;
}

@media (max-width: 359px) {
  .alc-saved-nav [data-saved-previous] span,
  .alc-saved-nav [data-saved-next] span { display: none; }
}

@media (min-width: 560px) {
  .alc-saved-overview { max-width: 720px; margin: auto; }
}

/* Page reader */
button { cursor: pointer; font: inherit; }
button:disabled { cursor: default; }
button:focus-visible { outline: 3px solid #e3aa45; outline-offset: -3px; }
.section-nav button[aria-current="page"] { background: var(--wine); border-color: var(--wine); color: #fff; }
.section-nav button { min-height: 44px; }
.page-frame img { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.page-nav {
  position: fixed;
  z-index: 5;
  inset-inline: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: var(--paper);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 20px #2116150a;
}
.page-nav button { min-height: 44px; border: 0; border-radius: 8px; padding: 8px 16px; background: var(--wine); color: #fff; font-size: 14px; }
.page-nav button:disabled { background: var(--line); color: var(--muted); }
.page-nav-label { display: grid; text-align: center; font-size: 12px; color: var(--muted); }
[data-page-status] { font-size: 16px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.has-saved-items main { padding-bottom: calc(220px + env(safe-area-inset-bottom)); }
.alc-saved-nav .alc-clear { margin-top: 0; padding-block: 6px; }
.rotation-pending { overflow: hidden; }
.rotate-prompt {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; border: 0; padding: max(32px, env(safe-area-inset-top)) 24px max(32px, env(safe-area-inset-bottom));
  background: var(--wine); color: var(--paper); text-align: center;
}
.rotate-prompt[open] { display: flex; flex-direction: column; align-items: center; justify-content: center; }
.rotate-prompt::backdrop { background: var(--wine); }
.rotate-brand { letter-spacing: .24em; font-size: 12px; margin-bottom: 40px; }
.rotate-icon { width: 120px; height: 120px; flex-shrink: 0; fill: none; stroke: #f1c9a4; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rotate-phone { transform-origin: 60px 60px; animation: rotate-phone 2.8s ease-in-out infinite; }
.rotate-arrow { stroke-width: 2; }
.rotate-prompt h2 { font: 30px/1.15 Georgia, serif; max-width: 300px; margin: 24px 0 12px; }
.rotate-prompt p { max-width: 280px; margin: 0; font-size: 15px; color: #f1d8c6; }
.rotate-hint { max-width: 280px; margin: 24px 0; font-size: 12px; color: #f1d8c6; }
.rotate-prompt button { background: transparent; color: var(--paper); border: 1px solid #f1c9a477; border-radius: 999px; padding: 12px 20px; min-height: 44px; font-size: 13px; }
@keyframes rotate-phone { 0%, 15% { transform: rotate(0); } 60%, 85% { transform: rotate(90deg); } 100% { transform: rotate(0); } }
@media (orientation: landscape) and (max-height: 500px) {
  .menu-head { display: flex; align-items: center; gap: 20px; padding-block: 4px; }
  .menu-head h1 { font-size: 18px; }
  .menu-head p { display: none; }
  .section-nav { padding: 0; }
  .section-title { margin-block: 8px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}

/* Compact toolbar leaves the image the full available reading height. */
main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.menu-head {
  display: flex; align-items: center; gap: 12px; height: 52px;
  padding: 4px max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
  z-index: 6;
}
.menu-head h1 { font-size: 17px; flex-shrink: 0; }
.menu-head p, .section-title, .page figcaption { display: none; }
.section-picker { position: relative; min-width: 0; margin-right: auto; }
.section-picker summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px;
  padding: 8px 12px; border-radius: 8px; color: var(--wine);
  background: #fff; border: 1px solid var(--line); cursor: pointer;
  font-size: 14px; font-weight: 600; list-style: none;
}
.section-picker summary::-webkit-details-marker { display: none; }
.section-picker summary [data-page-title] { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-picker summary:focus-visible { outline: 3px solid #e3aa45; }
.section-picker[open] .section-nav {
  position: absolute; left: 0; top: calc(100% + 6px); min-width: 240px;
  max-width: calc(100vw - 32px); max-height: calc(100dvh - 72px);
  display: grid; gap: 4px; overflow: auto; padding: 8px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
  box-shadow: 0 8px 28px #21161533;
}
.section-nav button { border-radius: 8px; text-align: left; white-space: normal; }
[data-page-status] { white-space: nowrap; font-size: 13px; flex-shrink: 0; }
.fullscreen-button {
  flex-shrink: 0; width: 44px; height: 44px; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; color: var(--wine);
}
.fullscreen-button[hidden] { display: none; }
.fullscreen-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.page-nav { inset: 52px 0 0; display: block; padding: 0; background: none; border: 0; box-shadow: none; pointer-events: none; }
.page-nav button {
  position: absolute; top: 50%; transform: translateY(-50%); pointer-events: auto;
  width: 44px; height: 52px; min-height: 44px; padding: 0; font-size: 22px;
  background: #7b131bea; box-shadow: 0 2px 10px #21161522;
}
.page-nav button span { display: none; }
[data-page-previous] { left: max(4px, env(safe-area-inset-left)); }
[data-page-next] { right: max(4px, env(safe-area-inset-right)); }
.page-nav button:disabled { opacity: .45; }
.alc-saved-nav { bottom: calc(12px + env(safe-area-inset-bottom)); }
.has-saved-items main { padding-bottom: calc(150px + env(safe-area-inset-bottom)); }
.alc-status { bottom: calc(154px + env(safe-area-inset-bottom)); }
.alc-toast, .alc-offline { bottom: calc(142px + env(safe-area-inset-bottom)); }
@media (max-width: 559px) {
  .menu-head { gap: 6px; }
  .menu-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .section-picker { flex: 1; }
  .section-picker summary { padding-inline: 8px; }
  .section-picker[open] .section-nav { min-width: 0; width: min(280px, calc(100vw - 32px)); }
}

/* Floating reader controls: no header or footer takes space from the image. */
.menu-head {
  position: fixed; top: max(8px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right));
  height: 44px; padding: 0; background: transparent; box-shadow: none;
  pointer-events: none; gap: 8px;
}
.menu-head h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.menu-head > :not(h1):not(p) { pointer-events: auto; }
.section-picker { flex: 0 1 auto; max-width: min(60vw, 300px); }
.section-picker summary, .fullscreen-button, [data-page-status] {
  background: #fffaf1ed; box-shadow: 0 2px 12px #21161522;
}
[data-page-status] { padding: 7px 10px; border-radius: 999px; }
.page-nav { inset: 0; }
.alc-status, .alc-toast, .alc-offline { bottom: calc(20px + env(safe-area-inset-bottom)); }

.reader-visibility { width: 44px; height: 44px; flex-shrink: 0; border: 1px solid var(--line); border-radius: 50%; background: #fffaf1ed; color: var(--wine); font-size: 22px; cursor: pointer; }
.reader-controls-hidden .section-picker, .reader-controls-hidden [data-page-status], .reader-controls-hidden .fullscreen-button, .reader-controls-hidden .page-nav { display: none; }
.reader-controls-hidden .menu-head { justify-content: flex-end; }

/* Fit the entire source page, with ivory letterboxing on wider screens. */
:root { --menu-backdrop: #F5EDD8; }
html, body { background: var(--menu-backdrop); }
main, .has-saved-items main { padding: 0; }
.page {
  display: grid; place-items: center; width: 100%; height: 100vh; height: 100dvh;
  padding: 0;
  background: var(--menu-backdrop);
}
.page-frame {
  width: min(100%, calc(100vh * var(--page-ratio, 1.414)));
  width: min(100%, calc(100dvh * var(--page-ratio, 1.414)));
  aspect-ratio: var(--page-ratio, 1.414); border: 0; background: var(--menu-backdrop);
}
.page-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.page-frame.failed { min-height: 0; }
.page-frame { touch-action: pinch-zoom; }
.page-frame.is-gripping { cursor: grabbing; }
.page-grip-layer {
  position: absolute; z-index: 8; pointer-events: none; background: var(--menu-backdrop);
  contain: paint; isolation: isolate; transform: translateZ(0); backface-visibility: hidden;
}
.page-grip-layer > img, .page-grip-front, .page-grip-front img, .page-grip-back, .page-grip-shadow { position: absolute; inset: 0; width: 100%; height: 100%; }
.page-grip-layer img { object-fit: contain; user-select: none; }
.page-grip-front { background: var(--menu-backdrop); will-change: clip-path; backface-visibility: hidden; }
.page-grip-back {
  transform-origin: 0 0;
  will-change: clip-path, transform;
  backface-visibility: hidden;
  background: linear-gradient(var(--page-grip-angle, 90deg), #4d0911, #711520 48%, #570c15);
}
.page-grip-back img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain;
  opacity: .18; filter: sepia(.2) saturate(.7) contrast(.82); mix-blend-mode: soft-light;
}
.page-grip-shadow {
  filter: drop-shadow(0 7px var(--page-grip-shadow-blur, 10px) rgb(33 22 21 / var(--page-grip-shadow-opacity, .28)));
}
.empty { color: var(--ink); }
.reader-controls-hidden .alc-saved-nav, .reader-controls-hidden [data-saved-overview] { display: none; }

/* On an upright phone, keep the menu page connected to the controls above it. */
@media (orientation: portrait) {
  .alc-phone .page {
    place-items: start center;
    padding-top: calc(128px + env(safe-area-inset-top));
  }
}

/* Phone landscape: compact section picker and messages near the bottom edge. */
@media (orientation: landscape) and (max-height: 500px) {
  /* The page already fits the viewport: lock document scrolling so
     horizontal page pulls don't fight vertical rubber-banding. */
  .alc-phone, .alc-phone body { overflow: hidden; overscroll-behavior: none; }
  .alc-phone .section-picker {
    flex: 0 0 44px;
    max-width: 44px;
  }
  .alc-phone .section-picker summary {
    width: 44px;
    justify-content: center;
    padding: 0;
  }
  .alc-phone .section-picker summary span { display: none; }
  .alc-phone .section-picker summary::after {
    content: "☰";
    font-size: 20px;
    line-height: 1;
  }

  .alc-phone .alc-toast {
    left: 50%; right: auto; transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 8px; padding: 4px 4px 4px 12px; border-radius: 999px;
    font-size: 13px;
  }
  .alc-phone .alc-toast button { min-height: 40px; padding: 0 14px; border-radius: 999px; }
  .alc-phone .alc-status, .alc-phone .alc-offline { bottom: calc(8px + env(safe-area-inset-bottom)); font-size: 12px; }
}

/* Unified reader dock. Its reserved space never intersects the menu image. */
:root { --reader-dock-height: calc(64px + env(safe-area-inset-bottom)); }
main, .has-saved-items main { padding: 0; }
.page, .alc-phone .page {
  height: calc(100vh - var(--reader-dock-height));
  height: calc(100dvh - var(--reader-dock-height));
  padding: 0; place-items: center;
}
.page-frame {
  width: min(100%, calc((100vh - var(--reader-dock-height)) * var(--page-ratio, 1.414)));
  width: min(100%, calc((100dvh - var(--reader-dock-height)) * var(--page-ratio, 1.414)));
}
.menu-head {
  position: fixed; inset: auto 0 0; height: var(--reader-dock-height);
  display: flex; justify-content: center; align-items: center; gap: 12px;
  padding: 9px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--paper); border-top: 1px solid var(--line); box-shadow: none;
  pointer-events: auto;
}
.section-picker, .alc-phone .section-picker {
  flex: 1 1 180px; max-width: 260px; min-width: 0; margin: 0;
}
.section-picker summary, .alc-phone .section-picker summary {
  width: auto; min-height: 44px; padding: 0 12px; justify-content: space-between;
  background: transparent; border: 1px solid var(--line); border-radius: 10px; box-shadow: none;
}
.alc-phone .section-picker summary span { display: block; }
.alc-phone .section-picker summary::after { content: none; }
.section-picker[open] .section-nav {
  top: auto; bottom: calc(100% + 12px); max-height: calc(100dvh - var(--reader-dock-height) - 24px);
}
.menu-head .page-nav {
  position: static; inset: auto; display: flex; flex-shrink: 0; align-items: center;
  gap: 2px; padding: 0; margin: 0; background: transparent; border: 0; box-shadow: none;
}
.menu-head .page-nav button, .menu-head .fullscreen-button, .menu-head .reader-visibility {
  position: relative; inset: auto; transform: none; display: grid; place-items: center;
  width: 44px; height: 44px; min-height: 44px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--wine); box-shadow: none; flex-shrink: 0;
}
.menu-head .fullscreen-button[hidden] { display: none; }
.menu-head svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu-head .page-nav button:disabled { opacity: .35; background: transparent; }
.menu-head [data-page-status] { min-width: 48px; padding: 0 4px; background: transparent; box-shadow: none; text-align: center; font-size: 12px; }
.menu-language { gap: 0; padding: 2px; background: #eee5da; border-radius: 10px; }
.menu-language button { min-width: 38px; min-height: 40px; border: 0; border-radius: 8px; background: transparent; font-size: 12px; }
.menu-language button[aria-pressed="true"] { background: var(--wine); color: var(--paper); }
[data-saved-overview]:not([data-count="0"])::after {
  content: attr(data-count); position: absolute; top: -4px; right: -4px;
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 8px;
  background: var(--wine); color: white; font: 10px/16px system-ui;
}
.empty { padding: 24px; }
.alc-status, .alc-phone .alc-status, .alc-offline, .alc-phone .alc-offline {
  bottom: calc(8px + env(safe-area-inset-bottom)); padding: 8px 12px;
  font-size: 12px; line-height: 1.3;
}
.alc-toast {
  bottom: calc(8px + env(safe-area-inset-bottom)); padding: 2px 8px;
  font-size: 12px; line-height: 1.3; pointer-events: none;
}
.alc-toast button { min-height: 40px; pointer-events: auto; }
@media (max-width: 599px) and (orientation: portrait) {
  :root { --reader-dock-height: calc(112px + env(safe-area-inset-bottom)); }
  .menu-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px 8px; padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .section-picker { grid-column: 1 / 3; grid-row: 1; max-width: none; }
  .menu-head .reader-visibility { grid-column: 3; grid-row: 1; }
  .menu-head .page-nav { grid-column: 1; grid-row: 2; }
  .menu-language { grid-column: 2; grid-row: 2; }
  .menu-head .fullscreen-button { grid-column: 3; grid-row: 2; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .menu-head { gap: 8px; }
}

/* Landscape reading: balanced side controls preserve the full image height. */
.section-icon { display: none; }
@media (orientation: landscape) {
  :root { --reader-dock-height: 0px; --reader-rail: 56px; }
  .page, .alc-phone .page {
    height: 100vh; height: 100dvh;
    padding: 0 calc(var(--reader-rail) + env(safe-area-inset-right)) 0 calc(var(--reader-rail) + env(safe-area-inset-left));
  }
  .page-frame { width: min(100%, calc(100vh * var(--page-ratio, 1.414))); width: min(100%, calc(100dvh * var(--page-ratio, 1.414))); }
  .menu-head {
    inset: 0; height: 100vh; height: 100dvh;
    display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px;
    grid-template-rows: 84px 44px 44px 20px; align-content: center; justify-items: center;
    gap: 10px 0; padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    background: transparent; border: 0; pointer-events: none;
  }
  .section-picker, .alc-phone .section-picker { grid-column: 1; grid-row: 1; width: 44px; max-width: 44px; }
  .section-picker summary, .alc-phone .section-picker summary { width: 44px; height: 44px; padding: 0; justify-content: center; }
  .section-picker summary span, .alc-phone .section-picker summary span { display: none; }
  .section-picker summary::after, .alc-phone .section-picker summary::after { content: none; }
  .section-icon { display: block; }
  .menu-head .reader-visibility { grid-column: 1; grid-row: 2; }
  .menu-language { grid-column: 3; grid-row: 1; flex-direction: column; width: 44px; }
  .menu-language button { width: 40px; min-width: 40px; }
  .menu-head .fullscreen-button { grid-column: 3; grid-row: 2; }
  .menu-head .page-nav { display: contents; pointer-events: none; }
  .menu-head [data-page-previous] { grid-column: 1; grid-row: 3; }
  .menu-head [data-page-next] { grid-column: 3; grid-row: 3; }
  .menu-head [data-page-status] { grid-column: 1; grid-row: 4; min-width: 44px; font-size: 11px; color: var(--muted); }
  .menu-head .page-nav button { pointer-events: auto; }
  .menu-head .page-nav button, .menu-head .fullscreen-button, .menu-head .reader-visibility, .section-picker summary {
    background: var(--paper); border-color: #dfd1bf; border-radius: 12px;
  }
  .section-picker[open] .section-nav { left: 52px; top: 0; bottom: auto; max-height: calc(100dvh - 100px); }
}

/* Stable corner controls and explicit anchors in both orientations. */
.menu-head .reader-toggle, .menu-head .fullscreen-button {
  position: fixed; top: max(6px, env(safe-area-inset-top)); bottom: auto;
  width: 44px; height: 44px; display: grid; place-items: center; padding: 8px;
  border: 1px solid #dfd1bf; border-radius: 12px; background: var(--paper); color: var(--wine);
  pointer-events: auto;
}
.menu-head .reader-toggle { left: max(6px, env(safe-area-inset-left)); right: auto; font: 24px/1 system-ui; }
.menu-head .fullscreen-button { right: max(6px, env(safe-area-inset-right)); left: auto; }
.reader-controls-hidden .menu-head > :not(.reader-toggle) { visibility: hidden; pointer-events: none; }
.reader-controls-hidden .menu-head .page-nav button { visibility: hidden; pointer-events: none; }
.reader-controls-hidden .menu-language { visibility: hidden; pointer-events: none; }
@media (orientation: landscape) {
  .menu-head .section-picker { position: fixed; left: max(6px, env(safe-area-inset-left)); top: calc(50% - 50px); }
  .menu-head .reader-visibility { position: fixed; left: max(6px, env(safe-area-inset-left)); top: calc(50% + 6px); }
  .menu-language { position: fixed; right: max(6px, env(safe-area-inset-right)); top: calc(50% - 42px); }
  .menu-head .page-nav [data-page-previous] { position: fixed; left: max(6px, env(safe-area-inset-left)); top: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  .menu-head .page-nav [data-page-next] { position: fixed; right: max(6px, env(safe-area-inset-right)); top: auto; bottom: max(8px, env(safe-area-inset-bottom)); }
  .menu-head [data-page-status] { position: fixed; left: max(6px, env(safe-area-inset-left)); bottom: calc(56px + env(safe-area-inset-bottom)); }
  .section-picker[open] .section-nav { top: 0; max-height: calc(50dvh + 26px); }
}
@media (orientation: portrait) {
  :root { --reader-dock-height: calc(112px + env(safe-area-inset-bottom)); }
  .page, .alc-phone .page { padding-top: 56px; }
  .page-frame { width: min(100%, calc((100dvh - var(--reader-dock-height) - 56px) * var(--page-ratio, 1.414))); }
  .menu-head { position: fixed; inset: 0; height: 100dvh; display: block; padding: 0; background: transparent; border: 0; pointer-events: none; }
  .menu-head .section-picker { position: fixed; bottom: calc(62px + env(safe-area-inset-bottom)); left: 12px; width: calc(100% - 116px); max-width: none; }
  .menu-language { position: fixed; right: 12px; bottom: calc(62px + env(safe-area-inset-bottom)); }
  .menu-head .reader-visibility { position: fixed; right: 12px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .menu-head .page-nav { display: contents; }
  .menu-head .page-nav [data-page-previous] { position: fixed; left: 12px; top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .menu-head .page-nav [data-page-next] { position: fixed; left: 64px; top: auto; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .menu-head [data-page-status] { position: fixed; left: 50%; bottom: calc(21px + env(safe-area-inset-bottom)); transform: translateX(-50%); }
  .section-picker summary { height: 44px; }
  .alc-status, .alc-phone .alc-status { bottom: calc(64px + env(safe-area-inset-bottom)); }
}
