:root {
  --ink: #17313a;
  --muted: #5d7780;
  --paper: #ffffff;
  --paper-soft: rgba(255, 255, 255, 0.86);
  --line: rgba(23, 49, 58, 0.14);
  --teal: #30b7b7;
  --teal-dark: #117b82;
  --coral: #ff6f61;
  --sun: #ffd64d;
  --grass: #70c76c;
  --sky: #b8edf0;
  --shadow: 0 18px 50px rgba(24, 63, 70, 0.16);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--sky);
}

* {
  box-sizing: border-box;
}

html,
body,
.app-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 214, 77, 0.42), transparent 26rem),
    linear-gradient(180deg, #b9edf3 0%, #e6faf5 46%, #f9fff4 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.audio-toggle {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  box-shadow: 0 8px 22px rgba(24, 63, 70, 0.18);
  backdrop-filter: blur(10px);
  font-size: 1.15rem;
  line-height: 1;
  transition: transform 0.12s ease, background 0.15s ease;
}

.audio-toggle:hover {
  transform: scale(1.06);
}

.audio-toggle.is-muted {
  background: rgba(255, 111, 97, 0.22);
  border-color: rgba(255, 111, 97, 0.5);
}

.audio-toggle .audio-icon {
  pointer-events: none;
}

/* --- Intro-Cinematic ------------------------------------------------------ */
.screen-intro {
  padding: 0;
  place-items: stretch;
  pointer-events: none;
  z-index: 20;
}

.intro-letterbox {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(8, 18, 22, 0.94) 0,
    rgba(8, 18, 22, 0) 9%,
    rgba(8, 18, 22, 0) 91%,
    rgba(8, 18, 22, 0.94) 100%
  );
  opacity: 0.85;
  transition: opacity 0.8s ease;
}

.intro-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 220px 50px rgba(6, 14, 18, 0.5);
  transition: box-shadow 0.8s ease;
}

/* Sommer-Szene: deutlich weniger dunkle Ränder als im Noir-Office-Teil. */
.screen-intro.is-bright .intro-vignette {
  box-shadow: inset 0 0 170px 10px rgba(24, 46, 30, 0.18);
}

.screen-intro.is-bright .intro-letterbox {
  opacity: 0.3;
}

.intro-loading {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 18px;
  background: radial-gradient(circle at 50% 40%, #0e2f35, #061417 75%);
  color: #eaf6ff;
  z-index: 6;
  pointer-events: auto;
}

.intro-loading.is-visible {
  display: grid;
}

.intro-loading-ring {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 5px solid rgba(255, 255, 255, 0.22);
  border-top-color: var(--sun);
  animation: introspin 0.9s linear infinite;
}

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

.intro-loading p {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.intro-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 24%;
  padding: 0 16px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 1.1s ease, transform 1.1s ease;
}

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

.intro-title .eyebrow {
  color: var(--sun);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5);
}

.intro-title h1 {
  margin: 0.08em 0 0.18em;
  font-size: clamp(2rem, 8.5vw, 4.6rem);
  line-height: 1.02;
  color: #ffffff;
  letter-spacing: 0.5px;
  text-shadow: 0 6px 34px rgba(0, 0, 0, 0.55), 0 0 22px rgba(255, 214, 77, 0.4);
}

.intro-tagline {
  margin: 0;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  font-size: clamp(0.92rem, 3.6vw, 1.25rem);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.55);
}

.intro-skip {
  position: absolute;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(16px, env(safe-area-inset-right));
  z-index: 8;
  pointer-events: auto;
  background: var(--paper-soft);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 800;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: transform 0.12s ease, background 0.15s ease;
}

.intro-skip:hover {
  transform: translateY(-1px);
  background: #ffffff;
}

/* Weißblende für den cinematic "Schritt ins Licht"-Schnitt (Opacity per JS gesteuert). */
.intro-flash {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 46%, #ffffff 0%, #fff4da 55%, #ffe9bd 100%);
}

.intro-fade {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 32%, #0e2f35, #061417 70%);
  transition: opacity 0.8s ease;
}

.intro-fade.is-active {
  opacity: 1;
  pointer-events: auto;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow: auto;
  z-index: 10;
}

.screen.is-active {
  display: grid;
}

.screen-menu {
  place-items: center;
}

.menu-panel,
.result-panel,
.loading-panel {
  width: min(1040px, 100%);
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.menu-panel {
  padding: clamp(18px, 3vw, 34px);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.3rem, 7vw, 5.2rem);
  line-height: 0.95;
}

h2,
h3 {
  margin-bottom: 10px;
}

.tagline {
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  margin-bottom: 22px;
}

.name-field {
  display: grid;
  gap: 8px;
  max-width: 430px;
  margin-bottom: 22px;
  font-weight: 700;
}

.name-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  outline: none;
}

.name-field input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(48, 183, 183, 0.18);
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
}

.section-heading h2,
.section-heading h3 {
  margin: 0;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.9rem;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.character-card {
  display: grid;
  gap: 10px;
  min-height: 154px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.character-card:hover,
.character-card.is-selected {
  transform: translateY(-2px);
  border-color: rgba(48, 183, 183, 0.62);
  box-shadow: 0 12px 26px rgba(17, 123, 130, 0.16);
}

.character-card.is-selected {
  background: #f2fffb;
}

.character-avatar {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal), var(--grass));
  color: #fff;
  font-weight: 900;
  font-size: 1.25rem;
}

.character-card strong {
  font-size: 1.1rem;
}

.character-card small {
  color: var(--muted);
  line-height: 1.35;
  word-break: break-word;
}

.character-card.has-error {
  border-color: rgba(255, 111, 97, 0.6);
}

.character-stage {
  position: relative;
  height: clamp(320px, 44vh, 460px);
  margin: 4px 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 16%, rgba(255, 214, 77, 0.32), transparent 62%),
    linear-gradient(180deg, #d7f3f6 0%, #eafaf3 58%, #ffffff 100%);
}

.preview-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.preview-name {
  position: absolute;
  left: 14px;
  bottom: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--ink);
  font-weight: 850;
  box-shadow: 0 6px 16px rgba(24, 63, 70, 0.14);
  opacity: 0;
  transition: opacity 200ms ease;
}

.character-stage.is-ready .preview-name {
  opacity: 1;
}

.preview-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.28);
}

.character-stage.is-loading .preview-hint,
.character-stage.is-ready .preview-hint {
  display: none;
}

.preview-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  border: 6px solid rgba(48, 183, 183, 0.22);
  border-top-color: var(--coral);
  animation: spin 850ms linear infinite;
  display: none;
}

.character-stage.is-loading .preview-loader {
  display: block;
}

/* Ergebnis-Screen: tanzender Charakter + Wechsel-Auswahl */
.result-hero {
  display: grid;
  gap: 14px;
  margin: 6px 0 18px;
}

.result-stage {
  height: clamp(280px, 40vh, 420px);
  margin: 0;
}

.result-switch {
  display: grid;
  gap: 8px;
}

.result-switch > span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.character-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.switch-chip {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  color: var(--ink);
  font-weight: 800;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.switch-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(48, 183, 183, 0.6);
}

.switch-chip.is-active {
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(17, 123, 130, 0.22);
}

@media (min-width: 720px) {
  .result-hero {
    grid-template-columns: 1.4fr 1fr;
    align-items: center;
  }
}

.instruction-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.instruction-strip div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.instruction-strip strong,
.instruction-strip span {
  display: block;
}

.instruction-strip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.menu-error {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 111, 97, 0.42);
  background: rgba(255, 111, 97, 0.12);
  color: #8d2d24;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 48px;
  border-radius: 8px;
  padding: 0 18px;
  font-weight: 850;
}

.primary-button {
  color: #fff;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  box-shadow: 0 10px 24px rgba(17, 123, 130, 0.24);
}

.secondary-button {
  color: var(--ink);
  background: #fff5c8;
  border: 1px solid rgba(218, 167, 32, 0.32);
}

.ghost-button {
  color: var(--teal-dark);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

.req {
  color: var(--coral);
  font-style: normal;
  font-weight: 900;
}

.screen-tutorial {
  place-items: center;
}

.tutorial-panel {
  padding: clamp(18px, 3vw, 34px);
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 22px;
}

.tutorial-card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
}

.tutorial-icon {
  font-size: 1.7rem;
  line-height: 1;
  margin-bottom: 8px;
}

.tutorial-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.02rem;
}

.tutorial-card span {
  display: block;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.tutorial-card em {
  font-style: normal;
  font-weight: 800;
  color: var(--teal-dark);
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font:
    700 0.82em/1.4 ui-monospace,
    "SFMono-Regular", Menlo, monospace;
  text-align: center;
}

.tutorial-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.screen-loading {
  place-items: center;
  background: rgba(232, 250, 246, 0.44);
}

.loading-panel {
  width: min(420px, 100%);
  padding: 26px;
  text-align: center;
}

.loading-ring {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 7px solid rgba(48, 183, 183, 0.2);
  border-top-color: var(--coral);
  animation: spin 850ms linear infinite;
}

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

.hud {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  top: max(12px, env(safe-area-inset-top));
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(72px, 120px) minmax(72px, 120px) minmax(0, 1fr);
  gap: 10px;
  pointer-events: none;
}

/* hidden-Attribut muss die display:grid-Regel schlagen, sonst scheint das HUD
   auf Menue/Tutorial/Ergebnis durch. */
.hud[hidden] {
  display: none;
}

.hud-card {
  min-height: 58px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 8px 22px rgba(24, 63, 70, 0.12);
}

.hud-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hud-card strong {
  display: block;
  margin-top: 2px;
  font-size: 1.3rem;
}

.hud-card.wide strong {
  font-size: clamp(0.96rem, 2vw, 1.3rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.powerup-bar {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  top: calc(max(12px, env(safe-area-inset-top)) + 68px);
  display: flex;
  gap: 8px;
  pointer-events: none;
}

.powerup-pill {
  padding: 7px 10px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 850;
  background: var(--coral);
  box-shadow: 0 8px 18px rgba(255, 111, 97, 0.24);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(118px + env(safe-area-inset-bottom));
  z-index: 9;
  max-width: min(92vw, 520px);
  transform: translate(-50%, 18px);
  padding: 11px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(23, 49, 58, 0.9);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.touch-controls {
  position: fixed;
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 9;
  display: none;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: 10px;
  pointer-events: none;
}

.touch-controls button {
  min-height: 64px;
  border-radius: 8px;
  color: #fff;
  background: rgba(17, 123, 130, 0.86);
  box-shadow: 0 12px 28px rgba(17, 123, 130, 0.24);
  font-weight: 900;
  pointer-events: auto;
}

.touch-controls button[data-control="jump"] {
  background: rgba(255, 111, 97, 0.9);
}

.screen-result {
  place-items: center;
  background: rgba(232, 250, 246, 0.58);
}

.result-panel {
  padding: clamp(18px, 3vw, 30px);
}

.rating-text {
  color: var(--muted);
  font-size: 1.1rem;
}

.result-summary,
.item-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 20px;
}

.result-summary div,
.item-summary div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.result-summary span,
.item-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.result-summary strong,
.item-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
  max-height: 240px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
  counter-reset: leaderboard;
}

.leaderboard-list li {
  counter-increment: leaderboard;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.leaderboard-list li::before {
  content: counter(leaderboard);
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--teal);
  font-weight: 900;
}

.leaderboard-list strong,
.leaderboard-list span {
  display: block;
}

.leaderboard-list span {
  color: var(--muted);
  font-size: 0.86rem;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

@media (max-width: 860px) {
  .character-grid,
  .instruction-strip,
  .tutorial-grid,
  .result-summary,
  .item-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .hud-card.wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px), (pointer: coarse) {
  .screen {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .menu-panel,
  .result-panel {
    align-self: start;
  }

  .character-grid,
  .instruction-strip,
  .result-summary,
  .item-summary {
    grid-template-columns: 1fr;
  }

  .touch-controls.is-active {
    display: grid;
  }

  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .hud-card {
    min-height: 50px;
    padding: 8px 10px;
  }

  .toast {
    bottom: calc(94px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: clamp(2.25rem, 13vw, 4.2rem);
  }
}
