* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: #eee;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  padding: 1.5rem;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport for mobile */
}

.screen.active {
  display: flex;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
  color: #e94560;
}

/* Home Screen */
#screen-home {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.logo h1 {
  font-size: 3rem;
  font-weight: 800;
  background: linear-gradient(135deg, #e94560, #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.tagline {
  font-size: 1.2rem;
  color: #888;
  margin-bottom: 3rem;
}

.home-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 300px;
}

.build-version {
  position: absolute;
  bottom: 1rem;
  right: 1rem;
  font-size: 0.7rem;
  color: #444;
}

/* Buttons */
.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: linear-gradient(135deg, #e94560, #ff6b6b);
  color: white;
}

.btn-secondary {
  background: #0f3460;
  color: #eee;
}

.btn-danger {
  background: #c0392b;
  color: white;
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
}

.btn-small {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  min-height: auto;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #888;
}

input, select {
  width: 100%;
  padding: 0.875rem;
  border: 2px solid #0f3460;
  border-radius: 12px;
  background: #16213e;
  color: #eee;
  font-size: 1rem;
}

input:focus, select:focus {
  outline: none;
  border-color: #e94560;
}

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

/* Checkbox styling */
.checkbox-group {
  display: flex;
  flex-direction: column;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  color: #eee !important;
}

.checkbox-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: #e94560;
  cursor: pointer;
}

.checkbox-group .hint {
  font-size: 0.75rem;
  color: #666;
  margin-top: 0.25rem;
  margin-left: 2rem;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.actions .btn {
  flex: 1;
}

/* Lobby */
.share-section {
  background: #16213e;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.game-code {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.game-code .label {
  color: #888;
}

.game-code .code {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.25rem;
  color: #e94560;
}

.share-buttons {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #0f3460;
}

.qr-container.hidden {
  display: none;
}

#qr-canvas {
  background: white;
  padding: 8px;
  border-radius: 8px;
}

.qr-hint {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #888;
}

.config-summary {
  text-align: center;
  color: #888;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.players-list {
  flex: 1;
  background: #16213e;
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.players-list h3 {
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 0.75rem;
}

.players-list ul {
  list-style: none;
}

.players-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #0f3460;
}

.players-list li:last-child {
  border-bottom: none;
}

.players-list .host-badge {
  font-size: 0.75rem;
  background: #e94560;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-left: auto;
}

.players-list .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #27ae60;
}

.players-list .status-dot.disconnected {
  background: #888;
}

.lobby-status {
  text-align: center;
  color: #888;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* Get Ready Screen */
#screen-getready {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.getready-content {
  animation: getready-appear 0.5s ease-out;
}

@keyframes getready-appear {
  0% {
    opacity: 0;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

.round-announcement {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 2rem;
}

.round-label {
  font-size: 1rem;
  letter-spacing: 0.3em;
  color: #888;
  text-transform: uppercase;
}

.round-number {
  font-size: 6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #e94560, #ff6b6b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  animation: round-pulse 0.8s ease-in-out infinite;
}

@keyframes round-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.round-total {
  font-size: 1.2rem;
  color: #888;
}

.getready-text {
  font-size: 2rem;
  font-weight: 700;
  color: #eee;
  margin-bottom: 0.5rem;
}

.getready-hint {
  font-size: 1rem;
  color: #888;
}

/* Game Play */
#screen-play {
  padding: 0.5rem;
  justify-content: space-between;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport for mobile */
  min-height: auto;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
}

.game-header {
  padding: 0.5rem;
  text-align: center;
  flex-shrink: 0;
}

#round-indicator {
  font-size: 1rem;
  font-weight: 600;
  color: #888;
}

.timer-bar {
  height: 6px;
  background: #0f3460;
  border-radius: 3px;
  margin-top: 0.5rem;
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #e94560, #ff6b6b);
  width: 100%;
  transition: width linear;
}

.images-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem 0;
  justify-content: center;
  min-height: 0; /* Allow flex to shrink */
}

.image-choice {
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 3px solid transparent;
  background: #16213e;
  flex: 1;
  min-height: 0;
  max-height: calc(50dvh - 50px);
  max-height: calc(50vh - 50px);
}

.image-choice img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-choice:active {
  transform: scale(0.98);
}

.image-choice.selected {
  border-color: #e94560;
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
}

.image-choice.disabled {
  pointer-events: none;
}

.answer-status {
  text-align: center;
  padding: 0.75rem;
  font-size: 1rem;
  color: #888;
  flex-shrink: 0;
}

.answer-status.answered {
  color: #27ae60;
}

/* Round Result */
#screen-result {
  justify-content: flex-start;
  padding-top: 0.5rem;
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.reveal-title {
  font-size: 1.25rem;
  text-align: center;
  margin-bottom: 0.5rem;
  min-height: 1.5rem;
  flex-shrink: 0;
}

.reveal-title.suspense {
  animation: pulse-text 0.5s ease-in-out infinite;
}

@keyframes pulse-text {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.result-images {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-shrink: 0;
  justify-content: center;
}

.result-image {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 3px solid transparent;
  transition: all 0.3s ease;
  flex: 0 0 auto;
  width: calc(50% - 0.25rem);
  max-width: 150px;
}

.result-image.hidden-result {
  filter: brightness(0.6);
}

.result-image img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.result-image .result-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.5rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.result-image.revealed .result-label {
  transform: translateY(0);
}

.result-image.is-ai {
  border-color: #e94560;
  animation: ai-reveal-glow 0.8s ease-out;
}

.result-image.is-ai .result-label {
  background: #e94560;
}

.result-image.is-real .result-label {
  background: #27ae60;
}

@keyframes ai-reveal-glow {
  0% {
    box-shadow: 0 0 0 rgba(233, 69, 96, 0);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 40px rgba(233, 69, 96, 0.8);
    transform: scale(1.02);
  }
  100% {
    box-shadow: 0 0 20px rgba(233, 69, 96, 0.4);
    transform: scale(1);
  }
}

.round-results {
  background: #16213e;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.round-results .result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid #0f3460;
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.3s ease;
}

.round-results .result-row.visible {
  opacity: 1;
  transform: translateX(0);
}

.round-results .result-row:last-child {
  border-bottom: none;
}

.round-results .player-result {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.round-results .result-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.round-results .result-icon.correct {
  background: #27ae60;
}

.round-results .result-icon.incorrect {
  background: #e94560;
}

.round-results .result-icon.timeout {
  background: #555;
}

.round-results .points {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.round-results .base-points {
  font-weight: 600;
}

.round-results .base-points.correct {
  color: #27ae60;
}

.round-results .base-points.incorrect {
  color: #888;
}

.round-results .bonus {
  color: #f39c12;
  font-size: 0.75rem;
  font-weight: 600;
  animation: bonus-pop 0.4s ease-out;
  margin-left: 0.25rem;
}

.round-results .bonus.speed { color: #f39c12; }
.round-results .bonus.streak { color: #e94560; }
.round-results .bonus.lucky { color: #9b59b6; }
.round-results .bonus.comeback { color: #27ae60; }
.round-results .bonus.underdog { color: #3498db; }

@keyframes bonus-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.scoreboard {
  background: #16213e;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.scoreboard h3 {
  font-size: 0.75rem;
  color: #888;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scoreboard .score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  transition: all 0.5s ease;
  font-size: 0.9rem;
}

.scoreboard .score-row.ellipsis {
  justify-content: center;
  color: #666;
  padding: 0.1rem 0;
}

.scoreboard .score-row.current-player {
  background: rgba(233, 69, 96, 0.2);
  margin: 0 -0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.scoreboard .score-row .player-rank {
  width: 1.5rem;
  color: #888;
  flex-shrink: 0;
}

.scoreboard .score-row .player-name {
  flex: 1;
}

.scoreboard .score-row .player-score {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: right;
}

.scoreboard .score-row.leader {
  color: #f39c12;
}

.scoreboard .score-row.score-changed .player-score {
  animation: score-bump 0.4s ease-out;
}

@keyframes score-bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.3); color: #27ae60; }
  100% { transform: scale(1); }
}

/* Game Over */
#screen-gameover {
  position: relative;
  overflow: hidden;
}

#confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.gameover-title {
  font-size: 2rem;
  text-align: center;
  margin-bottom: 1.5rem;
  animation: title-bounce 0.6s ease-out;
}

@keyframes title-bounce {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.podium-container {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  min-height: 220px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  opacity: 0;
  transform: translateY(50px);
  animation: podium-rise 0.5s ease-out forwards;
}

.podium-place.first { animation-delay: 0.3s; }
.podium-place.second { animation-delay: 0.1s; }
.podium-place.third { animation-delay: 0.2s; }

@keyframes podium-rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.podium-crown {
  font-size: 2rem;
  animation: crown-bounce 0.5s ease-out 0.8s both;
}

@keyframes crown-bounce {
  0% { transform: scale(0) rotate(-30deg); }
  50% { transform: scale(1.3) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.podium-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.podium-place.first .podium-avatar {
  background: linear-gradient(135deg, #f39c12, #f1c40f);
  color: #1a1a2e;
  width: 60px;
  height: 60px;
  font-size: 1.8rem;
}

.podium-place.second .podium-avatar {
  background: linear-gradient(135deg, #95a5a6, #bdc3c7);
  color: #1a1a2e;
}

.podium-place.third .podium-avatar {
  background: linear-gradient(135deg, #cd6133, #e67e22);
  color: #1a1a2e;
}

.podium-name {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
  text-align: center;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-score {
  font-size: 0.85rem;
  color: #888;
  margin-bottom: 0.5rem;
}

.podium-block {
  width: 80px;
  border-radius: 8px 8px 0 0;
}

.podium-place.first .podium-block {
  height: 100px;
  background: linear-gradient(180deg, #f39c12, #d68910);
  width: 90px;
}

.podium-place.second .podium-block {
  height: 70px;
  background: linear-gradient(180deg, #95a5a6, #7f8c8d);
}

.podium-place.third .podium-block {
  height: 50px;
  background: linear-gradient(180deg, #cd6133, #a04000);
}

.other-rankings {
  background: #16213e;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.other-rankings:empty {
  display: none;
}

.other-rankings .rank-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid #0f3460;
}

.other-rankings .rank-row:last-child {
  border-bottom: none;
}

.other-rankings .rank {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.8rem;
  background: #0f3460;
}

.other-rankings .name {
  flex: 1;
}

.other-rankings .score {
  font-weight: 600;
  color: #e94560;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 46, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #0f3460;
  border-top-color: #e94560;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#loading-text {
  margin-top: 1rem;
  color: #888;
}

/* Error Toast */
.error-toast {
  position: fixed;
  bottom: 2rem;
  left: 1rem;
  right: 1rem;
  background: #c0392b;
  color: white;
  padding: 1rem;
  border-radius: 12px;
  text-align: center;
  z-index: 200;
  animation: slideUp 0.3s ease;
}

.error-toast.hidden {
  display: none;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Responsive */
@media (min-width: 600px) {
  .screen {
    max-width: 500px;
    margin: 0 auto;
  }

  .images-container {
    gap: 1rem;
  }
}

/* Wide screens: side by side layout */
@media (min-width: 700px) and (min-height: 500px) {
  #screen-play {
    max-width: 900px;
  }

  .images-container {
    flex-direction: row;
  }

  .image-choice {
    max-height: calc(100dvh - 120px);
    max-height: calc(100vh - 120px);
  }
}
