/* Buzzer — thème sombre, mobile-first. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-hi: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --go: #2ea043;
  --go-hi: #3fb950;
  --danger: #f85149;
  --gold: #e3b341;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Un buzzer se tapote vite et fort : pas de zoom, pas de sélection parasite. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.screen {
  min-height: 100%;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}

[hidden] {
  display: none !important;
}

/* ------------------------------------------------------------- accueil */

.home-header {
  text-align: center;
  margin-top: 8vh;
}

.home-header h1 {
  margin: 0;
  font-size: 2.75rem;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  user-select: text;
}

input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  text-align: center;
  font-weight: 700;
  font-size: 1.3rem;
}

.join-row {
  display: flex;
  gap: 10px;
}

.join-row .code-input {
  flex: 1;
  min-width: 0;
}

.separator {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
}

.separator::before,
.separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ------------------------------------------------------------- boutons */

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: filter 0.12s ease, transform 0.06s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

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

.btn-primary {
  background: var(--accent);
}

.btn-secondary {
  background: var(--surface-hi);
  border-color: var(--border);
}

.btn-lg {
  padding: 20px;
  font-size: 1.15rem;
}

.btn-sub {
  font-size: 0.72rem;
  font-weight: 400;
  opacity: 0.8;
}

.btn-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  padding: 4px;
}

/* ------------------------------------------------------------- en-tête */

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-code {
  color: var(--muted);
  font-size: 0.85rem;
}

.room-code strong {
  color: var(--text);
  letter-spacing: 0.15em;
}

.code-display {
  display: block;
  font-size: 2rem;
  letter-spacing: 0.25em;
  user-select: text;
}

/* -------------------------------------------------------------- buzzer */

.buzzer {
  flex: 1;
  min-height: 45vh;
  width: 100%;
  border: none;
  border-radius: 50%;
  aspect-ratio: 1;
  max-height: 60vh;
  margin: 0 auto;
  background: var(--surface-hi);
  color: var(--muted);
  font-family: inherit;
  font-size: clamp(2rem, 12vw, 4rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  cursor: not-allowed;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.35);
  transition: background 0.1s ease, transform 0.06s ease, box-shadow 0.06s ease;
}

.buzzer.is-armed {
  background: var(--go);
  color: #fff;
  cursor: pointer;
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(46, 160, 67, 0.6);
  animation: pulse 1.6s ease-out infinite;
}

.buzzer.is-armed:active,
.buzzer.is-pressed {
  transform: translateY(6px) scale(0.98);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.3);
  animation: none;
}

.buzzer.is-locked {
  background: var(--surface);
  color: var(--muted);
  animation: none;
  cursor: default;
}

@keyframes pulse {
  0% {
    box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(46, 160, 67, 0.5);
  }
  70% {
    box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.28), 0 0 0 26px rgba(46, 160, 67, 0);
  }
  100% {
    box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.28), 0 0 0 0 rgba(46, 160, 67, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .buzzer.is-armed {
    animation: none;
  }
}

.status {
  text-align: center;
  color: var(--muted);
  margin: 0;
  min-height: 1.4em;
  font-size: 1rem;
}

.status.is-live {
  color: var(--go-hi);
  font-weight: 600;
}

/* --------------------------------------------------------- classement */

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  animation: slide-in 0.18s ease-out;
}

.leaderboard li.is-me {
  border-color: var(--accent);
}

.leaderboard li.rank-1 {
  border-color: var(--gold);
  background: linear-gradient(90deg, rgba(227, 179, 65, 0.14), transparent);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}

.rank {
  font-weight: 800;
  font-size: 1.1rem;
  min-width: 1.6em;
  color: var(--muted);
}

.rank-1 .rank {
  color: var(--gold);
}

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

.gap {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.9rem;
}

.leaderboard-lg li {
  padding: 16px;
  font-size: 1.15rem;
}

/* ------------------------------------------------------------- joueurs */

.players h2 {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count {
  background: var(--surface-hi);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.8rem;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.player-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 7px;
}

.player-list li.is-offline {
  opacity: 0.45;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.is-online .dot {
  background: var(--go-hi);
}

.has-buzzed .dot {
  background: var(--gold);
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* ------------------------------------------------------------ statuts */

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

.banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 7px;
  font-size: 0.88rem;
  font-weight: 600;
}

.host-controls {
  display: flex;
  gap: 10px;
}

.host-controls .btn-primary {
  flex: 1;
}
