/* Shared viewport contract for the door, letters, atlas and conversation. */
:root {
  --viewport-height:100vh;
  --viewport-top:0px;
  --safe-top:env(safe-area-inset-top,0px);
  --safe-right:env(safe-area-inset-right,0px);
  --safe-bottom:env(safe-area-inset-bottom,0px);
  --safe-left:env(safe-area-inset-left,0px);
}
@supports(height:100dvh) {:root{--viewport-height:100dvh}}
html {-webkit-text-size-adjust:100%;text-size-adjust:100%}
html.modal-scroll-locked {overflow:hidden;overscroll-behavior:none}
html.modal-scroll-locked body {position:fixed;top:calc(-1 * var(--modal-scroll-y,0px));left:0;right:0;width:100%;overflow:hidden;overscroll-behavior:none}
/* This heading receives initial focus for screen readers without opening the
   phone keyboard. It is not a control; Safari's default blue frame is noise. */
#entry-title:focus {outline:none}
button,a,input,select,textarea {-webkit-tap-highlight-color:transparent}
img,video,audio {max-width:100%}
#scene-canvas {touch-action:pan-y pinch-zoom}

#entry-dialog.entry-vault {inset:var(--viewport-top) 0 auto;height:var(--viewport-height)}
#entry-dialog .vault-layout {min-height:var(--viewport-height)}
#index-dialog,#reader-dialog {top:var(--viewport-top);bottom:auto;height:var(--viewport-height)}

@media(max-width:1050px) {
  .header {padding-left:max(6vw,var(--safe-left));padding-right:max(6vw,var(--safe-right));height:calc(80px + var(--safe-top));padding-top:var(--safe-top)}
  .header-nav .menu-button {width:44px;height:44px;flex-shrink:0;padding:11px}
  .header-nav .terminal-nav {min-height:44px}
  .header-nav {flex-shrink:0}
  .stage {min-height:0}
  .cinema-panel {top:calc(120px + var(--safe-top));bottom:calc(120px + var(--safe-bottom));left:max(8vw,var(--safe-left));right:max(8vw,var(--safe-right))}
  .hero-panel {top:calc(125px + var(--safe-top));bottom:calc(110px + var(--safe-bottom))}
  .terminal-panel {top:calc(110px + var(--safe-top));bottom:calc(100px + var(--safe-bottom))}
  .hero-frame {top:calc(90px + var(--safe-top));bottom:calc(88px + var(--safe-bottom));left:max(14px,var(--safe-left));right:max(14px,var(--safe-right))}
  .journey-bottom {bottom:calc(8px + var(--safe-bottom));left:max(6vw,var(--safe-left));right:max(6vw,var(--safe-right));padding-top:8px}
  .journey-bottom button {min-height:44px}
  .chapter-nav {right:max(0px,var(--safe-right));top:50%;gap:0;transform:translateY(-50%)}
  .chapter-nav button {width:30px;height:44px}
  .chapter-nav button::before {left:13px;top:20px}
  .afterword {padding-left:max(7vw,var(--safe-left));padding-right:max(7vw,var(--safe-right));padding-bottom:var(--safe-bottom)}
  .afterword footer button {min-height:44px}
  .scroll-line {top:var(--safe-top)}
  .toast {max-width:calc(100% - 32px);bottom:calc(24px + var(--safe-bottom))}

  /* The scroll containers include the safe margins; the content remains fully
     reachable when a keyboard occupies most of a landscape screen. */
  #index-dialog,#reader-dialog {
    --sheet-gutter-left:max(6vw,var(--safe-left));--sheet-gutter-right:max(6vw,var(--safe-right));
    padding-top:0;padding-bottom:calc(35px + var(--safe-bottom));
    padding-left:max(6vw,var(--safe-left));padding-right:max(6vw,var(--safe-right));
    scroll-padding-top:calc(78px + var(--safe-top));scroll-padding-bottom:24px;
  }
  #index-dialog .sheet-top,#reader-dialog .sheet-top {
    position:sticky;top:0;z-index:12;isolation:isolate;background:#0b1513;
    margin-left:calc(-1 * var(--sheet-gutter-left));margin-right:calc(-1 * var(--sheet-gutter-right));
    padding:calc(12px + var(--safe-top)) var(--sheet-gutter-right) 12px var(--sheet-gutter-left);
    min-height:calc(68px + var(--safe-top));overflow:visible;
  }
  #index-dialog .sheet-top::after,#reader-dialog .sheet-top::after {
    content:none;
  }
  #index-dialog .close-button,#reader-dialog .close-button,#reply-dialog .close-button,#settings-dialog .close-button,#menu-dialog .close-button {width:44px;height:44px;flex-shrink:0}
  /* The focus ring belongs inside the button. An outward ring was painted
     under the sticky header's cover and looked like a cropped close icon. */
  dialog .close-button:focus-visible,
  #index-dialog .close-button:focus-visible,#reader-dialog .sheet-top .close-button:focus-visible,
  #reply-dialog .close-button:focus-visible,#settings-dialog .close-button:focus-visible,#menu-dialog .close-button:focus-visible {
    outline:2px solid #d6e5b1;outline-offset:-5px;
  }
  dialog .close-button:focus:not(:focus-visible) {outline:none}
  /* iOS can pan the visual viewport independently while showing the keyboard.
     A fully opaque backdrop covers the layout viewport throughout that move. */
  dialog::backdrop,#memory-dialog.terminal-v6::backdrop,
  #index-dialog::backdrop,#reader-dialog::backdrop,#reply-dialog::backdrop {
    background:#0b1513;backdrop-filter:none;-webkit-backdrop-filter:none;
  }
  dialog[open]:not(#letter-opening-dialog):not(#entry-dialog) {animation-name:mobile-dialog-in;transform:none}
  .keyboard-open #memory-dialog.terminal-v6 .memory-empty {justify-content:center;padding:0;min-height:0}
  .keyboard-open #memory-dialog.terminal-v6 .terminal-orbit {display:none}
  .keyboard-open #memory-dialog.terminal-v6 .memory-empty>p {font-size:24px;line-height:1.1;margin-top:0}
  #index-dialog .catalogue-search input,#reply-dialog :is(textarea,select),#settings-dialog select {font-size:16px;min-width:0}
  #reader-dialog .reading-article {overflow-wrap:anywhere}
  #reader-dialog .reader-neighbours {flex-wrap:wrap}
  #reader-dialog .reader-neighbours button {min-height:44px;max-width:100%}

  #menu-dialog {
    inset:calc(var(--viewport-top) + 10px + var(--safe-top)) max(10px,var(--safe-right)) auto auto;
    width:calc(100% - max(10px,var(--safe-left)) - max(10px,var(--safe-right)));
    max-height:calc(var(--viewport-height) - 20px - var(--safe-top) - var(--safe-bottom));
    padding:16px 20px 24px;scroll-padding:20px;
  }
  #menu-dialog .menu-links {grid-template-columns:repeat(2,minmax(0,1fr))}
  #menu-dialog .sheet-top {position:sticky;top:0;z-index:12;background:#14211a}
  #menu-dialog .sheet-top::after {content:'';position:absolute;bottom:100%;left:0;right:0;height:18px;background:#14211a;pointer-events:none}
  #menu-dialog .menu-links>button {min-width:0}
  #menu-dialog .menu-links>button:last-child {grid-column:1/-1;min-height:115px}
  #menu-dialog .menu-links>button:last-child::after {right:30%;top:25px}
  #settings-dialog,#reply-dialog {
    inset:calc(var(--viewport-top) + 12px + var(--safe-top)) 0 auto;
    margin:0 auto;max-height:calc(var(--viewport-height) - 24px - var(--safe-top) - var(--safe-bottom));
    width:min(530px,calc(100% - 24px - var(--safe-left) - var(--safe-right)));padding:42px 26px 28px;
    scroll-padding:20px;overscroll-behavior:contain;
  }
  #settings-dialog select,#reply-dialog select,#reply-dialog textarea {width:100%;max-width:100%}
  #reply-dialog .text-link {min-height:44px}
  #reply-dialog .small-note {overflow-wrap:anywhere}

  .vault-top {top:calc(16px + var(--safe-top));left:max(6vw,var(--safe-left));right:max(6vw,var(--safe-right))}
  #entry-motion {min-width:44px;min-height:44px;justify-content:flex-end}
  #entry-dialog .vault-layout {min-height:calc(var(--viewport-height) - 54px - var(--safe-bottom));padding-top:calc(80px + var(--safe-top));padding-bottom:30px;padding-left:max(9vw,var(--safe-left));padding-right:max(9vw,var(--safe-right))}
  #entry-dialog .vault-bottom {position:relative;inset:auto;margin:0 max(6vw,var(--safe-right)) 0 max(6vw,var(--safe-left));padding:16px 0 calc(20px + var(--safe-bottom))}
  #entry-submit {min-height:48px}
}
@keyframes mobile-dialog-in {from{opacity:0}to{opacity:1}}
@media(max-width:760px) and (orientation:portrait) {
  .regards-panel {display:flex;flex-direction:column;padding-top:0}
  .regards-panel h2 {font-size:clamp(32px,10vw,48px);line-height:1.06;margin:18px 0 14px}
  .regards-panel h2 em {font-size:inherit}
  .regards-choices {position:static;margin-top:auto;flex:none}
  .regards-choices button {font-size:clamp(20px,5.5vw,28px);padding:12px 0;min-height:60px;gap:12px}
}
@media(max-width:360px) {
  .header {gap:10px;padding-left:14px;padding-right:14px}
  .header-nav {gap:9px}
  #menu-dialog .menu-links>button {font-size:25px}
}
@media(max-width:760px) and (max-height:720px) {
  #entry-dialog .vault-layout {padding-top:calc(72px + var(--safe-top))}
}
@media(max-width:760px) and (max-height:720px) and (orientation:portrait) {
  .terminal-panel {gap:22px}
  .terminal-preview {max-width:260px}
  .terminal-preview-body {padding:14px 20px}
  .terminal-preview-body .terminal-prompt {display:none}
  .terminal-preview-body>p {font-size:28px;margin:8px 0}
  .terminal-chapter h2 {font-size:clamp(30px,9vw,42px);margin:12px 0}
}
@media(max-height:550px) and (max-width:1050px) {
  .header {height:calc(58px + var(--safe-top))}
  .header-nav>button[data-catalogue] {display:none}
  .header-caption {display:none}
  .header .seal-wordmark {width:44px;height:44px;flex-basis:44px}
  .cinema-panel,.hero-panel,.terminal-panel {top:calc(76px + var(--safe-top));bottom:calc(70px + var(--safe-bottom))}
  .hero-frame {top:calc(65px + var(--safe-top));bottom:calc(63px + var(--safe-bottom))}
  .hero-name {top:-16px;font-size:12vw}
  .hero-introduction {bottom:0}
  .hero-start.glass-control,.hero-explore {min-height:44px;padding-top:7px;padding-bottom:7px}
  .hero-interaction {display:none}
  .chapter-copy h2,.poems-panel .chapter-copy h2 {font-size:clamp(36px,8.8vw,76px);line-height:.9;margin-bottom:12px}
  .chapter-copy .pill-link {min-height:44px;padding-top:7px;padding-bottom:7px}
  .regards-panel h2 {width:44%;font-size:5.2vw;line-height:1.05;margin:14px 0}
  .regards-panel h2 em {font-size:inherit}
  .regards-choices {left:47%}
  .regards-choices button {font-size:clamp(18px,3vw,26px);min-height:44px;padding:6px 0;gap:10px}
  .terminal-preview-body .terminal-prompt {display:none}
  .terminal-preview-bar,.terminal-preview-bottom {padding:8px 14px}
  .terminal-preview-body {padding:8px 14px}
  .terminal-preview-body>p {font-size:clamp(21px,3.2vw,28px);margin:6px 0}
  .terminal-chapter h2 {font-size:clamp(27px,4.5vw,40px);margin:8px 0}
  .terminal-chapter>p:not(.eyebrow) {font-size:10px;margin-bottom:10px}
  .terminal-chapter .pill-link {min-height:44px;padding-top:7px;padding-bottom:7px}
  .chapter-nav button {height:34px}
  .chapter-nav button::before {top:15px}
  #entry-dialog .vault-layout {display:grid;grid-template-columns:.8fr 1fr;gap:5vw;padding-top:calc(72px + var(--safe-top));padding-bottom:20px;align-items:center}
  #entry-dialog .vault-object {width:100%;height:180px;margin:0}
  #entry-dialog .vault-seal {width:115px}
  #entry-dialog .vault-copy {padding:0}
  #entry-title {font-size:42px}
  #entry-intro {display:none}
  
  #menu-dialog .menu-links {grid-template-columns:repeat(3,minmax(0,1fr))}
  #menu-dialog .menu-links>button {min-height:125px;font-size:clamp(24px,4vw,34px);padding:15px 12px}
  #menu-dialog .menu-links>button:last-child {grid-column:span 2}
}
/* Keyboard reflow affects overlays only, never the height of the journey. */
.keyboard-open #entry-dialog .vault-layout {min-height:0}
@media print {#reader-dialog {height:auto;top:auto}}
