/* ====== Reset & Base ====== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --secondary: #00cec9;
  --danger: #e17055;
  --success: #00b894;
  --bg: #0a0a1a;
  --card-bg: #1a1a2e;
  --text: #eee;
  --text-dim: #888;
  --radius: 12px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Safe area for notched phones */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ====== Screens ====== */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.screen.active {
  display: flex;
  opacity: 1;
}

/* Countdown overlay */
.countdown-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.85);
}

.countdown-number {
  font-size: 120px;
  font-weight: 900;
  color: white;
  animation: countdownPop 0.8s ease-out;
}

.countdown-go {
  font-size: 80px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: countdownPop 0.5s ease-out;
}

@keyframes countdownPop {
  0% { transform: scale(2); opacity: 0; }
  50% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

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

.btn-success:hover {
  background: #00a383;
}

/* ====== LOBBY ====== */
.lobby-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 400px;
  margin: auto;
  padding: 24px;
}

.game-title {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}

.game-subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 14px;
}

.lobby-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
}

.lobby-card label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.lobby-card input[type="text"],
.lobby-card input[type="number"] {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #111;
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 16px;
}

.lobby-card input:focus {
  border-color: var(--primary);
}

.lobby-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider-text {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}

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

.join-row input {
  flex: 1;
  margin-bottom: 0 !important;
}

/* Settings */
.settings-toggle {
  margin-top: 16px;
  text-align: center;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}

.settings-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #333;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
  cursor: pointer;
}

.toggle-row input[type="checkbox"] {
  width: 40px;
  height: 22px;
}

.toggle-row input[type="number"] {
  width: 60px;
  padding: 6px;
  border: 1px solid #333;
  border-radius: 6px;
  background: #111;
  color: var(--text);
  font-size: 14px;
  text-align: center;
}

.toggle-desc {
  font-size: 11px;
  color: var(--text-dim);
  width: 100%;
  margin-top: 2px;
}

/* ====== Lobby Room List ====== */
.lobby-rooms {
  width: 100%;
  max-width: 400px;
  margin-top: 20px;
}

.lobby-rooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
}

.room-list-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.room-list-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 16px;
}

.room-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 12px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.room-list-item:active {
  background: #2a2a4e;
}

.room-list-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.room-list-id {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 2px;
  color: var(--secondary);
}

.room-list-host {
  font-size: 12px;
  color: var(--text-dim);
}

.room-list-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.room-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
}

.room-tag.infection {
  background: #8e44ad;
  color: white;
}

.room-list-count {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 600;
}

/* ====== Buttons ====== */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

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

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

.btn-secondary {
  background: #333;
  color: var(--text);
}

.btn-secondary:hover {
  background: #444;
}

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

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-large {
  padding: 16px;
  font-size: 18px;
}

/* ====== ROOM SCREEN ====== */
.room-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  max-width: 400px;
  margin: 60px auto auto;
  padding: 24px;
}

.room-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.room-id-display {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--secondary);
}

.player-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.player-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  padding: 12px 16px;
  border-radius: 8px;
}

.player-item .player-name {
  font-weight: 600;
}

.player-item .player-role {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #333;
}

.player-role.catcher {
  background: var(--danger);
  color: white;
}

.player-role.runner {
  background: var(--success);
  color: white;
}

.player-role.dead {
  background: #555;
  color: #999;
}

.player-role.infected {
  background: #8e44ad;
  color: white;
}

.player-item .player-host {
  font-size: 11px;
  color: gold;
}

.player-item .player-qr-assigned {
  font-size: 11px;
  color: #00b894;
  margin-left: 4px;
}

.room-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* Room QR preview */
.room-qr-section {
  text-align: center;
  margin-bottom: 16px;
}

.room-qr-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 8px;
}

/* Shared base for every QR image (room preview, modal, runner mini-badge). */
.room-qr-img,
.qr-modal img,
.runner-qr-badge img {
  background: white;
  border-radius: 8px;
  display: block;
}

.room-qr-img {
  width: 140px;
  height: 140px;
  display: inline-block;
}

/* ====== Error ====== */
.error-msg {
  color: var(--danger);
  text-align: center;
  margin-top: 12px;
  font-size: 14px;
}

/* ====== GAME SCREEN ====== */
#screen-game {
  background: #000;
  overflow: hidden;
}

#camera-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

.game-hud {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  pointer-events: auto;
}

.hud-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.role-badge {
  font-size: 16px;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 20px;
  display: inline-block;
}

.role-badge.catcher-badge {
  background: var(--danger);
}

.role-badge.runner-badge {
  background: var(--success);
}

#hud-alive-count {
  font-size: 13px;
  color: var(--text-dim);
}

.hud-timer {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.hud-room-info {
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(0,0,0,0.5);
  padding: 4px 10px;
  border-radius: 8px;
}

.hud-bottom {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 16px;
  padding: 24px;
  background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
  pointer-events: auto;
}

.hud-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.hud-btn-label {
  font-size: 9px;
  font-weight: 500;
  opacity: 0.8;
}

.hud-btn-scan {
  width: 80px;
  height: 80px;
  background: var(--primary);
  font-size: 14px;
}

/* Scanning indicator */
.scanning-active .hud-btn-scan {
  animation: pulse 1s infinite;
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(225, 112, 85, 0.4); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(225, 112, 85, 0); }
}

/* ====== Modals ====== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
}

.modal-content h3 {
  margin-bottom: 16px;
}

.qr-modal img {
  width: 200px;
  height: 200px;
  margin: 16px auto;
}

.qr-hint {
  color: var(--text-dim);
  font-size: 13px;
}

.modal-content .btn {
  margin-top: 12px;
  width: 100%;
}

/* ====== GAME OVER ====== */
.gameover-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 400px;
  margin: auto;
  padding: 24px;
}

#gameover-title {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 8px;
}

#gameover-reason {
  color: var(--text-dim);
  margin-bottom: 8px;
}

.gameover-duration {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 20px;
}

#gameover-winners {
  margin-bottom: 16px;
}

.winner-item {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  padding: 8px 16px;
  border-radius: 20px;
  display: inline-block;
  margin: 4px;
  font-weight: 600;
}

/* ====== Game Notifications (slide-in toasts) ====== */
.game-notification {
  position: fixed;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: top 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.game-notification.show {
  top: 20px;
}

/* ====== Dead/Infected badges ====== */
.role-badge.dead-badge {
  background: #555;
  color: #999;
}

.role-badge.infected-badge {
  background: #8e44ad;
}

/* ====== Runner QR Badge (floating, always visible for runners) ====== */
.runner-qr-badge {
  position: absolute;
  /* Offset below the device's top safe-area and the HUD top bar so the badge
     doesn't collide with the room-id display on notched phones. */
  top: calc(env(safe-area-inset-top) + 72px);
  right: 16px;
  z-index: 25;
  background: rgba(0,0,0,0.7);
  border: 2px solid var(--success);
  border-radius: 12px;
  padding: 6px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  text-align: center;
  transition: transform 0.2s;
}

.runner-qr-badge:active {
  transform: scale(0.95);
}

.runner-qr-badge img {
  width: 64px;
  height: 64px;
}

.runner-qr-label {
  font-size: 9px;
  color: var(--success);
  display: block;
  margin-top: 2px;
  font-weight: 600;
}
