* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  background: #000;
  color: #f5efe4;
  overflow: hidden;
}

.story {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  cursor: pointer;
  isolation: isolate;
}

.bg-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.85) contrast(0.9);
  transform: scale(1.02);
}

.blur-layer {
  position: absolute;
  inset: 0;
  backdrop-filter: blur(3px);
  background: rgba(0, 0, 0, 0.28);
  z-index: 1;
}

.vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.78));
  z-index: 2;
}

.fade-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.fade-overlay.active {
  opacity: 1;
}

.text-box {
  position: absolute;
  bottom: 6vh;
  left: 4vw;
  z-index: 3;
  width: min(44rem, 90vw);
  padding: 1.1rem 1.2rem;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.86));
  border-radius: 10px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
  transition: left 340ms ease, right 340ms ease, width 340ms ease, opacity 340ms ease;
}

.text-box.right {
  left: auto;
  right: 4vw;
}

.text-box.bottom-wide {
  left: 3vw;
  right: 3vw;
  width: auto;
}

.text-box.center-intro {
  left: 50%;
  top: 50%;
  bottom: auto;
  transform: translate(-50%, -50%);
  width: min(62rem, 88vw);
  text-align: center;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.4));
}

.text-box.hidden {
  display: none;
}

#scene-title {
  margin: 0 0 0.65rem 0;
  font-size: clamp(1rem, 1.8vw, 1.45rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f7dca8;
}

#scene-body {
  margin: 0;
  font-size: clamp(1rem, 2.1vw, 1.35rem);
  line-height: 1.5;
  white-space: pre-line;
}

.chat-thread {
  position: absolute;
  z-index: 3;
  left: 3vw;
  right: 3vw;
  bottom: 8vh;
  max-height: min(56vh, 34rem);
  height: fit-content;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.2rem 0.25rem;
  scrollbar-gutter: stable;
}

.chat-thread.chat-thread--bottom {
  gap: 0;
  padding: 0;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0.86));
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
}

.chat-thread.hidden {
  display: none;
}

.chat-bubble {
  width: fit-content;
  max-width: min(84vw, 40rem);
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  color: #f5efe4;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.33);
  background: rgba(12, 10, 8, 0.74);
}

.chat-bubble.left {
  align-self: flex-start;
  border-top-left-radius: 5px;
}

.chat-bubble.right {
  align-self: flex-end;
  border-top-right-radius: 5px;
  background: rgba(46, 30, 14, 0.78);
}

.chat-bubble.bottom {
  align-self: stretch;
  width: 100%;
  max-width: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0.95rem 1.1rem;
  background: transparent;
}

.chat-thread.chat-thread--bottom .chat-bubble.bottom + .chat-bubble.bottom {
  border-top: 1px solid rgba(247, 220, 168, 0.12);
}

.chat-thread.chat-thread--bottom .chat-bubble.bottom {
  border-radius: 0;
}

.chat-speaker {
  margin: 0 0 0.25rem 0;
  font-size: clamp(0.73rem, 1.35vw, 0.86rem);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #f7dca8;
  opacity: 0.95;
}

.chat-text {
  margin: 0;
  font-size: clamp(0.92rem, 1.8vw, 1.16rem);
  line-height: 1.45;
  white-space: pre-line;
}

.click-hint {
  position: absolute;
  z-index: 4;
  bottom: 2vh;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(246, 233, 205, 0.75);
  background: rgba(0, 0, 0, 0.35);
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
}

.click-hint.hidden {
  opacity: 0;
}

.ui-button {
  position: absolute;
  z-index: 5;
  border: 1px solid rgba(247, 220, 168, 0.55);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  color: #f7dca8;
  font-family: inherit;
  font-size: clamp(0.8rem, 1.7vw, 1rem);
  line-height: 1.2;
  letter-spacing: 0.03em;
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  backdrop-filter: blur(2px);
}

.ui-button:hover {
  background: rgba(0, 0, 0, 0.68);
}

.replay-button {
  left: 50%;
  bottom: 11vh;
  transform: translateX(-50%);
}

.fullscreen-button {
  right: max(0.8rem, env(safe-area-inset-right));
  bottom: max(0.8rem, env(safe-area-inset-bottom));
}

.ui-button.hidden {
  display: none;
}

@media (max-width: 920px) {
  .text-box {
    width: min(48rem, 92vw);
    left: 4vw;
    right: 4vw;
    padding: 0.95rem 1rem;
  }

  .text-box.right {
    left: auto;
    right: 4vw;
  }

  #scene-title {
    font-size: clamp(0.95rem, 2.8vw, 1.2rem);
    letter-spacing: 0.08em;
  }

  #scene-body {
    font-size: clamp(0.95rem, 2.9vw, 1.15rem);
    line-height: 1.45;
  }

  .chat-thread {
    left: 2.5vw;
    right: 2.5vw;
    bottom: 8.5vh;
    max-height: min(58vh, 31rem);
  }

  .chat-thread.chat-thread--bottom {
    gap: 0;
  }

  .chat-bubble {
    max-width: min(90vw, 34rem);
  }

  .click-hint {
    font-size: 0.78rem;
    bottom: 1.5vh;
  }

  .replay-button {
    bottom: 12.5vh;
  }
}

@media (max-width: 640px) {
  .text-box {
    bottom: 7.5vh;
    left: 3vw;
    right: 3vw;
    width: auto;
    max-width: none;
    padding: 0.9rem;
    border-radius: 8px;
  }

  .text-box.center-intro {
    width: min(96vw, 40rem);
    padding: 1rem 0.9rem;
  }

  #scene-body {
    font-size: clamp(0.96rem, 3.8vw, 1.08rem);
  }

  .chat-thread {
    left: 2vw;
    right: 2vw;
    bottom: 9.5vh;
    max-height: min(61vh, 27rem);
    gap: 0.55rem;
  }

  .chat-thread.chat-thread--bottom {
    gap: 0;
    border-radius: 8px;
  }

  .chat-thread.chat-thread--bottom .chat-bubble.bottom {
    padding: 0.85rem 0.95rem;
  }

  .chat-bubble {
    max-width: 92vw;
    padding: 0.62rem 0.72rem;
    border-radius: 11px;
  }

  .chat-text {
    font-size: clamp(0.9rem, 3.4vw, 1.03rem);
  }

  .ui-button {
    padding: 0.45rem 0.75rem;
    font-size: clamp(0.74rem, 3vw, 0.92rem);
  }

  .replay-button {
    bottom: 14vh;
    width: max-content;
    max-width: 80vw;
  }

  .fullscreen-button {
    right: max(0.6rem, env(safe-area-inset-right));
    bottom: max(0.6rem, env(safe-area-inset-bottom));
  }
}
