body { overflow: hidden; }
body:not(.development) .workspace { grid-template-columns: minmax(0, 1fr); }
body:not(.development) .dev-panel { display: none; }

#investigation {
  max-width: 1920px;
  height: calc(100dvh - 66px);
  margin: 0 auto;
  padding: 12px 24px 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 9px;
}
.scene-heading, .scene-tools {
  display: flex;
  align-items: center;
  gap: 9px;
}
.scene-heading { justify-content: space-between; }
#scene-number { color: var(--muted); font-variant-numeric: tabular-nums; }
.scene-help { margin-right: auto; color: var(--muted); font-size: .86rem; }
.scene-tools { justify-content: flex-end; }
#scene-stage {
  position: relative;
  min-height: 0;
  border: 1px solid #a5a392;
  border-radius: 8px;
  overflow: hidden;
  background: #d3cbb9;
  isolation: isolate;
}
#scene-viewport { position: absolute; inset: 0; overflow: hidden; user-select: none; touch-action: none; }
#scene-viewport.panning { cursor: grabbing; }
#scene-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 1000px;
  height: 560px;
  transform-origin: top left;
}
.scene-art { display: block; width: 100%; height: 100%; }
.illustrated-mode #scene-stage { background: #28231d; }
.scene-hotspots { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scene-hotspot { fill: transparent; pointer-events: all; cursor: pointer; }
/* SVG can still paint a browser outline after pointer focus returns from the dialog. */
.scene-hotspot:focus:not(:focus-visible) { outline: none; }
.scene-hotspot:focus-visible, .development .scene-hotspot {
  outline: none;
  stroke: #f9db85;
  stroke-width: 2px;
  vector-effect: non-scaling-stroke;
}
.development .scene-hotspot { fill: #f9db854a; }
.scene-hotspots text {
  text-anchor: middle;
  fill: #fff4cc;
  stroke: #261b10;
  stroke-width: 6px;
  paint-order: stroke;
  font: 700 29px system-ui, sans-serif;
}
.scene-item {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 1px solid #7e6c57;
  background: #f4ead4;
  color: #41372d;
}
.scene-item:hover, .scene-item:focus-within { background: #fff8e8; }
.scene-sign { padding: 4px 10px; border-radius: 4px; white-space: nowrap; }
.scene-paper {
  display: grid;
  place-items: center;
  width: 47px;
  height: 34px;
  padding: 0;
  border-radius: 3px;
  font-size: 22px;
  line-height: 1;
  box-shadow: 2px 2px 0 #785f424f;
}
.scene-talk { width: 49px; height: 36px; padding: 0; font-size: 1.55rem; line-height: 1; border-radius: 18px; }
.scene-arrow {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 52px;
  padding: 0;
  transform: translateY(-50%);
  background: #f9f6eedb;
  font-size: 1.38rem;
  box-shadow: 0 2px 5px #4a382525;
}
.scene-arrow:hover { background: #fff9ef; }
#scene-prev { left: 10px; }
#scene-next { right: 10px; }

.reading-overlay[open], #book-overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #181d1b99;
  display: grid;
  place-items: center;
  overflow: clip;
}
.reading-overlay::backdrop { background: transparent; }
#paper-overlay[open] { background: #181d1bb8; }
/* Measure and retain the book's existing scroll containers even while closed. */
#book-overlay:not([open]) {
  visibility: hidden;
  pointer-events: none;
}
#paper-frame {
  position: relative;
  /* A multi-click in the space above the sheet can select the reading image. */
  -webkit-user-select: none;
  user-select: none;
}
#paper-sheet {
  position: absolute;
  inset: 0 auto auto 0;
  width: 716px;
  padding: 27px 37px 32px;
  border: 1px solid #9f8c6d;
  border-radius: 4px;
  background: #fcf5e5;
  box-shadow: 0 12px 40px #17180f5e;
  color: #2e2b23;
  font-size: 18px;
  line-height: 1.65;
  transform-origin: top left;
}
#paper-title {
  margin: 0 0 17px;
  padding: 0 30px 10px;
  border-bottom: 2px solid #ad9d7f;
  text-align: center;
  font-size: 1.48rem;
}
.close-reading {
  width: 37px;
  height: 37px;
  padding: 0;
  font-size: 1.36rem;
  line-height: 1;
}
#close-paper { position: absolute; right: 8px; top: 8px; }
.image-reading #paper-sheet { padding: 0; border: 0; background: transparent; box-shadow: none; }
.landscape-reading #paper-sheet {
  max-width: min(var(--landscape-width, 960px), calc(75dvh * var(--paper-ratio)));
}
.landscape-reading[data-reading="E05"] { --landscape-width: 840px; }
.image-reading #paper-sheet img { display: block; width: 100%; height: auto; }
.paper-image-page { position: relative; }
.image-word-hit {
  position: absolute;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  touch-action: manipulation;
}
.image-word-hit:hover { background: transparent; }
.image-word-hit[data-debug-label]::after {
  content: attr(data-debug-label);
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  color: #a4ebdc;
  font: 700 29px system-ui, sans-serif;
  text-shadow: 1px 1px 3px #241509;
  white-space: nowrap;
  pointer-events: none;
}
.image-reading #close-paper { top: 0; right: 0; }
#paper-original {
  position: absolute;
  top: 0;
  right: 45px;
  display: grid;
  place-items: center;
  height: 37px;
  padding: 0 10px;
  border: 1px solid #ad9d7f;
  border-radius: 6px;
  background: #f9f6ee;
  color: #41372d;
  font-size: .9rem;
  white-space: nowrap;
  text-decoration: none;
}
#paper-original:hover { background: #fff8e8; }
.paper-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.paper-table :is(th, td) { border: 1px solid #ad9d7f; text-align: left; padding: 4px 8px; }
.paper-table th { background: #eae0c8; font-weight: 650; }
.paper-fields, .paper-review { display: grid; grid-template-columns: max-content minmax(0, 1fr); margin: 0; }
.paper-review { width: 52%; margin: 14px 0 0 auto; }
:is(.paper-fields, .paper-review) :is(dt, dd) {
  border-bottom: 1px solid #ad9d7f;
  padding: 4px 10px;
  margin: 0;
}
:is(.paper-fields, .paper-review) dt { background: #eae0c8; }
.paper-total, .paper-signature { margin: 12px 0 0; text-align: right; }
.paper-signature { font-family: "DFKai-SB", KaiTi, serif; font-size: 1.36em; }
.paper-letter p { margin: 0 0 14px; }
.paper-letter p:last-child { text-align: right; margin: 0; }
.evidence-word {
  display: inline;
  border: 0;
  border-radius: 2px;
  padding: 0;
  background: transparent;
  color: #315750;
  line-height: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: .18em;
  white-space: nowrap;
  vertical-align: baseline;
}
.evidence-word:not([data-collected="true"]):hover { color: #1f443b; background: #cfdcd0; }
.evidence-word[data-collected="true"] {
  color: inherit;
  background: transparent;
  text-decoration-style: dashed;
  text-decoration-color: color-mix(in srgb, currentColor 23%, transparent);
  text-decoration-thickness: 1px;
}

/* One mark for live text and image-based words, independent of the hit box.
   --word-unit offsets the scene and paper transforms for constant stroke widths. */
.office-word { isolation: isolate; }
.evidence-word.office-word, .evidence-word.office-word:hover {
  position: relative;
  color: inherit;
  background: transparent;
  text-decoration: none;
}
.word-mark {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: -1;
}
.evidence-word .word-mark { top: 3px; height: calc(100% - 6px); }
/* Keep the ink signature and its existing rule separate at every scale. */
.paper-image-page [data-collect="維恩"] .word-mark { top: -4%; height: 92%; }
.word-mark rect { fill: none; vector-effect: non-scaling-stroke; }
.word-mark .word-outline { fill: #58938a30; stroke: #285d54; stroke-width: calc(1.1 * var(--word-unit, 1px)); }
.office-word[data-collected="false"]:not(:hover, :focus-visible) .word-outline {
  fill: #58938a29;
  stroke: #285d54d9;
}
.office-word:is(:hover, :focus-visible) .word-outline { fill: #58938a4a; }
.office-word[data-collected="true"] .word-outline {
  fill: none;
  stroke: #4a5650c4;
  stroke-width: calc(.85 * var(--word-unit, 1px));
  stroke-dasharray: calc(3 * var(--word-unit, 1px)) calc(2.6 * var(--word-unit, 1px));
}
.office-word[data-collected="true"]:hover .word-outline { fill: #58938a1f; }
.word-focus { stroke: #1f4c42; stroke-width: calc(1.4 * var(--word-unit, 1px)); visibility: hidden; }
.office-word:focus-visible { outline: none; }
.office-word:focus-visible .word-focus { visibility: visible; }
.development .image-word-hit { outline: 2px dotted #b67d38; }
.word-mark .word-flash {
  fill: #ffdc77;
  fill-opacity: .48;
  stroke: #c28830;
  stroke-width: calc(1.65 * var(--word-unit, 1px));
  opacity: 0;
}
.word-added .word-flash { animation: word-added .8s ease-out both; }
@keyframes word-added {
  0%, 20% { opacity: .65; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .word-added .word-flash { animation: none; opacity: .65; }
}
@media (forced-colors: active) {
  .office-word:focus-visible { outline: 2px solid Highlight; }
}

.word-receipt {
  position: fixed;
  z-index: 5;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  display: grid;
  justify-items: center;
  width: max-content;
  min-width: 88px;
  max-width: calc(100vw - 24px);
  gap: 2px;
  padding: 6px 15px 7px;
  border: 1px solid #95734e;
  border-radius: 4px;
  background: url("paper-grain.png"), linear-gradient(#f6ecd6, #ebd7b3);
  color: #442d1d;
  box-shadow: inset 0 0 0 2px #fff0cd7a, 0 3px 8px #23160e77;
  text-align: center;
  font-family: "LXGW WenKai TC", "霞鶩文楷 TC", PMingLiU, "Microsoft JhengHei", serif;
  line-height: 1.2;
}
.word-receipt:empty { display: none; }
.receipt-label { color: #694c33; font-size: .73rem; }
.receipt-word { font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }

#scene-dialogue {
  position: absolute;
  inset: auto max(65px, 12%) 7%;
  display: flex;
  align-items: center;
  gap: 15px;
  min-height: 92px;
  padding: 14px 17px;
  background: #fcfaf3;
  border: 1px solid #9e9481;
  border-radius: 7px;
  box-shadow: 0 4px 16px #32271635;
  cursor: pointer;
  user-select: none;
}
#dialogue-line { margin: 0; flex: 1; line-height: 1.75; font-size: 1.08rem; }
#advance-dialogue { flex: none; min-width: 36px; padding: 5px; }

@media (max-width: 850px) {
  #investigation { padding-inline: 12px; }
}
@media (max-width: 600px) {
  #investigation { padding-inline: 8px; }
  #scene-dialogue { inset-inline: 10px; bottom: 8%; }
  .scene-help { display: none; }
  .scene-arrow { width: 34px; height: 43px; }
  #scene-prev { left: 4px; }
  #scene-next { right: 4px; }
  .scene-paper::before, .scene-talk::before {
    content: "";
    position: absolute;
    inset: -8px;
  }
}
@media (max-width: 600px) and (min-height: 620px) {
  /* Use the lower letterbox on narrow portrait screens so the right arrow
     leaves Rosa's small paper fully reachable. */
  .illustrated-mode .scene-arrow { top: auto; bottom: 8px; transform: none; }
}
