/* Illustration-first stage. Every reading/interaction surface overlays the art. */
:root { color-scheme: dark; font-family: "Avenir Next", Avenir, "Segoe UI", "Trebuchet MS", sans-serif; color: #f4ecda; background: #142320; font-synthesis: none; --ivory: #f4ecda; --muted: #c4c5b4; --brass: #a89a69; --panel: #203a32; }
* { box-sizing: border-box; }
body { margin: 0; }
button, summary { font: inherit; cursor: pointer; touch-action: manipulation; min-height: 44px; }
button, dialog { color: inherit; }
button:focus-visible, summary:focus-visible, .story-panel:focus-visible, .scene-window:focus-visible { outline: 3px solid #f9d48d; outline-offset: -3px; }
button:hover { filter: brightness(1.13); }
[hidden] { display: none !important; }
.prototype { max-width: 1680px; margin: 0 auto; padding: 8px; }
.art-frame { position: relative; isolation: isolate; height: max(420px, calc(100vh - 16px)); height: max(420px, calc(100dvh - 16px)); background: #20372e; box-shadow: 0 8px 32px #0005; }
.stage-body, .scene-window { position: absolute; inset: 0; }
.scene-window { overflow: hidden; }
.scene-window[data-pan="true"] { overflow-x: auto; overscroll-behavior-x: contain; }
.scene-visual { position: absolute; width: 100%; height: 100%; container-type: inline-size; }
.scene-art { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: cover; }
.scene-art--arriving { animation: art-arrive 180ms ease-out; }
.scene-art--scene-arriving { animation: scene-arrive 420ms ease-out; }
@keyframes art-arrive { from { opacity: .55; } to { opacity: 1; } }
@keyframes scene-arrive { from { opacity: 0; } to { opacity: 1; } }
.scene-visual[data-page-hidden="true"] .scene-art, .scene-visual[data-page-hidden="true"] .journal-ink { animation-play-state: paused; }
.art-frame[data-loading="true"] .scene-visual, .art-frame[data-art-failed="true"] .scene-art { visibility: hidden; }
.art-frame[data-art-failed="true"] .tea-steam { display: none; }

/* HUD floats above the painting. Options consume space only when opened. */
.stage-toolbar { position: absolute; z-index: 4; top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px; pointer-events: none; }
.stage-tools { display: flex; flex-wrap: wrap; gap: 4px; align-items: start; font-size: 13px; }
.stage-tools > *, .hud-menu-content { pointer-events: auto; }
.quiet-button, .hud-menu summary { border: 1px solid #a89a6980; color: var(--ivory); background: #142820ed; padding: 8px 12px; }
#autoplay-button { color: #f1ddb2; }
#phone-button { position: relative; }
#phone-button[data-unread="true"] { padding-right: 25px; }
.message-badge { position: absolute; top: 2px; right: 2px; display: grid; place-items: center; min-width: 17px; height: 17px; padding: 0 3px; border-radius: 50%; background: #a72b35; color: #fff; font-size: 11px; font-weight: 600; line-height: 1; }
.hud-menu { position: relative; margin-left: auto; }
.hud-menu summary { display: flex; align-items: center; list-style: none; }
.hud-menu summary::after { content: ' ⋮'; margin-left: 8px; }
.hud-menu summary::-webkit-details-marker { display: none; }
.hud-menu-content { position: absolute; top: 100%; right: 0; width: min(300px, calc(100vw - 36px)); padding: 12px; background: #182c25fa; border: 1px solid var(--brass); max-height: 60vh; max-height: 60dvh; overflow: auto; }
.stage-location { display: grid; gap: 6px; font-size: 13px; line-height: 1.5; }
#reading-status, #save-summary { font-size: 13px; color: var(--muted); }
.save-status, .art-error { position: absolute; z-index: 5; top: 64px; left: 12px; max-width: min(480px, calc(100% - 24px)); max-height: 22%; overflow: auto; margin: 0; padding: 10px 12px; background: #203a32f5; border: 1px solid #d6b36b; font-size: 14px; line-height: 1.5; }
.art-error { top: 100px; }
.pan-hint { display: none; position: absolute; pointer-events: none; top: 108px; right: 12px; padding: 4px 8px; background: #142820c9; font-size: 12px; }
.scene-window[data-pan="true"] ~ .pan-hint { display: block; }

/* Content grows within a bounded overlay, never below the scene. */
.story-panel { position: absolute; z-index: 2; left: 3%; bottom: 4%; width: fit-content; max-width: min(62%, 780px); max-height: 44%; padding: 6px 9px; overflow: auto; overscroll-behavior: contain; scrollbar-gutter: auto; background: var(--panel); border: 1px solid var(--brass); box-shadow: 0 4px 18px #101b2060; overflow-wrap: anywhere; }
.scene-kicker, .speaker-label { font-size: 11px; font-weight: 600; letter-spacing: .13em; line-height: 1.5; }
.scene-kicker { color: #d2c59e; margin: 0 0 8px; }
.story-panel .scene-kicker { display: none; }
.art-frame[data-placement="choice"] .scene-kicker, .art-frame[data-placement="end"] .scene-kicker { display: block; }
.story-content p { margin: 0; }
.story-content .speaker-label { color: #dfd0a9; margin-bottom: 2px; }
.story-panel .dialogue-text, .story-panel .narration-text { font-size: 1rem; font-weight: 400; line-height: 1.4; }
.art-frame[data-placement="narration"] .story-panel { color: #20372f; background: #eee2c5; border-color: #9c895e; border-left: 4px solid #b48745; }
.art-frame[data-placement="narration"] .scene-kicker { color: #52664e; }
.art-frame[data-placement="thought"] .story-panel { background: #36313c; border-color: #b4a2b9; }
.art-frame[data-placement="thought"] .speaker-label { color: #ddc9df; }
.art-frame[data-placement="narration"] .story-panel, .art-frame[data-placement="thought"] .story-panel { top: 80px; bottom: auto; max-width: min(46%, 620px); }
.art-frame[data-placement="choice"] .story-panel, .art-frame[data-placement="conviction"] .story-panel { width: min(520px, 52%); max-width: none; max-height: calc(100% - 116px); }
.story-controls { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.story-controls:empty, .advance-controls:empty { display: none; }
.choice-list { display: grid; gap: 6px; width: 100%; }
.choice-button { width: 100%; text-align: left; padding: 8px 10px; background: #2c473d; border: 1px solid #78846a; line-height: 1.45; font-size: 16px; }
.choice-button:hover { background: #3c5948; }
.primary-button { padding: 8px 16px; border: 1px solid #b5a372; background: #354d3e; font-size: 14px; }
.primary-button::after { content: ' →'; padding-left: 8px; color: #e3c58e; }
.advance-controls { display: flex; justify-content: flex-end; margin-top: 4px; }
.advance-chevron { width: 44px; min-width: 44px; min-height: 44px; padding: 0; border: 1px solid transparent; background: transparent; color: inherit; font-size: 20px; line-height: 1; }
.advance-chevron:hover { border-color: currentColor; }
.journal-controls { position: absolute; z-index: 2; right: 3%; bottom: max(18px, env(safe-area-inset-bottom)); }
.journal-controls:empty { display: none; }

/* Scene composition profiles are authored in scene metadata. */
.art-frame[data-overlay="kitchen"][data-placement="brother"] .story-panel { top: 80px; bottom: auto; max-width: 42%; }
.art-frame[data-overlay="kitchen"][data-placement="choice"] .story-panel { left: 20%; width: 36%; }
.art-frame[data-overlay="home"] .story-panel { left: auto; right: 3%; top: 80px; bottom: auto; width: min(340px, 31%); max-width: 31%; max-height: calc(100% - 112px); }
.art-frame[data-overlay="doorway"] .story-panel { left: 3%; right: auto; max-width: 39%; }
.art-frame[data-overlay="bookshelf"][data-placement="explore"] .story-panel { left: 2%; top: 80px; bottom: auto; width: 30%; max-width: 30%; max-height: calc(100% - 112px); }
/* Keep notebook narration above the paper; writing has no dialogue panel. */
.art-frame[data-notebook="evening"] .story-panel, .art-frame[data-notebook="morning"] .story-panel { top: 80px; bottom: auto; max-height: 38%; }
.art-frame[data-placement="conviction"] .story-panel { top: 80px; bottom: auto; max-height: calc(100% - 110px); }
.art-frame[data-placement="end"] .scene-window { display: none; }
.art-frame[data-placement="end"] { background: #111b19; }
.art-frame[data-placement="end"] .story-panel { top: 25%; bottom: auto; left: 50%; transform: translateX(-50%); width: min(600px, 90%); max-width: 90%; max-height: 65%; background: none; border: 0; box-shadow: none; text-align: center; }

/* These coordinates remain in the uncropped illustration's coordinate system. */
.tea-steam { display: none; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scene-visual[data-home="true"][data-motion="on"]:not([data-page-hidden="true"]) .tea-steam { display: block; }
.steam-wisp { fill: none; stroke: #fff3dc; stroke-width: 2.5; stroke-linecap: round; opacity: 0; animation: steam-rise 6.7s ease-in-out infinite; }
.steam-wisp--second { animation-duration: 8.3s; animation-delay: -3.2s; }
@keyframes steam-rise { 0%,100% { opacity: 0; transform: translate(0,8px); } 25% { opacity: .09; } 65% { opacity: .06; } 90% { opacity: 0; transform: translate(4px,-20px); } }
.journal-page { position: absolute; left: 53.7%; top: 52.7%; width: 19%; color: #29221c; transform: rotate(3deg) skewX(-2deg); transform-origin: top left; font-family: "Bradley Hand", "Segoe Print", "Noteworthy", "Chalkboard SE", cursive; font-size: 2cqw; font-weight: 400; line-height: 1.15; cursor: pointer; }
.journal-page:focus-visible { outline: 2px solid #574329; outline-offset: 8px; }
.journal-sentence { margin: 0 0 .45em; }
.journal-line { display: block; white-space: pre; }
.journal-ink { animation: ink-arrive 180ms linear both; }
@keyframes ink-arrive { from { opacity: 0; } to { opacity: 1; } }
.art-frame[data-notebook="morning"] .journal-page { left: 52.5%; top: 53.4%; }
.art-frame[data-paged-journal="true"] .journal-page { font-size: 1.7cqw; line-height: 1.2; }
.art-frame[data-journal-fallback="true"] .scene-visual { background: #cfa775; }
.art-frame[data-journal-fallback="true"] .journal-page { background: #e8d2aa; }
.bookshelf-hotspots { position: absolute; inset: 0; pointer-events: none; }
.book-hotspot { position: absolute; pointer-events: auto; min-width: 44px; min-height: 44px; border: 2px solid #e4c383b3; background: #f2d59512; color: #fff5e1; padding: 4px; font-size: clamp(12px, 1.1vw, 17px); text-shadow: 0 1px 3px #000; display: flex; align-items: end; justify-content: center; }
.book-hotspot:hover, .book-hotspot:focus-visible { background: #142320b3; border-color: #f9d48d; }
.dev-navigation { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 16px; padding: 6px 8px; font-size: 12px; }
.dev-navigation span { color: var(--muted); }
.dev-navigation button:disabled { opacity: .4; cursor: default; }

.reflection-dialog { width: min(820px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: 24px; background: var(--panel); border: 1px solid var(--brass); }
.reflection-dialog::backdrop { background: #071510c9; }
.reflection-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.reflection-header h2 { margin: 0; font-weight: 500; }
.icon-button { border: 1px solid #889175; background: transparent; font-size: 24px; min-width: 44px; }
.reflection-intro, .reflection-columns { line-height: 1.6; }
.reflection-columns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; }
.reflection-columns h3 { font-size: 15px; font-weight: 600; }
.reflection-columns ul { padding-left: 20px; font-size: 15px; }
.reflection-columns li { margin-bottom: 10px; }
.reflection-actions { margin-top: 16px; text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.inquiry-cards { display: grid; gap: 12px; margin-block: 20px; }
.inquiry-cards details { border: 1px solid var(--brass); padding: 12px; line-height: 1.5; }
.inquiry-cards summary { cursor: pointer; min-height: 44px; }
.inquiry-cards summary:focus-visible { outline: 3px solid #f9d48d; outline-offset: 4px; }
.phone-dialog { width: min(860px, calc(100% - 24px)); }
.phone-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 20px; margin-top: 20px; }
#phone-art { width: 100%; max-height: 60vh; object-fit: contain; }
.phone-conversation { max-height: 60vh; overflow-y: auto; overscroll-behavior: contain; }
#phone-messages { list-style: none; padding: 0; margin: 0; }
.message { padding: 12px 16px; margin-bottom: 16px; background: #e8dcc2; color: #20372f; border-radius: 4px; line-height: 1.5; }
.message--outgoing { margin-left: 20px; background: #c7d0b2; }
.message p { margin: 0; }
.message .message-label { margin-bottom: 8px; font-size: 13px; }
.phone-dialog { overflow-y: auto; }
.phone-dialog[data-view="threads"] .phone-layout, .phone-dialog[data-view="call"] .phone-layout { grid-template-columns: minmax(0, 1fr); }
.phone-conversation { min-width: 0; overflow-wrap: anywhere; }
#phone-threads { list-style: none; margin: 0; padding: 0; }
#phone-threads button { width: 100%; text-align: left; margin-bottom: 8px; }
#phone-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#phone-actions button { min-height: 44px; white-space: normal; text-align: left; max-width: 100%; }
#phone-draft { margin-top: 12px; }
#phone-draft-label { display: block; margin-bottom: 6px; }
#phone-draft-text { width: 100%; box-sizing: border-box; padding: 9px; font: inherit; line-height: 1.45; resize: vertical; color: #20372f; background: #e8dcc2; border: 1px solid var(--brass); }
#phone-draft-text:focus-visible, #phone-call:focus-visible { outline: 3px solid #f9d48d; outline-offset: -3px; }
#phone-call { padding: 12px; border: 1px solid var(--brass); line-height: 1.45; }
#phone-call[data-kind="thought"] { background: #483346; }
#phone-call[data-kind="narration"] { background: #e8dcc2; color: #20372f; }
#phone-status:empty { display: none; }
#phone-save-status { border-left: 3px solid var(--brass); padding-left: 8px; }
@media (max-height: 600px), (max-width: 450px) {
  .phone-dialog { padding: 12px; max-height: calc(100dvh - 16px); }
  .phone-dialog .phone-layout { grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
  .phone-dialog #phone-art { display: none; }
  .phone-dialog .phone-conversation { max-height: none; }
}
#conviction-preview { padding-block: 12px; line-height: 1.5; }

@media (max-width: 700px) {
  .stage-tools { font-size: 12px; gap: 3px; }
  .stage-tools .quiet-button, .hud-menu summary { padding: 6px 8px; }
  .story-panel, .art-frame[data-overlay][data-placement] .story-panel,
  .art-frame[data-placement="narration"] .story-panel, .art-frame[data-placement="thought"] .story-panel {
    left: 10px; right: 10px; top: auto; bottom: 22px; transform: none; width: auto; max-width: none; max-height: 44%;
  }
  .art-frame[data-overlay][data-placement="choice"] .story-panel, .art-frame[data-overlay][data-placement="conviction"] .story-panel { max-height: calc(100% - 140px); }
  .art-frame[data-notebook="morning"][data-placement] .story-panel, .art-frame[data-notebook="evening"][data-placement] .story-panel { top: 112px; bottom: auto; max-height: 32%; }
  .art-frame[data-overlay][data-placement="conviction"] .story-panel { max-height: calc(100% - 140px); }

  .art-frame[data-overlay="bookshelf"][data-placement="explore"] .story-panel { top: auto; bottom: 8px; max-height: 22%; }
  .art-frame[data-overlay][data-placement="end"] .story-panel { top: 25%; max-height: 65%; }
  .art-frame[data-overlay="home"][data-placement] .story-panel { max-height: 32%; }
  .reflection-columns { grid-template-columns: 1fr; gap: 0; }
  .reflection-dialog { padding: 18px; }
  .phone-layout { grid-template-columns: 1fr; }
  #phone-art { max-height: 160px; object-fit: cover; object-position: center 22%; }
  .phone-conversation { max-height: 45vh; }
}
@media (max-height: 500px) and (min-width: 701px) {
  .story-panel { max-height: calc(100% - 100px); }
  .art-frame[data-placement="narration"] .story-panel, .art-frame[data-placement="thought"] .story-panel { top: 68px; }
}
@media (prefers-reduced-motion: reduce) {
  .tea-steam, #motion-button { display: none !important; }
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 700px) and (orientation: portrait) {
  .art-frame[data-overlay="bookshelf"] { height: min(calc(100vh - 16px), calc((100vw - 16px) * 1.2)); height: min(calc(100dvh - 16px), calc((100vw - 16px) * 1.2)); min-height: 340px; }
}

/* Ordinary prose shares its final text row with a small visible chevron and a
   full 44px hit target. Keep authored actions/choices and notebook UI separate. */
.art-frame[data-overlay][data-placement] .story-panel:has(.advance-chevron) {
  display: grid; grid-template-columns: minmax(0, 1fr) 44px;
  align-items: end; column-gap: 4px; width: fit-content;
}
.story-panel:has(.advance-chevron) .story-content { grid-column: 1; grid-row: 1; min-width: 0; }
.story-panel:has(.advance-chevron) .advance-controls { grid-column: 2; grid-row: 1; margin-top: 0; }
.story-panel > .scene-kicker { margin-bottom: 4px; }
@media (max-width: 700px) {
  .art-frame[data-overlay][data-placement] .story-panel:has(.advance-chevron) { max-width: calc(100% - 20px); }
}
