/* ===== Design System ===== */
:root {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --accent-dim: #c13550;
  --text-primary: #eeeeee;
  --text-secondary: #a8a8c0;
  --text-muted: #76768a;
  --success: #00c853;
  --success-dim: #009940;
  --warning: #ffd600;
  --error: #ff1744;
  --info: #448aff;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f5f5f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #ecedf2;
  --accent: #d63852;
  --accent-hover: #e94560;
  --accent-dim: #b82e45;
  --text-primary: #1a1a2e;
  --text-secondary: #555566;
  --text-muted: #888899;
  --success: #16a34a;
  --success-dim: #15803d;
  --warning: #ca8a04;
  --error: #dc2626;
  --info: #2563eb;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

/* ===== Home Button ===== */
#home-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 999;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8rem;
  font-family: inherit;
  transition: all 0.2s ease;
}
#home-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

#app {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Typography ===== */
h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

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

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.4);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.875rem;
}

.btn-full {
  width: 100%;
}

/* ===== Inputs ===== */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.input-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-field {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-primary);
  transition: border-color var(--transition);
  outline: none;
}

.input-field:focus {
  border-color: var(--accent);
}

.input-field::placeholder {
  color: var(--text-muted);
}

select.input-field {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%23a0a0b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* ===== Range Slider ===== */
.range-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.range-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.range-header label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.range-value {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent);
  min-width: 30px;
  text-align: right;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  appearance: none;
  background: var(--bg-primary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

/* ===== View Transitions ===== */
.view {
  animation: fadeIn 0.3s ease-out;
  flex: 1;
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Landing View ===== */
.landing-header {
  text-align: center;
  padding: 40px 0 32px;
}

.landing-header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover), #ffd700);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.landing-header p {
  color: var(--text-secondary);
  font-size: 1.125rem;
}

.landing-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .landing-cards {
    grid-template-columns: 1fr;
  }
}

.landing-card {
  text-align: center;
}

.landing-card h2 {
  margin-bottom: 20px;
  color: var(--text-primary);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

/* ===== Lobby View ===== */
.lobby-header {
  text-align: center;
  margin-bottom: 24px;
}

.room-code {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: var(--bg-secondary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  border: 2px dashed rgba(233, 69, 96, 0.3);
}

.room-code:hover {
  border-color: var(--accent);
  box-shadow: 0 0 20px rgba(233, 69, 96, 0.2);
}

.room-code-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.lobby-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .lobby-content {
    grid-template-columns: 1fr;
  }
}

.player-list-section h3,
.config-section h3 {
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.player-item.disconnected {
  opacity: 0.5;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: white;
  flex-shrink: 0;
}

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

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-host {
  background: var(--gold);
  color: #1a1a2e;
}

.badge-you {
  background: var(--accent);
  color: white;
}

.lobby-footer {
  margin-top: 24px;
  text-align: center;
}

.waiting-text {
  color: var(--text-muted);
  font-style: italic;
  padding: 12px;
}

/* ===== Question View ===== */
.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.question-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.badge-category {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
}

.badge-difficulty {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
}

.badge-difficulty.easy { background: rgba(0, 200, 83, 0.2); color: var(--success); }
.badge-difficulty.medium { background: rgba(255, 214, 0, 0.2); color: var(--warning); }
.badge-difficulty.hard { background: rgba(255, 23, 68, 0.2); color: var(--error); }

.question-number {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.question-body {
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.question-text {
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.5;
  margin-bottom: 28px;
  padding: 20px;
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 500px) {
  .answers-grid {
    grid-template-columns: 1fr;
  }
}

.answer-btn {
  padding: 16px 20px;
  background: var(--bg-secondary);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  word-wrap: break-word;
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.answer-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.1);
  transform: translateY(-2px);
}

.answer-btn:active:not(:disabled) {
  transform: translateY(0);
}

.answer-btn.selected {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.2);
}

.answer-btn.correct {
  border-color: var(--success);
  background: rgba(0, 200, 83, 0.2);
  color: var(--success);
}

.answer-btn.wrong {
  border-color: var(--error);
  background: rgba(255, 23, 68, 0.2);
  color: var(--error);
}

.answer-btn:disabled {
  cursor: default;
  opacity: 0.85;
}

.streak-indicator {
  text-align: center;
  margin-top: 12px;
  font-size: 0.875rem;
  color: var(--warning);
  font-weight: 600;
}

.timer-container {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

/* ===== Timer (SVG Circle) ===== */
.timer-svg {
  width: 80px;
  height: 80px;
  transform: rotate(-90deg);
}

.timer-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 5;
}

.timer-ring {
  fill: none;
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s linear, stroke 0.5s ease;
}

.timer-ring.green { stroke: var(--success); }
.timer-ring.yellow { stroke: var(--warning); }
.timer-ring.red { stroke: var(--error); }

.timer-text-group {
  transform: rotate(90deg);
  transform-origin: center;
}

.timer-text {
  fill: var(--text-primary);
  font-family: var(--font);
  font-size: 20px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

/* ===== Round Result View ===== */
.result-header {
  text-align: center;
  margin-bottom: 24px;
}

.result-verdict {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.result-verdict.correct-verdict {
  color: var(--success);
}

.result-verdict.wrong-verdict {
  color: var(--error);
}

.result-verdict.timeout-verdict {
  color: var(--warning);
}

.correct-answer-text {
  color: var(--text-secondary);
  font-size: 1.125rem;
}

.correct-answer-text strong {
  color: var(--success);
}

.score-breakdown {
  text-align: center;
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.score-total {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent);
}

.score-details {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.advance-timer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 16px;
}

/* ===== Leaderboard ===== */
.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.leaderboard-row.highlight {
  background: rgba(233, 69, 96, 0.1);
  border: 1px solid rgba(233, 69, 96, 0.2);
}

.leaderboard-rank {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.leaderboard-rank.rank-1 { background: var(--gold); color: #1a1a2e; }
.leaderboard-rank.rank-2 { background: var(--silver); color: #1a1a2e; }
.leaderboard-rank.rank-3 { background: var(--bronze); color: white; }
.leaderboard-rank.rank-other { background: var(--bg-tertiary); color: var(--text-secondary); }

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

.leaderboard-score {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.leaderboard-delta {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--success);
  min-width: 50px;
  text-align: right;
}

.leaderboard-delta.zero {
  color: var(--text-muted);
}

/* ===== Final Result View ===== */
.final-header {
  text-align: center;
  margin-bottom: 24px;
}

.final-header h1 {
  font-size: 2.5rem;
  background: linear-gradient(135deg, var(--gold), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.podium {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 32px;
  padding: 0 20px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  max-width: 160px;
}

.podium-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
  margin-bottom: 8px;
  border: 3px solid transparent;
}

.podium-place.first .podium-avatar { border-color: var(--gold); width: 72px; height: 72px; font-size: 1.5rem; }
.podium-place.second .podium-avatar { border-color: var(--silver); }
.podium-place.third .podium-avatar { border-color: var(--bronze); }

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

.podium-score {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.podium-bar {
  width: 100%;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  margin-top: 8px;
}

.podium-place.first .podium-bar { height: 100px; background: linear-gradient(to top, #b8860b, var(--gold)); }
.podium-place.second .podium-bar { height: 72px; background: linear-gradient(to top, #8a8a8a, var(--silver)); }
.podium-place.third .podium-bar { height: 50px; background: linear-gradient(to top, #8b5e20, var(--bronze)); }

.final-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
}

/* ===== Countdown Overlay ===== */
.countdown-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 35, 0.9);
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

.countdown-number {
  font-size: 6rem;
  font-weight: 800;
  color: var(--accent);
  animation: countPulse 1s ease-in-out infinite;
}

.countdown-label {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-top: 12px;
}

@keyframes countPulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

/* ===== Fetching Overlay ===== */
.fetching-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15, 15, 35, 0.95);
  z-index: 100;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

/* ===== Confetti ===== */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(1);
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg) scale(0.5);
    opacity: 0;
  }
}

/* ===== Toast Notifications ===== */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease-out;
  max-width: 320px;
}

.toast.toast-exit {
  animation: toastOut 0.3s ease-in forwards;
}

.toast-info { background: var(--info); }
.toast-success { background: var(--success-dim); }
.toast-error { background: var(--error); }

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

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

/* ===== Utility ===== */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ===== Light Mode Element Overrides ===== */
[data-theme="light"] .card {
  border-color: var(--border-color);
}

[data-theme="light"] .btn-secondary {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

[data-theme="light"] .btn-secondary:hover:not(:disabled) {
  background: var(--bg-tertiary);
  border-color: var(--text-muted);
}

[data-theme="light"] .input-field {
  border-color: var(--border-color);
}

[data-theme="light"] .divider::before,
[data-theme="light"] .divider::after {
  background: var(--border-color);
}

[data-theme="light"] .answer-btn {
  border-color: var(--border-color);
}

[data-theme="light"] .timer-bg {
  stroke: var(--border-color);
}

[data-theme="light"] .spinner {
  border-color: var(--border-color);
  border-top-color: var(--accent);
}

[data-theme="light"] .countdown-overlay {
  background: rgba(245, 245, 248, 0.92);
}

[data-theme="light"] .fetching-overlay {
  background: rgba(245, 245, 248, 0.95);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}
