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

/* Accessibility - Skip link */
.skip-link:focus {
  top: 0 !important;
}

/* Accessibility - Focus styles */
:focus {
  outline: 3px solid #ffd700;
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

:focus-visible {
  outline: 3px solid #ffd700;
  outline-offset: 2px;
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:root {
  --primary: #46178f;
  --primary-light: #6c3cb4;
  --red: #e21b3c;
  --blue: #1368ce;
  --yellow: #d89e00;
  --green: #26890c;
  --white: #ffffff;
  --gray: #f2f2f2;
  --dark: #1a1a2e;
  --success: #26890c;
  --error: #e21b3c;
}

body {
  font-family: 'Nunito', sans-serif;
  background: var(--primary);
  color: var(--white);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.spinner {
  width: 60px;
  height: 60px;
  border: 5px solid rgba(255,255,255,0.3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* Cards */
.card {
  background: var(--white);
  color: var(--dark);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 32px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.btn:active {
  transform: translateY(0);
}

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

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

.btn-large {
  padding: 20px 48px;
  font-size: 1.4rem;
}

.btn-full {
  width: 100%;
}

/* Inputs */
.input {
  width: 100%;
  padding: 16px 20px;
  font-size: 1.2rem;
  font-family: inherit;
  border: 3px solid transparent;
  border-radius: 8px;
  outline: none;
  transition: border-color 0.2s;
}

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

.input-large {
  padding: 20px 24px;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 0.2em;
}

/* Home Screen */
.home {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.home h1 {
  font-size: 3rem;
  margin-bottom: 10px;
}

.home .subtitle {
  font-size: 1.2rem;
  opacity: 0.8;
  margin-bottom: 40px;
}

.home .join-box {
  background: var(--white);
  color: var(--dark);
  border-radius: 16px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
}

.home .join-box h2 {
  margin-bottom: 20px;
}

.home .join-box .input {
  margin-bottom: 16px;
}

.home .links {
  margin-top: 32px;
  display: flex;
  gap: 24px;
}

.home .links a {
  color: var(--white);
  opacity: 0.8;
}

.home .links a:hover {
  opacity: 1;
}

/* Lobby Screen */
.lobby {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.lobby .game-code {
  font-size: 6rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  margin: 20px 0;
  text-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.lobby .qr-code {
  background: var(--white);
  padding: 20px;
  border-radius: 16px;
  margin: 20px 0;
}

.lobby .qr-code img {
  width: 200px;
  height: 200px;
}

.lobby .join-url {
  font-size: 1.5rem;
  opacity: 0.9;
  margin-bottom: 30px;
}

.lobby .players {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  margin: 30px 0;
  max-width: 800px;
}

.lobby .player-tag {
  background: rgba(255,255,255,0.2);
  padding: 10px 20px;
  border-radius: 25px;
  font-weight: 600;
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  from {
    transform: scale(0);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Player Waiting */
.player-waiting {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.player-waiting h1 {
  font-size: 2rem;
  margin-bottom: 20px;
}

.player-waiting .pulse {
  width: 80px;
  height: 80px;
  background: var(--white);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

/* Question Screen */
.question-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.question-header {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.question-number {
  font-size: 1.2rem;
  font-weight: 600;
}

.timer {
  font-size: 2.5rem;
  font-weight: 800;
  background: var(--white);
  color: var(--primary);
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer.warning {
  background: var(--yellow);
  color: var(--dark);
  animation: shake 0.5s ease-in-out infinite;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.question-text {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  text-align: center;
}

.question-text h1 {
  font-size: 2.5rem;
  max-width: 900px;
}

/* Answer Buttons */
.answers {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 20px;
}

.answer-btn {
  padding: 30px 20px;
  font-size: 1.3rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--white);
  transition: transform 0.2s, opacity 0.2s;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.answer-btn:nth-child(1) { background: var(--red); }
.answer-btn:nth-child(2) { background: var(--blue); }
.answer-btn:nth-child(3) { background: var(--yellow); color: var(--dark); }
.answer-btn:nth-child(4) { background: var(--green); }

.answer-btn:hover {
  transform: scale(1.02);
}

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

.answer-btn.selected {
  opacity: 0.7;
  transform: scale(0.95);
}

.answer-btn.correct {
  animation: correctPulse 0.5s ease-out;
}

@keyframes correctPulse {
  0% { box-shadow: 0 0 0 0 rgba(38, 137, 12, 0.7); }
  100% { box-shadow: 0 0 0 20px rgba(38, 137, 12, 0); }
}

/* True/False buttons */
.answers.true-false {
  grid-template-columns: repeat(2, 1fr);
}

.answers.true-false .answer-btn:first-child {
  background: var(--green);
}

.answers.true-false .answer-btn:last-child {
  background: var(--red);
}

/* Free text input */
.free-text-input {
  padding: 20px;
}

.free-text-input .input {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

/* Result Screen */
.result-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}

.result-icon {
  font-size: 8rem;
  margin-bottom: 20px;
}

.result-screen h1 {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.result-score {
  font-size: 3rem;
  font-weight: 800;
  color: var(--yellow);
}

.result-time {
  font-size: 1.2rem;
  opacity: 0.8;
  margin-top: 10px;
}

.streak-bonus {
  background: var(--yellow);
  color: var(--dark);
  padding: 10px 20px;
  border-radius: 25px;
  font-weight: 700;
  margin-top: 15px;
  display: inline-block;
}

/* Scoreboard */
.scoreboard {
  min-height: 100vh;
  padding: 40px 20px;
}

.scoreboard h1 {
  text-align: center;
  font-size: 2.5rem;
  margin-bottom: 40px;
}

.scoreboard-list {
  max-width: 600px;
  margin: 0 auto;
}

.scoreboard-item {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  margin-bottom: 12px;
  background: rgba(255,255,255,0.1);
  border-radius: 12px;
  animation: slideIn 0.5s ease-out;
}

.scoreboard-item:nth-child(1) { background: linear-gradient(135deg, #ffd700, #ffb700); color: var(--dark); }
.scoreboard-item:nth-child(2) { background: linear-gradient(135deg, #c0c0c0, #a0a0a0); color: var(--dark); }
.scoreboard-item:nth-child(3) { background: linear-gradient(135deg, #cd7f32, #b87333); }

@keyframes slideIn {
  from {
    transform: translateX(-50px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.scoreboard-rank {
  font-size: 1.8rem;
  font-weight: 800;
  width: 50px;
}

.scoreboard-name {
  flex: 1;
  font-size: 1.3rem;
  font-weight: 600;
}

.scoreboard-score {
  font-size: 1.5rem;
  font-weight: 800;
}

/* Podium */
.podium {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.podium h1 {
  font-size: 3rem;
  margin-bottom: 60px;
}

.podium-places {
  display: flex;
  align-items: flex-end;
  gap: 20px;
}

.podium-place {
  text-align: center;
  animation: riseUp 0.8s ease-out;
}

.podium-place.first { animation-delay: 0.4s; }
.podium-place.second { animation-delay: 0.2s; }
.podium-place.third { animation-delay: 0s; }

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

.podium-player {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 10px;
}

.podium-score {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 15px;
}

.podium-stand {
  width: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 800;
  border-radius: 8px 8px 0 0;
}

.podium-place.first .podium-stand {
  height: 150px;
  background: linear-gradient(to top, #ffd700, #ffed4a);
  color: var(--dark);
}

.podium-place.second .podium-stand {
  height: 110px;
  background: linear-gradient(to top, #c0c0c0, #e0e0e0);
  color: var(--dark);
}

.podium-place.third .podium-stand {
  height: 80px;
  background: linear-gradient(to top, #cd7f32, #daa06d);
  color: var(--white);
}

/* Confetti */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
}

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

@keyframes confettiFall {
  to {
    transform: translateY(100vh) rotate(720deg);
  }
}

/* Admin Dashboard */
.admin-header {
  background: var(--dark);
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-header h1 {
  font-size: 1.5rem;
}

.admin-content {
  background: var(--gray);
  min-height: calc(100vh - 70px);
  padding: 24px;
  color: var(--dark);
}

.quiz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.quiz-card {
  background: var(--white);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
}

.quiz-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.quiz-card h3 {
  font-size: 1.2rem;
  margin-bottom: 8px;
}

.quiz-card .meta {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 12px;
}

.quiz-card .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quiz-card .actions button,
.quiz-card .actions a {
  padding: 8px 16px;
  font-size: 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  border: none;
  font-family: inherit;
  font-weight: 600;
}

.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-published {
  background: var(--green);
  color: var(--white);
}

.badge-draft {
  background: #ccc;
  color: var(--dark);
}

/* Library */
.library {
  background: var(--gray);
  min-height: 100vh;
  padding: 24px;
  color: var(--dark);
}

.library-header {
  max-width: 1200px;
  margin: 0 auto 24px;
}

.library-header h1 {
  color: var(--primary);
  margin-bottom: 16px;
}

.library-filters {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.library-filters input,
.library-filters select {
  padding: 12px 16px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-family: inherit;
}

/* Mobile */
@media (max-width: 768px) {
  .home h1 { font-size: 2rem; }
  .lobby .game-code { font-size: 3.5rem; }
  .question-text h1 { font-size: 1.5rem; }
  .answers { grid-template-columns: 1fr; }
  .answer-btn { min-height: 70px; font-size: 1.1rem; }
  .timer { width: 60px; height: 60px; font-size: 1.8rem; }
  .podium-places { flex-direction: column; }
  .podium-place { order: 0; }
  .podium-place.first { order: -1; }
}

/* Host view specific */
.host-view .question-text h1 {
  font-size: 3rem;
}

.host-view .answers {
  pointer-events: none;
}

.answer-count {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  padding: 10px 20px;
  border-radius: 25px;
  font-size: 1.2rem;
}

/* Distribution Chart */
.distribution {
  display: flex;
  gap: 12px;
  justify-content: center;
  padding: 20px;
  flex-wrap: wrap;
}

.distribution-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.distribution-bar .bar {
  width: 60px;
  background: rgba(255,255,255,0.3);
  border-radius: 4px;
  margin-bottom: 8px;
  position: relative;
  min-height: 20px;
}

.distribution-bar .bar-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-radius: 4px;
  transition: height 0.5s ease-out;
}

.distribution-bar .count {
  font-size: 1.2rem;
  font-weight: 700;
}

.distribution-bar .label {
  font-size: 0.9rem;
  opacity: 0.8;
}
