/* The rollers and name slip stay outside the independently scrolling sheet. */
#overlay {
  --ink: #352d24;
  --gutter: clamp(20px, 4vw, 66px);
  --figure: clamp(175px, 25vw, 400px);
  display: grid;
  place-items: end center;
  padding: 16px 0 clamp(16px, 3vh, 34px);
  background: linear-gradient(0deg, #21130e47, transparent 36%);
  backdrop-filter: none;
}
#overlay[hidden], #dialogFigure[hidden] { display: none; }
#overlay.documentWindow {
  place-items: center;
  background: #241a1559;
  padding: 24px 0;
}
#overlay .scrollWindow {
  position: relative;
  isolation: isolate;
  width: min(81%, 1440px);
  max-height: none;
  overflow: visible;
  color: var(--ink);
  background-image: linear-gradient(95deg,#fff0d1f5 8%,#f7e5c7eb 55%,#f6e1bfcb),url(art/kaifeng-ink-screen.webp);
  background-position: center, right bottom;
  background-size: cover, cover;
  background-repeat: no-repeat;
  background-color: #f6e4c5;
  border: 1px solid #824530;
  box-shadow: inset 0 0 0 3px #f4dfb6, inset 0 0 0 4px #bd8650, inset 0 0 0 8px #f9e8c7, inset 0 0 0 9px #d5ae75, 0 8px 24px #27150f52;
}
.scrollWindow::before,.scrollWindow::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: clamp(8px, 1vw, 15px);
  inset-block: -10px;
  border-radius: 3px;
  border: 1px solid #74412c;
  background:
    linear-gradient(to bottom,#93612e 0 2px,#f2ca7a 2px 5px,#9c6231 5px 7px,transparent 7px calc(100% - 8px),#ad7838 calc(100% - 8px),#f1c578 calc(100% - 5px),#a57539),
    linear-gradient(90deg,#642a25,#ac5441 38%,#832f29 78%,#643225);
}
.scrollWindow::before {left:-6px}
.scrollWindow::after {right:-6px}
#overlay.documentWindow article { width: min(660px, 90%); }
#overlay[data-dialog="map"] article { width: min(770px, 90%); }
.scrollHeading {
  position: absolute;
  z-index: 2;
  left: var(--gutter);
  top: 0;
  transform: translateY(-50%);
  max-width: calc(100% - var(--gutter) - 52px);
  min-width: min(11.5vw, 194px);
  padding: .10em .9em;
  border: 8px solid transparent;
  border-image: url(art/dialogue/place-frame.png) 10 fill / 8px;
  color: #432916;
  font-size: clamp(14px,1.22vw,21px);
  font-weight: 600;
  text-align: center;
  letter-spacing: .12em;
  line-height: 1.14;
}
#dialogPlace { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#overlay #modal {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  min-height: clamp(142px,21vh,225px);
  max-height: 48dvh;
  padding: clamp(28px,4vh,48px) var(--gutter) clamp(20px,3vh,36px);
  scrollbar-width: thin;
  scrollbar-color: #b18a59 transparent;
}
#overlay.withPortrait #modal { margin-right: calc(var(--figure) + 12px); padding-right: 12px; }
#overlay.documentWindow #modal { max-height: 76dvh; padding: 29px clamp(18px,3vw,44px) 24px; }

#overlay #modal h2 { margin: 1px 0 9px; font-size: clamp(21px,1.7vw,28px); color:#552e24; }
#modal .spokenTitle {
  position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap;
}
#overlay #modal p,#overlay #modal li { margin: 0 0 .5em; font: inherit; font-size: clamp(16px,1.58vw,26px); line-height: 1.7; }
#overlay.documentWindow #modal p,#overlay.documentWindow #modal li { font-size: 16px; }
#overlay #modal small { font-size: .85em; color:#705332; }
#overlay #modal button,#overlay #modal #mapPlaces button {
  min-height: 36px;
  padding: .20em .92em;
  margin: 5px 7px 2px 0;
  border: 8px solid transparent;
  border-radius: 0;
  border-image: url(art/dialogue/action-frame.png) 16 fill / 12px;
  background: transparent;
  color: #f9d58e;
  font-size: clamp(15px,1.13vw,19px);
  letter-spacing: .08em;
}
#overlay #modal button:hover:not(:disabled) { filter:brightness(1.15); }
#overlay #modal #mapPlaces button[aria-pressed="true"] { filter:brightness(.82);text-decoration:underline; }
#overlay #modal button:focus-visible { outline:0;filter:brightness(1.22) drop-shadow(0 0 2px #895523); }
#overlay button:focus-visible { outline:2px solid #693125;outline-offset:2px; }
#overlay #modal button:disabled { opacity:.55;cursor:default; }
#overlay #modal #mapPlaces { gap:4px; }
#overlay #modal #mapPlaces button { margin:0; min-height:30px; padding:.32em .72em; font-size:13px; }
#overlay #close {
  position:absolute; right:14px;top:12px;z-index:4;
  width:27px;height:27px;line-height:1;padding:0;
  border:1px solid #b47750;border-radius:2px;background:#893327;color:#ffeac4;font:21px Georgia,serif;
}
#overlay.withPortrait #close { right:-12px;top:-18px; }
#overlay.withPortrait #modal > button:only-of-type {min-width:clamp(104px,12.3vw,210px);min-height:clamp(40px,3.35vw,57px);font-size:clamp(18px,1.6vw,27px);letter-spacing:.16em;}
#dialogFigure { position:absolute;right:8px;bottom:4px;width:var(--figure);height:min(45dvh,calc(var(--figure) * 1.12));pointer-events:none; }
#dialogPortrait { width:100%;height:100%;object-fit:contain;object-position:bottom right; }
#dialogName {
  position:absolute;right:2.7%;top:clamp(-52px,-3vw,-25px);
  writing-mode:vertical-rl;text-orientation:upright;white-space:nowrap;
  pointer-events:none;text-align:center;
  border:9px solid transparent;
  border-image:url(art/dialogue/name-frame.png) 14 fill / 11px;
  color:#3b2618;
  padding:.22em .1em;
  font-size:clamp(18px,1.52vw,26px);line-height:1.19;letter-spacing:.21em;
}
#overlay:not(.withPortrait) #dialogName {display:none;}
@media (min-width:761px) {
  #overlay.withPortrait {--gutter:clamp(48px,6.25vw,105px);}
  #overlay.withPortrait .scrollHeading {left:6.6%;}
}
@media (max-width:760px) {
  #overlay { --figure:clamp(86px,23vw,170px);--gutter:20px; }
  #overlay .scrollWindow { width:92%; }
  #overlay #modal { min-height:138px;max-height:52dvh;padding-top:24px;padding-bottom:18px; }
  #overlay.withPortrait #modal {margin-right:var(--figure);padding-right:1px;}
  #overlay #modal p,#overlay #modal li {font-size:15px;line-height:1.55;}
  .scrollHeading {padding:2px 12px;}
  #overlay #close {width:24px;height:24px;top:-12px;}
  #dialogFigure {right:5px;height:min(42dvh,calc(var(--figure) * 1.55));}
  #dialogName {right:12px;top:-18px;font-size:14px;border-width:6px;border-image-width:8px;}
}
@media(max-height:500px) {
  #overlay {padding-bottom:10px;--figure:min(23vw,40vh);}
  #overlay #modal { min-height:92px;max-height:57dvh;padding-block:20px 12px; }
  #overlay.documentWindow #modal {max-height:69dvh;}
  #dialogFigure {height:52dvh;}
  #overlay #modal p {font-size:15px;line-height:1.45;}
}
