:root {
  --blush: #f8c9d4;
  --blush-dark: #e8a3b5;
  --gold: #c9a15a;
  --gold-light: #e6cb95;
  --ink: #3a2e2f;
  --cream: #fffaf5;
  --choice-a: #6c8ae4;
  --choice-b: #e46ca0;
  --success: #4caf7d;
  --danger: #d96565;
  --radius: 16px;
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, Helvetica, Arial, sans-serif;
  background: linear-gradient(160deg, var(--cream) 0%, var(--blush) 120%);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 {
  font-family: Georgia, 'Times New Roman', serif;
  margin: 0 0 0.5em;
}

.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(40px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
  position: relative;
}

.mute-toggle {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  font-size: 1.3rem;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(58, 46, 47, 0.18);
  z-index: 50;
}

.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--gold-light);
  color: var(--ink);
}

.connection-banner.error {
  background: var(--danger);
  color: #fff;
}

.link-btn {
  display: inline;
  width: auto;
  padding: 0 0 0 8px;
  background: none;
  border: none;
  color: inherit;
  text-decoration: underline;
  font-weight: 700;
  font-size: inherit;
}

.wide {
  max-width: 900px;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(58, 46, 47, 0.12);
  padding: 28px 24px;
  width: 100%;
}

.center {
  text-align: center;
}

.subtitle {
  color: #7a6a6b;
  margin-bottom: 1.5em;
}

input[type="text"], input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  font-size: 1.1rem;
  border: 2px solid var(--blush-dark);
  border-radius: 12px;
  outline: none;
  margin-bottom: 16px;
  background: var(--cream);
}

input[type="text"]:focus, input[type="password"]:focus {
  border-color: var(--gold);
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  background: var(--gold);
  color: #fff;
  transition: transform 0.1s ease, opacity 0.15s ease;
}

button:active {
  transform: scale(0.98);
}

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

button.secondary {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--blush-dark);
}

button.danger {
  background: var(--danger);
}

.error {
  color: var(--danger);
  font-weight: 600;
  margin-bottom: 12px;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--blush);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
}

.lobby-players {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 20px 0;
}

.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--blush);
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.prep-banner {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 16px;
}

.timer-bar-wrap {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--blush);
  overflow: hidden;
  margin-bottom: 16px;
}

.timer-bar {
  height: 100%;
  border-radius: 999px;
  background: var(--success);
  transition: width 1s linear, background 0.3s ease;
}

.timer-bar.warn {
  background: var(--gold);
}

.timer-bar.urgent {
  background: var(--danger);
}

.question-image {
  width: 100%;
  border-radius: var(--radius);
  aspect-ratio: 10 / 7;
  object-fit: cover;
  margin-bottom: 16px;
  background: var(--blush);
}

.question-text {
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 20px;
}

.choices {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.choice-btn {
  padding: 22px 16px;
  border-radius: var(--radius);
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  border: none;
  cursor: pointer;
}

.choice-btn.a {
  background: var(--choice-a);
}

.choice-btn.b {
  background: var(--choice-b);
}

.choice-btn.correct {
  background: var(--success) !important;
  outline: 4px solid #2e7d54;
}

.choice-btn.wrong {
  opacity: 0.45;
}

.choice-btn:disabled {
  cursor: default;
}

.result-banner {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.result-banner.correct { color: var(--success); }
.result-banner.wrong { color: var(--danger); }

.result-banner.waiting {
  color: var(--gold);
  font-size: 1.05rem;
}

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

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  background: var(--cream);
}

.leaderboard li.me {
  background: var(--blush);
  border: 2px solid var(--gold);
}

.leaderboard .rank {
  font-weight: 700;
  width: 28px;
  flex-shrink: 0;
  text-align: center;
  color: var(--gold);
}

.leaderboard .name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard .score {
  flex-shrink: 0;
  font-weight: 700;
}

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  margin: 30px 0;
}

.podium .place {
  background: linear-gradient(180deg, var(--gold-light), var(--gold));
  border-radius: 12px 12px 0 0;
  text-align: center;
  padding: 14px 10px;
  color: #fff;
  font-weight: 700;
}

.podium .place .medal { font-size: 2rem; display: block; }
.podium .p1 { height: 160px; order: 2; width: 33%; }
.podium .p2 { height: 120px; order: 1; width: 30%; }
.podium .p3 { height: 90px; order: 3; width: 30%; }

.footer-note {
  margin-top: 24px;
  font-size: 0.8rem;
  color: #a08e8f;
  text-align: center;
}

.admin-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 24px;
}

.admin-controls button {
  width: auto;
  flex: 1;
  min-width: 140px;
}

table.questions {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
}

table.questions th, table.questions td {
  text-align: left;
  padding: 10px;
  border-bottom: 1px solid #f0e3e6;
  font-size: 0.9rem;
}

table.questions img {
  width: 60px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.qr-box {
  text-align: center;
  margin: 20px 0;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  border: 4px solid #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--blush);
  margin-bottom: 16px;
}

.spectator-body {
  background: linear-gradient(160deg, #2b1f21 0%, #4a2f36 100%);
  color: #fff;
}

.spectator-body .card {
  background: rgba(255,255,255,0.06);
  color: #fff;
  backdrop-filter: blur(6px);
}

.spectator-body .leaderboard li {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

.spectator-body .leaderboard li.me {
  background: rgba(230, 203, 149, 0.25);
}

@media (min-width: 640px) {
  .app { padding-top: 48px; }
}

.confetti-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 60;
}

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

@keyframes confetti-fall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0.3;
  }
}
