:root {
  --bg-void: #05070d;
  --panel: rgba(8, 14, 24, 0.82);
  --panel-border: rgba(120, 220, 255, 0.28);
  --cyan: #7ee7ff;
  --amber: #ffc857;
  --text: #e8f1ff;
  --muted: #9bb0c9;
  --danger: #ff6b7a;
  --radius: 14px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-void);
  color: var(--text);
  font-family: var(--font);
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  background-color: #0a1220;
  background-size: cover;
  background-position: center;
  filter: saturate(1.05) contrast(1.05);
  transform: scale(1.02);
  transition: background-image 0.45s ease;
}

#bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(120, 40, 60, 0.18), transparent 55%),
    linear-gradient(to top, rgba(2, 4, 10, 0.92) 0%, rgba(2, 4, 10, 0.25) 42%, rgba(2, 4, 10, 0.35) 100%);
  pointer-events: none;
}

/* fallback tint if image missing */
#bg[data-fallback="bg_crash"] {
  background-image: linear-gradient(160deg, #1a3a2a, #0b1020 60%, #2a1830);
}
#bg[data-fallback="bg_station"] {
  background-image: linear-gradient(160deg, #1a2840, #0a0e18 55%, #203040);
}
#bg[data-fallback="bg_anomaly"] {
  background-image: linear-gradient(160deg, #3a2a18, #120c18 50%, #2a4060);
}
#bg[data-fallback="bg_atlas"] {
  background-image: radial-gradient(circle at 50% 40%, #8b1e2d, #120208 70%);
}
#bg[data-fallback="title_bg"] {
  background-image: radial-gradient(circle at 50% 30%, #3a1020, #05070d 65%);
}

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  z-index: 2;
}

#sprite {
  max-height: min(72vh, 720px);
  max-width: min(46vw, 420px);
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.55));
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  margin-bottom: 18vh;
}

#sprite[hidden] {
  display: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  pointer-events: none;
}

#hud-flags {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 6px 12px;
  backdrop-filter: blur(8px);
  max-width: 70vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#hud-actions button {
  appearance: none;
  border: 1px solid rgba(126, 231, 255, 0.25);
  background: rgba(8, 14, 24, 0.65);
  color: var(--cyan);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}

#hud-actions button:hover {
  border-color: var(--cyan);
}

#title-screen {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 14px;
}

#title-screen[hidden] {
  display: none;
}

#title-kicker {
  color: var(--amber);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 11px;
}

#title-headline {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 700;
  text-shadow: 0 8px 40px rgba(0, 0, 0, 0.7);
}

#title-tagline {
  margin: 0;
  max-width: 28rem;
  color: var(--muted);
  line-height: 1.5;
}

#title-start {
  margin-top: 18px;
  appearance: none;
  border: 1px solid rgba(126, 231, 255, 0.45);
  background: linear-gradient(180deg, rgba(40, 90, 120, 0.55), rgba(10, 20, 36, 0.85));
  color: var(--text);
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 1rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

#title-start:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

#dialogue {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(920px, 100% - 20px);
  z-index: 4;
  padding: 0 0 18px;
}

#dialogue[hidden] {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
  padding: 16px 18px 14px;
}

#speaker {
  display: inline-block;
  color: var(--cyan);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
  border-left: 3px solid var(--amber);
  padding-left: 8px;
}

#speaker[hidden] {
  display: none;
}

#text {
  min-height: 4.5em;
  line-height: 1.55;
  font-size: clamp(0.98rem, 2.4vw, 1.12rem);
  white-space: pre-wrap;
}

#continue {
  appearance: none;
  margin-top: 10px;
  border: none;
  background: transparent;
  color: var(--amber);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  float: right;
}

#continue[hidden] {
  display: none;
}

#choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.choice {
  appearance: none;
  text-align: left;
  width: 100%;
  border: 1px solid rgba(126, 231, 255, 0.22);
  background: rgba(6, 12, 22, 0.72);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.98rem;
  line-height: 1.4;
  cursor: pointer;
  animation: choiceIn 0.28s ease both;
}

.choice:hover,
.choice:focus-visible {
  border-color: var(--cyan);
  background: rgba(20, 50, 70, 0.75);
  outline: none;
}

@keyframes choiceIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#ending {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#ending[hidden] {
  display: none;
}

#ending .panel {
  width: min(640px, 100%);
  text-align: left;
}

#ending-title {
  margin: 0 0 12px;
  color: var(--amber);
  font-size: 1.35rem;
}

#ending-text {
  margin: 0 0 14px;
  line-height: 1.6;
  color: var(--text);
}

#ending-epilogue {
  margin: 0 0 18px;
  color: var(--muted);
  font-style: italic;
  line-height: 1.5;
}

#ending-restart {
  appearance: none;
  border: 1px solid rgba(126, 231, 255, 0.4);
  background: rgba(20, 40, 60, 0.7);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 20px;
  cursor: pointer;
}

.toast {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  animation: fade 1.4s ease both;
}

@keyframes fade {
  0% {
    opacity: 0;
  }
  15% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (max-width: 720px) {
  #sprite {
    max-height: 48vh;
    max-width: 78vw;
    margin-bottom: 28vh;
  }

  #hud-flags {
    font-size: 10px;
    max-width: 58vw;
  }

  #dialogue {
    width: calc(100% - 12px);
    padding-bottom: 10px;
  }

  .panel {
    padding: 14px 12px 12px;
  }

  #text {
    min-height: 5.2em;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
