:root {
  --paper: #f1ece4;
  --paper-soft: #c8c0b6;
  --muted: #91887f;
  --gold: #d5a562;
  --gold-light: #efc982;
  --ink: #12100f;
  --glass: rgba(18, 16, 15, 0.56);
  --glass-deep: rgba(12, 11, 10, 0.72);
  --line: rgba(255, 241, 220, 0.13);
  --line-soft: rgba(255, 241, 220, 0.075);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", sans-serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ink);
  scroll-behavior: smooth;
  scrollbar-color: rgba(213, 165, 98, 0.34) rgba(0, 0, 0, 0.18);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--paper);
  background: var(--ink);
  font-family: var(--sans);
  font-synthesis: none;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

svg {
  display: block;
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

::selection {
  color: #21160e;
  background: rgba(239, 201, 130, 0.9);
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 0.7rem 1rem;
  color: #21150d;
  background: var(--gold-light);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-180%);
  transition: transform 180ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.night-scene,
.night-scene__video,
.night-scene__veil,
.window-vignette {
  position: fixed;
  inset: 0;
}

.night-scene {
  z-index: 0;
  overflow: hidden;
  background: #0d1014;
  pointer-events: none;
}

.night-scene__video {
  z-index: 0;
  width: 100%;
  height: 100%;
  background: #0d1014 url("/assets/cafe-rainy-night.webp") center 53% / cover no-repeat;
  border: 0;
  object-fit: cover;
  object-position: center 53%;
  pointer-events: none;
}

.night-scene__veil {
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(7, 8, 10, 0.22), rgba(9, 8, 8, 0.06) 38%, rgba(8, 6, 5, 0.42)),
    radial-gradient(circle at 50% 24%, transparent 4%, rgba(6, 6, 7, 0.12) 61%, rgba(5, 4, 5, 0.44) 100%),
    linear-gradient(104deg, rgba(165, 192, 201, 0.035), transparent 38%, rgba(228, 185, 123, 0.025));
}

.window-vignette {
  z-index: 2;
  box-shadow:
    inset 0 0 140px rgba(0, 0, 0, 0.44),
    inset 0 0 24px rgba(0, 0, 0, 0.24);
}

.read-progress {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: rgba(255, 255, 255, 0.025);
}

.read-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #9f6c3d, var(--gold-light));
  box-shadow: 0 0 12px rgba(213, 165, 98, 0.38);
  transition: width 80ms linear;
}

.page-shell {
  position: relative;
  z-index: 10;
  width: min(900px, calc(100% - 48px));
  margin: 0 auto;
  padding: clamp(44px, 7vw, 88px) 0 clamp(70px, 10vw, 130px);
}

.reader-shell {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(255, 248, 236, 0.05), transparent 30%),
    linear-gradient(180deg, rgba(18, 16, 15, 0.76), rgba(10, 9, 9, 0.84));
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow:
    0 38px 120px rgba(0, 0, 0, 0.48),
    inset 0 1px rgba(255, 255, 255, 0.055);
  isolation: isolate;
}

.reader-shell::before {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 11% 1%, rgba(227, 172, 99, 0.075), transparent 24%),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015), transparent 28%);
  content: "";
  pointer-events: none;
}

.reader-header,
.prose {
  position: relative;
  z-index: 1;
}

.reader-header {
  padding: clamp(34px, 7vw, 66px) clamp(28px, 8vw, 78px) clamp(34px, 6vw, 54px);
  border-bottom: 1px solid var(--line-soft);
}

.reader-topline {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  justify-content: space-between;
}

.reader-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 0.62rem;
  font-weight: 720;
  letter-spacing: 0.24em;
}

.bgm-toggle {
  display: inline-flex;
  min-height: 38px;
  gap: 0.48rem;
  align-items: center;
  padding: 0 0.75rem;
  color: #b9b0a5;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.095);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.61rem;
  font-weight: 690;
  letter-spacing: 0.11em;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.bgm-toggle small {
  color: #746d66;
  font-size: 0.5rem;
  font-weight: 560;
  letter-spacing: 0.06em;
}

.bgm-toggle:hover,
.bgm-toggle:focus-visible,
.bgm-toggle[aria-pressed="true"] {
  color: var(--gold-light);
  background: rgba(213, 165, 98, 0.075);
  border-color: rgba(213, 165, 98, 0.27);
  outline: none;
}

.bgm-toggle:hover {
  transform: translateY(-1px);
}

.bgm-toggle[aria-pressed="true"] small {
  color: #b79567;
}

.bgm-icon {
  display: flex;
  width: 14px;
  height: 12px;
  gap: 2px;
  align-items: center;
  justify-content: center;
}

.bgm-icon i {
  width: 2px;
  height: 4px;
  background: currentColor;
  border-radius: 2px;
}

body.music-playing .bgm-icon i {
  animation: sound-bar 720ms ease-in-out infinite alternate;
}

body.music-playing .bgm-icon i:nth-child(2) {
  animation-delay: -240ms;
}

body.music-playing .bgm-icon i:nth-child(3) {
  animation-delay: -480ms;
}

.reader-header > h1 {
  margin: clamp(34px, 6vw, 54px) 0 0;
  font-family: var(--serif);
  max-width: 9em;
  font-size: clamp(2.8rem, 8vw, 5.65rem);
  font-weight: 460;
  letter-spacing: 0.055em;
  line-height: 1.08;
  text-shadow: 0 5px 30px rgba(0, 0, 0, 0.36);
  text-wrap: balance;
}

.reader-deck {
  max-width: 520px;
  margin: 1.45rem 0 0;
  color: #b7aea4;
  font-family: var(--serif);
  font-size: clamp(0.82rem, 2vw, 0.96rem);
  letter-spacing: 0.06em;
  line-height: 1.9;
}

.reader-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
  margin: 1rem 0 0;
  color: #817870;
  font-size: 0.57rem;
  letter-spacing: 0.08em;
}

.reader-meta i {
  width: 3px;
  height: 3px;
  background: rgba(213, 165, 98, 0.58);
  border-radius: 50%;
}

.narration-player {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: clamp(14px, 3vw, 26px);
  align-items: center;
  margin-top: clamp(32px, 6vw, 48px);
  padding: 16px clamp(16px, 3vw, 22px) 15px;
  background: rgba(7, 7, 7, 0.2);
  border: 1px solid rgba(255, 244, 227, 0.09);
  border-radius: 18px;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
}

.transport-controls {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  justify-content: center;
}

.transport-controls button,
.narration-heading button {
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  place-items: center;
  color: #938a81;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.transport-controls button:hover:not(:disabled),
.transport-controls button:focus-visible,
.narration-heading button:hover,
.narration-heading button:focus-visible {
  color: var(--gold-light);
  background: rgba(255, 255, 255, 0.045);
  outline: none;
}

.transport-controls button:disabled {
  opacity: 0.26;
  cursor: default;
}

.transport-controls .narration-play {
  width: 44px;
  height: 44px;
  color: #24160e;
  background: linear-gradient(145deg, #edc37f, #ae713b);
  border: 1px solid rgba(255, 237, 207, 0.25);
  box-shadow: 0 7px 22px rgba(158, 95, 43, 0.22);
}

.transport-controls .narration-play:hover,
.transport-controls .narration-play:focus-visible {
  color: #160d08;
  background: linear-gradient(145deg, #f5d394, #c78a4c);
}

.narration-play .pause-icon {
  display: none;
}

.narration-play[aria-pressed="true"] .play-icon {
  display: none;
}

.narration-play[aria-pressed="true"] .pause-icon {
  display: block;
}

.narration-main {
  min-width: 0;
}

.narration-heading {
  display: flex;
  gap: 1rem;
  align-items: end;
  justify-content: space-between;
}

.narration-heading div {
  min-width: 0;
}

.narration-heading p {
  margin: 0 0 0.18rem;
  color: #756d66;
  font-size: 0.48rem;
  font-weight: 650;
  letter-spacing: 0.12em;
}

.narration-heading h2 {
  margin: 0;
  overflow: hidden;
  font-family: var(--serif);
  font-size: 0.8rem;
  font-weight: 520;
  letter-spacing: 0.07em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.narration-heading button {
  flex: 0 0 30px;
}

.narration-heading button[aria-pressed="true"] {
  color: #b87855;
}

.timeline {
  min-width: 0;
  margin-top: 0.48rem;
}

.timeline input {
  width: 100%;
  height: 14px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
}

.timeline input::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--gold) 0 var(--range-progress, 0%), rgba(255, 255, 255, 0.115) var(--range-progress, 0%));
  border-radius: 999px;
}

.timeline input::-moz-range-track {
  height: 2px;
  background: rgba(255, 255, 255, 0.115);
  border: 0;
  border-radius: 999px;
}

.timeline input::-moz-range-progress {
  height: 2px;
  background: var(--gold);
  border-radius: 999px;
}

.timeline input::-webkit-slider-thumb {
  width: 10px;
  height: 10px;
  margin-top: -4px;
  background: #e5bb77;
  border: 2px solid #4c3321;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(213, 165, 98, 0.08);
  appearance: none;
}

.timeline input::-moz-range-thumb {
  width: 8px;
  height: 8px;
  background: #e5bb77;
  border: 2px solid #4c3321;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(213, 165, 98, 0.08);
}

.timeline input:focus-visible {
  outline: 1px solid rgba(239, 201, 130, 0.62);
  outline-offset: 4px;
}

.timeline-meta {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  gap: 0.5rem;
  align-items: center;
  color: #716961;
  font-size: 0.45rem;
  font-variant-numeric: tabular-nums;
}

.timeline-meta span {
  overflow: hidden;
  color: #827970;
  letter-spacing: 0.05em;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeline-meta time:last-child {
  text-align: right;
}

.prose {
  max-width: 700px;
  margin: 0 auto;
  padding: clamp(48px, 8vw, 82px) clamp(28px, 7vw, 66px) clamp(70px, 10vw, 110px);
  outline: none;
}

.prose-section {
  margin: 0;
  padding: 0 0 clamp(76px, 11vw, 112px);
  scroll-margin-top: 28px;
}

.prose-section + .prose-section {
  padding-top: clamp(8px, 2vw, 20px);
  border-top: 1px solid var(--line-soft);
}

.volume-label {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin: 0 0 clamp(28px, 5vw, 42px);
  color: var(--gold);
  font-size: 0.58rem;
  font-weight: 680;
  letter-spacing: 0.2em;
}

.volume-label::before {
  width: 28px;
  height: 1px;
  background: currentColor;
  content: "";
}

.prose-line {
  margin: 0 0 1.42em;
  color: #d7d0c7;
  font-family: var(--serif);
  font-size: clamp(1.02rem, 2.4vw, 1.2rem);
  font-weight: 410;
  letter-spacing: 0.055em;
  line-height: 2.05;
  text-wrap: pretty;
  transition: color 180ms ease;
}

.prose-line:first-of-type {
  color: #f3ede5;
  font-size: clamp(1.28rem, 3.5vw, 1.72rem);
  line-height: 1.8;
}

.prose-line.is-current {
  color: #eee7de;
}

.prose-source {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 0.2rem 0.85rem;
  margin-top: 12px;
  padding-top: 28px;
  color: #746c64;
  border-top: 1px solid var(--line-soft);
}

.prose-source__seal {
  display: grid;
  grid-row: 1 / span 2;
  width: 31px;
  height: 31px;
  place-items: center;
  color: #29180e;
  background: #a66f3d;
  border-radius: 50%;
  font-family: var(--serif);
  font-size: 0.63rem;
  font-weight: 800;
}

.prose-source strong {
  color: #9b9289;
  font-family: var(--serif);
  font-size: 0.64rem;
  font-weight: 540;
  letter-spacing: 0.1em;
}

.prose-source p {
  margin: 0;
  font-size: 0.51rem;
  line-height: 1.75;
}

.prose-loading {
  display: grid;
  min-height: 42vh;
  place-content: center;
  place-items: center;
  color: #8f867d;
  font-family: var(--serif);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
}

.prose-loading span {
  width: 27px;
  height: 27px;
  border: 1px solid rgba(213, 165, 98, 0.18);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1.1s linear infinite;
}

.toast {
  position: fixed;
  z-index: 80;
  right: 18px;
  bottom: 18px;
  max-width: calc(100vw - 36px);
  padding: 0.65rem 0.95rem;
  color: #ded5ca;
  background: rgba(18, 15, 13, 0.9);
  border: 1px solid rgba(255, 238, 213, 0.13);
  border-radius: 999px;
  box-shadow: 0 12px 38px rgba(0, 0, 0, 0.36);
  opacity: 0;
  pointer-events: none;
  font-size: 0.58rem;
  letter-spacing: 0.05em;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes sound-bar {
  from { height: 3px; }
  to { height: 11px; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 700px) {
  .night-scene__video {
    object-position: 54% center;
  }

  .page-shell {
    width: calc(100% - 18px);
    padding: 18px 0 48px;
  }

  .reader-shell {
    background:
      linear-gradient(145deg, rgba(255, 248, 236, 0.045), transparent 30%),
      linear-gradient(180deg, rgba(18, 16, 15, 0.8), rgba(10, 9, 9, 0.88));
    border-radius: 23px;
  }

  .reader-header {
    padding: 27px 22px 30px;
  }

  .reader-kicker {
    font-size: 0.54rem;
    letter-spacing: 0.18em;
  }

  .bgm-toggle {
    min-height: 35px;
    padding-inline: 0.65rem;
  }

  .reader-header > h1 {
    margin-top: 34px;
    font-size: clamp(2.7rem, 13vw, 4.3rem);
  }

  .reader-deck {
    max-width: 310px;
  }

  .narration-player {
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 11px;
    margin-top: 32px;
    padding: 14px 12px;
    border-radius: 16px;
  }

  .transport-controls {
    gap: 0;
  }

  .transport-controls button {
    width: 24px;
  }

  .transport-controls .narration-play {
    width: 39px;
    height: 39px;
  }

  .narration-heading p {
    display: none;
  }

  .narration-heading h2 {
    font-size: 0.72rem;
  }

  .timeline-meta {
    grid-template-columns: 34px 1fr 34px;
    gap: 0.3rem;
    font-size: 0.41rem;
  }

  .prose {
    padding: 52px 27px 72px;
  }

  .prose-section {
    padding-bottom: 76px;
  }

  .prose-line {
    margin-bottom: 1.34em;
    font-size: 1rem;
    letter-spacing: 0.04em;
    line-height: 2;
  }

  .prose-line:first-of-type {
    font-size: 1.28rem;
  }

  .window-vignette {
    box-shadow: inset 0 0 72px rgba(0, 0, 0, 0.42);
  }
}

@media (max-width: 390px) {
  .reader-header {
    padding-inline: 18px;
  }

  .bgm-toggle small {
    display: none;
  }

  .prose {
    padding-inline: 22px;
  }

  .narration-player {
    grid-template-columns: 50px minmax(0, 1fr);
    padding-inline: 8px;
  }

  .narration-heading button {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
