#journal {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: clip;
  pointer-events: none;
  color: #512713;
  /* 手账永远压在街道事件层（#streetEventLayer z-index:3、#l4Prompt z-index:4）之上 */
  z-index: 20;
}

.journal-book {
  --spread: url("../assets/ui/journal-map-reference.webp");
  position: absolute;
  top: 51%;
  left: 49.7%;
  container-type: inline-size;
  width: 70%;
  aspect-ratio: 4 / 3;
  transform: translate(-50%, -50%);
  font-family: system-ui, "Microsoft YaHei", sans-serif;
}

.journal-book[data-page="tasks"] {
  --spread: url("../assets/ui/journal-task-reference.webp?v=2");
}

.journal-book::before {
  position: absolute;
  top: 19%;
  bottom: 35%;
  left: 3.8%;
  width: 6%;
  content: "";
  pointer-events: auto;
  background: linear-gradient(90deg,
    #3e1518 0% 8%, #9c2830 8% 20%, #c04349 20% 29%, #762129 29% 39%,
    #ea675e 39% 47%, #8d2731 47% 58%, #3b121a 58% 70%, #cc6653 70% 100%);
}

.journal-art {
  position: absolute;
  inset: 0;
  background: var(--spread) center / 100% 100% no-repeat;
  /* Retain the book silhouette and remove the reference's backdrop and left tabs. */
  clip-path: polygon(4% 14%, 7% 11%, 47% 11%, 50% 13%, 54% 11%, 94% 11%, 97% 14%,
    97% 86%, 95% 91%, 54% 91%, 50% 90%, 46% 90%, 46% 94%, 43% 92%, 40.5% 94%,
    40.5% 91%, 6% 91%, 3.7% 87%, 3.7% 64%, 8.8% 64%, 8.8% 20%, 3.7% 20%);
  pointer-events: auto;
}

.journal-map-page:not([hidden]) {
  position: absolute;
  inset: 18.65% 9.65% 18.5% 11.1%;
  display: grid;
  place-items: center;
  border: 1px solid #864b22;
  border-radius: .9cqw;
  background: #f8d6a5;
  overflow: hidden;
  pointer-events: auto;
}

.journal-map {
  position: relative;
  width: 100%;
  aspect-ratio: 2534 / 1428;
}

.journal-map > div {
  position: absolute;
  inset: 0;
}

.journal-map img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ---------- 未开发区域提示 ---------- */
.map-locked {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  padding: .45em 1.1em;
  /* 摆正、居中：不再斜着放，压在地图正中间 */
  transform: translate(-50%, -50%);
  border: 2px solid #5d3a20;
  border-radius: .5cqw;
  background: rgb(60 44 30 / 88%);
  color: #f6e3bd;
  font-size: clamp(10px, 2.1cqw, 23px);
  font-weight: 700;
  letter-spacing: .16em;
  white-space: nowrap;
  box-shadow: 0 .3cqw 0 rgb(30 20 12 / 45%);
  pointer-events: none;
}

.map-locked[hidden] {
  display: none;
}

.journal-map canvas:not([hidden]) {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: none;
  pointer-events: none;
}

.journal-map .map-back-button {
  font-size: clamp(8px, 1.95cqw, 20px);
}

.journal-tabs {
  position: absolute;
  top: 20.3%;
  left: 0.5%;
  width: 7%;
  display: grid;
  gap: .8cqw;
}

.journal-tabs button {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: max(1px, .33cqw) solid #522416;
  border-radius: 17%;
  background: linear-gradient(#ffdfa3, #efb673);
  box-shadow: inset 0 0 0 max(1px, .22cqw) #b26435, inset 0 .52cqw #fff0c0,
    0 .22cqw #3c1a12;
  pointer-events: auto;
}

.journal-tabs button[aria-pressed="true"] {
  background: linear-gradient(#fff199, #ffc545);
  box-shadow: inset 0 0 0 max(1px, .22cqw) #d68a20, inset 0 .52cqw #fff9ba,
    0 .22cqw #3c1a12;
}

.journal-tabs button::before {
  position: absolute;
  inset: 12%;
  content: "";
  border-radius: 18%;
  background: url("../assets/ui/journal-task-reference.webp?v=2") 2.55% var(--tab-y) / 1880% 1410% no-repeat;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.journal-tabs [data-journal-tab="map"] { --tab-y: 22.8%; }
.journal-tabs [data-journal-tab="tasks"] { --tab-y: 35.1%; }
.journal-tabs [data-journal-tab="exp"] { --tab-y: 47.3%; }
.journal-tabs [data-journal-tab="photo"] { --tab-y: 60%; }

.journal-close {
  position: absolute;
  top: 13.45%;
  left: 1.825%;
  width: 4.35%;
  aspect-ratio: 1;
  padding: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(#ffdfa2, #eeae66);
  border: max(1px, .29cqw) solid #572a19;
  border-radius: .5cqw;
  box-shadow: inset 0 0 0 max(1px, .19cqw) #965024, inset 0 .45cqw #fff1c3, 0 .19cqw #401b1a;
  pointer-events: auto;
}

.journal-close::before {
  content: "";
  width: 48%;
  aspect-ratio: 1;
  background: #642c1b;
  clip-path: polygon(0 0, 20% 0, 20% 20%, 40% 20%, 40% 40%, 60% 40%,
    60% 20%, 80% 20%, 80% 0, 100% 0, 100% 20%, 80% 20%, 80% 40%, 60% 40%,
    60% 60%, 80% 60%, 80% 80%, 100% 80%, 100% 100%, 80% 100%, 80% 80%,
    60% 80%, 60% 60%, 40% 60%, 40% 80%, 20% 80%, 20% 100%, 0 100%,
    0 80%, 20% 80%, 20% 60%, 40% 60%, 40% 40%, 20% 40%, 20% 20%, 0 20%);
}

.journal-status {
  position: absolute;
  bottom: 10%;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  padding: .35em .7em;
  border: 1px solid #743916;
  border-radius: 4px;
  background: #ffebbb;
  font-size: clamp(8px, 1.8cqw, 19px);
  white-space: nowrap;
}

.journal-status:empty {
  display: none;
}

#journal-tasks-page { position: absolute; inset: 0; }

.journal-quest {
  position: absolute;
  inset: 18.6% 9.6% 15.8% 11%;
  display: grid;
  grid-template-columns: 43% 57%;
  overflow: hidden;
  border: 1px solid #915125;
  border-radius: 1cqw;
  background: linear-gradient(90deg, #ffe8c0 41%, #d8a271 43%, #fff0d2 45%, #fbdcb1);
  color: #522b15;
  font-size: clamp(9px, 2.25cqw, 17px);
  line-height: 1.42;
  pointer-events: auto;
}
.journal-quest-placeholder[hidden] { display: none; }
.journal-quest-placeholder {
  pointer-events: none;
}
.journal-explore-dots {
  position: absolute;
  left: 39.3%;
  top: 39.15%;
  width: 6.05%;
  height: .95%;
  background: radial-gradient(circle closest-side, #572f1a 70%, transparent 84%) left center / calc(100% / 6) 100% repeat-x;
  animation: journal-explore-dots 2.4s step-end infinite;
}
@keyframes journal-explore-dots {
  0%, 100% { clip-path: inset(0 50% 0 0); }
  25%, 75% { clip-path: inset(0 16.666% 0 0); }
  50% { clip-path: inset(0); }
}
@media (prefers-reduced-motion: reduce) {
  .journal-explore-dots { animation: none; clip-path: inset(0 50% 0 0); }
}
#journal button:focus-visible,
#hud-journal-button:focus-visible {
  outline: 2px solid #215e88;
  outline-offset: 2px;
}


/* The color wash is confined to a control's hit area. */
.journal-map .art-button {
  transition: background-color 140ms ease, box-shadow 140ms ease;
}
.journal-map .art-button:is(:hover, :focus-visible) {
  background-color: rgb(255 211 115 / 24%);
  box-shadow: inset 0 0 .45cqw rgb(255 213 108 / 75%);
}
.journal-map .map-back-button:hover { background-color: #fff1c7; }
@media (prefers-reduced-motion: reduce) {
  .journal-map .art-button { transition: none; }
}

.map-locked { z-index: 3; }
.map-kowloon::before,
#enter-tsim-sha-tsui::before {
  content: "";
  position: absolute;
  width: clamp(12px, 3.2cqw, 27px);
  aspect-ratio: 1;
  left: 50%;
  bottom: 110%;
  background: url("../assets/ui/guide-down.png") center / contain no-repeat;
  transform: translateX(-50%);
  pointer-events: none;
  animation: map-guide 1.15s ease-in-out infinite alternate;
}
@keyframes map-guide {
  from { transform: translate(-50%, -22%); }
  to { transform: translate(-50%, 10%); }
}
@media (prefers-reduced-motion: reduce) {
  .map-kowloon::before, #enter-tsim-sha-tsui::before { animation: none; }
}

#journal.room-journal {
  position: fixed;
  z-index: 62;
}
#journal.room-journal .journal-book {
  width: min(70vw, 106svh);
}


:root { --game-popup-width: min(calc(100vw - 24px), clamp(222px, min(59vw, 104.9dvh), 740px)); }

#backpack {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 100;
  margin: 0;
  transform: translate(-50%, -50%);
  box-sizing: border-box;
  width: min(59vw, 690px);
  width: var(--game-popup-width);
  max-width: none;
  max-height: none;
  aspect-ratio: 1100 / 578;
  padding: 0;
  border: 0;
  overflow: visible;
  background: transparent;
  color: #532711;
  container-type: inline-size;
}
#backpack:not([open]) { display: none; }
#backpack[open] { display: block; }
.backpack-art {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
}
#backpack::backdrop { background: rgb(28 17 15 / 32%); }
.backpack-slots {
  position: absolute;
  inset: 25.5% 8.2% 12.7% 8%;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 5.5% 1.6%;
  list-style: none;
  margin: 0;
  padding: 0;
}
.backpack-slots button,
.backpack-close {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
}
.backpack-slots button:hover, .backpack-close:hover { background: rgb(255 255 222 / 26%); }
.backpack-slots button:focus-visible, .backpack-close:focus-visible {
  outline: 2px solid #215e88;
  outline-offset: -3px;
}
.backpack-slots img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  vertical-align: middle;
}
.backpack-close {
  position: absolute;
  top: 9.5%;
  right: 5.9%;
  width: 6.7%;
  height: 12%;
}
#backpack-tip {
  position: absolute;
  top: 39%;
  left: 40%;
  right: 10%;
  z-index: 1;
  margin: 0;
  padding: .45em .65em;
  border: 2px solid #8b431f;
  border-radius: 3px;
  background: #fff0cb;
  box-shadow: 0 2px #5e2e18;
  font: 650 clamp(10px, 3cqw, 17px) / 1.4 system-ui, "Microsoft YaHei", sans-serif;
  pointer-events: none;
}

/* Room dialogue lets clicks through to the floor except during settlement. */
#eventOverlay.room-mode.settle-mode { pointer-events: auto; }

.journal-quest-placeholder {
  inset: 14.2% 7.8% 12% 9.2%;
  display: block;
  border: 0;
  border-radius: 0;
  background: none;
}
.journal-tea-reference { display: block; width: 100%; height: 100%; }

/* Keep the paper layer clear of the book's right-hand clasp. */
.journal-quest .journal-tea-reference {
  clip-path: polygon(0 0, 100% 0, 100% 37%, 97% 37%, 97% 56%, 100% 56%, 100% 100%, 0 100%);
}

.journal-task-list, .journal-task-detail {
  position: absolute;
  top: 30.4%;
  bottom: 17%;
  overflow-y: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  scrollbar-width: thin;
  font: 700 clamp(7px, 2.14cqw, 16px) / 1.25 system-ui, "Microsoft YaHei", sans-serif;
}
.journal-task-list { left: 12.8%; width: 35.2%; }
.journal-task-detail { right: 11%; width: 35%; }
.journal-task-item {
  display: grid;
  grid-template-columns: 10% 19% minmax(0, 1fr) auto;
  align-items: center;
  gap: 5%;
  width: 98%;
  min-height: 7.7cqw;
  margin-bottom: .75cqw;
  padding: .65cqw 1cqw;
  text-align: left;
  color: #572c13;
  font: inherit;
  border: 1px solid #a35923;
  border-radius: .8cqw;
  background: #ffe2a7;
}
.journal-task-item[aria-pressed="true"] { background: #ffce66; box-shadow: inset 0 0 0 1px #fff6bc; }
.journal-task-item[data-complete] { filter: grayscale(.8); }
.journal-task-check {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid #934f26;
  background: #fff0cc;
}
.journal-task-item img, .journal-task-heading img { width: 100%; max-height: 6.5cqw; object-fit: contain; }
.journal-task-heading { display: grid; grid-template-columns: 20% 1fr auto; gap: 4%; align-items: center; }
.journal-task-detail :is(h3,h4,p,ul) { margin: 0 0 .65cqw; }
.journal-task-heading h3 { font-size: 1.13em; }
.journal-task-heading > span { padding: .15em .4em; border-radius: .5em; background: #a74917; color: #fff5d8; white-space: nowrap; font-size: .77em; }
.journal-task-category { color: #8c4b26; font-size: .8em; }
.journal-task-detail :is(.journal-task-description,ul,.journal-task-reward) { padding: .65cqw 1cqw; border: 1px solid #bc814e; border-radius: .75cqw; background: #fbe4b8; }
.journal-task-detail h4 { color: #8e471f; }
.journal-task-detail ul { list-style: none; }

.backpack-slots button[hidden] { display: none; }
.office-journal-flight.l4-pickup-flight { z-index: 75; pointer-events: none; }
#backpack-tip { max-width: 46%; overflow-wrap: anywhere; }


/* Reuse the street guide arrow on the dorm journal's map tab. */
#residence-scene:not([hidden]) #journal[open]:not(.room-journal) [data-journal-tab="map"]::after {
  content: "";
  position: absolute;
  z-index: 1;
  top: 50%;
  left: calc(100% + .65cqw);
  width: clamp(14px, 3.4cqw, 26px);
  aspect-ratio: 1;
  background: url("../assets/ui/guide-down.png") center / contain no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
  transform: translateY(-50%) rotate(90deg);
  animation: journal-map-guide-slide 2.4s ease-in-out infinite alternate;
}

@keyframes journal-map-guide-slide {
  from { transform: translate(0, -50%) rotate(90deg); }
  to { transform: translate(24%, -50%) rotate(90deg); }
}

@media (prefers-reduced-motion: reduce) {
  #residence-scene:not([hidden]) #journal[open]:not(.room-journal) [data-journal-tab="map"]::after {
    animation: none;
  }
}
