#novel {
  --novel-street: var(--home-art);
  --novel-type: "Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif CJK JP", serif;
  --reading-size: clamp(22px, min(3.55vw, 5.7vh), 54px);
  --reading-edge: clamp(24px, 6vw, 136px);
  position: absolute;
  z-index: 1;
  inset: 0;
  isolation: isolate;
  overflow: hidden;
  background: #071213;
  color: #f5f3e9;
}

.novel-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.novel-backdrop, #novel::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.novel-backdrop {
  z-index: -2;
  background: center / cover no-repeat var(--novel-street);
  filter: saturate(.78);
}
#novel[data-place="park"] { --novel-street: var(--park-art); }
#novel[data-place="park"][data-view="left"] { --novel-street: var(--park-left-art); }
#novel[data-place="underpass"] { --novel-street: var(--underpass-art); }
#novel[data-place="arcade"] { --novel-street: var(--arcade-art); }
#novel[data-place="arcade"][data-view="left"] { --novel-street: var(--arcade-left-art); }
#novel[data-place="laundry"] { --novel-street: var(--laundry-art); }
#novel[data-place="inside"] { --novel-street: var(--inside-art); }

#novel::before {
  content: "";
  z-index: -1;
  background: linear-gradient(180deg, #02090cbd, #030b0f9c 38%, #0410164d 75%, #03101466);
}

.novel-content {
  position: absolute;
  inset: 0 0 max(58px, calc(env(safe-area-inset-bottom) + 52px));
  padding: max(6.7vh, env(safe-area-inset-top)) max(var(--reading-edge), env(safe-area-inset-right)) 1.25em max(var(--reading-edge), env(safe-area-inset-left));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: manipulation;
  scrollbar-width: thin;
  font: 500 var(--reading-size)/1.68 var(--novel-type);
  letter-spacing: .035em;
  line-break: strict;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 2px #020609, 0 1px 7px #020609, 0 0 16px #020609c9;
}
#novel-lines p { margin: 0; }
#novel-lines p + p { margin-top: .27em; }

#novel-next {
  position: relative;
  display: inline-block;
  width: .95em;
  height: 1em;
  margin: 0 .12em;
  padding: 0;
  vertical-align: -.08em;
  border: 0;
  background: transparent;
  color: #f2deb0;
  font: inherit;
  text-shadow: inherit;
}
#novel-next::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
  margin: auto;
  border: solid transparent;
  border-width: .15em 0 .15em .26em;
  border-left-color: currentColor;
}
#novel-next[data-action="page"]::before {
  border-width: .25em .16em 0;
  border-top-color: currentColor;
  border-left-color: transparent;
}
#novel-next[data-action="reveal"]:not(:focus-visible)::before { opacity: 0; }

#novel-choices, #novel-end-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .12em;
  margin-top: .62em;
}
.novel-actions button {
  max-width: 100%;
  min-height: 44px;
  position: relative;
  border: 0;
  padding: .05em .25em .05em 1.35em;
  background: transparent;
  text-align: start;
  color: inherit;
  font: inherit;
  line-height: 1.55;
  letter-spacing: inherit;
  text-shadow: inherit;
}
#novel-choices button {
  padding-inline-start: 1.55em;
  text-indent: -1.3em;
}
#novel-end-actions button::before {
  content: "›";
  position: absolute;
  inset-inline-start: .26em;
}
.novel-actions button:focus-visible, #novel-next:focus-visible {
  outline: 1px solid #f4dfac;
  outline-offset: 2px;
}
.novel-actions button:focus-visible, .novel-actions button:hover { color: #ffe2a5; }
#novel-ending-label {
  width: fit-content;
  margin: .9em 0 0;
  font: 600 .72em/1.6 var(--novel-type);
  letter-spacing: .12em;
  color: #f4dcad;
}
#novel-end-actions { font-size: max(17px, .59em); }

body[data-mode="novel"] #world, body[data-mode="novel"] .bottombar { display: none; }
body[data-mode="novel"] .topbar {
  top: auto;
  bottom: max(7px, env(safe-area-inset-bottom));
  right: max(var(--edge), env(safe-area-inset-right));
}
body[data-mode="novel"] .topbar nav {
  align-items: center;
  gap: 2px;
}
body[data-mode="novel"] .topbar button {
  min-height: 44px;
  padding-inline: 10px;
  border: 0;
  background: transparent;
  backdrop-filter: none;
  color: #edece2;
  text-shadow: 0 1px 5px #010607;
}
#novel-exit { font-size: 12px; }
body[data-mode="novel"] #sound { width: 44px; filter: drop-shadow(0 1px 3px #010607); }
@media (hover: hover) {
  body[data-mode="novel"] .topbar button:hover { color: #ffe2a5; }
}

@media (max-width: 650px) {
  #novel { --reading-edge: clamp(18px, 5.8vw, 32px); --reading-size: clamp(20px, 5.4vw, 28px); }
  .novel-content { padding-top: max(4.8vh, env(safe-area-inset-top)); line-height: 1.7; }
}
@media (max-height: 510px) and (orientation: landscape) {
  #novel { --reading-edge: 4.5vw; --reading-size: clamp(18px, 4.7vh, 23px); }
  .novel-content { padding-top: max(16px, env(safe-area-inset-top)); line-height: 1.48; }
}

#novel-bad-end {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: clamp(24px, 5vh, 48px);
  background: #040607;
  color: #eeede6;
}
#novel-bad-heading {
  margin: 0;
  font: 500 clamp(24px, 4vw, 42px)/1.5 "Hiragino Mincho ProN", "Yu Mincho", YuMincho, serif;
  letter-spacing: .12em;
}
#novel-restart { min-height: 44px; }
body[data-mode="novel-bad-end"] :is(.topbar, .bottombar, #world) { display: none; }

#novel-credits {
  --novel-credits-duration: 30s;
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  color: #f6f3e9;
  text-align: center;
  background-color: #091014;
  background-image: linear-gradient(180deg, #040b0da3, #050b0ec9 50%, #04090b9e), var(--inside-art);
  background-position: center;
  background-size: cover;
  text-shadow: 0 1px 7px #02070a;
}
#novel-credit-audio[controls] {
  position: absolute;
  inset-inline-start: var(--edge);
  bottom: max(58px, calc(env(safe-area-inset-bottom) + 52px));
  width: min(300px, 85%);
}
.novel-credit-names {
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 4vh, 42px);
  width: 100%;
  max-height: calc(100% - 112px);
  padding-inline: max(20px, env(safe-area-inset-left), env(safe-area-inset-right));
  overflow-y: auto;
  font: 500 clamp(18px, 2.1vw, 26px)/1.45 "Hiragino Mincho ProN", "Yu Mincho", YuMincho, serif;
  letter-spacing: .08em;
}
.novel-credit-names > * { flex: none; }
.novel-credit-names p { margin: 0; }
#novel-credit-title {
  margin: 0 0 .35em;
  font-size: clamp(26px, 4.6vw, 62px);
  line-height: 1.3;
  letter-spacing: .1em;
}
#novel-credit-ending, .novel-credit-names small {
  display: block;
  margin-top: .45em;
  color: #e0d4ba;
  font: 500 clamp(12px, 1.15vw, 16px)/1.65 "Hiragino Sans", "Yu Gothic", sans-serif;
  letter-spacing: .09em;
}
.novel-credit-names small { margin: 0 0 .18em; }
#novel-credit-skip {
  position: absolute;
  bottom: max(7px, env(safe-area-inset-bottom));
  left: max(var(--edge), env(safe-area-inset-left));
  min-height: 44px;
}
body[data-mode="novel-credits"] #world, body[data-mode="novel-credits"] .bottombar { display: none; }

@media (prefers-reduced-motion: no-preference) {
  #novel-credits:not([hidden]) .novel-credit-names > * {
    animation: novel-credit-appear 1.6s ease-out both;
  }
  #novel-credits:not([hidden]) .novel-credit-maker { animation-delay: min(6s, calc(var(--novel-credits-duration) * .15)); }
  #novel-credits:not([hidden]) .novel-credit-music { animation-delay: min(12s, calc(var(--novel-credits-duration) * .31)); }
  body.scene-paused #novel-credits:not([hidden]) .novel-credit-names > * { animation-play-state: paused; }
  @keyframes novel-credit-appear { from { opacity: 0; } to { opacity: 1; } }
}
@media (max-height: 450px) {
  .novel-credit-names { gap: 10px; font-size: 17px; }
  #novel-credit-title { font-size: 25px; }
}
