/* === SCENE CONTAINERS === */
#game-container {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.scene {
  display: none;
  width: 100%;
  min-height: 100%;
  padding: 40px;
}

.scene.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: scene-enter 0.55s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

/* The previously-active scene is kept on screen during its fade-out,
   stacked over the incoming scene so the new content can ease in
   underneath. JS removes this class once the leave animation finishes. */
.scene.is-leaving {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  min-height: 100%;
  padding: 40px;
  z-index: 1;
  pointer-events: none;
  animation: scene-leave 0.32s ease-in forwards;
}

@keyframes scene-enter {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
    filter: blur(3px);
  }
  60% {
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@keyframes scene-leave {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-8px) scale(0.992);
    filter: blur(2px);
  }
}

/* === TITLE SCREEN === */
#scene-title {
  justify-content: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}

#scene-title .title-text {
  font-family: var(--font-heading);
  font-size: 3.5rem;
  color: var(--accent-gold);
  margin-bottom: 12px;
  text-shadow: 0 0 30px rgba(200, 169, 110, 0.3);
}

#scene-title .subtitle {
  font-family: var(--font-body);
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

#scene-title .title-bg-image {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.55;
  z-index: 0;
  filter: contrast(1.1) saturate(0.85);
  transform: scale(1.04);
}

#scene-title .fog-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at center, transparent 25%, rgba(10, 10, 10, 0.85) 75%, var(--bg) 100%),
    linear-gradient(to bottom, rgba(10, 10, 10, 0.4) 0%, transparent 35%, transparent 65%, rgba(10, 10, 10, 0.7) 100%);
  pointer-events: none;
  z-index: 1;
}

#scene-title .title-text,
#scene-title .subtitle,
#scene-title #btn-begin {
  position: relative;
  z-index: 2;
}

/* === TITLE SCREEN ANIMATIONS === */

/* Two layers of drifting fog wisps behind the title text. */
#scene-title.active::before,
#scene-title.active::after {
  content: '';
  position: absolute;
  top: -15%;
  left: -25%;
  width: 150%;
  height: 130%;
  pointer-events: none;
  z-index: 1;
  filter: blur(6px);
  opacity: 0;
  will-change: transform, opacity;
}

#scene-title.active::before {
  background:
    radial-gradient(ellipse 800px 220px at 30% 40%, rgba(220, 220, 220, 0.07), transparent 70%),
    radial-gradient(ellipse 600px 180px at 70% 60%, rgba(200, 200, 200, 0.06), transparent 65%),
    radial-gradient(ellipse 500px 150px at 50% 85%, rgba(180, 180, 180, 0.05), transparent 70%);
  animation:
    fog-drift-1 42s ease-in-out infinite alternate,
    fog-fade-in 3.5s ease-out 0.4s forwards;
}

#scene-title.active::after {
  background:
    radial-gradient(ellipse 700px 200px at 60% 25%, rgba(210, 210, 210, 0.06), transparent 70%),
    radial-gradient(ellipse 900px 240px at 20% 70%, rgba(190, 190, 190, 0.055), transparent 70%);
  animation:
    fog-drift-2 56s ease-in-out infinite alternate,
    fog-fade-in 4.5s ease-out 1.1s forwards;
}

@keyframes fog-drift-1 {
  0%   { transform: translate(-4%, 0%); }
  50%  { transform: translate(3%, -2%); }
  100% { transform: translate(-4%, 1%); }
}

@keyframes fog-drift-2 {
  0%   { transform: translate(3%, 1%); }
  50%  { transform: translate(-3%, -1%); }
  100% { transform: translate(3%, 1%); }
}

@keyframes fog-fade-in {
  to { opacity: 0.9; }
}

/* Slow Ken-Burns drift on the background image while title is shown. */
#scene-title.active .title-bg-image {
  animation: title-bg-drift 32s ease-in-out infinite alternate;
}

@keyframes title-bg-drift {
  0%   { transform: scale(1.04) translate(0, 0); }
  100% { transform: scale(1.10) translate(-1.5%, -1%); }
}

/* Title text breathes in with letter-spacing settling and a soft de-blur. */
#scene-title.active .title-text {
  animation: title-text-reveal 2.6s cubic-bezier(0.2, 0.8, 0.2, 1) 0.35s both;
}

@keyframes title-text-reveal {
  0% {
    opacity: 0;
    letter-spacing: 0.45em;
    filter: blur(8px);
  }
  60% {
    opacity: 1;
    filter: blur(0);
  }
  100% {
    opacity: 1;
    letter-spacing: 0.05em;
    filter: blur(0);
  }
}

/* Subtitles fade in one after another. */
#scene-title.active .subtitle {
  opacity: 0;
  animation: subtitle-fade-in 1.6s ease-out forwards;
}

#scene-title.active .subtitle:nth-of-type(1) {
  animation-delay: 1.7s;
}

#scene-title.active .subtitle:nth-of-type(2) {
  animation-delay: 2.5s;
}

@keyframes subtitle-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Begin Investigation button drifts in last. */
#scene-title.active #btn-begin {
  opacity: 0;
  animation: subtitle-fade-in 1.4s ease-out 3.4s forwards;
}

/* === BRIEFING SCREEN === */
#scene-briefing {
  justify-content: center;
}

#scene-briefing.active .telegram {
  animation: telegram-appear 0.7s ease-out both;
}

#scene-briefing.active #btn-to-street {
  opacity: 0;
  animation: telegram-button-fade 1s ease-out 0.4s forwards;
}

@keyframes telegram-appear {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes telegram-button-fade {
  to { opacity: 1; }
}

.telegram {
  max-width: 500px;
  background: var(--surface);
  border: 2px solid var(--accent-gold);
  padding: 30px;
  position: relative;
}

/* Typewriter caret rendered inline at the end of the typed text. */
.telegram .typewriter-cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.1em;
  background: var(--accent-gold);
  vertical-align: text-bottom;
  margin-left: 2px;
  opacity: 0.85;
  animation: caret-blink 1s steps(1) infinite;
  box-shadow: 0 0 6px rgba(200, 169, 110, 0.5);
}

@keyframes caret-blink {
  0%,    50%   { opacity: 0.85; }
  50.01%,100% { opacity: 0;    }
}

/* Sender line is hidden until the body finishes typing. */
.telegram .telegram-sender {
  transition: opacity 0.7s ease;
}

.telegram .telegram-sender.is-pending {
  opacity: 0;
}

.telegram::before {
  content: 'TELEGRAM';
  position: absolute;
  top: -10px;
  left: 20px;
  background: var(--surface);
  padding: 0 10px;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--accent-gold);
}

.telegram .telegram-text {
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 2;
  color: var(--text-primary);
}

.telegram .telegram-sender {
  margin-top: 20px;
  text-align: right;
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1rem;
}

/* === NEWSPAPER SCREEN === */
.newspaper {
  max-width: 600px;
  background: #1c1a15;
  border: 1px solid var(--accent-gold-dim);
  padding: 40px;
  text-align: center;
}

.newspaper .newspaper-header {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--accent-gold-dim);
  padding-bottom: 8px;
  margin-bottom: 20px;
}

.newspaper .newspaper-headline {
  font-family: var(--font-heading);
  font-size: 2.1rem;
  color: var(--text-primary);
  margin-bottom: 16px;
  line-height: 1.3;
}

.newspaper .newspaper-body {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.9;
  text-align: justify;
}

/* === WIN / LOSE SCREENS === */
#scene-win, #scene-lose {
  justify-content: center;
  text-align: center;
}

.result-card {
  max-width: 550px;
  background: var(--surface);
  border: 2px solid var(--success);
  padding: 40px;
}

.result-card.loss {
  border-color: var(--danger);
}

.result-card .result-image {
  display: block;
  width: calc(100% + 80px);
  margin: -40px -40px 24px;
  border-bottom: 1px solid var(--accent-gold-dim);
  filter: brightness(0.92) contrast(1.05);
  max-height: 300px;
  object-fit: cover;
  object-position: center 30%;
}

.result-card.loss .result-image {
  border-bottom-color: var(--danger);
}

.result-card h2 {
  margin-bottom: 20px;
}

.result-card .confession {
  text-align: left;
  font-size: 1rem;
  line-height: 1.9;
  color: var(--text-secondary);
  margin-bottom: 24px;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 10px;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin: 24px 0;
}

.score-item {
  text-align: center;
}

.score-item .score-value {
  font-size: 2rem;
  color: var(--accent-gold);
  font-family: var(--font-heading);
}

.score-item .score-label {
  font-size: 0.85rem;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  .scene.active,
  .scene.is-leaving,
  #scene-title.active::before,
  #scene-title.active::after,
  #scene-title.active .title-bg-image,
  #scene-title.active .title-text,
  #scene-title.active .subtitle,
  #scene-title.active #btn-begin,
  #scene-briefing.active .telegram,
  #scene-briefing.active #btn-to-street {
    animation: none !important;
    opacity: 1 !important;
    letter-spacing: normal !important;
    filter: none !important;
    transform: none !important;
  }
  .scene.is-leaving {
    display: none !important;
  }
  #scene-title.active::before,
  #scene-title.active::after {
    opacity: 0.85 !important;
  }
  .telegram .typewriter-cursor {
    display: none !important;
  }
}
