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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  display: flex;
  flex-direction: column;
}

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  padding: 16px;
}

.screen.active {
  display: flex;
}

/* ===== Connect Screen ===== */
#connect-screen {
  align-items: center;
  justify-content: center;
  gap: 24px;
}

#connect-screen h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: #e94560;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #bbb;
  display: inline-block;
  margin-right: 8px;
}

.status-dot.connected { background: #43a047; }
.status-dot.disconnected { background: #e53935; }
.status-dot.connecting { background: #f9a825; }

#conn-status {
  font-size: 1rem;
  color: #666;
}

/* ===== Dashboard Screen ===== */
#dashboard-screen {
  align-items: center;
  justify-content: center;
  gap: 32px;
}

#dashboard-screen h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: #e94560;
}

.dash-subtitle {
  font-size: 1.4rem;
  font-weight: 600;
  color: #666;
}

.preset-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.preset-card {
  background: #fff;
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 24px 32px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.1s;
  min-width: 160px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.preset-card:active {
  transform: scale(0.95);
}

.preset-card:hover {
  border-color: #e94560;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.preset-icon {
  font-size: 2.5rem;
}

.preset-name {
  font-size: 1.3rem;
  font-weight: 700;
}

.preset-cats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  font-size: 0.85rem;
  color: #555;
}

.preset-cat-line {
  white-space: nowrap;
}

/* ===== Register Screen ===== */
#register-screen {
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

#register-screen h2 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.reg-preset-label {
  font-size: 1rem;
  color: #e94560;
  font-weight: 600;
}

.reg-prompt {
  font-size: 1.2rem;
  margin-top: 8px;
}

.reg-status {
  background: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.reg-name-area {
  display: flex;
  gap: 8px;
  align-items: center;
}

.reg-name-input {
  background: #fff;
  border: 2px solid #e94560;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 1rem;
  color: #1a1a2e;
  outline: none;
  width: 200px;
}

.reg-name-input::placeholder {
  color: #999;
}

.btn-save {
  background: #e94560;
  color: #fff;
  border: none;
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
}

.btn-save:active {
  transform: scale(0.95);
}

.reg-player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-height: 120px;
  overflow-y: auto;
}

.player-chip {
  background: #e8e8e8;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-chip .remove {
  cursor: pointer;
  opacity: 0.5;
}

.player-chip .remove:hover {
  opacity: 1;
}

.reg-actions {
  display: flex;
  gap: 12px;
}

.btn-primary {
  background: #e94560;
  color: #fff;
  border: none;
  padding: 12px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
}

.btn-primary:active {
  transform: scale(0.95);
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
  border: 2px solid #ccc;
  padding: 12px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
}

.btn-secondary:active {
  transform: scale(0.95);
}

/* ===== Waiting Screen ===== */
#waiting-screen {
  padding: 0;
}

.waiting-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
}

.waiting-main {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
}

.waiting-prompt-text {
  font-size: 1.8rem;
  font-weight: 700;
  text-align: center;
}

.waiting-player-name {
  font-size: 1.4rem;
  color: #d4a017;
  font-weight: 600;
}

.waiting-status {
  font-size: 1rem;
  color: #e94560;
}

.leaderboard-sidebar {
  flex: 1;
  background: #fff;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: -2px 0 8px rgba(0,0,0,0.05);
}

.leaderboard-sidebar h3 {
  font-size: 1.2rem;
  color: #d4a017;
  margin-bottom: 8px;
}

.lb-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f5f5f5;
}

.lb-entry .lb-rank {
  font-weight: 700;
  color: #888;
  width: 28px;
}

.lb-entry .lb-name {
  flex: 1;
  font-weight: 600;
}

.lb-entry .lb-score {
  font-weight: 700;
  color: #d4a017;
}

.lb-entry.lb-current {
  border: 2px solid #e94560;
}

.lb-entry.lb-top {
  background: #fff8e1;
}

.btn-end-game {
  background: #e53935;
  color: #fff;
  border: none;
  padding: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

.btn-end-game:active {
  background: #c62828;
}

/* ===== Playing Screen (Landscape Primary) ===== */
#playing-screen {
  padding: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.score-display {
  font-size: 1.8rem;
  font-weight: 700;
  color: #d4a017;
}

.timer-display {
  font-size: 1.8rem;
  font-weight: 700;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #e94560;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-display.warning {
  background: #e53935;
  animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.1); }
}

.game-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
}

.question-area {
  flex: 0 0 35%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.question-text {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.4;
}

.answers-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}

.answer-tile {
  border: none;
  font-size: 1.5rem;
  font-weight: 700;
  border-radius: 16px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.1s, opacity 0.3s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.answer-tile:active {
  transform: scale(0.95);
}

.answer-tile .letter {
  font-size: 0.9rem;
  opacity: 0.8;
}

.answer-tile.a { background: #e53935; }
.answer-tile.b { background: #1e88e5; }
.answer-tile.c { background: #f9a825; color: #1a1a2e; }
.answer-tile.d { background: #43a047; }

.answer-tile.correct {
  background: #00c853 !important;
  color: #fff !important;
}

.answer-tile.wrong {
  background: #d50000 !important;
  opacity: 0.7;
}

.answer-tile.reveal {
  opacity: 0.5;
}

.bottom-bar {
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  color: #666;
  font-size: 0.9rem;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

/* ===== Result Screen ===== */
#result-screen {
  align-items: center;
  justify-content: center;
  gap: 24px;
  text-align: center;
}

.result-title {
  font-size: 2rem;
  color: #d4a017;
}

.result-leaderboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 320px;
}

.result-leaderboard .lb-entry {
  padding: 12px 16px;
  font-size: 1.1rem;
}

.result-leaderboard .lb-entry:nth-child(1) {
  border: 2px solid #d4a017;
  background: #fff8e1;
}

.result-leaderboard .lb-entry:nth-child(2) {
  border: 2px solid #aaa;
}

.result-leaderboard .lb-entry:nth-child(3) {
  border: 2px solid #cd7f32;
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

/* ===== Portrait Fallback ===== */
@media (orientation: portrait) {
  .game-body {
    flex-direction: column;
  }
  .question-area {
    flex: none;
    min-height: 30%;
    padding: 20px 16px;
  }
  .question-text {
    font-size: 1.4rem;
  }
  .answers-grid {
    gap: 8px;
    padding: 8px;
  }
  .answer-tile {
    font-size: 1.2rem;
  }
  .top-bar { padding: 8px 12px; }
  .score-display { font-size: 1.3rem; }
  .timer-display { width: 44px; height: 44px; font-size: 1.3rem; }
  .bottom-bar { padding: 8px 12px; font-size: 0.8rem; }

  .waiting-body {
    flex-direction: column;
  }
  .waiting-main {
    flex: none;
    padding: 20px;
    min-height: 30%;
  }
  .waiting-prompt-text {
    font-size: 1.3rem;
  }
}
