:root {
  --color-bg: #000058;
  --color-surface: #1e293b;
  --color-border: #334155;
  --color-text: #f8fafc;
  --color-muted: #94a3b8;
  --color-accent: #0ea5e9;
  --color-accent-dim: rgba(14, 165, 233, 0.25);
  --color-good: #34d399;
  --font-sans: "DM Sans", system-ui, sans-serif;
  --font-display: "Outfit", var(--font-sans);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  height: 100%;
  margin: 0;
}

html {
  background-color: var(--color-bg);
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--color-bg);
}

.app-bg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.85;
}

.shell {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
}

/* tabindex=-1 + game.js focus() — browser default outline looks like a white frame */
#app-root:focus {
  outline: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand img {
  height: 48px;
  width: auto;
}

.brand h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  margin: 0;
  letter-spacing: -0.02em;
}

.brand p {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* Survey / form page — mobile-first */
body.survey-page {
  /* Avoid horizontal rubber-banding on narrow phones while scrolling the form */
  overflow-x: hidden;
}

body.survey-page .shell {
  padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
  padding-left: max(1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1rem, env(safe-area-inset-right, 0px));
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
}

body.survey-page .brand--survey {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

body.survey-page .brand--survey img {
  flex-shrink: 0;
  height: clamp(36px, 9vw, 48px);
  width: auto;
}

body.survey-page .brand__titles {
  min-width: 0;
}

@media (max-width: 420px) {
  body.survey-page .brand--survey {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.game-main {
  min-width: 0;
}

/* Same track for buzzer card and Ergebnis/QR card (they never show at once) */
body.game-page {
  --game-side-card: minmax(260px, min(42vw, 400px));
  --game-rocket-frame-w: 800px;
}

body.game-page .brand {
  margin-top: 2rem;
  margin-bottom: 3rem;
}

body.game-page .layout .panel {
  min-height: 800px;
}

.game-panels {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  min-width: 0;
}

/* Wide layout: rocket | (button card XOR Ergebnis card) — equal width side column */
@media (min-width: 720px) {
  body.game-page .game-panels:has(#game-panel-controls:not([hidden])):not(:has(#game-panel-result:not([hidden]))),
  body.game-page .game-panels:has(#game-panel-result:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) var(--game-side-card);
    align-items: stretch;
  }
}

@media (max-height: 640px) and (min-width: 560px) {
  body.game-page {
    --game-side-card: minmax(220px, min(40vw, 380px));
  }

  body.game-page .game-panels:has(#game-panel-controls:not([hidden])):not(:has(#game-panel-result:not([hidden]))),
  body.game-page .game-panels:has(#game-panel-result:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) var(--game-side-card);
    align-items: stretch;
  }
}

.game-panel--controls,
.game-panel--result {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.game-panel--controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
}

.game-panel--controls .state-hint {
  margin: 0;
  max-width: 28ch;
}

/* `hidden` must win over `display: flex` above (author CSS beats UA [hidden]) */
#game-panel-controls[hidden] {
  display: none !important;
}

.game-panel--controls .buzzer-wrap {
  margin-top: 0;
}

.game-panel--result {
  align-self: start;
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1fr 320px;
    align-items: start;
  }
}

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: clamp(1.25rem, 3vw, 2rem);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

.panel h2 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel h2.sr-only {
  margin: 0;
}

.game-stage {
  text-align: center;
  min-height: min(52vh, 520px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

/* Avoid forcing a tall play area on short viewports (running state overflow) */
@media (max-height: 720px) {
  body.game-page .game-stage {
    min-height: 0;
    padding-block: 0.25rem;
  }
}

.state-hint {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  color: var(--color-muted);
  max-width: 28ch;
  margin: 0;
}

.state-hint strong {
  color: var(--color-text);
}

.buzzer-wrap {
  margin-top: 0.5rem;
}

.buzzer-btn {
  appearance: none;
  border: none;
  cursor: pointer;
  max-width: 80%;
  width: min(440px, min(95vw, 90vh));
  aspect-ratio: 1;
  height: auto;
  border-radius: 50%;
  background: linear-gradient(165deg, #ef4444 0%, #b91c1c 100%);
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  letter-spacing: 0.04em;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow:
    0 16px 0 #7f1d1d,
    0 24px 48px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.buzzer-icon {
  display: block;
  flex-shrink: 0;
  opacity: 0.95;
  filter: brightness(0) invert(1);
}

.buzzer-label {
  line-height: 1.1;
}

.buzzer-btn:active:not(:disabled) {
  transform: translateY(8px);
  box-shadow:
    0 8px 0 #7f1d1d,
    0 12px 24px rgba(0, 0, 0, 0.35);
}

.buzzer-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.buzzer-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 4px;
}

.result-big {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-good);
  margin: 0;
}

.result-sub {
  font-size: 1.1rem;
  color: var(--color-muted);
  margin: 0;
}

.qr-block {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 12px;
  border: 1px solid var(--color-border);
}

.qr-block canvas {
  display: block;
  margin: 0 auto;
  border-radius: 8px;
}

.qr-block img {
  display: block;
  margin: 0 auto;
  max-width: min(480px, 92vw);
  height: auto;
}

.survey-caption-wrap {
  margin: 0.75rem 0 0;
}

.survey-caption {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-accent);
  text-decoration: none;
}

.survey-caption:hover {
  text-decoration: underline;
}

.survey-caption:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

.survey-url-details {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-muted);
}

.survey-url-details summary {
  cursor: pointer;
  color: var(--color-muted);
}

.survey-url {
  font-size: 0.8rem;
  color: var(--color-muted);
  word-break: break-all;
  margin: 0.5rem 0 0;
}

.survey-error {
  font-size: 0.9rem;
  color: #f87171;
  margin: 0.75rem 0 0;
}

.survey-fallback-msg {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 0;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}

.btn-secondary {
  appearance: none;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1rem;
  padding: 0.65rem 1.25rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.12);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.leaderboard {
  font-size: 0.95rem;
}

body.game-page .leaderboard {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
  scrollbar-width: thin;
}

body.game-page .leaderboard h2 {
  flex-shrink: 0;
  margin-bottom: 0;
}

body.game-page #leaderboard-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(50vh, 460px);
  max-height: min(50svh, 460px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

body.game-page .leaderboard li {
  padding: 0.35rem 0;
  font-size: 0.88rem;
}

.leaderboard ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard li {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.leaderboard li:last-child {
  border-bottom: none;
}

.lb-rank {
  color: var(--color-muted);
  font-variant-numeric: tabular-nums;
}

.lb-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-variant-numeric: tabular-nums;
  color: var(--color-accent);
}

.leaderboard-empty {
  color: var(--color-muted);
  margin: 0;
}

/* Survey page */
.survey-back {
  display: none;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.75rem;
  width: fit-content;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-muted);
  text-decoration: none;
  border-radius: 8px;
  padding: 0.35rem 0.5rem 0.35rem 0;
  margin-left: -0.5rem;
  transition: color 0.15s ease, background 0.15s ease;
}

.survey-back::before {
  content: "←";
  display: inline-block;
  margin-right: 0.15rem;
  color: var(--color-accent);
}

.survey-back:hover {
  color: var(--color-text);
  background: rgba(148, 163, 184, 0.1);
}

.survey-back:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

@media (min-width: 720px) {
  .survey-back {
    display: inline-flex;
  }
}

.survey-main {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

body.survey-page .survey-form {
  display: flex;
  flex-direction: column;
  gap: 1.125rem;
}

body.survey-page .survey-form .form-group {
  margin-bottom: 0;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--color-muted);
  margin-bottom: 0.35rem;
}

body.survey-page .form-group label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.4rem;
}

.form-group input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
}

/* 16px+ avoids iOS zooming inputs on focus */
body.survey-page .form-group input {
  min-height: 48px;
  padding: 0.7rem 0.85rem;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.form-group input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-dim);
}

.score-banner {
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(14, 165, 233, 0.35);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.score-banner p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--color-muted);
}

.score-banner strong {
  color: var(--color-good);
  font-size: 1.25rem;
}

body.survey-page .score-banner {
  padding: 1rem 1.1rem;
}

body.survey-page .score-banner p {
  line-height: 1.45;
}

.btn-primary {
  appearance: none;
  border: none;
  background: linear-gradient(165deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  cursor: pointer;
  width: 100%;
  margin-top: 0.5rem;
}

.btn-primary--survey {
  min-height: 52px;
  margin-top: 0.25rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-primary--survey:active:not(:disabled) {
  filter: brightness(0.96);
  transform: translateY(1px);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.form-footnote {
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-top: 1rem;
}

body.survey-page .form-footnote {
  line-height: 1.5;
  margin-top: 1.25rem;
  padding-bottom: 0.25rem;
}

.form-footnote a {
  color: var(--color-accent);
}

.msg-error {
  color: #f87171;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.msg-success {
  color: var(--color-good);
  font-size: 1rem;
  margin-top: 0.5rem;
}

/* Game — rocket celebration (see ROCKET_SCORE_RULES in game.js) */
#result-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 0.35rem;
}

.game-rocket-caption {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0.25rem 0 0;
  max-width: 34ch;
  text-align: center;
}

.game-rocket-wrap {
  width: 100%;
  max-width: 420px;
  margin: 0.35rem auto 0.75rem;
  aspect-ratio: 4 / 5;
  flex-shrink: 0;
}

/* Fixed rocket frame size on the game page (no responsive shrinking) */
body.game-page #game-rocket-wrap {
  width: var(--game-rocket-frame-w, 800px);
  max-width: min(var(--game-rocket-frame-w, 800px), 100%);
  height: auto;
  aspect-ratio: 4 / 5;
  margin-left: auto;
  margin-right: auto;
}

/* rocket.css caps .rocket-stage-wrap at 420px — fill the game wrapper instead */
body.game-page #game-rocket-wrap .rocket-stage-wrap {
  width: 100%;
  max-width: none;
}

/* Running: glow on the cockpit window (SVG), replaces pulse ring */
#game-rocket-wrap .rocket-stage-wrap.rocket-stage--ready {
  overflow: visible;
}

#game-rocket-wrap .rocket-stage--ready .rocket-window-shell {
  animation: rocket-window-glow 1.25s ease-in-out infinite;
}

@keyframes rocket-window-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 3px rgb(14 165 233 / 0.9)) drop-shadow(0 0 10px rgb(14 165 233 / 0.45));
  }

  50% {
    filter: drop-shadow(0 0 8px rgb(14 165 233 / 1)) drop-shadow(0 0 20px rgb(14 165 233 / 0.7));
  }
}

.rocket-load-error {
  color: var(--color-muted);
  font-size: 0.9rem;
  text-align: center;
  margin: 0;
}

/*
 * Game page — widescreen / short viewports.
 * Do not gate on max-height alone: wide but tall windows (e.g. 1920×1080) are still
 * landscape / widescreen and need the same layout. `orientation` can also be flaky
 * in some embeds — min-aspect-ratio is a second signal (viewport width ÷ height).
 */
@media (orientation: landscape),
  (min-aspect-ratio: 4/3),
  (max-height: 560px) and (min-width: 480px) {
  body.game-page {
    overflow-x: clip;
  }

  body.game-page .shell {
    min-height: 100vh;
    min-height: 100dvh;
    padding: clamp(0.35rem, 1.2vmin, 1rem);
    box-sizing: border-box;
  }

  body.game-page .brand {
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
  }

  body.game-page .brand img {
    height: clamp(28px, 6vmin, 42px);
  }

  body.game-page .brand h1 {
    font-size: clamp(1rem, 2.2vmin, 1.45rem);
  }

  body.game-page .brand p {
    font-size: 0.78rem;
    margin-top: 0.05rem;
  }

  body.game-page .layout {
    gap: 0.65rem;
    align-items: stretch;
  }

  /* Side-by-side main column + leaderboard */
  @media (min-width: 680px) {
    body.game-page .layout {
      grid-template-columns: minmax(0, 1fr) minmax(160px, 240px);
    }

    body.game-page .leaderboard {
      max-height: calc(100vh - 4.5rem);
      max-height: calc(100dvh - 4.5rem);
      overflow: hidden;
      align-self: stretch;
    }

    body.game-page #leaderboard-list {
      max-height: none;
      flex: 1 1 auto;
    }

    body.game-page .panel {
      padding: clamp(0.65rem, 1.5vmin, 1.25rem);
    }
  }

  /* Ergebnis card: scroll inside panel if needed */
  body.game-page .game-panel--result {
    max-height: calc(100vh - 5rem);
    max-height: calc(100dvh - 5rem);
    overflow-y: auto;
    min-height: 0;
  }

  body.game-page .game-stage {
    min-height: 0;
    gap: 0.4rem;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  body.game-page .state-hint {
    font-size: clamp(0.85rem, 1.8vmin, 1.05rem);
    max-width: none;
    margin: 0;
  }

  /* Same fixed rocket size as base game page (do not shrink in landscape) */
  body.game-page #game-rocket-wrap {
    overflow: hidden;
  }

  body.game-page #game-rocket-wrap .rocket-stage-wrap {
    width: 100%;
    height: auto;
    max-width: none;
    max-height: none;
  }

  /* Narrow landscape: leaderboard stays short so the page does not grow past the viewport */
  @media (max-width: 679px) {
    body.game-page .leaderboard {
      max-height: min(42dvh, 320px);
      overflow: hidden;
      padding: 0.65rem 0.85rem;
      font-size: 0.88rem;
    }

    body.game-page #leaderboard-list {
      max-height: none;
    }

    body.game-page .leaderboard h2 {
      font-size: 0.75rem;
      margin-bottom: 0;
    }
  }

  body.game-page .game-panel--controls .buzzer-btn {
    max-width: 80%;
    width: min(240px, 52vmin);
    aspect-ratio: 1;
    height: auto;
    font-size: clamp(1rem, 4.8vmin, 1.85rem);
  }

  body.game-page .game-panel--controls .buzzer-icon {
    width: 80px;
    height: 80px;
  }

  body.game-page .game-panel--result .result-big {
    font-size: clamp(1.5rem, 4.5vmin, 2.5rem);
  }

  body.game-page .game-panel--result .result-sub {
    font-size: 0.9rem;
  }

  body.game-page .game-panel--result .qr-block {
    margin-top: 0.5rem;
    padding: 0.65rem 0.75rem;
  }

  body.game-page .game-panel--result #qr-host img {
    max-width: min(360px, 58vmin);
    width: auto !important;
    height: auto !important;
  }
}
