/* One viewport, one readable page. Story pagination is owned by expedition-app.mjs. */
:root {
  --viewport-height: 100dvh;
  --reader-gutter: 20px;
  --reader-gap: 8px;
  --reader-font: 16px;
  --reader-leading: 1.4;
  --pager-height: 56px;
}

html,
body {
  width: 100%;
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }
.book,
.event-dialog,
.modal.screen-modal,
.modal.art-view {
  height: var(--viewport-height, 100dvh);
  max-height: var(--viewport-height, 100dvh);
  overflow: hidden;
}
#event-content {
  /* A dialog can be populated while closed. Keep its child independent from
     an unresolved percentage height when the browser promotes it to top layer. */
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
}
.screen-card *,
.screen-modal * { min-width: 0; }
.screen-card [hidden],
.screen-modal [hidden] { display: none !important; }

/* The map has a bounded footer, leaving every island space reachable. */
.board-footer {
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
}
.board-footer .journey-status {
  display: flex;
  font-size: 10px;
  line-height: 1.2;
}
.board-footer #board-hint {
  margin: 6px 0 8px;
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.3;
}
.board-footer .primary {
  min-height: 44px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.3;
}
.map-spaces, .map-routes {
  top: calc(212px + env(safe-area-inset-top));
  bottom: calc(144px + env(safe-area-inset-bottom));
  height: calc(100% - 356px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
.map-space { min-height: 44px; }
.space-card { width: 40px; height: 36px; }
.map-space.current .space-card { width: 44px; height: 40px; }
.space-label { margin-top: 3px; padding: 1px 4px; font-size: 10px; line-height: 1.2; }
.space-number { font-size: 18px; }
.map-space.current .space-number { font-size: 22px; }
.map-space.seen:not(.completed):not(.current) .space-card {
  border-color: #a8c3ab;
  background: #204635;
}
.map-space.completed:not(.current) .space-card {
  border-color: #b7dca0;
  background: #345b39;
}
.map-space.completed .space-check { display: grid; place-items: center; }
.map-space.has-new:not(.current) .space-card {
  border-color: #ffe0a0;
  box-shadow: 0 0 0 2px #e9bd603b, 0 4px 12px #00160ab3;
}
.space-status {
  position: absolute;
  z-index: 3;
  top: -9px;
  right: -9px;
  max-width: 72px;
  padding: 2px 5px;
  border: 1px solid #b4c6a8;
  border-radius: 4px;
  background: #163c2e;
  color: #eef4df;
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
}
.space-status:empty { display: none; }
.map-space.completed .space-status { background: #bad4a0; color: #183322; border-color: #d7e8b9; }
.map-space.completed:disabled .space-card {
  animation: none;
  border-color: #829780;
  background: #263f32;
  box-shadow: none;
  filter: saturate(.55);
}
.map-space.completed:disabled .space-label { color: #bfccb9; background: #17342be6; }
.map-space.has-new .space-status { background: #efd08a; color: #26351c; border-color: #ffe6b3; }
.restart-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #dbc18b80;
  border-radius: 6px;
  background: #12362bea;
  color: #f0d7a5;
  font-size: 12px;
  line-height: 1.2;
}

/* The painting yields space to readable text; it never pushes navigation away. */
.screen-card {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #08251e;
}
.screen-card .card-topbar {
  position: relative;
  top: auto;
  min-height: calc(56px + env(safe-area-inset-top));
  flex: 0 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) 14px 6px;
  background: #092b23;
  border-bottom: 1px solid #e2c48d29;
  gap: 8px;
}
.screen-card .card-topbar .back { min-height: 44px; padding-block: 7px; }
.screen-card .card-topbar .header-right { gap: 7px; }
.screen-card .card-topbar .score { font-size: 15px; }
.screen-card .card-topbar .score > span { font-size: 18px; }
.screen-card .card-topbar .score small { font-size: 10px; }

.screen-art {
  position: relative;
  /* Absolute-positioned images have no intrinsic flex size. Reserve a visible
     painting instead of allowing long controls to shrink this item to zero. */
  flex: 1 1 auto;
  min-height: clamp(88px, 18dvh, 148px);
  width: 100%;
  overflow: hidden;
  isolation: isolate;
  background: #0d332b;
  --subject-y: 50%;
}
.screen-image {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% var(--subject-y);
  pointer-events: none;
}
.screen-art[data-scene='arrival'] { --subject-y: 58%; }
.screen-art[data-scene='goggles'] { --subject-y: 43%; }
.screen-art[data-scene='leaf'] { --subject-y: 37%; }
.screen-art[data-scene='branch'] { --subject-y: 34%; }
.screen-art[data-scene='net'] { --subject-y: 45%; }
.screen-art[data-scene='waterfall'] { --subject-y: 28%; }
.screen-art[data-scene='engine'] { --subject-y: 14%; }
.screen-art[data-scene='abyss'] { --subject-y: 59%; }
.screen-art[data-scene='island'] { --subject-y: 56%; }
.screen-art[data-scene='eloi-meeting'] { --subject-y: 42%; }
.screen-art[data-scene='eloi-engine'] { --subject-y: 42%; }
.screen-art[data-scene='arrival'] .screen-image,
.screen-art[data-scene='goggles'] .screen-image,
.screen-art[data-scene='engine'] .screen-image,
.screen-art .screen-image[src*='atlas-eloi-'] {
  object-fit: contain;
  object-position: center;
  background: radial-gradient(ellipse at 50% 40%, #214b3b, #06271f 80%);
}
.screen-art.unlit .screen-image { visibility: hidden; }
.screen-art.dark-cavern .screen-image { filter: brightness(.06); }
.screen-art.dark-cavern.illuminated .screen-image { filter: none; }
.screen-art .screen-image.unrevealed { opacity: 0; }
.screen-art .inspect-art { z-index: 3; top: 8px; right: 10px; }
.companion-trigger {
  position: absolute;
  z-index: 3;
  bottom: 9px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  max-width: calc(100% - 72px);
  padding: 4px 10px 4px 4px;
  border: 1px solid #e4c384b5;
  border-radius: 6px;
  background: #0a291feb;
  box-shadow: 0 3px 12px #001b1766;
  color: #f4ddb2;
  text-align: left;
  font-size: 13px;
  line-height: 1.25;
}
.companion-trigger img {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 3px;
  object-fit: cover;
  object-position: 50% 30%;
}
.companion-trigger span { display: block; }
.companion-trigger small { display: block; font-size: 11px; color: #d2d6bb; }
.companion-trigger .companion-portrait-wrap {
  position: relative;
  display: block;
  flex: none;
  width: 44px;
  height: 44px;
  overflow: visible;
}
.companion-portrait-wrap .companion-dot {
  position: absolute;
  z-index: 2;
  top: -4px;
  right: -4px;
  display: block;
  width: 12px;
  height: 12px;
  border: 2px solid #17382a;
  border-radius: 50%;
  background: #ffcf69;
  box-shadow: 0 0 0 2px #ffdf9b82;
  pointer-events: none;
}
.companion-trigger.has-news { border-color: #ffe0a0; box-shadow: 0 0 0 1px #f0c67955, 0 3px 12px #001b1766; }
.companion-trigger.has-news small { color: #ffe0a0; }
.screen-art:has(.exploration-spots) .companion-trigger { top: 9px; bottom: auto; }

/* Every panel is content-sized; long prose is split into pages in JavaScript. */
.reader-panel {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--reader-gap);
  padding: 14px var(--reader-gutter) 12px;
  background: linear-gradient(115deg, #102e25, #08251e);
  border-top: 1px solid #d8b87754;
  box-shadow: 0 -5px 16px #001c1526;
  overflow-wrap: break-word;
}
.screen-eyebrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-family: var(--sans);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: .09em;
  color: #e4c184;
  text-transform: uppercase;
}
.frame-read-state {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 4px;
  font-family: var(--sans);
  font-size: 9px;
  line-height: 1.3;
  letter-spacing: 0;
  color: #bed1b6;
  text-transform: none;
  white-space: nowrap;
}
.reader-panel #card-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 400;
  line-height: 1.08;
  letter-spacing: -.015em;
  color: #f5e7c9;
  text-wrap: balance;
}
.screen-text {
  margin: 0;
  font-family: var(--serif);
  font-size: var(--reader-font);
  line-height: var(--reader-leading);
  color: #f3ead6;
  overflow-wrap: break-word;
}
.screen-text:empty { display: none; }
.screen-note { margin: 0; font-family: var(--sans); font-size: 12px; line-height: 1.35; color: #d5d9bf; }
.screen-actions,
.sheet-actions,
.speaker-actions {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: 8px;
}
.screen-actions:empty,
.sheet-actions:empty { display: none; }
.screen-actions { margin-top: 2px; }
.screen-card .primary,
.screen-card .secondary,
.screen-card .answer-button,
.screen-modal .primary,
.screen-modal .secondary,
.screen-modal .answer-button {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: break-word;
}
.screen-actions .item-icon { width: 22px; height: 22px; flex: none; }
.screen-actions .primary,
.screen-actions .secondary { display: flex; align-items: center; justify-content: center; gap: 8px; }
.screen-widget { flex: 0 0 auto; min-width: 0; }
.screen-widget:empty { display: none; }

/* Paging stays anchored and uses at least a 44px touch target. */
.screen-pager,
.sheet-pager {
  position: relative;
  z-index: 4;
  flex: 0 0 auto;
  min-height: calc(var(--pager-height) + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 14px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid #d7b77933;
  background: #08241efa;
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.2;
  color: #d7d8bd;
}
.screen-pager button,
.sheet-pager button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid #d2b4765e;
  border-radius: 5px;
  background: #173b2e;
  color: #f3dba6;
  font-size: 13px;
  line-height: 1.2;
}
.screen-pager button:disabled,
.sheet-pager button:disabled { opacity: .45; }
.screen-pager .text-button,
.sheet-pager .text-button {
  width: auto;
  margin: 0;
  padding-inline: 7px;
  border-color: transparent;
  background: transparent;
  font-size: 12px;
  text-underline-offset: 3px;
}
.screen-pager > span,
.sheet-pager > span { flex: 0 0 auto; text-align: center; font-variant-numeric: tabular-nums; }
.screen-pager button:focus-visible,
.sheet-pager button:focus-visible { outline-offset: 2px; }

/* Puzzles are a single page each, separate from their introductory narration. */
.screen-card[data-mode='puzzle'] .reader-panel { padding-top: 10px; gap: 7px; }
.screen-card[data-mode='puzzle'] .screen-art { min-height: 76px; }
.screen-card[data-mode='puzzle'] #card-title { font-size: 22px; }
.screen-card[data-mode='puzzle'] .screen-text { font-size: 15px; line-height: 1.35; }
.screen-widget .cipher-puzzle { margin: 0; }
.screen-widget .cipher-paper {
  --lens-size: 100px;
  height: clamp(150px, 23dvh, 190px);
  touch-action: none;
}
.screen-widget .cipher-paper.assisted { --lens-size: 130px; }
.screen-widget .red-lens {
  width: var(--lens-size);
  height: var(--lens-size);
  min-width: var(--lens-size);
  min-height: var(--lens-size);
  border-width: 4px;
}
.screen-widget .cipher-reveal { clip-path: circle(calc(var(--lens-size) / 2) at var(--lens-x, 18%) var(--lens-y, 84%)); }
.screen-widget .cipher-paper.decoded .cipher-reveal { clip-path: none; }
.screen-widget .lens-handle {
  left: calc(50% + var(--lens-size) * .31);
  top: calc(50% + var(--lens-size) * .31);
  width: 13px;
  height: 35px;
}
.screen-widget .cipher-line { font-size: 12px; line-height: 1.25; }
.screen-widget .cipher-paper.decoded .cipher-line { font-size: 12px; }
.screen-widget .cipher-noise { padding: 10px; font-size: 13px; }
.screen-widget .cipher-tools { margin-top: 5px; gap: 6px; }
.screen-widget .cipher-tools .secondary { min-height: 44px; font-size: 12px; padding-block: 8px; }
.screen-widget .cipher-progress { margin: 4px 0 0; font-size: 11px; line-height: 1.25; }
.screen-widget .lens-control { padding: 8px 10px; }
.screen-widget .lens-control label { font-size: 14px; line-height: 1.25; }
.screen-widget .lens-control p { min-height: 0; margin-top: 3px; font-size: 11px; line-height: 1.3; }
.screen-widget .lens-readout { min-height: 40px; margin-top: 6px; }
.screen-widget .optical-reveal { padding: 5px; }
.screen-widget .optical-reveal strong { font-size: 18px; }
.screen-widget .lens-control input[type='range'] { display: block; width: 100%; min-height: 44px; margin: 0; }
.screen-widget .die-area { padding: 3px 0; gap: 14px; }
.screen-widget .die { width: 50px; height: 50px; padding: 8px; gap: 4px; }
.screen-widget .die-area strong { font-size: 18px; }

/* The same fixed-page shell serves dialogue, satchel and help. */
.modal.screen-modal {
  position: fixed;
  inset: 0 auto auto 50%;
  transform: translateX(-50%);
  width: var(--stage-width);
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #0a2b22;
}
.screen-modal .modal-content,
.screen-modal.nemo-transmission .modal-content {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
.screen-modal .close {
  position: absolute;
  z-index: 8;
  width: 44px;
  height: 44px;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  background: #0c2d23ed;
  border-color: #d4b87599;
}
.sheet-head {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  min-height: calc(80px + env(safe-area-inset-top));
  padding: calc(19px + env(safe-area-inset-top)) 68px 12px 22px;
  border-bottom: 1px solid #e0bd7638;
  background: #0b2a21e6;
}
.screen-modal .sheet-head h2,
.screen-modal .speaker-head h2 {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 26px;
  line-height: 1.12;
  letter-spacing: -.02em;
  color: #f3ddb2;
}
.screen-modal .sheet-head .eyebrow,
.screen-modal .speaker-head .eyebrow { font-size: 10px; line-height: 1.3; letter-spacing: .08em; color: #e1c188; }
.screen-modal p.sheet-subtitle { margin-top: 6px; font-size: 12px; line-height: 1.35; color: #d3d8c2; }
.sheet-body {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  min-height: 0;
  gap: 12px;
  padding: 18px 22px;
  overflow-wrap: break-word;
}
.screen-modal p.sheet-message {
  margin: 0;
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.45;
  color: #f2e7cd;
}
.sheet-actions,
.screen-modal .speaker-actions { position: relative; z-index: 2; padding: 10px 22px 12px; }
.sheet-actions .text-button { margin: 0; font-size: 13px; }
.sheet-background,
.screen-modal .transmission-background {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: 50% 50%;
  pointer-events: none;
}
.screen-modal.dialogue-sheet .modal-content::before,
.screen-modal.nemo-transmission .modal-content::before {
  content: '';
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(#06281f4d, #05271e99 25%, #05241ebf 80%, #05271ed9);
  pointer-events: none;
}
.speaker-head {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: calc(110px + env(safe-area-inset-top));
  padding: calc(16px + env(safe-area-inset-top)) 66px 12px 20px;
}
.speaker-portrait {
  width: 80px;
  height: 80px;
  flex: none;
  object-fit: cover;
  object-position: 50% 27%;
  border: 2px solid #c5a164;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px #ffe4a66b, 0 5px 18px #001a1566;
}
.screen-modal.nemo-transmission .speaker-portrait { object-position: 50% 23%; }
.screen-modal .speaker-head h2 { font-size: 25px; }
.screen-modal .speaker-head p { font-size: 11px; line-height: 1.35; }
.speaker-copy { gap: 12px; }
.screen-modal .typewriter-message,
.screen-modal.nemo-transmission .typewriter-message {
  position: relative;
  width: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Courier New', Courier, monospace;
  font-size: 17px;
  line-height: 1.5;
  letter-spacing: -.025em;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  color: #fff0cc;
  text-shadow: 0 2px 8px #001910;
}
.screen-modal .typewriter-layout { display: block; visibility: hidden; }
.screen-modal .typewriter-ink { position: absolute; inset: 0; display: block; }
.screen-modal .typewriter-skip,
.screen-modal.nemo-transmission .typewriter-skip {
  min-height: 44px;
  margin: 0 auto;
  padding: 10px 6px;
  font-size: 12px;
  line-height: 1.3;
  color: #ead2a6;
}
.screen-modal .typewriter-skip:disabled { color: #c0cbb6; }
.inventory-detail { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.inventory-detail > .item-icon { width: 72px; height: 72px; padding: 10px; border: 1px solid #d1ad675c; border-radius: 8px; background: #14392c; }
.screen-modal .inventory-detail h3,
.screen-modal .inventory-detail strong { margin: 0; font-family: var(--serif); font-size: 23px; line-height: 1.2; font-weight: 400; color: #efd098; }
.screen-modal .inventory-detail p { margin: 0; font-size: 15px; line-height: 1.45; color: #e3dfc7; }
.screen-modal .inventory-detail .item-state { font-size: 11px; line-height: 1.3; }
.screen-modal p.inventory-feedback { margin: 0; padding-left: 10px; font-size: 14px; line-height: 1.4; }
.screen-modal .buddy-reply { padding: 12px 14px; border-left: 2px solid #dbb975; background: #0b2b21ba; font-family: var(--serif); font-size: 17px; line-height: 1.4; color: #f1e3c4; }

/* Inspecting art is the one-page uncropped view, with the same close target. */
.modal.art-view { max-height: none; }
.art-view .modal-content { width: 100%; height: 100%; min-height: 0; overflow: hidden; padding: 0; }
.uncropped-art { width: 100%; height: 100%; max-width: 100%; object-fit: contain; }

@media (max-width: 360px) {
  :root { --reader-gutter: 16px; }
  .screen-card .card-topbar { padding-inline: 10px; gap: 5px; }
  .screen-card .card-topbar .header-right { gap: 5px; }
  .screen-card .card-topbar .back { padding-inline: 8px; font-size: 11px; }
  .reader-panel #card-title { font-size: 22px; }
  .screen-pager, .sheet-pager { padding-inline: 10px; gap: 4px; }
  .screen-pager button, .sheet-pager button { font-size: 12px; padding-inline: 7px; }
  .screen-pager .text-button, .sheet-pager .text-button { font-size: 11px; padding-inline: 4px; }
  .sheet-body { padding-inline: 18px; }
  .sheet-actions { padding-inline: 18px; }
  .speaker-head { padding-left: 16px; gap: 10px; }
  .screen-modal .speaker-head h2 { font-size: 23px; }
  .board-header:has(.restart-control) .brand > span { display: none; }
  .card-topbar:has(.restart-control) .header-right { gap: 4px; }
  .card-topbar:has(.restart-control) .back { padding-inline: 6px; }
}

@media (max-height: 700px) {
  :root { --reader-gap: 7px; --reader-leading: 1.35; }
  .map-spaces, .map-routes {
    top: calc(178px + env(safe-area-inset-top));
    bottom: calc(128px + env(safe-area-inset-bottom));
    height: calc(100% - 306px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .space-card { width: 38px; height: 29px; }
  .map-space.current .space-card { width: 42px; height: 33px; }
  .space-label { font-size: 9px; line-height: 1.1; }
  .space-number { font-size: 16px; }
  .map-space.current .space-number { font-size: 19px; }
  .space-mark .compass { width: 26px; height: 26px; }
  .reader-panel { padding-block: 11px 10px; }
  .reader-panel #card-title { font-size: 22px; }
  .screen-modal p.sheet-message { font-size: 17px; line-height: 1.4; }
  .sheet-body { padding-block: 12px; gap: 10px; }
  .screen-modal .typewriter-message,
  .screen-modal.nemo-transmission .typewriter-message { font-size: 16px; line-height: 1.45; }
  .speaker-head { min-height: calc(100px + env(safe-area-inset-top)); padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 8px; }
  .sheet-actions, .screen-modal .speaker-actions { padding-block: 8px 10px; }
}

@media (max-height: 580px) {
  :root { --reader-gap: 6px; }
  .map-spaces, .map-routes {
    top: calc(156px + env(safe-area-inset-top));
    bottom: calc(120px + env(safe-area-inset-bottom));
    height: calc(100% - 276px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .board-footer { padding-top: 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .board-footer #board-hint { margin: 4px 0 6px; }
  .reader-panel { padding-top: 9px; padding-bottom: 8px; }
  .reader-panel #card-title { font-size: 21px; }
  .screen-eyebrow { font-size: 9px; }
  .screen-actions { gap: 6px; }
  .screen-card .primary, .screen-card .secondary, .screen-modal .primary, .screen-modal .secondary { padding-block: 9px; }
  .screen-card[data-mode='puzzle'] .reader-panel { padding-top: 7px; gap: 5px; }
  .screen-card[data-mode='puzzle'] #card-title { font-size: 21px; }
  .screen-widget .cipher-paper { height: 150px; }
  .speaker-head { min-height: calc(88px + env(safe-area-inset-top)); padding-top: calc(12px + env(safe-area-inset-top)); }
  .speaker-portrait { width: 68px; height: 68px; }
  .screen-modal .speaker-head h2 { font-size: 22px; }
  .screen-modal p.sheet-message { font-size: 16px; }
  .sheet-head { min-height: calc(74px + env(safe-area-inset-top)); padding-top: calc(16px + env(safe-area-inset-top)); padding-bottom: 10px; }
  .screen-modal .sheet-head h2 { font-size: 24px; }
  .sheet-body { gap: 8px; padding-top: 10px; padding-bottom: 10px; }
  .screen-modal .inventory-detail { gap: 9px; }
  .inventory-detail > .item-icon { width: 64px; height: 64px; }
}

/* Browser address bars can leave less than 540px on a portrait phone. Give the
   lens a smaller page of its own, while keeping every instruction and action. */
@media (max-height: 540px) and (orientation: portrait) {
  .screen-card .card-topbar {
    min-height: calc(50px + env(safe-area-inset-top));
    padding-top: calc(3px + env(safe-area-inset-top));
    padding-bottom: 3px;
  }
  .screen-pager {
    min-height: calc(50px + env(safe-area-inset-bottom));
    padding-top: 3px;
    padding-bottom: calc(3px + env(safe-area-inset-bottom));
  }
  .screen-card[data-mode='puzzle'] .reader-panel { padding-block: 6px; gap: 4px; }
  .screen-card[data-mode='puzzle'] .screen-eyebrow { display: none; }
  .screen-card[data-mode='puzzle'] #card-title { font-size: 20px; }
  .screen-card[data-mode='puzzle'] .screen-text { font-size: 14px; line-height: 1.35; }
  .screen-widget .cipher-paper { height: 120px; }
  .screen-widget .cipher-paper.assisted { --lens-size: 112px; }
  .screen-widget .cipher-line { font-size: 11px; line-height: 1.2; }
  .screen-widget .cipher-progress { font-size: 10px; margin-top: 3px; }
}

@media (min-width: 450px) and (min-height: 800px) {
  :root { --reader-gutter: 26px; --reader-font: 18px; }
  .reader-panel { padding-block: 16px 14px; gap: 10px; }
  .reader-panel #card-title { font-size: 28px; }
  .screen-card .primary, .screen-card .secondary, .screen-modal .primary, .screen-modal .secondary { font-size: 16px; min-height: 48px; }
  .screen-modal .sheet-body { padding-inline: 28px; }
  .screen-modal .typewriter-message, .screen-modal.nemo-transmission .typewriter-message { font-size: 19px; }
}

/* A short landscape viewport has a side-by-side page instead of a scroll area. */
@media (orientation: landscape) and (max-height: 430px) {
  :root { --stage-width: 100vw; --reader-gutter: 16px; --reader-gap: 6px; --reader-font: 16px; }
  .screen-card { display: grid; grid-template-columns: 40% minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; }
  .screen-card .card-topbar { grid-column: 1 / -1; min-height: 50px; padding-block: 3px; }
  .screen-art,
  .screen-card[data-mode='puzzle'] .screen-art { grid-column: 1; grid-row: 2; height: 100%; min-height: 0; }
  .reader-panel { grid-column: 2; grid-row: 2; justify-content: center; padding-block: 8px; border-top: 0; border-left: 1px solid #d8b87754; }
  .reader-panel #card-title { font-size: 21px; }
  .screen-pager { grid-column: 1 / -1; min-height: 50px; padding-block: 3px; }
  .screen-actions { flex-direction: row; gap: 6px; }
  .screen-actions > button { flex: 1 1 0; }
  .screen-widget .cipher-paper { height: 150px; }
  .screen-card[data-mode='puzzle'] .reader-panel { justify-content: center; gap: 4px; }
  .screen-card[data-mode='puzzle'] .screen-eyebrow { display: none; }
  .screen-modal .modal-content, .screen-modal.nemo-transmission .modal-content { display: grid; grid-template-columns: 34% minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto; }
  .sheet-head, .speaker-head { grid-column: 1; grid-row: 1 / 3; padding: 16px; min-height: 0; align-self: stretch; }
  .speaker-head { flex-direction: column; justify-content: center; align-items: flex-start; gap: 10px; }
  .sheet-body { grid-column: 2; grid-row: 1; padding: 12px 64px 8px 18px; }
  .sheet-actions, .screen-modal .speaker-actions { grid-column: 2; grid-row: 2; padding: 4px 18px 8px; flex-direction: row; }
  .sheet-actions > button { flex: 1 1 0; }
  .sheet-pager { grid-column: 1 / -1; grid-row: 3; min-height: 50px; padding-block: 3px; }
  .screen-modal .inventory-detail { flex-direction: row; flex-wrap: wrap; gap: 8px; text-align: left; }
  .inventory-detail > .item-icon { width: 50px; height: 50px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen-art .screen-image { transition: none; }
}

/* Network failures retain a visible, accessible retry instead of a blank art area. */
.image-retry {position:absolute;z-index:7;left:50%;top:50%;transform:translate(-50%,-50%);width:calc(100% - 36px);max-width:280px;min-height:44px;padding:9px 12px;border:1px solid #eac887;border-radius:5px;background:#10372bf2;color:#ffe7b2;font-size:13px;line-height:1.3;}
