/* QuizMaster v2.1 – Modern UI */

:root {
  --bg: #f8fafc;
  --bg-gradient: linear-gradient(135deg, #f0f4ff 0%, #fdf2f8 50%, #f0fdf4 100%);
  --card: #ffffff;
  --card-border: rgba(0,0,0,0.06);
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-soft: #ede9fe;
  --secondary: #0ea5e9;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);
  --radius: 16px;
  --radius-sm: 12px;
  --answer-a: #ef4444;
  --answer-b: #3b82f6;
  --answer-c: #eab308;
  --answer-d: #22c55e;
  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-gradient: linear-gradient(135deg, #1e1b4b 0%, #0f172a 50%, #134e4a 100%);
  --card: #1e293b;
  --card-border: rgba(255,255,255,0.08);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #a78bfa;
  --primary-hover: #c4b5fd;
  --primary-soft: #2e1065;
  --secondary: #38bdf8;
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;
  --border: #334155;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Theme toggle */
.theme-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.theme-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-lg);
}

/* Screens */
.screen {
  display: none;
  min-height: 100vh;
  padding: 24px 16px 40px;
}
.screen.active {
  display: block;
  animation: fadeIn 0.35s ease;
}

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

.container {
  max-width: 680px;
  margin: 0 auto;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
  margin-top: 48px;
}

/* Typography */
h1 {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-align: center;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--primary), #ec4899);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 20px;
}

.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 36px;
}

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

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 28px;
  border: none;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
  line-height: 1.2;
}
.btn:active {
  transform: scale(0.97);
}
.btn.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}
.btn.primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.45);
  transform: translateY(-1px);
}
.btn.secondary {
  background: var(--secondary);
  color: white;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.3);
}
.btn.secondary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}
.btn.danger {
  background: var(--danger);
  color: white;
}
.btn.text {
  background: transparent;
  color: var(--primary);
  padding: 10px 16px;
}
.btn.small {
  padding: 9px 16px;
  font-size: 0.875rem;
  border-radius: 10px;
}
.btn.large {
  width: 100%;
  padding: 18px 32px;
  font-size: 1.15rem;
  border-radius: 16px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 28px 0;
}
@media (min-width: 520px) {
  .btn-group {
    flex-direction: row;
    justify-content: center;
  }
}

/* Inputs */
.input {
  width: 100%;
  padding: 16px 18px;
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 1.05rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.input::placeholder {
  color: var(--text-muted);
}

/* Quiz list */
.quiz-list {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.quiz-item {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.quiz-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.quiz-item h3 {
  font-size: 1.15rem;
  font-weight: 600;
  flex: 1;
  min-width: 160px;
}
.quiz-item h3 small {
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 6px;
}
.quiz-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* PIN + QR box */
.pin-box {
  text-align: center;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 36px 24px;
  margin: 24px 0;
  box-shadow: var(--shadow-lg);
}
.pin-box p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 8px;
}
.pin-box h1 {
  font-size: 3.4rem;
  letter-spacing: 0.18em;
  margin: 8px 0 20px;
  background: none;
  -webkit-text-fill-color: var(--primary);
  color: var(--primary);
  font-weight: 800;
}

#qrcode {
  display: flex;
  justify-content: center;
  margin: 20px 0 8px;
}
#qrcode canvas,
#qrcode img {
  max-width: 200px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Player list */
.player-list {
  list-style: none;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 8px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
.player-list li {
  padding: 12px 16px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  transition: background 0.15s;
}
.player-list li:hover {
  background: var(--primary-soft);
}

/* Question area */
.question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 20px;
  font-size: 1rem;
}
#timerDisplay,
#playerTimer {
  background: var(--primary);
  color: white;
  padding: 6px 16px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 52px;
  text-align: center;
}

#hostQuestionText,
#playerQuestionText {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 8px;
}

/* Answer buttons */
.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 28px 0;
}
.answer-btn {
  padding: 22px 16px;
  border: none;
  border-radius: 16px;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
  color: white;
  cursor: pointer;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  position: relative;
  overflow: hidden;
}
.answer-btn:active {
  transform: scale(0.96);
}
.answer-btn.a { background: var(--answer-a); }
.answer-btn.b { background: var(--answer-b); }
.answer-btn.c { background: var(--answer-c); color: #1e293b; }
.answer-btn.d { background: var(--answer-d); }

.answer-btn.selected {
  outline: 4px solid white;
  box-shadow: 0 0 0 4px var(--primary), 0 8px 20px rgba(0,0,0,0.2);
}
.answer-btn.correct {
  outline: 4px solid #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.4);
}
.answer-btn.wrong {
  opacity: 0.45;
  filter: grayscale(0.4);
}

.answers-grid.player .answer-btn {
  min-height: 76px;
  font-size: 1rem;
}

/* Stats & Leaderboard */
.stats {
  background: var(--card);
  border: 1px solid var(--card-border);
  padding: 18px;
  border-radius: var(--radius-sm);
  margin: 16px 0;
  font-size: 0.95rem;
}
.hidden { display: none !important; }

.leaderboard {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
}
.leaderboard h4 {
  margin-bottom: 12px;
  font-size: 0.95rem;
  color: var(--text-muted);
}
.leaderboard-item {
  display: flex;
  justify-content: space-between;
  padding: 10px 8px;
  border-radius: 8px;
  font-weight: 500;
}
.leaderboard-item:nth-child(odd) {
  background: var(--primary-soft);
}

/* Podium */
.podium {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 28px 0;
}
.podium-item {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  box-shadow: var(--shadow);
}
.podium-item.rank-1 {
  border-left: 6px solid #fbbf24;
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.08), transparent);
}
.podium-item.rank-2 {
  border-left: 6px solid #94a3b8;
}
.podium-item.rank-3 {
  border-left: 6px solid #d97706;
}
.rank-badge {
  font-size: 1.7rem;
  font-weight: 800;
  min-width: 48px;
  text-align: center;
}

/* Question editor */
.question-editor {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.question-editor textarea,
.question-editor input[type="text"],
.question-editor input[type="number"] {
  width: 100%;
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}
.question-editor textarea:focus,
.question-editor input:focus {
  outline: none;
  border-color: var(--primary);
}
.option-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.option-row input[type="text"] {
  flex: 1;
  margin-bottom: 0;
}
.option-row input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

/* Feedback */
.feedback {
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  margin-top: 20px;
  min-height: 1.6em;
}
.feedback.correct { color: var(--success); }
.feedback.wrong { color: var(--danger); }

/* Spinner */
.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 28px auto;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Settings */
.settings-row {
  margin: 20px 0;
  text-align: center;
}
.settings-row label {
  font-weight: 500;
  color: var(--text-muted);
}
.settings-row select {
  margin-left: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

/* Responsive */
@media (max-width: 520px) {
  h1 { font-size: 2.1rem; }
  .pin-box h1 {
    font-size: 2.5rem;
    letter-spacing: 0.12em;
  }
  .answers-grid {
    grid-template-columns: 1fr;
  }
  .card {
    padding: 24px 18px;
    margin-top: 32px;
  }
  .answer-btn {
    min-height: 72px;
  }
}
