* { box-sizing: border-box; }
:root { color-scheme: light; }
body { margin: 0; background: #242318; color: #fff6e4; font-family: Baskerville, "Baskerville Old Face", Georgia, serif; }
button, a { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid #ffb650; outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, blockquote, p { margin: 0; }
#stage { position: relative; height: 100vh; height: 100dvh; overflow: hidden; isolation: isolate; background: #594a32; }
.set, .wash, #world { position: absolute; inset: 0; }
.set { background: #594a32 url(assets/cover.webp) center 37% / cover; z-index: -3; }
#world { overflow: hidden; z-index: -2; background: #746546; }
#world-frame { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#final-art, #opening-art { display: block; position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; pointer-events: none; }
#opening-art { opacity: 1; transition: opacity .46s ease-in-out; }
.revealed #opening-art { opacity: 0; }
.wash { z-index: -1; pointer-events: none; background: linear-gradient(180deg,#1c1a1294,transparent 30%,transparent 65%,#191a102b); }
#stage[data-scene=cover] .wash { background: linear-gradient(90deg,#31200eda,transparent 80%),linear-gradient(0deg,#271b0caa,transparent 45%); }
nav { position: absolute; z-index: 3; top: max(12px,env(safe-area-inset-top)); left: max(18px,env(safe-area-inset-left)); right: max(18px,env(safe-area-inset-right)); display: flex; justify-content: space-between; pointer-events: none; }
nav button { pointer-events: auto; min-height: 44px; border: 1px solid #ece4d56b; background: #302918c9; color: #fff5dd; border-radius: 30px; padding: 8px 16px; }
#home { min-width: 44px; }
#stage[data-scene=cover] #home { visibility: hidden; }
#count { font-size: .82em; }
#cover { position: absolute; bottom: 12%; left: 7%; max-width: 87%; }
.date, #note small, #menu span { font: 600 .68rem/1.3 system-ui,sans-serif; text-transform: uppercase; letter-spacing: .16em; }
h1 { font-weight: 400; letter-spacing: -.045em; }
#cover h1 { font-size: clamp(4rem,9vw,9.5rem); line-height: .87; margin: .18em 0 .25em; }
#cover p:not(.date) { font-size: clamp(1.1rem,2vw,1.6rem); line-height: 1.25; }
.primary, #actions button, #next { border: 0; border-radius: 4px; padding: 9px 17px; min-height: 44px; background: #455038; color: #fff9e8; }
.primary { margin-top: 24px; color: #382a1c; background: #faf0d5; }
.primary span { padding-left: 16px; }
#play > header { position: absolute; left: 6%; top: calc(max(12px,env(safe-area-inset-top)) + 56px); max-width: 88%; text-shadow: 0 1px 6px #1f2119; }
#play > header h1 { font-size: clamp(2rem,4.4vw,4.5rem); line-height: 1; font-style: italic; margin-top: 5px; }
.dock { position: absolute; left: max(4%,env(safe-area-inset-left)); bottom: max(12px,env(safe-area-inset-bottom)); width: min(92%,430px); height: 193px; padding: 14px 18px 12px; display: grid; grid-template-rows: 1fr 44px; gap: 4px; color: #3d3428; background: linear-gradient(105deg,#f6eacdfc,#ece0c1fa); border: 1px solid #d2bf91; border-radius: 3px 6px 4px 2px; box-shadow: 0 5px 24px #2d241943; }
#dialogue, #note { min-height: 0; overflow: auto; }
blockquote { font-size: clamp(1.3rem,2.35vw,1.75rem); line-height: 1.12; font-style: italic; }
blockquote::before { content: '“'; }
blockquote::after { content: '”'; }
#setup, #fact { margin-top: 6px; font-size: 1rem; line-height: 1.22; }
#note h2 { font-size: 1.5rem; line-height: 1; margin: 4px 0; font-style: italic; font-weight: 400; }
#note { animation: appear .35s ease-out; }
#actions, #note-actions { display: flex; align-items: stretch; gap: 8px; }
#actions button:disabled { opacity: .6; }
#note-actions { align-items: center; justify-content: space-between; }
#source { color: #584f37; min-height: 44px; display: inline-flex; align-items: center; }
#menu { display: none; position: absolute; top: var(--menu-top); left: -2%; width: 104%; bottom: -1%; padding: 13px 0; display: none; align-content: start; text-align: center; color: #efe0b4; background: repeating-linear-gradient(0deg,#ffffff04 0px 1px,transparent 1px 3px),#414b37; border: 6px double #b4a778; box-shadow: 0 -3px 10px #201b1340; appearance: none; border-radius: 0; pointer-events: auto; transition: transform .72s cubic-bezier(.45,.02,.66,1); }
#menu i, #menu small, #menu span { display: block; }
#menu i { font-size: clamp(1.65rem,4vw,3rem); line-height: 1.2; }
#menu small { margin-top: 3px; }
/* The folded menu conceals the diner's whole pose until the player lowers it. */
[data-scene=pond] #world-frame { --menu-top: 46%; }
[data-scene=pond]:not(.revealed) #final-art {
  clip-path: inset(0 0 calc(100% - var(--menu-top)) 0);
}
[data-scene=pond] #menu {
  display: grid;
  height: calc(101% - var(--menu-top));
  gap: 3px;
  padding: clamp(14px, 3vh, 27px) 16px;
  background:
    repeating-linear-gradient(0deg, #f3ead909 0 1px, transparent 1px 3px),
    linear-gradient(105deg, #344330, #4d5a40 48%, #374732);
}
[data-scene=pond] #menu::after {
  content: ''; position: absolute; inset: 7px; border: 1px solid #e4d39870;
  pointer-events: none;
}
[data-scene=pond]:not(.revealed) #menu { transition: none; }
.revealed #menu { transform: translateY(104%); }
#fly, .saucer { display: none; }
[data-scene=fly] #fly { display: block; position: absolute; z-index: 1; width: var(--fly-width,10%); left: var(--fly-x); top: var(--fly-y); transform: translate(-50%,-96%); transition: left .58s ease-in-out, top .58s ease-in-out; pointer-events: none; }
#fly img { display: block; width: 100%; }
[data-fly=hover] #fly img { animation: hover 1.2s ease-in-out infinite alternate; }
[data-scene=fly]:not(.revealed) .saucer { display: block; position: absolute; width: 19%; min-width: 44px; height: 9%; min-height: 44px; transform: translate(-50%,-50%); border: 0; background: transparent; }
#salt { left: var(--salt-x); top: var(--salt-y); }
#sugar { left: var(--sugar-x); top: var(--sugar-y); }
@keyframes hover { to { transform: translate(3%, -8%) rotate(-3deg); } }
@keyframes appear { from { opacity: 0; } to { opacity: 1; } }
@media (orientation: landscape) and (max-height: 560px) {
  #play > header { top: max(12px,env(safe-area-inset-top)); left: calc(max(18px,env(safe-area-inset-left)) + 58px); width: 51%; }
  #play > header h1 { font-size: 1.7rem; }
  #cover { bottom: 7%; }
  #cover h1 { font-size: 3.7rem; }
  .dock { left: max(16px,env(safe-area-inset-left)); width: min(47%,420px); bottom: max(6px,env(safe-area-inset-bottom)); height: 152px; padding: 8px 14px; }
  #setup, #fact { margin-top: 3px; font-size: .92rem; }
  #note h2 { font-size: 1.2rem; margin: 2px 0; }
  blockquote { font-size: 1.18rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
/* On a phone turned sideways, the saucers need the lower half for direct taps. */
@media (orientation: landscape) and (max-height: 560px) {
  .dock { top: calc(max(12px,env(safe-area-inset-top)) + 60px); bottom: auto; }
}
@media (orientation: landscape) and (max-height: 560px) {
  #stage:not([data-scene=cover]) {
    background: linear-gradient(118deg,#484a36,#333b2d 45%,#272e26);
  }
  #stage:not([data-scene=cover]) .set { display: none; }
  #world { left: 35%; mask-image: linear-gradient(90deg,transparent,#000 4%); }
  #play > header { left: max(16px,env(safe-area-inset-left)); top: 60px; width: 31%; }
  #play > header h1 { font-size: clamp(1.25rem,2.7vw,1.7rem); }
  .dock {
    top: auto; bottom: max(8px,env(safe-area-inset-bottom)); left: max(12px,env(safe-area-inset-left));
    width: calc(35% - max(12px,env(safe-area-inset-left))); height: min(56%,205px); padding: 9px 12px;
  }
  #setup, #fact { font-size: .88rem; line-height: 1.16; }
  #note-actions { gap: 4px; }
  #actions button, #next { padding-inline: 9px; }
}

/* The paper sits over the illustration and underneath the dialogue. */
.paint-paper { position:absolute; inset:0; width:100%; height:100%; z-index:1; pointer-events:none; }
@media (prefers-reduced-motion:reduce) { .paint-paper { display:none; } }

@media (orientation: landscape) and (max-height: 560px) {
  [data-scene=bird] #world::before {
    content: ''; position: absolute; inset: -30px; background: var(--set-backdrop) center / cover;
    filter: blur(20px) brightness(.66);
  }
}

/* Follow the diner's bill beneath the water while the reading panel stays put. */
@media (orientation: portrait) {
  [data-scene=pond] #world-frame { transition: top .75s ease-in-out; }
  [data-scene=pond].revealed #world-frame { top: 40%; }
}

/* Dialogue travels with the photographed speaker, independently of the field note. */
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
#speech { position:absolute; z-index:2; width:max-content; max-width:min(210px,64vw,92%); margin:0;
  pointer-events:none; color:#403320; background:#fff3d8;
  border-radius:15px 17px 14px 12px; padding:8px 13px; text-align:center;
  font:italic 1.12rem/1.17 Baskerville,Georgia,serif; filter:drop-shadow(0 2px 2px #30210f38); }
#speech::before { content:none; }
#speech::after { content:''; position:absolute; left:var(--tip); top:calc(100% - 1px); width:14px; height:12px;
  background:#fff3d8; transform:translateX(-50%); clip-path:polygon(0 0,100% 0,50% 100%); }
#speech[data-voice=fly] { transition:left .58s ease-in-out,top .58s ease-in-out; }
#note { animation:appear .8s ease-out; }
@media (orientation:landscape) and (max-height:560px) { #speech { font-size:.91rem; padding:6px 9px; } }
@media (prefers-reduced-motion:reduce) { #speech,#note { transition:none; animation:none; } }

#cover #release-status { margin-top: 14px; font-size: 1rem; font-style: italic; }

#speech[data-edge=left]::after,#speech[data-edge=right]::after {
  top:var(--tip); width:12px; height:12px; transform:translateY(-50%);
}
#speech[data-edge=left]::after { left:-11px; clip-path:polygon(100% 0,100% 100%,0 50%); }
#speech[data-edge=right]::after { left:calc(100% - 1px); clip-path:polygon(0 0,100% 50%,0 100%); }
#speech[data-edge=top]::after { top:-11px; clip-path:polygon(50% 0,100% 100%,0 100%); }

/* Give the factual aside its own reading voice and let longer entries use the page. */
#fact { font: 400 1.0625rem/1.42 -apple-system, BlinkMacSystemFont, system-ui, sans-serif; }
.dock:has(#note:not([hidden])) {
  height: auto;
  min-height: 193px;
  max-height: 46dvh;
  grid-template-rows: minmax(0,1fr) 44px;
}
@media (orientation: landscape) and (max-height:560px) {
  #fact { font-size: 1rem; line-height: 1.4; }
  .dock:has(#note:not([hidden])) { min-height: 0; max-height: 64dvh; }
}
