:root {
  --bg-1: #0b1a4a;
  --bg-2: #142a7a;
  --card: rgba(255, 255, 255, 0.08);
  --card-border: rgba(255, 255, 255, 0.14);
  --text: #f4f6ff;
  --muted: #a9b4e0;
  --gold: #f5c518;
  --gold-dark: #c99a00;
  --blue: #2f6bff;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 50% -20%, var(--bg-2), var(--bg-1) 70%) fixed;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

h1, h2, p { margin: 0; }
h2 { font-size: 1.05rem; margin-bottom: 12px; }

.muted { color: var(--muted); font-size: 0.95rem; }
.center { text-align: center; }

/* --- Kopf ---------------------------------------------------------------- */

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 8px 0 20px;
}
.brand h1 { font-size: 1.35rem; letter-spacing: 0.01em; }
.brand-q {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--bg-1);
  font-weight: 900;
  font-size: 1.3rem;
  box-shadow: 0 0 18px rgba(245, 197, 24, 0.5);
}

/* --- Bildschirme --------------------------------------------------------- */

.screen { display: none; flex-direction: column; gap: 14px; }
.screen.active { display: flex; animation: fade-in 0.25s ease; }

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

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card.center { align-items: center; }

/* --- Eingaben und Buttons ------------------------------------------------ */

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.95rem; color: var(--muted); }

input {
  width: 100%;
  font: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: rgba(0, 0, 0, 0.25);
  border: 2px solid var(--card-border);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
}
input:focus { border-color: var(--gold); }

#code {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
}

.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; min-width: 0; }
.join-row .btn { width: auto; }

/* Einladungslink: nur Name und Beitreten */
.card.invited .no-invite,
.card:not(.invited) .invite-only { display: none; }

.btn {
  width: 100%;
  font: inherit;
  font-weight: 700;
  font-size: 1.05rem;
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-gold { background: var(--gold); color: var(--bg-1); box-shadow: 0 4px 0 var(--gold-dark); }
.btn-blue { background: var(--blue); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); border: 2px solid var(--card-border); }
.btn-small { width: auto; padding: 8px 14px; font-size: 0.9rem; }

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--card-border); }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--card-border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Lobby --------------------------------------------------------------- */

.lobby-code {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.25em;
  padding-left: 0.25em;
  color: var(--gold);
}

.player-list, .score-list, .ranking { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.player-list li, .score-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
}
.player-list li.offline, .score-list li.offline { opacity: 0.5; }

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-weight: 800;
  color: #fff;
}
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.8rem; color: var(--muted); }

.segmented { display: flex; gap: 8px; }
.segmented button {
  flex: 1;
  font: inherit;
  font-weight: 700;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid var(--card-border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.segmented button.selected { border-color: var(--gold); background: rgba(245, 197, 24, 0.15); color: var(--gold); }

/* --- Frage --------------------------------------------------------------- */

.question-top { display: flex; justify-content: space-between; gap: 8px; }
.pill {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--card-border);
  font-size: 0.85rem;
  font-weight: 700;
}
.pill-gold { color: var(--gold); border-color: rgba(245, 197, 24, 0.4); }

.timer { height: 10px; border-radius: 999px; background: rgba(0, 0, 0, 0.3); overflow: hidden; }
.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--gold), #ffdd55);
  transform-origin: left;
  transition: transform 0.2s linear, background-color 0.3s;
}
.timer-bar.urgent { background: var(--red); }
.timer-text { text-align: right; font-size: 0.85rem; color: var(--muted); margin-top: -8px; min-height: 1.2em; }

.question-text { font-size: 1.35rem; line-height: 1.35; margin: 4px 0; }

.answers { display: flex; flex-direction: column; gap: 10px; }

.answer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: linear-gradient(180deg, #1f3a9e, #172d80);
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.3s, opacity 0.3s, transform 0.08s;
}
.answer:active:not(:disabled) { transform: scale(0.98); }
.answer:disabled { cursor: default; }
.answer-main { display: flex; align-items: center; gap: 12px; font-size: 1.1rem; font-weight: 600; }
.answer-letter {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  font-weight: 900;
}
.answer.selected { border-color: var(--gold); }
.answer.selected .answer-letter { background: var(--gold); color: var(--bg-1); }
.answer.locked { border-color: var(--gold); background: linear-gradient(180deg, #8a6d00, #6b5400); }
.answer.dimmed { opacity: 0.55; }

.answer.correct {
  border-color: var(--green);
  background: linear-gradient(180deg, #16803e, #11622f);
  animation: pop 0.45s ease;
}
.answer.correct .answer-letter { background: #fff; color: #11622f; }
.answer.wrong { opacity: 0.75; }
.answer.wrong.mine { border-color: var(--red); opacity: 0.9; }

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px 3px 3px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.3);
  font-size: 0.85rem;
  font-weight: 600;
  animation: fade-in 0.3s ease backwards;
}
.chip .avatar { width: 22px; height: 22px; font-size: 0.75rem; }

.status-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.status-row .chip { padding-right: 12px; }
.status-row .chip.done { background: rgba(34, 197, 94, 0.25); }

.explanation { line-height: 1.45; }
.explanation::before { content: "💡 "; }

.score-list .points { font-weight: 800; font-variant-numeric: tabular-nums; }
.plus { color: var(--green); font-weight: 800; font-size: 0.9rem; }

/* --- Endstand ------------------------------------------------------------ */

.ranking { width: 100%; }
.ranking li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  text-align: left;
  animation: fade-in 0.4s ease backwards;
}
.ranking li.first { background: rgba(245, 197, 24, 0.18); border: 2px solid var(--gold); }
.ranking .place { width: 32px; text-align: center; font-size: 1.4rem; font-weight: 900; }
.ranking .points { font-size: 1.3rem; font-weight: 900; font-variant-numeric: tabular-nums; }

.stat { display: flex; gap: 10px; align-items: baseline; line-height: 1.4; }
.stat-icon { font-size: 1.2rem; }

/* --- Hinweise ------------------------------------------------------------ */

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 8px 16px calc(8px);
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--red);
  color: #fff;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 10;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #fff;
  color: var(--bg-1);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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