:root {
  color-scheme: only light;
  --device-width: min(100vw, 27rem);
  --desktop-device-width: 26.5rem;
  --desktop-device-height: min(92svh, 56rem);
  --novel-font:
    "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho",
    "BIZ UDPMincho", serif;
  --ui-font:
    "Hiragino Sans", "Yu Gothic", "YuGothic", "Avenir Next", sans-serif;
  --bg-top: #ece1d0;
  --bg-bottom: #b69774;
  --ink: #20160f;
  --surface: rgba(252, 247, 241, 0.78);
  --surface-border: rgba(69, 48, 30, 0.14);
  --scene-shadow: rgba(14, 10, 8, 0.44);
  --progress: #fff6ea;
}

body[data-mood="fracture"] {
  --bg-top: #dfd9d2;
  --bg-bottom: #828891;
  --ink: #151a1f;
  --surface: rgba(246, 244, 242, 0.76);
  --surface-border: rgba(40, 48, 58, 0.16);
  --scene-shadow: rgba(12, 15, 19, 0.5);
  --progress: #d8e5f2;
}

body[data-mood="veil"] {
  --bg-top: #ebe0d9;
  --bg-bottom: #9d8e91;
  --ink: #1f1619;
  --surface: rgba(250, 245, 243, 0.76);
  --surface-border: rgba(70, 53, 59, 0.16);
  --scene-shadow: rgba(18, 14, 17, 0.5);
  --progress: #f2dddf;
}

body[data-mood="breach"] {
  --bg-top: #d7dde7;
  --bg-bottom: #556b87;
  --ink: #111d2b;
  --surface: rgba(242, 246, 250, 0.75);
  --surface-border: rgba(45, 72, 100, 0.18);
  --scene-shadow: rgba(11, 18, 27, 0.54);
  --progress: #e5f0ff;
}

body[data-mood="severance"] {
  --bg-top: #d0d5de;
  --bg-bottom: #485768;
  --ink: #101820;
  --surface: rgba(240, 244, 247, 0.74);
  --surface-border: rgba(44, 62, 80, 0.18);
  --scene-shadow: rgba(9, 14, 20, 0.58);
  --progress: #d7ebff;
}

body[data-mood="pursuit"] {
  --bg-top: #d7ddd7;
  --bg-bottom: #5b6965;
  --ink: #131c17;
  --surface: rgba(240, 245, 241, 0.74);
  --surface-border: rgba(51, 72, 64, 0.17);
  --scene-shadow: rgba(11, 16, 14, 0.58);
  --progress: #dff1e8;
}

body[data-mood="mirror"] {
  --bg-top: #d6d2dc;
  --bg-bottom: #605776;
  --ink: #171421;
  --surface: rgba(243, 241, 247, 0.75);
  --surface-border: rgba(67, 57, 86, 0.18);
  --scene-shadow: rgba(13, 10, 18, 0.58);
  --progress: #ebe5ff;
}

body[data-mood="coda"] {
  --bg-top: #d5d5da;
  --bg-bottom: #4c4f59;
  --ink: #15161b;
  --surface: rgba(243, 243, 247, 0.76);
  --surface-border: rgba(56, 58, 70, 0.16);
  --scene-shadow: rgba(10, 11, 14, 0.58);
  --progress: #edf0ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  scrollbar-width: none;
}

body {
  font-family: var(--novel-font);
  font-optical-sizing: auto;
  color: var(--ink);
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.2), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  transition: background 520ms ease, color 320ms ease;
}

body::-webkit-scrollbar {
  display: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 15%, transparent 85%, rgba(0, 0, 0, 0.08)),
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.14), transparent 18%);
  mix-blend-mode: soft-light;
}

.progress-track {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: calc(env(safe-area-inset-top) + 4px);
  background: rgba(255, 255, 255, 0.08);
}

.progress-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--progress), rgba(255, 255, 255, 0.55));
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 140ms linear;
}

.stage {
  min-height: 100svh;
}

.device-shell {
  width: 100%;
  height: 100svh;
  position: relative;
  background: rgba(18, 14, 12, 0.08);
}

.device-scroll {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.device-scroll::-webkit-scrollbar {
  display: none;
}

.novel {
  position: relative;
  width: var(--device-width);
  margin: 0 auto;
  padding: 0.75rem 0.7rem calc(env(safe-area-inset-bottom) + 18svh);
}

.loading-state {
  min-height: var(--reader-height, 100svh);
  display: grid;
  place-items: center;
  font-family: var(--ui-font);
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.88);
}

.scene {
  position: relative;
  margin: 0 0 3rem;
}

.scene-visual {
  position: sticky;
  top: calc(env(safe-area-inset-top) + 0.4rem);
  height: calc(var(--reader-height, 100svh) - env(safe-area-inset-top) - 0.8rem);
  border-radius: 1.8rem;
  overflow: hidden;
  box-shadow:
    0 40px 70px -48px rgba(0, 0, 0, 0.78),
    0 18px 36px -28px rgba(0, 0, 0, 0.52);
}

.scene-image,
.scene-veil,
.scene-grain {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-image {
  object-fit: cover;
  filter: saturate(0.96) contrast(0.98);
  transform: scale(1.03);
  transition: transform 700ms ease, filter 400ms ease;
}

.scene.is-active .scene-image {
  transform: scale(1);
}

.scene-veil {
  background:
    linear-gradient(180deg, rgba(8, 8, 8, 0.02), rgba(8, 8, 8, 0.18) 38%, rgba(8, 8, 8, 0.5) 100%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02));
}

.scene-grain {
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px),
    radial-gradient(circle at 70% 60%, rgba(255, 255, 255, 0.05) 0 1px, transparent 1px);
  background-size: 18px 18px, 22px 22px;
  mix-blend-mode: soft-light;
  opacity: 0.45;
}

.scene-hero {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 1.35rem);
  left: 0;
  right: 0;
  padding: 0 1.15rem;
  z-index: 2;
}

.story-title {
  margin: 0;
  width: 4.6em;
  max-width: none;
  font-weight: 500;
  font-size: clamp(2rem, 8vw, 3rem);
  line-height: 1.28;
  letter-spacing: 0.08em;
  color: rgba(255, 249, 242, 0.96);
  text-shadow: 0 12px 30px rgba(0, 0, 0, 0.34);
}

.story-title-line {
  display: block;
}

.scene-copy {
  position: relative;
  z-index: 2;
  margin-top: calc((var(--reader-height, 100svh) * -1) + env(safe-area-inset-top) + 1rem);
  padding: calc(var(--reader-height, 100svh) * 0.3) 0 calc(var(--reader-height, 100svh) * 0.2);
  display: grid;
  gap: calc(var(--reader-height, 100svh) * 0.18);
}

.scene:first-child .scene-copy {
  padding-top: calc(var(--reader-height, 100svh) + 0.75rem);
}

.beat {
  scroll-snap-align: center;
  width: min(100%, 21rem);
  margin: 0 auto;
  padding: 1rem 1rem 1.08rem;
  border-radius: 1.35rem;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow:
    0 18px 38px -28px var(--scene-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.44);
}

.beat:nth-child(odd) {
  transform: translateX(-0.35rem);
}

.beat:nth-child(even) {
  transform: translateX(0.35rem);
}

.beat-inner {
  display: grid;
  gap: 0.32rem;
}

.beat-line {
  margin: 0;
  font-size: clamp(1.12rem, 4.9vw, 1.42rem);
  line-height: 1.95;
  letter-spacing: 0.045em;
  text-wrap: pretty;
  font-feature-settings: "palt" 1;
}

.beat-dialogue {
  background: rgba(255, 250, 245, 0.84);
}

.beat-system,
.beat-list {
  background: rgba(240, 244, 248, 0.8);
}

.beat-system .beat-line,
.beat-list .beat-line {
  font-family: var(--ui-font);
  font-size: clamp(0.98rem, 4.2vw, 1.15rem);
  line-height: 1.82;
  letter-spacing: 0.04em;
}

@media (min-width: 430px) {
  .novel {
    padding-inline: 0.85rem;
  }

  .beat:nth-child(odd) {
    transform: translateX(-0.6rem);
  }

  .beat:nth-child(even) {
    transform: translateX(0.6rem);
  }
}

@media (min-width: 780px) {
  .stage {
    display: grid;
    place-items: center;
    padding: 2rem;
  }

  .device-shell {
    width: var(--desktop-device-width);
    height: var(--desktop-device-height);
    border-radius: 2.4rem;
    padding: 0.6rem;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.03)),
      rgba(23, 19, 18, 0.82);
    box-shadow:
      0 42px 90px -42px rgba(0, 0, 0, 0.72),
      0 18px 28px -18px rgba(0, 0, 0, 0.45),
      inset 0 1px 0 rgba(255, 255, 255, 0.18);
  }

  .device-shell::before {
    content: "";
    position: absolute;
    top: 0.38rem;
    left: 50%;
    transform: translateX(-50%);
    width: 34%;
    height: 1.5rem;
    border-radius: 0 0 1rem 1rem;
    background: rgba(13, 12, 15, 0.92);
    z-index: 25;
    pointer-events: none;
  }

  .device-shell::after {
    content: "";
    position: absolute;
    inset: 0.6rem;
    border-radius: 1.9rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: none;
  }

  .device-scroll {
    border-radius: 1.9rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0));
  }

  .novel {
    width: 100%;
    --device-width: 100%;
    padding-inline: 0.95rem;
  }
}
