:root {
  --accent: #22c55e;
  --accent-dark: #16a34a;
  --pink: #ec4899;
  --purple: #7c3aed;
  --bg-dark: #1a1230;
  --card-bg: #241a3d;
  --text: #f5f3ff;
  --text-dim: #c4b8e8;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: linear-gradient(160deg, var(--bg-dark), #2d1b4e 60%, #1a1230);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}
.screen.active { display: flex; }

h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle { color: var(--text-dim); margin: 0 0 28px; font-size: 0.95rem; }

.hero-img {
  width: 132px;
  height: 132px;
  object-fit: cover;
  border-radius: 22px;
  margin: 0 0 18px;
  border: 3px solid rgba(255,255,255,0.15);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.hero-subtitle {
  margin: -2px 0 22px;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--pink);
}

.card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 28px 22px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.05rem;
  border-radius: 12px;
  border: 2px solid #3d2c63;
  background: #150d29;
  color: var(--text);
  margin-bottom: 14px;
}
input[type="text"]:focus, input[type="password"]:focus {
  outline: none;
  border-color: var(--pink);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  color: white;
  transition: transform 0.1s ease, opacity 0.15s ease;
}
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  width: 100%;
  padding: 13px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 12px;
  background: #3d2c63;
  color: var(--text);
  margin-top: 10px;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #3d2c63;
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  color: #fca5a5;
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-bottom: 14px;
  display: none;
}
.error-msg.visible { display: block; }

/* ---- Game top bar ---- */
.game-topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 5;
}
.game-topbar .name { font-weight: 700; }
.game-topbar .progress { font-size: 0.85rem; color: var(--text-dim); }
.topbar-left { display: flex; align-items: center; gap: 10px; }

/* ---- Zurueck-Button ---- */
.back-btn {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  left: 14px;
  z-index: 3;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 15px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}
.back-btn:active { transform: scale(0.96); }
.back-btn-inline {
  position: static;
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* ---- Grid ---- */
.grid-wrap { width: 100%; padding: 10px; flex: none; }
.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  max-width: 480px;
  margin: 0 auto;
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #150d29;
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.tile .badge {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-radius: 8px;
  pointer-events: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.tile.marked .badge {
  border-color: var(--accent);
  background: rgba(34,197,94,0.25);
}
.tile.marked::after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
.modal-backdrop.active { display: flex; }
.modal-img-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.modal-img-wrap img {
  max-width: 92vw;
  max-height: 68vh;
  object-fit: contain;
  border-radius: 10px;
}
.modal-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.modal-mark-btn {
  margin: 16px;
  width: calc(100% - 32px);
  max-width: 400px;
  padding: 16px;
  font-size: 1.05rem;
  font-weight: 700;
  border-radius: 14px;
  background: #3d2c63;
  color: var(--text);
}
.modal-mark-btn.is-marked {
  background: var(--accent);
  color: #06280f;
}

/* ---- Bingo overlay ---- */
.bingo-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  background: radial-gradient(circle at 50% 30%, rgba(124,58,237,0.55), rgba(0,0,0,0.9));
  text-align: center;
  padding: 24px;
}
.bingo-overlay.active { display: flex; }
.bingo-overlay h2 {
  font-size: 3rem;
  margin: 0 0 8px;
  background: linear-gradient(90deg, #fbbf24, var(--pink), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
canvas#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 99;
}

/* ---- Warteraum: Foto-Laufband im Hintergrund ---- */
#screen-lobby {
  position: relative;
  overflow: hidden;
  padding: 0;
}

.lobby-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
}
.lobby-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(26,18,48,0.78), rgba(26,18,48,0.68) 45%, rgba(26,18,48,0.82) 100%);
}

.marquee-rows {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.marquee-track {
  display: flex;
  gap: 8px;
  width: max-content;
  animation: marquee-scroll 50s linear infinite;
}
.marquee-track img {
  height: 100px;
  width: 100px;
  object-fit: cover;
  border-radius: 12px;
  flex: none;
  opacity: 0.55;
}

@keyframes marquee-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.lobby-fg {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}
.lobby-fg h1 { filter: drop-shadow(0 2px 8px rgba(0,0,0,0.65)); }
.lobby-fg .subtitle { text-shadow: 0 1px 6px rgba(0,0,0,0.7); }

.lobby-players {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 380px;
  margin-top: 26px;
}
.player-pill {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  backdrop-filter: blur(4px);
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

@media (min-width: 700px) {
  .card { max-width: 420px; }
}
