:root {
  --bg-1: #5a1fad;
  --bg-2: #330f7a;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #64748b;
  --accent: #ffd60a;
  --accent-ink: #2b1256;
  --info: #3672e0;
  --danger: #cf4a4a;
  --red: #e0483f;
  --blue: #2f6fed;
  --yellow: #e0a72e;
  --green: #2f9e6f;
  --radius: 18px;
  --shadow: 0 8px 22px rgba(30, 8, 66, 0.25);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-size: 140% 140%;
  animation: bgDrift 24s ease-in-out infinite alternate;
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: "Inter", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

@keyframes bgDrift {
  from { background-position: 0% 0%; }
  to { background-position: 100% 100%; }
}

.glass-panel {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 28px 32px;
  backdrop-filter: blur(6px);
}

h1, h2, h3, .logo, .host-code, .q-text, .feedback, .score-badge, .lb-row {
  font-family: "Poppins", "Inter", system-ui, sans-serif;
}

a {
  color: inherit;
}

button, input, textarea {
  font-family: inherit;
}

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

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

.wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  gap: 20px;
  width: 100%;
}

.top {
  justify-content: flex-start;
}

.logo {
  font-size: clamp(26px, 5.5vw, 38px);
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
  text-align: center;
  animation: logoPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.logo span {
  color: var(--accent);
}

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

.fade-in {
  animation: fadeIn 0.35s ease both;
}

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

/* Applied by JS each time a full-screen view is shown, so every transition
   between game phases (lobby -> preview -> question -> reveal -> ...) gets
   the same smooth, deliberate motion instead of an abrupt cut. */
.view-enter {
  animation: viewEnter 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes viewEnter {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
  width: 100%;
  max-width: 420px;
}

.card.wide {
  max-width: 760px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}

input[type="text"],
input[type="number"],
textarea {
  border: 2px solid #e3e8ef;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 17px;
  font-family: inherit;
  width: 100%;
  outline: none;
  color: var(--text);
  transition: border-color 0.15s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
  border-color: var(--info);
}

.pin-input {
  font-size: clamp(26px, 8vw, 36px);
  text-align: center;
  letter-spacing: 8px;
  font-weight: 700;
  font-family: "Poppins", sans-serif;
}

button {
  cursor: pointer;
  border: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  padding: 15px 20px;
  font-size: 17px;
  font-weight: 700;
  width: 100%;
  transition: transform 0.08s ease, filter 0.15s ease, box-shadow 0.1s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(3px);
}

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

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 4px 0 #c9a300;
}

.btn-primary:active:not(:disabled) {
  box-shadow: 0 1px 0 #c9a300;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: #eaf0f9;
  color: #234c85;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.5);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 14px;
  width: auto;
}

.row {
  display: flex;
  gap: 12px;
  width: 100%;
}

.center {
  text-align: center;
}

.error {
  color: #ffe1e1;
  background: rgba(207, 74, 74, 0.9);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  min-height: 0;
}

.hidden {
  display: none !important;
}

.meta {
  font-size: 13px;
  color: var(--muted);
}

.links {
  display: flex;
  gap: 16px;
  color: #ffffffcc;
  font-size: 14px;
}

.links a {
  text-decoration: underline;
}

/* ---------- Quiz builder ---------- */

.question-block {
  border: 2px solid #eef1f5;
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
  position: relative;
}

.question-block h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.option-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  padding: 4px 8px;
  border: 2px solid transparent;
  transition: border-color 0.15s ease;
}

.option-row:has(.opt-correct:checked) {
  border-color: rgba(27, 39, 51, 0.3);
}

.opt-correct {
  width: 19px;
  height: 19px;
  accent-color: var(--accent-ink);
  cursor: pointer;
  flex-shrink: 0;
}

.option-row.opt-0 {
  background: #fbe6e4;
}
.option-row.opt-1 {
  background: #e3ecfb;
}
.option-row.opt-2 {
  background: #faf1dc;
}
.option-row.opt-3 {
  background: #e2f0e9;
}

.option-row input[type="text"] {
  border: none;
  background: transparent;
  padding: 10px 4px;
}

.remove-q {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  color: var(--danger);
  font-weight: 600;
  font-size: 13px;
}

.dash-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.dash-item {
  background: var(--card);
  border-radius: 12px;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.dash-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(30, 8, 66, 0.2);
}

/* ---------- Host screen ---------- */

.host-code {
  font-size: clamp(36px, 9vw, 64px);
  font-weight: 700;
  color: #fff;
  letter-spacing: 5px;
  text-align: center;
}

.player-chip {
  background: #fff;
  color: #234c85;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  animation: popIn 0.25s ease both;
}

/* ---------- Avatars ---------- */

.avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
}

.avatar-sm {
  width: 26px;
  height: 26px;
  font-size: 15px;
}

.avatar-md {
  width: 40px;
  height: 40px;
  font-size: 21px;
}

.avatar-lg {
  width: 72px;
  height: 72px;
  font-size: 38px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.avatar-option {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 3px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.avatar-option:hover {
  transform: scale(1.06);
}

.avatar-option.selected {
  border-color: var(--accent-ink);
  box-shadow: 0 0 0 2px var(--accent);
}

.avatar-wrap {
  position: relative;
  display: inline-flex;
}

.avatar-accessory {
  position: absolute;
  top: -6px;
  right: -6px;
  font-size: 0.6em;
  background: #fff;
  border-radius: 50%;
  width: 1.4em;
  height: 1.4em;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.avatar-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.avatar-tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 999px;
  background: #eef1f5;
  color: var(--muted);
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, color 0.15s ease;
}

.avatar-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Podium ---------- */

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 14px;
  width: 100%;
  max-width: 560px;
}

.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.podium-medal {
  font-size: 28px;
}

.podium-name {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.podium-score {
  color: #ffffffb0;
  font-size: 13px;
  font-weight: 600;
}

.podium-block {
  width: 100%;
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10px;
  font-weight: 800;
  font-size: 20px;
  color: var(--accent-ink);
  background: #fff;
  transform: scaleY(0);
  transform-origin: bottom;
  animation: podiumRise 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.podium-place.rank-0 .podium-block {
  height: 140px;
  background: var(--accent);
  animation-delay: 0.35s;
}

.podium-place.rank-1 .podium-block {
  height: 104px;
  background: #dbe1ea;
  animation-delay: 0.15s;
}

.podium-place.rank-2 .podium-block {
  height: 76px;
  background: #e7c9a4;
  animation-delay: 0s;
}

@keyframes podiumRise {
  to { transform: scaleY(1); }
}

@media (max-width: 480px) {
  .podium { gap: 8px; }
  .podium-medal { font-size: 22px; }
  .podium-name { font-size: 13px; }
  .podium-place.rank-0 .podium-block { height: 110px; }
  .podium-place.rank-1 .podium-block { height: 84px; }
  .podium-place.rank-2 .podium-block { height: 60px; }
}

/* Host screen podium: shown on a shared/projected display, so scaled up
   dramatically compared to the compact version on a player's phone. */
.avatar-xl {
  width: 120px;
  height: 120px;
  font-size: 64px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
}

.podium-host {
  max-width: 920px;
  gap: 40px;
}

.podium-host .podium-medal {
  font-size: 72px;
}

.podium-host .podium-name {
  font-size: 32px;
}

.podium-host .podium-score {
  font-size: 22px;
}

.podium-host .podium-block {
  font-size: 44px;
}

.podium-host .podium-place.rank-0 .podium-block {
  height: 380px;
}

.podium-host .podium-place.rank-1 .podium-block {
  height: 280px;
}

.podium-host .podium-place.rank-2 .podium-block {
  height: 200px;
}

/* ---------- Reveal answer-distribution bars ---------- */

.reveal-bars {
  display: grid;
  grid-template-columns: repeat(var(--bar-cols, 4), 1fr);
  gap: 14px;
  width: 100%;
  max-width: 900px;
  height: 140px;
  align-items: end;
}

.reveal-bar-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 8px;
}

.reveal-bar-count {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.reveal-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 8px 8px 0 0;
  transition: height 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  opacity: 0.6;
}

.reveal-bar.correct {
  opacity: 1;
  box-shadow: 0 0 0 3px #fff inset;
}

.correct-pulse {
  animation: correctPulse 0.6s ease 0.1s both;
}

@keyframes correctPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

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

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 900px;
}

.q-progress {
  color: #ffffffb0;
  font-weight: 600;
  font-size: 13px;
}

.q-text {
  color: #fff;
  font-size: clamp(20px, 4vw, 32px);
  font-weight: 600;
  text-align: center;
  max-width: 900px;
}

/* Countdown ring */
.timer-ring-wrap {
  position: relative;
  width: 60px;
  height: 60px;
  flex-shrink: 0;
}

.timer-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

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

.timer-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.2s linear, stroke 0.2s ease;
}

.timer-ring-wrap.urgent .timer-fill {
  stroke: var(--danger);
}

.timer-number {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  font-family: "Poppins", sans-serif;
}

/* Preview ("get ready") screen */
.preview-eyebrow {
  color: #ffffffb0;
  font-weight: 600;
  font-size: 13px;
}

.preview-ring {
  width: 84px;
  height: 84px;
  position: relative;
}

.preview-placeholder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 900px;
}

@media (max-width: 480px) {
  .preview-placeholder-grid {
    grid-template-columns: 1fr;
  }
}

.preview-placeholder {
  height: 72px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  border: 2px dashed rgba(255, 255, 255, 0.18);
}

/* Waiting / answer progress */
.progress-track {
  width: 100%;
  max-width: 360px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.progress-track.on-light {
  background: #eef1f5;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  width: 0%;
  transition: width 0.3s ease;
}

.waiting-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin: 0 2px;
  animation: dotPulse 1.2s ease-in-out infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.15s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  width: 100%;
  max-width: 900px;
}

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

.answer-card {
  border-radius: var(--radius);
  padding: 20px;
  color: #fff;
  font-weight: 700;
  font-size: clamp(16px, 3vw, 21px);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  opacity: 0;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
  animation: cardIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

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

.answer-card .shape {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  background: #fff;
}

.shape-triangle {
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.shape-diamond {
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
}
.shape-circle {
  border-radius: 50%;
}
.shape-square {
  border-radius: 4px;
}

.ans-0 {
  background: var(--red);
}
.ans-1 {
  background: var(--blue);
}
.ans-2 {
  background: var(--yellow);
}
.ans-3 {
  background: var(--green);
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 520px;
}

.lb-row {
  background: #fff;
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  animation: lbIn 0.3s ease forwards;
}

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

.lb-row.rank-0 {
  background: var(--accent);
  color: var(--accent-ink);
}

/* ---------- Player (phone) screen ---------- */

.answer-btn {
  border-radius: var(--radius);
  padding: 28px 16px;
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  min-height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  opacity: 0;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.18);
  animation: cardIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.answer-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.18);
}

.answer-btn.selected {
  box-shadow: 0 0 0 4px #fff inset;
}

.feedback {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 700;
  text-align: center;
  color: #fff;
}

.feedback.correct {
  color: #6fe0a0;
}

.feedback.wrong {
  color: #ff9b9b;
}

.score-badge {
  background: #fff;
  border-radius: 12px;
  padding: 12px 20px;
  font-weight: 700;
  color: #234c85;
  box-shadow: var(--shadow);
}

.pulse {
  animation: pulse 1.6s ease-in-out infinite;
}

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

.footer-note {
  color: #ffffff88;
  font-size: 12px;
  text-align: center;
}

/* Confetti (final results only, kept restrained) */
.confetti-piece {
  position: fixed;
  top: -20px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  border-radius: 2px;
  animation: confettiFall linear forwards;
  pointer-events: none;
  z-index: 5;
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(360deg);
    opacity: 0.4;
  }
}
