/* Immersion is an explicit preference. Native fullscreen is requested separately
   so the reader also fills the available page inside a restricted browser. */
html[data-immersion='true'] { --stage-width: 100vw; }
html[data-immersion='true'] body { width: 100vw; }
html[data-immersion='true'] .book,
html[data-immersion='true'] .event-dialog,
html[data-immersion='true'] .modal.screen-modal,
html[data-immersion='true'] .modal.art-view {
  width: 100vw;
  max-width: none;
  height: var(--viewport-height, 100dvh);
  max-height: var(--viewport-height, 100dvh);
  border-radius: 0;
  box-shadow: none;
}
html[data-immersion='true'] .book { position: fixed; inset: 0; margin: 0; }
html[data-immersion='true'] .event-dialog,
html[data-immersion='true'] .modal.screen-modal,
html[data-immersion='true'] .modal.art-view { inset: 0; transform: none; margin: 0; }
html[data-immersion='true'] .modal.screen-modal .modal-content {
  height: var(--viewport-height, 100dvh);
  max-height: var(--viewport-height, 100dvh);
}
html:fullscreen, html:-webkit-full-screen { background: #061a17; }

/* Reading controls are independent of adventure decisions. All touch targets
   stay reachable over the painting without adding a scrolling header. */
.reader-tools {
  position: absolute;
  z-index: 9;
  top: calc(10px + env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 24px);
}
.reader-tools > button,
.overlay-tools > button,
.immersion-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #e7c58b91;
  border-radius: 24px;
  background: #06271fea;
  color: #fff0d0;
  font: 500 12px/1.2 var(--sans, sans-serif);
  text-decoration: none;
  white-space: nowrap;
  box-shadow: 0 2px 12px #001c1a30;
  touch-action: manipulation;
}
.reader-tools > button:disabled,
.overlay-tools > button:disabled { opacity: .45; }
.reader-tools > button[aria-pressed='true'],
.overlay-tools > button[aria-pressed='true'],
.immersion-control[aria-pressed='true'] { background: #34523d; border-color: #f6d496; }
.reader-tools > button:focus-visible,
.overlay-tools > button:focus-visible,
.immersion-control:focus-visible { outline-offset: 2px; }

/* The board's three utility buttons and restart fit even at 320px. Passive
   counters share the following row with the title, outside the button flex.
   Map tabs and map hit targets retain their established coordinates. */
.board-header { gap: 6px; padding-inline: 12px; }
.board-header .header-right { flex: 0 0 auto; gap: 5px; }
.board-header .restart-control { padding-inline: 8px; font-size: 11px; }
.board-header #board-score {
  position: absolute;
  top: calc(64px + env(safe-area-inset-top));
  right: 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-height: 23px;
  pointer-events: none;
}
.board-header #board-score .score,
.board-header #board-score .life-meter { font-size: 12px; line-height: 1.25; }
.board-header #board-score .life-meter > span { font-size: 14px; }
.board-header #board-score small { font-size: 9px; }
.board-heading { top: calc(64px + env(safe-area-inset-top)); left: 12px; right: 136px; text-align: left; }
.board-heading .eyebrow { display: none; }
.board-heading h1 { margin: 0; font-size: 19px; line-height: 23px; letter-spacing: -.035em; white-space: nowrap; }

.screen-modal .overlay-tools {
  position: relative;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: calc(52px + env(safe-area-inset-top));
  padding: calc(6px + env(safe-area-inset-top)) 12px 2px;
  background: linear-gradient(#031c18b8, #031c183b);
}
.screen-modal .overlay-tools ~ .speaker-head,
.screen-modal.dialogue-sheet .overlay-tools ~ .speaker-head,
.screen-modal.nemo-transmission .overlay-tools ~ .speaker-head {
  min-height: 76px;
  padding-top: 6px;
  padding-bottom: 6px;
}
.screen-modal .overlay-tools ~ .sheet-head { min-height: 64px; padding-top: 6px; }
.screen-modal .overlay-tools ~ .close { top: calc(6px + env(safe-area-inset-top)); }

/* Re-reading is a separate, bounded page. Its two paging buttons share one
   row, leaving a single full-width return to the interrupted adventure. */
.screen-modal.reading-sheet .modal-content::before {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(#031e1870, #031e184d 22%, #031e18ce 55%, #031e18f2);
  pointer-events: none;
}
.screen-modal.reading-sheet .sheet-head { padding-right: 20px; background: #031e1852; }
.screen-modal.reading-sheet .sheet-head h2 { font-size: 24px; line-height: 1.12; }
.screen-modal.reading-sheet .sheet-body { justify-content: flex-end; padding: 16px 22px; }
.screen-modal.reading-sheet p.sheet-message { font-size: 18px; line-height: 1.45; text-shadow: 0 1px 7px #001710; }
.screen-modal.reading-sheet .sheet-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px 22px calc(16px + env(safe-area-inset-bottom));
}
.screen-modal.reading-sheet .sheet-actions > button {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 9px 10px;
  font-size: 13px;
  line-height: 1.25;
}
.screen-modal.reading-sheet [data-action='read-resume'] { grid-column: 1 / -1; }
.screen-modal.reading-sheet .sheet-actions > button:disabled { opacity: .45; }
.view-notice {
  position: absolute;
  z-index: 12;
  top: calc(100px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(calc(100% - 28px), 440px);
  margin: 0;
  padding: 9px 13px;
  border: 1px solid #d8c59485;
  border-radius: 10px;
  background: #052a24f5;
  box-shadow: 0 4px 18px #001b17a6;
  color: #fff0d0;
  font: 500 12px/1.35 var(--sans, sans-serif);
  text-align: center;
  overflow-wrap: break-word;
  pointer-events: none;
}
.view-notice:empty, .view-notice[hidden] { display: none; }

/* Keep the entire portrait painting readable on a wide monitor. Its existing
   blurred background still reaches all four edges of the fullscreen surface. */
@media (min-aspect-ratio: 1/1) and (min-height: 431px) {
  html[data-immersion='true'] .screen-card .screen-art .screen-image { object-fit: contain; }
  html[data-immersion='true'] .screen-card > .reader-panel,
  html[data-immersion='true'] .screen-card > .screen-pager {
    width: min(100%, 660px);
    align-self: center;
  }
  html[data-immersion='true'] .screen-modal .sheet-body,
  html[data-immersion='true'] .screen-modal .sheet-actions,
  html[data-immersion='true'] .screen-modal .guided-sheet-pager {
    width: min(100%, 660px);
    align-self: center;
  }
}
@media (max-width: 420px) {
  .screen-card .scene-status { top: calc(62px + env(safe-area-inset-top)); right: 12px; left: auto; }
  .reader-tools > button, .overlay-tools > button { padding-inline: 9px; font-size: 11px; }
  .board-header { gap: 6px; padding-inline: 12px; }
  .board-header .restart-control { padding-inline: 8px; font-size: 11px; }
  .board-header .header-right { gap: 5px; }
  .board-header .immersion-control { padding-inline: 8px; font-size: 11px; }
}
@media (max-height: 650px) {
  .screen-modal .overlay-tools ~ .speaker-head,
  .screen-modal.dialogue-sheet .overlay-tools ~ .speaker-head,
  .screen-modal.nemo-transmission .overlay-tools ~ .speaker-head { min-height: 62px; padding-block: 4px; }
  .screen-modal .overlay-tools ~ .speaker-head .speaker-portrait { width: 54px; height: 54px; }
  .screen-modal .overlay-tools ~ .sheet-head { min-height: 58px; padding-block: 5px; }
  .screen-modal.reading-sheet .sheet-head { padding-inline: 18px; }
  .screen-modal.reading-sheet .sheet-head h2 { font-size: 22px; }
  .screen-modal.reading-sheet .sheet-body { padding: 10px 18px; }
  .screen-modal.reading-sheet p.sheet-message { font-size: 16px; line-height: 1.4; }
  .screen-modal.reading-sheet .sheet-actions { gap: 6px; padding: 6px 18px calc(10px + env(safe-area-inset-bottom)); }
}
@media (orientation: landscape) and (max-height: 430px) {
  .screen-card .scene-status { top: calc(61px + env(safe-area-inset-top)); left: 12px; right: auto; }
  .screen-modal .modal-content:has(> .overlay-tools) { grid-template-rows: auto minmax(0, 1fr) auto auto; }
  .screen-modal .overlay-tools { grid-column: 1 / -1; grid-row: 1; min-height: 48px; padding-block: 2px; }
  .screen-modal .overlay-tools ~ .speaker-head,
  .screen-modal .overlay-tools ~ .sheet-head { grid-column: 1; grid-row: 2 / 4; min-height: 0; }
  .screen-modal .overlay-tools ~ .sheet-body { grid-column: 2; grid-row: 2; }
  .screen-modal .overlay-tools ~ .sheet-actions { grid-column: 2; grid-row: 3; }
  .screen-modal .overlay-tools ~ .sheet-pager,
  .screen-modal .overlay-tools ~ .guided-sheet-pager { grid-column: 2; grid-row: 4; }
  .screen-modal.reading-sheet .sheet-body { justify-content: center; padding-block: 6px; }
  .screen-modal.reading-sheet .sheet-actions { padding-top: 0; }
  .screen-modal.pickup-sheet .modal-content:has(> .overlay-tools) { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
  .screen-modal.pickup-sheet .overlay-tools ~ .sheet-head { grid-column: 2; grid-row: 2; padding: 4px 16px 4px 12px; }
  .screen-modal.pickup-sheet .overlay-tools ~ .pickup-art { grid-column: 1; grid-row: 2 / 6; }
  .screen-modal.pickup-sheet .overlay-tools ~ .pickup-copy { grid-column: 2; grid-row: 3; }
  .screen-modal.pickup-sheet .overlay-tools ~ .pickup-actions { grid-column: 2; grid-row: 4; }
  .screen-modal.pickup-sheet .overlay-tools ~ .pickup-note { grid-column: 2; grid-row: 5; }
  .view-notice { top: calc(56px + env(safe-area-inset-top)); max-width: min(calc(100% - 28px), 440px); }
}
