:root {
  --purple: #46178f;
  --purple-dark: #2e0f61;
  --a-color: #e21b3c;
  --b-color: #1368ce;
  --c-color: #d89e00;
  --d-color: #26890c;
  --bg: #f4f4f7;
  --text: #23232a;
  --card: #ffffff;
  --muted: #6b6b76;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--purple); }

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.topbar {
  background: var(--purple);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar a { color: #fff; text-decoration: none; font-weight: 600; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  padding: 28px;
  width: 100%;
  max-width: 420px;
}

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

h1, h2, h3 { margin-top: 0; }

.brand {
  font-size: 2rem;
  font-weight: 800;
  color: var(--purple);
  margin-bottom: 8px;
  text-align: center;
}

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  margin-bottom: 14px;
  font-family: inherit;
}

label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 6px; }

button, .btn {
  display: inline-block;
  background: var(--purple);
  color: #fff;
  border: none;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

button:hover, .btn:hover { background: var(--purple-dark); }

button.secondary, .btn.secondary { background: #eee; color: var(--text); }
button.secondary:hover, .btn.secondary:hover { background: #ddd; }

button.danger { background: var(--a-color); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.full { width: 100%; }

.error { color: var(--a-color); font-weight: 600; margin-bottom: 12px; }
.success { color: var(--d-color); font-weight: 600; margin-bottom: 12px; }

.qr-wrap {
  margin: 16px 0;
}

.qr-wrap canvas {
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.pin-display {
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--purple);
  margin: 12px 0;
}

.btn-copy {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.player-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.player-chip {
  background: var(--purple);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-weight: 600;
}

.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 20px;
}

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

.answer-btn {
  padding: 28px 16px;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

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

.answer-btn.a { background: var(--a-color); }
.answer-btn.b { background: var(--b-color); }
.answer-btn.c { background: var(--c-color); }
.answer-btn.d { background: var(--d-color); }

.answer-btn.correct { outline: 4px solid #16d160; }
.answer-btn.incorrect { outline: 4px solid #666; opacity: 0.5; }

.timer {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  color: var(--purple);
}

table { width: 100%; border-collapse: collapse; margin: 16px 0; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid #eee; }
th { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; }

.rank-row { display: flex; justify-content: space-between; padding: 10px 14px; border-radius: 8px; margin-bottom: 6px; background: #f4f4f7; }
.rank-row.me { background: #ffe9a8; font-weight: 700; }
.rank-row .rank { color: var(--muted); width: 32px; }

.question-text {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.muted { color: var(--muted); }
.center { text-align: center; }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

.question-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #eee;
}

.question-row:first-child { padding-top: 0; }
.question-row:last-child { padding-bottom: 0; border-bottom: none; }

.question-row .question-body { flex: 1; min-width: 0; }

.question-row .reorder { display: flex; flex-direction: column; gap: 4px; }
.question-row .reorder form { margin: 0; }

.reorder-btn {
  padding: 2px 12px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.5;
}

.quiz-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid #eee;
}

/* Two-column quiz edit page */
.edit-layout {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.edit-sidebar {
  flex: 0 0 360px;
  position: sticky;
  top: 24px;
}

.edit-main {
  flex: 1;
  min-width: 0;
}

.edit-layout .card,
.edit-layout .card.wide {
  max-width: none;
}

.edit-sidebar .card {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 20px;
}

.edit-sidebar .question-row { flex-wrap: wrap; }
.edit-sidebar .question-row .actions { margin-top: 8px; width: 100%; }

@media (max-width: 900px) {
  .edit-layout { flex-direction: column; }
  .edit-sidebar {
    position: static;
    flex-basis: auto;
    width: 100%;
  }
  .edit-sidebar .card { max-height: none; }
}
