/* Full-screen paintings with only the current story action above them.
   Loaded last: earlier reader styles reserve separate space for the picture. */
.screen-card {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  width: 100%;
  height: var(--viewport-height, 100dvh);
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: #061e18;
}
.screen-card > .card-topbar { display: none; }
.screen-card .screen-art,
.screen-card[data-mode='puzzle'] .screen-art {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  background: #061e18;
}
.screen-card .screen-art .screen-image {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% var(--subject-y, 50%);
  background: transparent;
}
.screen-art-backdrop {
  position: absolute;
  /* The backdrop precedes the sharp image in markup. The same non-negative
     layer keeps it above the host fill and below that following image. */
  z-index: 0;
  inset: -20px;
  width: calc(100% + 40px);
  height: calc(100% + 40px);
  max-width: none;
  object-fit: cover;
  filter: blur(18px) brightness(.55) saturate(.75);
  pointer-events: none;
}
/* Square object portraits retain the whole object. Their softly extended
   backdrop fills the viewport, while the sharp object stays above the caption. */
.screen-card .screen-art[data-scene^='item-'] .screen-image {
  top: calc(28px + env(safe-area-inset-top));
  height: 63%;
  object-fit: contain;
  object-position: 50% 28%;
}
.screen-card .screen-art.unlit .screen-art-backdrop { display: none; }
.scene-status {
  position: absolute;
  z-index: 4;
  top: calc(13px + env(safe-area-inset-top));
  right: 16px;
  display: flex;
  align-items: center;
  min-height: 26px;
  max-width: calc(100% - 32px);
  padding: 4px 9px;
  border: 1px solid #f4d49b35;
  border-radius: 30px;
  background: #05251b82;
  color: #f4deae;
  text-shadow: 0 1px 6px #00170d;
  pointer-events: none;
}
.scene-status .score { font-size: 12px; line-height: 1.2; }
.scene-status .score > span { font-size: 14px; }
.scene-status .score small { font-size: 9px; }

/* The gradient belongs to the caption rather than dimming the entire scene.
   Its extension also covers the single Continue button when one is present. */
.screen-card > .reader-panel,
.screen-card[data-mode='puzzle'] > .reader-panel {
  position: relative;
  z-index: 3;
  isolation: isolate;
  flex: 0 0 auto;
  width: 100%;
  margin: auto 0 0;
  padding: 18px var(--reader-gutter, 20px) 10px;
  gap: 8px;
  border: 0;
  box-shadow: none;
  background: transparent;
}
.screen-card > .reader-panel::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -70px 0 calc(-84px - env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #031b1600 0, #031b1699 54px, #031b16e8 112px, #031b16f5 100%);
  pointer-events: none;
}
.screen-card > .reader-panel:last-child {
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
.screen-card .screen-eyebrow { font-size: 10px; color: #f2d39a; }
.screen-card .reader-panel #card-title {
  font-size: 26px;
  line-height: 1.08;
  color: #fff0d2;
  text-shadow: 0 2px 14px #001d13;
}
.screen-card .screen-text {
  font-size: 16px;
  line-height: 1.4;
  color: #fff2dd;
  text-shadow: 0 1px 5px #00180f;
}
.screen-card .screen-actions { gap: 8px; margin-top: 3px; }
.screen-card .screen-actions > button { min-height: 46px; }
.screen-card > .screen-pager {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  display: flex;
  width: 100%;
  min-height: 0;
  gap: 8px;
  padding: 0 var(--reader-gutter, 20px) calc(16px + env(safe-area-inset-bottom));
  border: 0;
  background: transparent;
}
.screen-card > .screen-pager:empty { display: none; }
.screen-card > .screen-pager > button {
  flex: 1 1 0;
  min-height: 46px;
  padding: 11px 14px;
  border-color: #e7c382b8;
  background: #173e2ff0;
  color: #fff0ca;
  font-size: 14px;
  font-weight: 550;
}
.screen-card[data-mode='puzzle'] .reader-panel #card-title { font-size: 24px; }
.screen-card[data-mode='puzzle'] .screen-text { font-size: 15px; line-height: 1.35; }
.screen-card .screen-widget .cipher-paper { height: clamp(140px, 22dvh, 180px); }

/* Conversations use the same full painting. The portrait stays in the upper
   left and the typewritten Nemo message keeps its established central place. */
.screen-modal.dialogue-sheet .modal-content::before,
.screen-modal.nemo-transmission .modal-content::before {
  background: linear-gradient(180deg, #021a1440 0, #031d1510 22%, #031a14b5 46%, #031911ed 100%);
}
.screen-modal.dialogue-sheet .speaker-head,
.screen-modal.nemo-transmission .speaker-head {
  min-height: calc(90px + env(safe-area-inset-top));
  padding-top: calc(14px + env(safe-area-inset-top));
  padding-right: 20px;
  padding-bottom: 10px;
  background: linear-gradient(#041d16a6, transparent);
}
.screen-modal.dialogue-sheet .speaker-portrait,
.screen-modal.nemo-transmission .speaker-portrait {
  width: 64px;
  height: 64px;
}
.screen-modal.dialogue-sheet .sheet-message,
.screen-modal.nemo-transmission .typewriter-message {
  text-shadow: 0 1px 7px #00150f, 0 2px 18px #00150f;
}
.screen-modal.dialogue-sheet .sheet-pager,
.screen-modal.nemo-transmission .sheet-pager {
  border-top: 0;
  background: #031911b3;
}
.screen-modal .guided-sheet-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
  padding: 0 22px calc(16px + env(safe-area-inset-bottom));
  border: 0;
}
.screen-modal.dialogue-sheet .guided-sheet-pager,
.screen-modal.nemo-transmission .guided-sheet-pager { background: transparent; }
.screen-modal .guided-sheet-pager > button {
  flex: 1 1 0;
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 11px 14px;
  font-size: 14px;
}
.screen-modal.dialogue-sheet .sheet-actions:last-child,
.screen-modal.nemo-transmission .sheet-actions:last-child,
.screen-modal.inventory-sheet .sheet-actions:last-child {
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

@media (max-width: 360px), (max-height: 620px) {
  .screen-card > .reader-panel,
  .screen-card[data-mode='puzzle'] > .reader-panel {
    padding: 12px 16px 8px;
    gap: 6px;
  }
  .screen-card > .reader-panel:last-child { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .screen-card .reader-panel #card-title,
  .screen-card[data-mode='puzzle'] .reader-panel #card-title { font-size: 22px; }
  .screen-card .screen-text { font-size: 15px; line-height: 1.38; }
  .screen-card .screen-eyebrow { font-size: 9px; }
  .screen-card > .screen-pager { padding: 0 16px calc(12px + env(safe-area-inset-bottom)); }
  .screen-card .screen-actions { gap: 6px; }
  .screen-card .screen-actions > button,
  .screen-card > .screen-pager > button { min-height: 44px; }
  .screen-card .screen-widget .cipher-paper { height: 135px; }
  .scene-status { top: calc(10px + env(safe-area-inset-top)); right: 12px; }
  .screen-modal .guided-sheet-pager { padding-inline: 18px; }
  .screen-modal .guided-sheet-pager > button { min-height: 44px; }
}

/* Landscape also keeps the full-screen painting. Place text at the right so
   its shorter available height still fits the necessary actions without scroll. */
@media (orientation: landscape) and (max-height: 430px) {
  .screen-card { display: flex; flex-direction: column; align-items: flex-end; }
  .screen-card > .reader-panel,
  .screen-card[data-mode='puzzle'] > .reader-panel {
    width: 61%;
    padding: 10px 18px 6px;
    gap: 5px;
    justify-content: flex-end;
  }
  .screen-card > .reader-panel::before {
    inset: -56px -20px -80px -70px;
    background: linear-gradient(110deg, #031b1600, #031b16dc 22%, #031b16f2 100%);
  }
  .screen-card > .reader-panel:last-child { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .screen-card > .screen-pager { width: 61%; padding: 0 18px calc(10px + env(safe-area-inset-bottom)); }
  .screen-card .screen-eyebrow { display: none; }
  .screen-card .reader-panel #card-title,
  .screen-card[data-mode='puzzle'] .reader-panel #card-title { font-size: 21px; }
  .screen-card .screen-text,
  .screen-card[data-mode='puzzle'] .screen-text { font-size: 14px; line-height: 1.3; }
  .screen-card .screen-actions { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .screen-card .screen-actions > button { flex: 1 1 0; min-width: 100px; font-size: 12px; padding: 8px; }
  .screen-card .screen-widget .cipher-paper { height: 118px; }
  .screen-card .screen-widget .cipher-tools { margin-top: 3px; }
  .screen-card .screen-widget .cipher-progress { margin-top: 3px; }
  .screen-card .screen-art[data-scene^='item-'] .screen-image { inset: 12px auto 12px 0; width: 40%; height: calc(100% - 24px); object-position: 50% 50%; }
  .scene-status { left: 12px; right: auto; }
  .screen-modal.dialogue-sheet .speaker-head,
  .screen-modal.nemo-transmission .speaker-head { min-height: 0; padding: 16px; }
  .screen-modal .guided-sheet-pager {
    grid-column: 2;
    padding: 0 18px calc(10px + env(safe-area-inset-bottom));
  }
}

/* Life remains legible over the painting, distinct from discovery points. */
.life-meter { display: inline-flex; align-items: center; gap: 4px; color: #fae3d0; font: 600 13px/1.3 var(--sans, sans-serif); white-space: nowrap; }
.life-meter > span { color: #edaca5; font-size: 16px; }
.life-meter small { font-size: 10px; opacity: .8; }
.life-meter.life-low { color: #ffd8d1; }
.life-meter.life-low > span { color: #ff928b; }
.scene-status { gap: 12px; }
#board-score { display: flex; align-items: center; gap: 8px; }
.screen-card .screen-art.dark-entrance .screen-image { visibility: visible; opacity: 1; filter: brightness(.82); }
.screen-modal.rescue-sheet .rescue-body { gap: 16px; }
.screen-modal.rescue-sheet .life-meter { align-self: flex-start; padding: 7px 13px; border: 1px solid #f4d49b55; border-radius: 24px; background: #082820c9; font-size: 19px; }
.screen-modal.rescue-sheet .rescue-result { margin: 0; font-size: 20px; line-height: 1.3; font-weight: 600; color: #ffdfb7; }
.screen-modal.rescue-sheet .rescue-result.is-correct { color: #bbf1d0; }
.screen-modal.rescue-sheet .rescue-note { margin: 0; font-size: 14px; line-height: 1.4; color: #eee1c2; }
.screen-modal.rescue-sheet .sheet-actions { display: flex; flex-direction: column; gap: 9px; }
@media (max-height: 650px), (max-width: 360px) {
  .screen-modal.rescue-sheet .rescue-body { gap: 10px; padding-block: 10px; }
  .screen-modal.rescue-sheet .typewriter-message { font-size: 15px; line-height: 1.35; }
  .screen-modal.rescue-sheet .rescue-result { font-size: 18px; }
  .screen-modal.rescue-sheet .sheet-message { font-size: 16px; line-height: 1.4; }
  .screen-modal.rescue-sheet .life-meter { padding: 4px 10px; font-size: 16px; }
  .screen-modal.rescue-sheet .sheet-actions { gap: 6px; }
  .header-right { gap: 5px; }
  #board-score { flex-direction: column; gap: 1px; }
}

/* Every throw has an explicit, persistent die result, even a fatal encounter. */
.encounter-die-preview { display:flex; align-items:center; justify-content:center; gap:12px; }
.encounter-die-preview .screen-note { margin:0; text-align:left; }
.screen-widget .encounter-die-preview .die { width:42px; height:42px; padding:7px; gap:3px; border-radius:7px; }
.screen-modal.die-sheet .modal-content::before { content:''; position:absolute; z-index:1; inset:0; background:linear-gradient(#041e1850,#031e18d9 40%,#031e18f5); pointer-events:none; }
.screen-modal.die-sheet .sheet-head { padding-right:22px; }
.screen-modal.die-sheet .die-reveal { align-items:center; gap:30px; text-align:center; }
.screen-modal.die-sheet .die-area { justify-content:center; padding:15px; }
.screen-modal.die-sheet .die { width:110px; height:110px; padding:20px; gap:8px; border-radius:18px; }
.screen-modal.die-sheet .sheet-message { max-width:30ch; }
.screen-modal.die-sheet .sheet-actions { padding-bottom:calc(20px + env(safe-area-inset-bottom)); }
@media (max-height:620px) {
  .screen-modal.die-sheet .die-reveal { gap:20px; }
  .screen-modal.die-sheet .die { width:92px; height:92px; padding:16px; gap:7px; }
  .encounter-die-preview .screen-note { font-size:10px; line-height:1.3; }
}
@media (orientation:landscape) and (max-height:430px) {
  .screen-modal.die-sheet .die-reveal { flex-direction:row; gap:18px; padding:10px; }
  .screen-modal.die-sheet .die { width:76px; height:76px; padding:13px; gap:5px; }
}
/* Keep the workshop hidden until the player clears its foreground pane. */
.screen-card[data-activity='glass'] .screen-art .screen-image { filter:blur(15px) brightness(.58); transform:scale(1.04); }
