/* A paper caption grows with its copy, leaving the miniature in view. */
.dock {
  height: auto;
  min-height: 0;
  max-height: 48dvh;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: .65rem;
  color: #30291f;
  background: linear-gradient(110deg, #fff2d7, #f1e3c2);
}
#setup, #fact {
  font: 400 1.0625rem/1.46 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  margin: 0;
  overflow-wrap: break-word;
}
#note h2 {
  line-height: 1.12;
  margin: .3rem 0 .5rem;
  text-wrap: pretty;
}
#speech { font: 400 1.125rem/1.3 "Trebuchet MS", system-ui, sans-serif; }
@media (orientation: landscape) and (max-height: 560px) {
  #speech { font-size: 1rem; }
}
#actions button, #next, #source {
  font: 600 .96875rem/1.23 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}
#source { text-underline-offset: .2em; }
#actions:empty { display: none; }
#dialogue, #note { overscroll-behavior: contain; }
@media (orientation: landscape) and (max-height: 560px) {
  .dock { max-height: 58dvh; }
  #setup, #fact { font-size: 1rem; line-height: 1.4; }
  #note-actions { flex-wrap: wrap; }
}

/* A full-bleed leaf of the sketchbook. The whole page scrolls on small displays. */
#note {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  color: #382e21;
  background: #eee2c2;
  overscroll-behavior: contain;
}
#note[open] { animation: turn-leaf .32s ease-out; }
#note::backdrop { background: #3a3023; }
.note-page {
  min-height: 100%;
  max-width: 47rem;
  margin: auto;
  padding: max(14px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(24px,env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(9rem,1fr) auto auto;
  gap: clamp(10px,2vh,22px);
  background: linear-gradient(95deg,#e7d7b3,#faf0d6 4%,#f7ebcd 87%,#eddfbd);
}
.note-mast, #note-actions { display: flex; align-items: center; justify-content: space-between; }
.note-mast { border-bottom: 1px solid #b7a584; }
#note small { font: 650 .76rem/1.4 system-ui,sans-serif; letter-spacing: .12em; }
#close-note {
  border: 0; background: transparent; color: inherit;
  width: 44px; height: 44px; font: 400 1.7rem/1 system-ui,sans-serif;
}
.note-plate {
  justify-self: center; align-self: center; aspect-ratio: 1; width: min(100%,36dvh,24rem);
  mask-image: linear-gradient(to right,transparent,#000 7%,#000 93%,transparent),linear-gradient(to bottom,transparent,#000 7%,#000 93%,transparent);
  -webkit-mask-composite: source-in; mask-composite: intersect;
  display: grid; place-items: center;
}
#note-art { width: 100%; height: 100%; min-height: 0; object-fit: contain; mix-blend-mode: multiply; }
.note-copy { max-width: 36rem; width: 100%; margin: 0 auto; }
#note h2 { font-size: clamp(1.8rem,5vw,2.65rem); }
#note #fact { max-width: 56ch; }
#note #source { font-size: .9rem; }
#note-actions { border-top: 1px solid #b7a584; padding-top: .85rem; gap: .7rem; flex-wrap: wrap; }
#stamp, #note #next {
  margin-left: auto; min-height: 46px; border: 0; border-radius: 4px; padding: .65rem 1.2rem;
  color: #fff7e6; background: #43503a; font: 600 .97rem/1.25 system-ui,sans-serif;
}
#date-imprint:not(:empty) {
  display: inline-block; padding: .4em .7em; color: #793f29; border: 3px double currentColor;
  font: 700 .82rem/1.25 system-ui,sans-serif; text-transform: uppercase; letter-spacing:.06em;
  position: relative; transform: rotate(-4deg);
}
/* The rubber foot meets the paper just as the brick-red ink appears. */
#date-imprint:has(.field-stamp-tool) { animation: transfer-ink .78s both; }
.field-stamp-tool {
  pointer-events: none; position: absolute; z-index: 1; bottom: 0; left: -4%; width: 108%; height: 18px;
  border: 1px solid #4d301e; border-bottom: 5px solid #3b3030; border-radius: 3px;
  background: repeating-linear-gradient(2deg, transparent 0 3px,#683e2544 4px,transparent 5px),
              linear-gradient(#bd8556,#9e633b 65%,#815034);
  box-shadow: 1px 2px 3px #50372347;
  transform-origin: 50% 100%; animation: press-stamp .78s both;
}
.field-stamp-tool::before, .field-stamp-tool::after {
  content: ''; position: absolute; left: 50%; transform: translateX(-50%);
  border: 1px solid #4d301e; background: linear-gradient(90deg,#694027,#b98250 35%,#8b5532 75%,#664024);
}
.field-stamp-tool::before { width: 17px; height: 26px; bottom: 100%; border-radius: 40% 40% 6% 6%; }
.field-stamp-tool::after { width: 34px; height: 21px; bottom: calc(100% + 17px); border-radius: 50%; }
@keyframes press-stamp {
  0% { opacity: 0; transform: translate(13px,-64px) rotate(8deg); }
  20% { opacity: 1; transform: translate(5px,-42px) rotate(4deg); }
  42%, 54% { opacity: 1; transform: translateY(0) scaleY(.93); }
  75% { opacity: 1; transform: translate(-3px,-21px) rotate(-3deg); }
  100% { opacity: 0; transform: translate(-9px,-54px) rotate(-6deg); }
}
@keyframes transfer-ink {
  0%, 39% { color: transparent; }
  43%, 100% { color: #793f29; }
}
@keyframes turn-leaf { from { opacity:.65; transform:translateX(3%); } }
@media (orientation:landscape) and (max-height:560px) {
  .note-page { grid-template-columns: 36% 1fr; grid-template-rows: auto 1fr auto; }
  .note-mast, #note-actions { grid-column: 1/-1; }
  .note-plate { width: min(100%,49dvh,16rem); }
  .note-copy { align-self:center; }
}
@media (prefers-reduced-motion:reduce) { #note[open], #date-imprint:not(:empty) { animation:none; } }
@media (orientation: portrait) and (max-height: 640px) {
  .note-page { padding-block: max(10px,env(safe-area-inset-top)) max(10px,env(safe-area-inset-bottom)); gap: 8px; grid-template-rows: auto minmax(6rem,1fr) auto auto; }
  .note-plate { width: min(100%,26dvh); }
}

@media (prefers-reduced-motion: reduce) { .field-stamp-tool { display: none; } #date-imprint:has(.field-stamp-tool) { animation: none; } }

/* Open the story beside its mounted photograph when the book is turned sideways. */
@media (orientation: landscape) {
  #stage:not([data-scene=cover]) {
    --story-page: clamp(15rem, 39%, 38rem);
    background: linear-gradient(95deg, #e3d0a8, #f8ecd1 6%, #efe0bd);
  }
  #stage:not([data-scene=cover]) :is(.set, .wash) { display: none; }
  #world {
    left: var(--story-page);
    background: radial-gradient(ellipse, #635942, #35392d);
    mask-image: none;
    box-shadow: inset 6px 0 16px #24251e66;
  }
  #play {
    position: absolute;
    inset: max(64px, env(safe-area-inset-top)) auto 0 0;
    width: var(--story-page);
    padding: 1rem clamp(1rem, 4vw, 4rem);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    justify-content: safe center;
    gap: clamp(.65rem, 3vh, 2rem);
    color: #3a3022;
  }
  #play > header, #play .dock {
    position: static; width: 100%; max-width: none;
    text-shadow: none;
  }
  #play > header h1 { font-size: clamp(1.7rem, 4.3vw, 4.6rem); }
  #play .dock {
    height: auto; max-height: none; padding: .8rem 0 0;
    background: transparent; border: 0; border-top: 1px solid #baa781;
    border-radius: 0; box-shadow: none;
  }
  #play #dialogue { overflow: visible; }
  #play #actions { flex-wrap: wrap; }
  .note-page {
    max-width: 68rem; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto; column-gap: clamp(1rem, 4vw, 4rem);
  }
  .note-mast, #note-actions { grid-column: 1 / -1; }
  .note-plate { width: min(100%, 55dvh, 29rem); }
  .note-copy { align-self: center; }
}

/* Desktop: one reading rail and one place to turn the page. */
#keyboard-hint { display: none; }
@media (min-width: 900px) and (min-height: 600px) and (orientation: landscape) {
  #stage:not([data-scene=cover]) { --story-page: clamp(22rem, 37%, 36rem); }
  #stage:not([data-scene=cover]) nav {
    right: auto;
    width: calc(var(--story-page) - 3rem);
    left: 1.5rem;
    justify-content: flex-start;
    gap: 1rem;
  }
  #stage:not([data-scene=cover]) nav button {
    background: transparent;
    border: 0;
    border-radius: 0;
    color: #63533b;
    padding: .4rem 0;
    font: 500 .85rem/1.4 system-ui, sans-serif;
  }
  #stage:not([data-scene=cover]) #home { min-width: 0; }
  #play {
    padding: clamp(1.5rem, 4vh, 3rem) clamp(1.5rem, 3vw, 3rem) 1.5rem;
    justify-content: flex-start;
    gap: 1.5rem;
  }
  #play > header h1 { font-size: clamp(2rem, 3.3vw, 3.6rem); }
  #play .dock {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding-top: 1.25rem;
  }
  #play #actions { margin-top: auto; justify-content: flex-end; }
  #play #actions button {
    background: transparent;
    color: #43503a;
    border-radius: 0;
    padding: .65rem 0 .65rem 1rem;
    border-bottom: 1px solid #8e9478;
    font-size: 1.05rem;
  }
  #play #actions button:hover { color: #26331e; border-bottom-color: currentColor; }
  #keyboard-hint {
    display: block;
    text-align: right;
    color: #74654e;
    font: 400 .72rem/1.5 system-ui, sans-serif;
  }
  #note.inline-note {
    position: static;
    width: 100%; height: auto; max-height: none;
    overflow: visible;
    background: transparent;
    animation: appear .25s ease-out;
  }
  #note.inline-note .note-page {
    display: block;
    min-height: 0;
    padding: 0;
    background: transparent;
  }
  #note.inline-note .note-mast { display: none; }
  #note.inline-note .note-plate {
    display: grid; width: min(100%, 24dvh, 14rem);
    margin: 0 auto 1rem;
  }
  #note.inline-note .note-copy { max-width: none; }
  #note.inline-note h2 { font-size: clamp(1.5rem, 2.25vw, 2.1rem); margin: 0 0 .85rem; }
  #note.inline-note #source { margin-top: .6rem; font-weight: 400; font-size: .8rem; }
  #note.inline-note #note-actions { border: 0; padding-top: .75rem; }
  #note.inline-note :is(#stamp, #next) { display: none; }

}
@media (min-width: 900px) and (min-height: 600px) and (orientation: landscape) {
  /* Keep every progression click on the illustration side of the spread. */
  #play #actions {
    position: fixed;
    left: calc(var(--story-page) + (100% - var(--story-page)) / 2);
    bottom: 3rem;
    transform: translateX(-50%);
    z-index: 4;
    margin: 0;
    white-space: nowrap;
  }
  #play #actions button {
    padding: .65rem 1.1rem;
    border: 1px solid #c5b48e;
    border-radius: 3px;
    background: #fff2d7;
    box-shadow: 0 2px 10px #24231826;
  }
  #keyboard-hint {
    position: fixed;
    left: calc(var(--story-page) + (100% - var(--story-page)) / 2);
    bottom: 1.1rem;
    transform: translateX(-50%);
    color: #fff2d7;
    text-shadow: 0 1px 4px #242318;
    white-space: nowrap;
    pointer-events: none;
  }
}

/* A dated ink impression, large enough to feel like the reward for a discovery. */
#date-imprint:not(:empty) {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  padding: .6rem 1rem;
  border: 5px double currentColor;
  color: #963c29;
  background: #a5422510;
  font: 900 1.05rem/1.15 system-ui,sans-serif;
  letter-spacing: .09em;
  text-shadow: .4px .3px currentColor;
  box-shadow: inset 0 0 0 1px #963c2933;
  transform: rotate(-6deg);
}
#date-imprint.stamp-fresh { animation: bold-ink .78s both; }
@keyframes bold-ink {
  0%, 39% { color: transparent; background: transparent; box-shadow: none; }
  43% { color: #963c29; transform: rotate(-6deg) scale(1.09,.94); }
  58% { transform: rotate(-6deg) scale(.98,1.02); }
  100% { color: #963c29; transform: rotate(-6deg); }
}
#stamp-sound {
  margin-left: auto;
  padding: .5rem .25rem;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: #65533b;
  font: 400 .75rem/1.3 system-ui,sans-serif;
  text-decoration: underline;
  text-underline-offset: .2em;
}
@media (prefers-reduced-motion: reduce) { #date-imprint.stamp-fresh { animation: none; } }
