:root {
  --bg: #0b0c10;
  --card-bg: #16181d;
  --card-border: #2a2d35;
  --text: #f2f2f2;
  --text-dim: #9aa0ab;
  --accent: #6c8cff;
  --death: #ff5b6a;
  --win: #4ade80;
  --neutral: #f5b942;
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Muli", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--card-border);
}

.title {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1rem;
  color: var(--text-dim);
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 10px;
}

.ending-progress {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
  background: transparent;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.ending-progress:hover,
.ending-progress:focus-visible {
  color: var(--text);
  border-color: #f5b942;
  background: rgba(245, 185, 66, 0.1);
  outline: none;
}

.minigame-progress-badge {
  cursor: default;
}

.minigame-progress-badge:hover {
  color: var(--text-dim);
  border-color: var(--card-border);
  background: transparent;
}

.pulse {
  animation: badge-pulse 0.4s ease;
}

@keyframes badge-pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.restart {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.restart:hover,
.restart:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  background: rgba(108, 140, 255, 0.1);
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
  overflow: hidden;
}

.scene-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transform: scale(1.04);
  transition: opacity 0.5s ease;
  filter: saturate(0.9) brightness(0.55);
}

.scene.has-bg .scene-bg {
  opacity: 1;
}

.scene::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, transparent 0%, var(--bg) 92%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.scene.has-bg::after {
  opacity: 1;
}

.card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 560px;
  background: color-mix(in srgb, var(--card-bg) 88%, transparent);
  backdrop-filter: blur(6px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.card.fade-out {
  opacity: 0;
  transform: translateY(6px);
}

.card.shake {
  animation: card-shake 0.4s ease;
}

@keyframes card-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.flash {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--death);
  opacity: 0;
  pointer-events: none;
}

.flash-active {
  animation: flash-fade 0.4s ease-out;
}

@keyframes flash-fade {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

.confetti-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation-name: confetti-fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 0.9;
  }
  100% {
    transform: translate(var(--drift), 110vh) rotate(540deg);
    opacity: 0;
  }
}

.confetti-piece-mini {
  width: 6px;
  height: 10px;
  animation-name: confetti-fall-mini;
  z-index: 2;
}

@keyframes confetti-fall-mini {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 0.9;
  }
  100% {
    transform: translate(var(--drift), 170px) rotate(360deg);
    opacity: 0;
  }
}

.card.death {
  border-color: color-mix(in srgb, var(--death) 45%, var(--card-border));
}

.card.win {
  border-color: color-mix(in srgb, var(--win) 45%, var(--card-border));
}

.card.neutral {
  border-color: color-mix(in srgb, var(--neutral) 45%, var(--card-border));
}

.ending-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-dim);
}

.ending-badge[hidden] {
  display: none;
}

.card.death .ending-badge {
  color: var(--death);
  background: color-mix(in srgb, var(--death) 18%, transparent);
}

.card.win .ending-badge {
  color: var(--win);
  background: color-mix(in srgb, var(--win) 18%, transparent);
}

.card.neutral .ending-badge {
  color: var(--neutral);
  background: color-mix(in srgb, var(--neutral) 18%, transparent);
}

.scene-text {
  margin: 0 0 22px;
  font-size: 1.2rem;
  line-height: 1.55;
}

.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  position: relative;
  grid-column: 1 / -1;
}

.choice-enter {
  animation: choice-in 0.35s ease both;
}

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

.choice:hover,
.choice:focus-visible {
  background: rgba(108, 140, 255, 0.12);
  border-color: var(--accent);
  outline: none;
}

.choice:active {
  transform: scale(0.98);
}

.choice:not(.choice-tile) .choice-label {
  flex: 1;
}

.choice[data-key]:not(.choice-tile)::after {
  content: attr(data-key);
  font-size: 0.7rem;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  border-radius: 5px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.restart-choice {
  justify-content: center;
  font-weight: 700;
}

/* Bild-Kacheln für Entscheidungen mit thematischem Foto */
.choice-tile {
  position: relative;
  grid-column: span 1;
  display: block;
  height: 128px;
  padding: 0;
  overflow: hidden;
  background: #000;
}

.choice-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.choice-tile::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.15) 55%, transparent 80%);
}

.choice-tile:hover img,
.choice-tile:focus-visible img {
  transform: scale(1.06);
}

.choice-tile .choice-label {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 10px;
  z-index: 1;
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.25;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.choice-tile[data-key]::before {
  content: attr(data-key);
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  font-size: 0.7rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 480px) {
  .choice-tile {
    height: 150px;
  }
}

.foothint {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  padding: 10px;
}

@media (min-width: 640px) {
  .scene-text {
    font-size: 1.3rem;
  }
}

@media (max-width: 380px) {
  .card {
    padding: 22px 18px 18px;
  }

  .scene-text {
    font-size: 1.08rem;
  }

  .title {
    font-size: 0.9rem;
  }

  .ending-progress {
    font-size: 0.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .scene-bg,
  .scene::after,
  .card {
    transition: none;
  }

  .pulse,
  .minigame-skip {
    animation: none;
  }
}

/* Achievement-Toast */
.toast-layer {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  background: #1c1f26;
  border: 1px solid #f5b942;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* Enden-Galerie */
.gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.gallery-overlay[hidden] {
  display: none;
}

.gallery-modal {
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.gallery-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.gallery-close {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-dim);
  border-radius: 999px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: color 0.15s, border-color 0.15s;
}

.gallery-close:hover,
.gallery-close:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  outline: none;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.gallery-card {
  position: relative;
  height: 110px;
  border-radius: 12px;
  overflow: hidden;
  background: #000 center / cover no-repeat;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--card-border);
}

.gallery-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0.1) 60%);
}

.gallery-card.locked {
  background: repeating-linear-gradient(
    45deg,
    #1c1f26,
    #1c1f26 10px,
    #20232b 10px,
    #20232b 20px
  );
}

.gallery-card.locked::after {
  background: none;
}

.gallery-label {
  position: relative;
  z-index: 1;
  padding: 8px 10px;
  font-size: 0.82rem;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.gallery-card.locked .gallery-label {
  color: var(--text-dim);
  text-shadow: none;
}

.gallery-card.ending-death {
  border-color: color-mix(in srgb, var(--death) 40%, var(--card-border));
}

.gallery-card.ending-win {
  border-color: color-mix(in srgb, var(--win) 40%, var(--card-border));
}

.gallery-card.ending-neutral {
  border-color: color-mix(in srgb, var(--neutral) 40%, var(--card-border));
}

/* Gesperrte Choice (benötigt Minispiel) */
.choice-locked {
  border-style: dashed;
}

.choice-lock {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1;
  font-size: 0.85rem;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.choice:not(.choice-tile) .choice-lock {
  position: static;
  background: none;
  border: none;
  width: auto;
  height: auto;
  order: -1;
}

/* Minispiel-Modal */
.minigame-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.minigame-overlay[hidden] {
  display: none;
}

.minigame-modal {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.minigame-modal .gallery-header {
  text-align: left;
}

.minigame-instructions {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 0 0 18px;
}

.minigame-stage {
  position: relative;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  overflow: hidden;
}

.minigame-feedback {
  min-height: 1.2em;
  margin: 14px 0 0;
  font-weight: 700;
  font-size: 0.9rem;
}

.minigame-feedback.minigame-success {
  color: var(--win);
}

.minigame-feedback.minigame-fail {
  color: var(--death);
}

.minigame-action {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 28px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.1s, filter 0.15s;
}

.minigame-action:hover,
.minigame-action:focus-visible {
  filter: brightness(1.1);
  outline: none;
}

.minigame-action:active {
  transform: scale(0.96);
}

.minigame-skip {
  display: block;
  margin: 16px auto 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-family: inherit;
  text-decoration: underline;
  cursor: pointer;
  animation: choice-in 0.3s ease both;
}

.minigame-skip[hidden] {
  display: none;
}

.minigame-skip:hover,
.minigame-skip:focus-visible {
  color: var(--text);
  outline: none;
}

/* Nerven-Probe */
.listen-track {
  position: relative;
  width: 100%;
  height: 14px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.listen-zone {
  position: absolute;
  left: 38%;
  width: 24%;
  top: 0;
  bottom: 0;
  background: color-mix(in srgb, var(--win) 35%, transparent);
}

.listen-marker {
  position: absolute;
  top: -3px;
  left: 0;
  width: 4px;
  height: 20px;
  background: var(--text);
  border-radius: 2px;
  transform: translateX(-50%);
}

/* Durchzwängen */
.crawl-bar {
  width: 100%;
  height: 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.crawl-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--win));
  transition: width 0.1s ease;
}

/* Im Dunkeln erkennen */
.spot-area {
  position: relative;
  width: 100%;
  height: 160px;
  background: #050608;
  border-radius: 12px;
  overflow: hidden;
}

.spot-status {
  position: absolute;
  top: 6px;
  left: 10px;
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-dim);
  z-index: 1;
}

.spot-dot {
  position: absolute;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
  animation: spot-pop 0.15s ease;
}

@keyframes spot-pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Hilfe-Modal */
.help-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 0.9rem;
  line-height: 1.4;
}

.help-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

/* Titel-Screen */
.title-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow: hidden;
  padding: 24px;
}

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

.title-bg {
  position: absolute;
  inset: -10%;
  background:
    radial-gradient(circle at 25% 20%, color-mix(in srgb, var(--accent) 22%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 78% 75%, color-mix(in srgb, var(--win) 14%, transparent) 0%, transparent 50%),
    radial-gradient(circle at 85% 15%, color-mix(in srgb, var(--death) 14%, transparent) 0%, transparent 45%);
  animation: title-drift 14s ease-in-out infinite alternate;
}

@keyframes title-drift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-2%, 2%) scale(1.08); }
}

.title-content {
  position: relative;
  z-index: 1;
  max-width: 440px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.title-emoji {
  font-size: 3.2rem;
  margin-bottom: 6px;
  animation: title-bob 2.4s ease-in-out infinite;
}

@keyframes title-bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}

.title-heading {
  margin: 0 0 10px;
  font-size: 1.8rem;
  line-height: 1.25;
}

.title-tagline {
  margin: 0 0 26px;
  color: var(--text-dim);
  font-size: 0.95rem;
  line-height: 1.5;
}

.title-start-btn {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--win)));
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 16px 40px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 45%, transparent);
  animation: title-pulse 2.2s ease-in-out infinite;
  transition: transform 0.15s;
}

.title-start-btn:hover,
.title-start-btn:focus-visible {
  transform: scale(1.05);
  outline: none;
}

.title-start-btn:active {
  transform: scale(0.97);
}

@keyframes title-pulse {
  0%, 100% { box-shadow: 0 8px 30px color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 8px 42px color-mix(in srgb, var(--accent) 70%, transparent); }
}

.title-returning {
  margin: 18px 0 0;
  font-size: 0.82rem;
  color: var(--neutral);
}

.title-help-link {
  margin-top: 22px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.82rem;
  font-family: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.title-help-link:hover,
.title-help-link:focus-visible {
  color: var(--text);
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .title-bg,
  .title-emoji,
  .title-start-btn {
    animation: none;
  }
}
