/* Components — buttons, inputs, cards, modals, tiles, spinner, leaderboard */

/* ============ Buttons ============ */
.btn, button {
  font: inherit;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  line-height: 1.2;
  transition: transform 0.12s ease, background 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}
.btn:hover, button:hover {
  background: var(--surface-soft);
  border-color: var(--border-strong);
}
.btn:active, button:active { transform: translateY(1px); }

.btn.primary, button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 6px 18px -6px var(--primary-ring);
}
.btn.primary:hover, button.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: var(--shadow-lift);
}

.btn.secondary, button.secondary {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn.secondary:hover, button.secondary:hover {
  background: var(--primary-soft);
}

.btn.danger, button.danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--border);
}
.btn.danger:hover, button.danger:hover {
  background: var(--danger-bg);
  border-color: var(--danger);
}

.btn.big, button.big {
  padding: 16px 36px;
  font-size: 17px;
  border-radius: var(--radius);
}

.btn[disabled], button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============ Inputs ============ */
input, textarea, select {
  font: inherit;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-ring);
}
textarea { resize: vertical; min-height: 64px; }

/* ============ Cards ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.card:hover {
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
}

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

/* ============ Badges / Pills ============ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

/* ============ Modal (native <dialog>) ============ */
dialog.modal {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-lg);
  max-width: 560px;
  width: calc(100% - 32px);
  box-shadow: 0 24px 60px -10px rgba(15, 23, 42, 0.25);
  position: fixed;
  inset: 0;
  margin: auto;
  max-height: calc(100dvh - 64px);
  overflow: auto;
}
dialog.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}
.modal-body { padding: 28px; display: grid; gap: 18px; }
.modal-body h2 { font-size: 22px; font-weight: 700; margin: 0; }
.modal-body label {
  display: grid;
  gap: 6px;
  font-weight: 500;
  font-size: 14px;
  color: var(--text-body);
}
.modal-body label input[type=text] {
  font-size: 16px;
  font-weight: 400;
}
.modal-divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}
.modal-import { display: grid; gap: 12px; }
.modal-import input[type=file] {
  font-size: 14px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-1);
  border: 1px dashed var(--border-strong);
  cursor: pointer;
}
.modal-import input[type=file]::file-selector-button {
  font-family: inherit;
  font-weight: 700;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  padding: 6px 12px;
  margin-right: 12px;
  cursor: pointer;
}
.template-row { display: flex; gap: 8px; flex-wrap: wrap; }
.template-row .btn { font-size: 13px; padding: 6px 12px; }
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 4px;
}
.modal-err {
  color: var(--danger);
  font-weight: 500;
  font-size: 14px;
  min-height: 1.2em;
}

/* ============ Answer Option Tiles (shared host/play/editor) ============ */
.opt-tile {
  position: relative;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: clamp(18px, 2.3vw, 24px);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-direction: column;
  gap: 14px;
  padding: 28px 24px;
  min-height: 130px;
  text-align: center;
  cursor: default;
  width: 100%;
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}
.opt-tile.opt-0 { background: linear-gradient(135deg, var(--opt-0) 0%, #ff8559 100%); }
.opt-tile.opt-1 { background: linear-gradient(135deg, var(--opt-1) 0%, #fbbf24 100%); }
.opt-tile.opt-2 { background: linear-gradient(135deg, var(--opt-2) 0%, #f97316 100%); }
.opt-tile.opt-3 { background: linear-gradient(135deg, var(--opt-3) 0%, #fdba74 100%); }

.opt-tile .opt-letter {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 20px;
  flex: 0 0 auto;
  backdrop-filter: blur(4px);
}

.opt-tile.dim { opacity: 0.35; }
.opt-tile.correct {
  transform: scale(1.05);
  box-shadow: 0 0 0 4px var(--success), var(--shadow-lift);
  z-index: 2;
}

.opt-count {
  margin-left: auto;
  font-weight: 900;
  font-size: clamp(22px, 3vw, 30px);
}

.answer-count {
  text-align: center;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
  font-size: 13px;
}

/* ============ Leaderboard ============ */
.leaderboard {
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.leaderboard h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text);
}
.leaderboard ol { list-style: none; counter-reset: rank; }
.leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 500;
  color: var(--text);
}
.leaderboard li:last-child { border-bottom: 0; }
.leaderboard li::before {
  content: counter(rank);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 14px;
}
.leaderboard li > :last-child {
  font-weight: 700;
  color: var(--text);
}

/* ============ Player chips (lobby) ============ */
.player-chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.player-chips .chip {
  background: linear-gradient(135deg, var(--primary-soft) 0%, var(--bg-3) 100%);
  border: 1px solid var(--primary-ring);
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
  animation: chipPop 0.3s ease;
}
@keyframes chipPop {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 12px 30px -6px rgba(15, 23, 42, 0.4);
  z-index: 100;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ============ Skeleton loader ============ */
.skeleton {
  background: linear-gradient(90deg, var(--border-soft) 0%, #f8fafc 50%, var(--border-soft) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
.skel-card {
  height: 84px;
  margin-bottom: 12px;
}
