:root {
  --brand: #4338ca;
  --brand-dark: #2e2a86;
  --tile-1: #fb7185;
  --tile-2: #38bdf8;
  --tile-3: #f59e0b;
  --tile-4: #34d399;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b6b8a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: rgb(12, 28, 125);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--card);
  border-radius: 20px;
  padding: 36px 32px;
  max-width: 728px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  text-align: center;
}

.card.wide { max-width: 1426px; text-align: left; }

h1.brand {
  color: #fff;
  font-size: 2.6rem;
  font-weight: 800;
  margin: 0 0 8px;
  letter-spacing: -1px;
}

.tagline { color: rgba(255,255,255,0.85); margin-bottom: 32px; font-size: 1.05rem; }

h2 { margin-top: 0; }

.btn {
  display: inline-block;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-block { display: block; width: 100%; }
.btn-secondary { background: #f0f0f5; color: var(--text); }
.btn-danger { background: var(--tile-1); color: #fff; }
.btn-success { background: var(--tile-4); color: #0d3b2b; }
.btn-lg { font-size: 1.3rem; padding: 18px 36px; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 12px; }
.row.center { justify-content: center; align-items: center; }
.row.between { justify-content: space-between; align-items: center; }

input[type=text], input[type=password], input[type=number], input[type=email], select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 10px;
  border: 2px solid #ddd;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--brand); }

input[type=file] {
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: 2px dashed #ccc;
  font-size: 0.95rem;
}

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 600; }
.flash.error { background: #ffe4e6; color: #be123c; }
.flash.success { background: #d1fae5; color: #047857; }

.pin-display {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: 6px;
  color: var(--brand);
  background: #eef2ff;
  border-radius: 14px;
  padding: 12px 24px;
  margin: 12px 0;
}

.muted { color: var(--muted); }

.choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 20px;
}
@media (max-width: 520px) {
  .choices-grid { grid-template-columns: 1fr; }
}

.choice-tile {
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  padding: 24px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 90px;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.choice-tile:active { transform: scale(0.97); }
.choice-tile:disabled { opacity: 0.55; cursor: default; }
.choice-tile .shape {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
}

.choice-0 { background: var(--tile-1); }
.choice-1 { background: var(--tile-2); }
.choice-2 { background: var(--tile-3); }
.choice-3 { background: var(--tile-4); }

.question-banner {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 10px;
}

.timer-bar-track {
  background: rgba(255,255,255,0.25);
  border-radius: 8px;
  height: 14px;
  overflow: hidden;
  margin: 10px 0 22px;
}
.timer-bar-fill {
  background: var(--tile-2);
  height: 100%;
  width: 100%;
  transition: width 1s linear;
}

.status-pill {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 700;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

.leaderboard-list { list-style: none; padding: 0; margin: 20px 0; }
.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eef2ff;
  border-radius: 10px;
  padding: 12px 18px;
  margin-bottom: 8px;
  font-weight: 700;
}
.leaderboard-list li .rank { color: var(--brand); width: 32px; }
.leaderboard-list li.me { background: var(--brand); color: #fff; }
.leaderboard-list li.me .rank { color: var(--tile-3); }

.podium { display: flex; align-items: flex-end; justify-content: center; gap: 16px; margin: 30px 0; }
.podium .place { text-align: center; }
.podium .bar { border-radius: 10px 10px 0 0; display: flex; align-items: flex-start; justify-content: center; padding-top: 10px; color: #fff; font-weight: 800; font-size: 1.6rem; }
.podium .p1 .bar { background: #d4af37; height: 150px; width: 100px; }
.podium .p2 .bar { background: #a8a8a8; height: 110px; width: 100px; }
.podium .p3 .bar { background: #b5651d; height: 80px; width: 100px; }
.podium .name { margin-top: 8px; font-weight: 700; }

.result-banner {
  border-radius: 16px;
  padding: 40px 20px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
}
.result-correct { background: var(--tile-4); color: #0d3b2b; }
.result-wrong { background: var(--tile-1); }

table.qtable { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.qtable th, table.qtable td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #eee; }

.qr-box { background: #fff; padding: 14px; border-radius: 14px; display: inline-block; }

.lobby-columns { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; margin-top: 20px; }
.lobby-col-left { flex: 1; min-width: 300px; }
.lobby-col-right { flex: 1; min-width: 280px; }

.participant-list-wrap {
  max-height: 360px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid #eee;
  border-radius: 10px;
}
.participant-list-wrap table.qtable { min-width: 420px; }
.participant-list-wrap table.qtable { margin-top: 0; }
.participant-list-wrap thead th {
  position: sticky;
  top: 0;
  background: #fff;
}

footer.hint { text-align: center; color: rgba(255,255,255,0.7); font-size: 0.85rem; padding: 16px; }

.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 220px; margin: 24px 0; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.bar-chart .bar-fill { width: 100%; border-radius: 8px 8px 0 0; color: #fff; font-weight: 800; display: flex; align-items: flex-start; justify-content: center; padding-top: 6px; min-height: 4px; }
.bar-chart .bar-label { margin-top: 8px; font-weight: 700; text-align: center; font-size: 0.9rem; }

.divider { border: none; border-top: 1px solid #eee; margin: 24px 0; }

.stat-tile {
  background: #f5f5fb;
  border-radius: 12px;
  padding: 16px 24px;
  text-align: center;
  min-width: 140px;
  flex: 1;
}
.stat-value { font-size: 2rem; font-weight: 800; color: var(--brand); }
.stat-label { color: var(--muted); font-weight: 600; font-size: 0.85rem; margin-top: 4px; }

.question-report { border-bottom: 1px solid #eee; padding: 18px 0; }
.question-report:last-child { border-bottom: none; }
.question-report h3 { margin: 0 0 4px; }

.choice-report-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.choice-report-row {
  display: grid;
  grid-template-columns: 200px 1fr 90px;
  align-items: center;
  gap: 10px;
}
@media (max-width: 640px) {
  .choice-report-row { grid-template-columns: 1fr; gap: 4px; }
  .choice-report-pct { text-align: left; }
}
.choice-report-row.correct .choice-report-label { font-weight: 800; color: #047857; }
.choice-report-bar-track { background: #f0f0f5; border-radius: 6px; height: 14px; overflow: hidden; }
.choice-report-bar-fill { background: var(--brand); height: 100%; border-radius: 6px; }
.choice-report-row.correct .choice-report-bar-fill { background: var(--tile-4); }
.choice-report-pct { text-align: right; color: var(--muted); font-weight: 700; font-size: 0.9rem; }

.back-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 50;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  backdrop-filter: blur(4px);
  transition: background 0.15s ease;
}
.back-btn:hover { background: rgba(255,255,255,0.3); }

.table-filter-row { margin: 4px 0 14px; }
.table-filter-input.table-filter-input { max-width: 320px; text-align: left; }

th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable-th:hover { color: var(--brand); }
.sort-arrow { font-size: 0.8em; margin-left: 4px; color: #bbb; display: inline-block; width: 12px; }
.sort-arrow.active { color: var(--brand); font-weight: 800; }
