/* The docked folio lives in Three.js. This DOM source stays available to
   assistive technology and becomes the readable overlay after the flight. */
#text-panel.reading-semantic-mirror:not(.focus) {
  position: fixed !important;
  top: 0 !important; left: -10000px !important;
  width: 640px !important; height: 1px !important;
  margin: 0 !important; padding: 0 !important;
  overflow: hidden !important; clip-path: inset(50%) !important;
  transform: none !important; opacity: 0 !important;
  pointer-events: none !important;
  animation: none !important;
}

#text-panel.reading-semantic-mirror[hidden] { display: none !important; }
#focus-veil { display: none !important; }

/* Once the scene card reaches the viewer, it hands off to a fixed folio.
   Its position never follows the camera or the book while expanded. */
#text-panel.reading-semantic-mirror.focus {
  position: fixed !important;
  top: max(76px, env(safe-area-inset-top)) !important;
  left: max(16px, env(safe-area-inset-left)) !important;
  right: auto !important; bottom: auto !important;
  box-sizing: border-box !important;
  display: flex !important; flex-direction: column !important;
  width: min(47.3vw, 594px) !important;
  height: auto !important;
  max-width: calc(100vw - 32px) !important;
  max-height: calc(100dvh - 190px) !important;
  margin: 0 !important; padding: 0 !important;
  overflow: hidden !important; clip-path: none !important;
  transform: none !important; transform-origin: center !important;
  animation: none !important;
  opacity: 0 !important; pointer-events: none !important;
  z-index: 18 !important;
  border: 1px solid #cdbd93 !important;
  border-radius: 6px !important;
  /* The docked canvas passes through the scene renderer and appears as this paper shade. */
  background: #ebe8df !important;
  color: var(--night-paper-ink) !important;
  box-shadow: 0 17px 48px #080e1870 !important;
  transition: opacity 140ms ease-out !important;
}
#text-panel.reading-semantic-mirror.focus.focus-ready:not(.turning) {
  opacity: 1 !important;
  pointer-events: auto !important;
}
#text-panel.reading-semantic-mirror.focus .text-panel-inner {
  box-sizing: border-box;
  flex: 1 1 auto;
  min-height: 0;
  max-height: inherit;
  padding: 44px 24px 18px !important;
  gap: 5px;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  touch-action: pan-y;
  scrollbar-width: thin;
  -webkit-mask-image: none !important;
  mask-image: none !important;
}
#text-panel.reading-semantic-mirror.focus.overflowing:not(.at-end)::after { display: none !important; }
#text-panel.reading-semantic-mirror.focus .page-heading {
  margin: 0 0 2px;
  font-size: clamp(22px, 2.2vw, 29.7px);
  line-height: 1.3;
}
#text-panel.reading-semantic-mirror.focus .page-words,
#text-panel.reading-semantic-mirror.focus .translation-chinese {
  font-size: clamp(19.8px, 1.815vw, 26.4px);
  line-height: 1.62;
}
#text-panel.reading-semantic-mirror.focus .page-words.primary-english { font-size: clamp(14.3px, 1.32vw, 19.8px); }
#text-panel.reading-semantic-mirror.focus .story-translation { font-size: .76em; line-height: 1.5; }
#text-panel.reading-semantic-mirror.focus .page-foot { margin-top: 1px; padding-top: 8px; }

/* A quiet corner control with a full finger-sized hit area. */
#text-panel.reading-semantic-mirror.focus .reading-expand {
  position: absolute;
  top: 6px; left: 6px;
  display: grid; place-items: center;
  width: 32px; height: 32px;
  border: 1px dashed #8f846b8f;
  border-radius: 7px;
  background: #eadfbead;
  color: #596156;
  box-shadow: none;
  opacity: .75;
  z-index: 2;
}
#text-panel.reading-semantic-mirror.focus .reading-expand:hover,
#text-panel.reading-semantic-mirror.focus .reading-expand:focus-visible {
  opacity: 1;
  background: #f7efd9;
  outline-color: #9f8756;
}
#text-panel.reading-semantic-mirror.focus .reading-expand::before { content:""; position:absolute; inset:-6px; }
#text-panel.reading-semantic-mirror.focus .reading-expand .icon { width: 16px; height: 16px; transform:none; }
#text-panel.reading-semantic-mirror.focus .reading-expand[aria-expanded="true"] .icon { transform:none; }
#text-panel.reading-semantic-mirror.focus .reading-expand .icon-collapse {
  --night-icon:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3l7 7M10 4v6H4m17 11-7-7m0 6v-6h6' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (max-height: 500px) and (orientation: landscape) {
  #text-panel.reading-semantic-mirror.focus {
    top: max(54px, env(safe-area-inset-top)) !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    width: min(47.3vw, 396px) !important;
    max-height: calc(100dvh - 156px) !important;
  }
  #text-panel.reading-semantic-mirror.focus .text-panel-inner { padding: 38px 16px 12px !important; gap: 3px; }
  #text-panel.reading-semantic-mirror.focus .page-heading { font-size: 20px; line-height: 1.25; }
  #text-panel.reading-semantic-mirror.focus .page-words,
  #text-panel.reading-semantic-mirror.focus .translation-chinese { font-size: 18px; line-height: 1.52; }
  #text-panel.reading-semantic-mirror.focus .page-words.primary-english { font-size: 13px; }
  #text-panel.reading-semantic-mirror.focus .story-translation { font-size: 13px; line-height: 1.45; }
  #text-panel.reading-semantic-mirror.focus .page-foot { padding-top: 5px; }
}

@media (orientation: portrait) and (max-width: 700px) {
  #text-panel.reading-semantic-mirror.focus {
    top: max(74px, env(safe-area-inset-top)) !important;
    left: 12px !important;
    width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 210px) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  #text-panel.reading-semantic-mirror.focus,
  #text-panel.reading-semantic-mirror.focus .text-panel-inner { transition: none !important; scroll-behavior: auto; }
}
