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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  background: linear-gradient(135deg, #4338ca 0%, #6d28d9 50%, #9333ea 100%);
  color: #1f2937;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 16px;
}

.wrap { width: 100%; max-width: 720px; }

.brand {
  text-align: center;
  color: #fff;
  margin-bottom: 24px;
}
.brand h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; }
.brand p { opacity: 0.85; margin-top: 4px; font-size: 14px; }

.card {
  background: #fff;
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
  margin-bottom: 20px;
}

.card h2 { font-size: 20px; margin-bottom: 16px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }

input[type=text] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 12px;
  outline: none;
}
input[type=text]:focus { border-color: #6d28d9; }

button {
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 16px;
  font-weight: 700;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: #6d28d9; color: #fff; width: 100%; }
.btn-primary:hover { background: #5b21b6; }
.btn-secondary { background: #eef2ff; color: #4338ca; width: 100%; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-ghost { background: transparent; color: #6d28d9; text-decoration: underline; font-weight: 600; }

.divider { text-align: center; color: #9ca3af; margin: 18px 0; font-size: 13px; font-weight: 600; }

.code-display {
  text-align: center;
  padding: 20px;
}
.code-display .code {
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 6px;
  color: #4338ca;
  margin: 8px 0;
}
.code-display .hint { color: #6b7280; font-size: 13px; }
#qrcode { display: flex; justify-content: center; margin-top: 14px; }

.status-pill {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-lobby { background: #fef3c7; color: #92400e; }
.status-active { background: #dcfce7; color: #166534; }
.status-revealed { background: #dbeafe; color: #1e40af; }
.status-ended { background: #f3f4f6; color: #374151; }

.timer-wrap { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.timer-num {
  font-weight: 900; font-size: 22px; color: #4338ca; min-width: 42px; text-align: center;
  background: #eef2ff; border-radius: 10px; padding: 4px 0;
  transition: color 0.2s, background-color 0.2s;
}
.timer-num.low { color: #fff; background: #dc2626; animation: pulse 0.6s infinite; }
.timer-track { flex: 1; height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.timer-fill { height: 100%; background: #6d28d9; width: 100%; transition: width 0.2s linear, background-color 0.3s; }
.timer-fill.low { background: #dc2626; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.qnum { color: #6d28d9; font-weight: 700; font-size: 13px; margin-bottom: 6px; text-transform: uppercase; }
.qtext { font-size: 24px; font-weight: 800; margin-bottom: 20px; line-height: 1.3; }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .options { grid-template-columns: 1fr; } }

.opt {
  position: relative;
  border-radius: 12px;
  padding: 16px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  border: none;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}
.opt .letter {
  background: rgba(255,255,255,0.25);
  border-radius: 8px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.opt-a { background: #e21b3c; }
.opt-b { background: #1368ce; }
.opt-c { background: #d89e00; }
.opt-d { background: #26890c; }
.opt.selected { outline: 4px solid #fff; box-shadow: 0 0 0 4px #4338ca; }
.opt.correct { outline: 4px solid #16a34a; box-shadow: 0 0 0 4px #16a34a; }
.opt.wrong { opacity: 0.5; }
.opt:disabled { cursor: default; }

.bar-bg {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: rgba(255,255,255,0.25);
  z-index: 0;
}
.opt-content { position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; width: 100%; }
.count-badge { margin-left: auto; background: rgba(0,0,0,0.2); padding: 2px 10px; border-radius: 999px; font-size: 13px; }

.controls { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.controls button { flex: 1; min-width: 140px; }

.center { text-align: center; }
.muted { color: #6b7280; font-size: 14px; }
.big-emoji { font-size: 56px; margin-bottom: 10px; }

.leaderboard { list-style: none; margin-top: 10px; }
.leaderboard li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-radius: 10px; background: #f9fafb; margin-bottom: 8px;
  font-weight: 700;
}
.leaderboard li:nth-child(1) { background: #fef3c7; }
.leaderboard li:nth-child(2) { background: #f3f4f6; }
.leaderboard li:nth-child(3) { background: #ffedd5; }
.rank { color: #6d28d9; margin-right: 10px; }

footer { color: rgba(255,255,255,0.6); font-size: 12px; margin-top: 20px; text-align: center; }

textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin-bottom: 12px;
  outline: none;
  resize: vertical;
  min-height: 220px;
  line-height: 1.5;
}
textarea:focus { border-color: #6d28d9; }

.field-label { font-size: 13px; font-weight: 700; color: #374151; margin-bottom: 6px; display: block; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
input[type=date] {
  width: 100%; padding: 12px 14px; border: 2px solid #e5e7eb; border-radius: 10px;
  font-size: 15px; margin-bottom: 12px; outline: none;
}
input[type=date]:focus { border-color: #6d28d9; }

.hint-box {
  background: #f5f3ff; border: 1px solid #ddd6fe; border-radius: 10px;
  padding: 12px 14px; font-size: 12.5px; color: #5b21b6; margin-bottom: 14px; line-height: 1.5;
  white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.preview-box { font-size: 13px; margin-bottom: 14px; }
.preview-ok { color: #166534; font-weight: 700; }
.preview-err { color: #b91c1c; margin-top: 6px; }
.preview-err ul { margin: 4px 0 0 18px; }

.quiz-search { margin-bottom: 16px; }

.event-group { margin-bottom: 22px; }
.event-group h3 {
  font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: #6d28d9;
  margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}

.quiz-item {
  border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px 16px;
  margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.quiz-item .qi-info { flex: 1; min-width: 180px; }
.quiz-item .qi-title { font-weight: 800; font-size: 15px; }
.quiz-item .qi-meta { color: #6b7280; font-size: 12.5px; margin-top: 2px; }
.quiz-item .qi-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quiz-item .qi-actions button { padding: 8px 14px; font-size: 13px; }

.btn-sm { padding: 8px 14px !important; font-size: 13px !important; width: auto !important; }
.empty-note { color: #6b7280; font-size: 14px; text-align: center; padding: 20px 0; }
