/* QuizCards — clean & minimal */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-border: #c7d2fe;
  --green: #16a34a;
  --green-soft: #f0fdf4;
  --green-border: #bbf7d0;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --red-border: #fecaca;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  background: none;
  font: inherit;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
}
.brand:hover { background: var(--accent-soft); }

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  padding: 12px 20px 28px;
}

h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 19px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 24px; font-size: 14.5px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
}
.btn:hover { background: #f1f5f9; }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red-border); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f1f5f9; color: var(--text); }
.btn.small { font-size: 13px; padding: 6px 11px; border-radius: 8px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.quiz-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.quiz-row .meta { min-width: 0; }
.quiz-row .title { font-weight: 650; font-size: 16.5px; }
.quiz-row .count { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.quiz-row .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 10px; }

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input[type="text"], textarea {
  width: 100%;
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="text"]:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 44px; }

/* Editor question block */
.qblock { position: relative; }
.qblock .qhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.qblock .qnum { font-weight: 700; font-size: 13.5px; color: var(--accent); }
.choice-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.choice-row input[type="radio"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
  cursor: pointer;
}
.choice-row input[type="text"] { flex: 1; }
.choice-row .btn { flex-shrink: 0; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.editor-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 8px;
}

/* Test mode */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.progress-track {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}
.progress-label { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.question-card { padding: 26px 24px; }
.question-text { font-size: 19px; font-weight: 650; margin: 0 0 20px; white-space: pre-wrap; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 15.5px;
  padding: 13px 16px;
  margin-bottom: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.option:hover { border-color: #cbd5e1; background: #f8fafc; }
.option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.option .bullet {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
}
.option.selected .bullet { background: var(--accent); border-color: var(--accent); color: #fff; }

.test-nav {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 22px;
}

/* Results */
.score-card {
  text-align: center;
  padding: 34px 24px;
}
.score-num { font-size: 46px; font-weight: 800; line-height: 1.1; }
.score-pct { font-size: 15px; color: var(--muted); margin-top: 4px; }
.score-msg { margin-top: 10px; font-size: 15.5px; }

.review-item { padding: 16px 18px; }
.review-item .rq { font-weight: 650; margin-bottom: 10px; white-space: pre-wrap; }
.review-choice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14.5px;
  margin-bottom: 6px;
  color: var(--muted);
}
.review-choice.correct {
  background: var(--green-soft);
  border-color: var(--green-border);
  color: #14532d;
  font-weight: 600;
}
.review-choice.wrong {
  background: var(--red-soft);
  border-color: var(--red-border);
  color: #7f1d1d;
  font-weight: 600;
}
.review-tag {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 999px;
  flex-shrink: 0;
  margin-top: 2px;
}
.review-tag.ok { background: var(--green); color: #fff; }
.review-tag.no { background: var(--red); color: #fff; }
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  margin-left: 8px;
  vertical-align: middle;
}
.badge.ok { background: var(--green-soft); color: var(--green); border: 1px solid var(--green-border); }
.badge.no { background: var(--red-soft); color: var(--red); border: 1px solid var(--red-border); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
  color: var(--text);
  margin-bottom: 10px;
  cursor: pointer;
}
.checkbox-line input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

@media (max-width: 520px) {
  .container { padding: 18px 14px 50px; }
  .question-card { padding: 20px 16px; }
  .quiz-row .actions { width: 100%; }
}

/* ---- v2: players, history, quick create, drag & drop ---- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.chip:hover { background: #f1f5f9; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.danger { color: var(--red); }
.chip.danger:hover { background: var(--red-soft); border-color: var(--red-border); }

/* history */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
}
.history-item .htitle { font-weight: 650; }
.history-item .hsub { color: var(--muted); font-size: 13px; margin-top: 1px; }
.history-item .hscore {
  font-weight: 800;
  font-size: 18px;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.history-item .hpct { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.history-item .hscore.ok { color: var(--green); }
.history-item .hscore.mid { color: #d97706; }
.history-item .hscore.no { color: var(--red); }
.history-summary {
  display: flex;
  gap: 26px;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  padding: 14px 18px;
}
.history-summary span { display: block; font-size: 20px; font-weight: 800; color: var(--text); }

/* quick create format help */
.format-help .fh-row {
  display: flex;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 8px;
  font-size: 13.5px;
  color: var(--muted);
}
.format-help code {
  flex-shrink: 0;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  padding: 1px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  white-space: nowrap;
}

/* editor extras */
.type-sel {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.order-num { font-weight: 700; color: var(--muted); min-width: 22px; text-align: right; }
.match-arrow { color: var(--muted); flex-shrink: 0; }

/* typed answer input in test */
.typed-input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  padding: 13px 16px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.typed-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* drag & drop lists */
.sortable { user-select: none; -webkit-user-select: none; }
.drag-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  margin-bottom: 8px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 15px;
  cursor: grab;
  touch-action: none;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.drag-row:active { cursor: grabbing; }
.drag-row.dragging {
  pointer-events: none;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.18);
  opacity: 0.95;
  z-index: 5;
  position: relative;
}
.drag-handle { color: var(--muted); font-size: 15px; flex-shrink: 0; }
.drag-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.drag-arrows { display: flex; gap: 4px; flex-shrink: 0; }
.arrow-btn {
  font: inherit;
  font-size: 11px;
  width: 28px; height: 28px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.arrow-btn:hover { background: #f1f5f9; color: var(--text); }

/* numbered ordering list — CSS counters stay correct mid-drag */
.numbered { counter-reset: pos; }
.numbered .drag-row { counter-increment: pos; }
.numbered .drag-row::before {
  content: counter(pos);
  flex-shrink: 0;
  width: 24px; height: 24px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* matching grid */
.match-grid { display: flex; gap: 12px; align-items: flex-start; }
.match-lefts { flex: 1; min-width: 0; }
.match-rights { flex: 1; min-width: 0; }
.match-left-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  text-align: right;
  min-height: 47px;
  margin-bottom: 8px;
  padding: 11px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.match-rights .drag-row { min-height: 47px; }

@media (max-width: 520px) {
  .match-left-cell { font-size: 13.5px; padding: 11px 6px; }
  .history-summary { gap: 18px; }
}

/* ---- v3: login, parent/child ---- */
.login-hero { text-align: center; padding: 18px 0 6px; }
.login-hero .big { font-size: 44px; margin-bottom: 6px; }
.login-hero h1 { margin-bottom: 6px; }
.assign-panel[hidden] { display: none; }
.assign-panel { border-top: 1px dashed var(--border); margin-top: 14px; padding-top: 2px; }
input[type="password"] {
  font: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="password"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---- v5: word-chip matching board ---- */
.match-board { }
.match-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.word-slot {
  flex: 0 0 40%;
  min-width: 0;
  min-height: 46px;
  border: 1.5px dashed transparent;
  border-radius: 10px;
  display: flex;
  align-items: stretch;
  transition: border-color 0.12s, background 0.12s;
}
.word-slot.drop-target {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.word-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 14.5px;
  font-weight: 650;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.word-chip:active { cursor: grabbing; }
.word-chip.chip-dragging {
  pointer-events: none;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.22);
  z-index: 60;
}
.chip-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.match-arrow2 { color: var(--muted); flex-shrink: 0; }
.match-def {
  flex: 1;
  min-width: 0;
  font-size: 14.5px;
  color: var(--text);
  overflow-wrap: anywhere;
}
@media (max-width: 520px) {
  .word-slot { flex-basis: 46%; }
  .word-chip { font-size: 13.5px; padding: 8px 8px; gap: 6px; }
  .match-def { font-size: 13.5px; }
}

/* ---- v6: drag-word-to-meaning question ---- */
.chip-tray {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 6px;
  margin-bottom: 14px;
  border: 1.5px dashed var(--accent-border);
  border-radius: 10px;
  background: var(--accent-soft);
}
.chip-tray .word-chip { max-width: 260px; }
.chip-tray.empty { border-color: var(--border); background: transparent; }
.tray-hint { font-size: 12.5px; color: var(--muted); padding: 0 6px; }
.drop-zone {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}
.drop-zone:hover { border-color: #cbd5e1; background: #f8fafc; }
.drop-zone.drop-hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.drop-zone.chosen {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-zone .zone-slot { flex: 0 0 auto; max-width: 45%; display: flex; }
.drop-zone .zone-slot:empty { display: none; }
.drop-zone .zone-slot .word-chip { padding: 6px 9px; font-size: 13.5px; }
.drop-zone .zone-text { flex: 1; min-width: 0; font-size: 14.5px; overflow-wrap: anywhere; }
.drag-word { cursor: grab; }

/* ---- v7: motivation, confetti ---- */
.score-emoji { font-size: 44px; line-height: 1; margin-bottom: 6px; animation: pop-in 0.5s cubic-bezier(0.2, 1.6, 0.4, 1); }
.score-card .score-num { animation: pop-in 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
.score-card.celebrate { border-color: var(--accent-border); box-shadow: 0 6px 24px rgba(79, 70, 229, 0.14); }
.score-extra {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--green-soft);
  border: 1px solid var(--green-border);
  color: #14532d;
  font-size: 14px;
  font-weight: 650;
}
@keyframes pop-in {
  0% { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 999;
}
.confetti i {
  position: absolute;
  top: -20px;
  border-radius: 2px;
  animation-name: confetti-fall;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}
@keyframes confetti-fall {
  0% { transform: translate3d(0, -20px, 0) rotate(0deg); opacity: 1; }
  90% { opacity: 1; }
  100% { transform: translate3d(var(--drift, 0px), 105vh, 0) rotate(var(--spin, 360deg)); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .score-emoji, .score-card .score-num { animation: none; }
}
