:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --fg: #1d2033;
  --muted: #6b7088;
  --line: #e1e3ec;
  --accent: #2f3a8f;
  --accent-2: #f2b134;
  --danger: #c0392b;
  --ok: #1e8e5a;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.45;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; }
h1 { margin: 0 0 16px; font-size: 1.7rem; }
h2 { font-size: 1.25rem; margin: 0 0 12px; }

/* ---------- layout ---------- */
.topbar {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 20px;
  flex-wrap: wrap;
}
.topbar .brand { font-weight: 700; font-size: 1.15rem; margin-right: 18px; padding: 14px 0; color: #fff; text-decoration: none; }
.topbar .brand span { color: var(--accent-2); }
.topbar a.nav { color: #dfe2ff; text-decoration: none; padding: 16px 12px; border-bottom: 3px solid transparent; }
.topbar a.nav:hover, .topbar a.nav.active { color: #fff; border-bottom-color: var(--accent-2); }
.topbar .spacer { flex: 1; }
main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

.stat { font-size: 2rem; font-weight: 700; color: var(--accent); }

/* ---------- flash ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.success { background: #e3f6ec; color: var(--ok); }
.flash.error { background: #fbe7e5; color: var(--danger); }

/* ---------- forms ---------- */
label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #c9ccda;
  border-radius: 7px;
  font: inherit;
  background: #fff;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9aa5ff; border-color: transparent; }
.field { margin-bottom: 14px; }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.filters > * { flex: 1 1 140px; }
.filters .grow { flex: 3 1 220px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font: inherit; font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn.secondary { background: #fff; color: var(--accent); }
.btn.gold { background: var(--accent-2); border-color: var(--accent-2); color: #1d2033; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: .82rem; }
.btn.icon { padding: 3px 8px; font-size: .85rem; }
form.inline { display: inline; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:hover td { background: #fafbff; }
td.q-text { max-width: 520px; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  font-size: .75rem; font-weight: 600; background: #eceef8; color: var(--accent);
  white-space: nowrap;
}
.badge.low { background: #e3f6ec; color: var(--ok); }
.badge.medium { background: #fff3d6; color: #9a6a00; }
.badge.high { background: #fbe7e5; color: var(--danger); }
.badge.type-hints { background: #efe6fb; color: #6b3fb0; }
.badge.type-approximate { background: #e0f2fb; color: #1b6c95; }
.badge.type-multiple { background: #fdeee0; color: #a85a12; }
.badge.type-music { background: #fde7f1; color: #b0306a; }
.badge.type-picture { background: #e6f5ea; color: #2c7a43; }
.badge.used { background: #eee; color: #777; }

/* ---------- question form ---------- */
.type-section { display: none; border-left: 4px solid var(--accent-2); padding: 4px 0 4px 14px; margin: 14px 0; }
.type-section.visible { display: block; }
.tier-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.tier-row input { width: 110px; }
.media-pick { display: grid; gap: 8px; }
.media-preview img { max-width: 220px; max-height: 160px; border-radius: 6px; border: 1px solid var(--line); }
.media-preview audio { width: 100%; max-width: 360px; }

/* ---------- media library ---------- */
.media-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.media-item { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.media-item .thumb { height: 140px; display: flex; align-items: center; justify-content: center; background: #f0f1f7; border-radius: 6px; overflow: hidden; }
.media-item .thumb img { max-width: 100%; max-height: 100%; }
.media-item audio { width: 100%; }
.media-item input { font-size: .85rem; padding: 4px 6px; }

/* ---------- quiz builder ---------- */
.round { border-top: 4px solid var(--accent); }
.round.picture { border-top-color: #1b6c95; }
.round.music { border-top-color: #a85a12; }
.round.hints { border-top-color: #6b3fb0; }
.round-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.count.ok { color: var(--ok); }
.count.warn { color: #9a6a00; }
.item-row td { padding: 6px 8px; }
.thumb-sm { max-height: 44px; max-width: 70px; border-radius: 4px; vertical-align: middle; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 600; margin: 6px 0; }
.output-links .btn { margin: 0 6px 6px 0; }

/* ---------- user menu / auth ---------- */
.topbar .user { color: #dfe2ff; font-size: .9rem; display: flex; align-items: center; gap: 8px; margin-left: 10px; }
.topbar .user a { color: #fff; }
.topbar .user button { background: none; border: 0; color: #dfe2ff; cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.auth-box { max-width: 420px; margin: 8vh auto; }
.auth-box h1 { text-align: center; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; margin-bottom: -2px; font-weight: 600; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.badge.public { background: #e3f6ec; color: var(--ok); }
.badge.shared { background: #e0f2fb; color: #1b6c95; }
.badge.owner { background: #f3f0e8; color: #7a5b1e; }
.bulkbar { position: sticky; bottom: 0; background: #fff; border-top: 2px solid var(--accent); padding: 10px 14px; margin: 0 -20px -18px; border-radius: 0 0 var(--radius) var(--radius); display: none; }
.bulkbar.visible { display: flex; }
.bulkbar select { width: auto; }
.readonly-note { background: #fff8e6; border: 1px solid #f2d58a; border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

/* ---------- import ---------- */
tr.has-error td { background: #fdf0ef; }
tr.is-dupe td { background: #fafafa; color: var(--muted); }
.msg-error { color: var(--danger); font-size: .82rem; }
.msg-warn { color: #9a6a00; font-size: .82rem; }
code.inline { background: #eceef8; padding: 1px 6px; border-radius: 4px; }

/* ---------- teams ---------- */
.team-board { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.team-col { background: #fff; border: 1px solid var(--line); border-top: 5px solid var(--team, var(--accent)); border-radius: var(--radius); padding: 10px; min-height: 140px; }
.team-col.unassigned { border-top-color: #bbb; background: #fafbfd; }
.team-col.drag-over { outline: 3px dashed var(--accent-2); }
.team-col h3 { margin: 0 0 8px; font-size: 1rem; display: flex; align-items: center; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 40px; }
.chip { background: #eef0fa; border-radius: 99px; padding: 3px 4px 3px 10px; font-size: .88rem; cursor: grab; user-select: none; display: inline-flex; align-items: center; gap: 4px; }
.chip.dragging { opacity: .4; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .8rem; padding: 0 4px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; color: #1d2033; font-size: .8rem; overflow: hidden; flex-shrink: 0; background: var(--team, #ccc); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.team-edit { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; }
input[type=color] { width: 44px; height: 36px; padding: 2px; border: 1px solid #c9ccda; border-radius: 7px; }

/* ---------- scoring grid ---------- */
.score-grid { overflow-x: auto; }
.score-grid table { border-collapse: separate; border-spacing: 0; }
.score-grid th, .score-grid td { border-bottom: 1px solid var(--line); padding: 5px; text-align: center; white-space: nowrap; }
.score-grid th.team, .score-grid td.team { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; min-width: 180px; }
.score-grid th .max { display: block; font-weight: 400; text-transform: none; letter-spacing: 0; }
.score-grid input { width: 58px; text-align: center; padding: 6px 4px; }
.score-grid input.over { background: #fbe7e5; border-color: var(--danger); }
.score-grid td.total { font-weight: 700; font-size: 1.1rem; color: var(--accent); min-width: 70px; }
.score-grid tr:hover td { background: #f6f7ff; }
.score-grid td.team .row { flex-wrap: nowrap; }
.dirty-note { color: #9a6a00; font-weight: 600; display: none; }
.dirty .dirty-note { display: inline; }

/* ---------- presentation theme editor ---------- */
.theme-editor { display: grid; grid-template-columns: 1fr 420px; gap: 24px; align-items: start; }
@media (max-width: 900px) { .theme-editor { grid-template-columns: 1fr; } }
.preset { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.preset span { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.theme-preview { background: var(--bg); color: var(--fg); border-radius: 10px; padding: 16px 20px 22px; aspect-ratio: 16 / 9; position: relative; overflow: hidden; box-shadow: 0 4px 18px rgba(0,0,0,.18); }
.theme-preview .tp-head { display: flex; justify-content: space-between; color: var(--accent); font-weight: 700; font-size: .62rem; letter-spacing: .05em; text-transform: uppercase; }
.theme-preview .tp-q { font-size: 1.15rem; font-weight: 700; margin-top: 26px; line-height: 1.25; }
.theme-preview .tp-sub { font-size: .75rem; margin-top: 4px; }
.theme-preview .tp-answer { font-size: 1.6rem; font-weight: 800; margin-top: 10px; }
.theme-preview .tp-note { display: inline-block; background: var(--bg2); border-radius: 6px; padding: 3px 8px; font-size: .72rem; margin-top: 6px; }
.theme-preview .tp-accent { color: var(--accent); }
.theme-preview .tp-muted { color: var(--muted); }
.theme-preview .tp-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--line); }
.theme-preview .tp-bar span { display: block; height: 100%; background: var(--accent); }

/* ---------- drag & drop of round questions ---------- */
.drag-handle { cursor: grab; color: var(--muted); padding: 0 6px 0 0; user-select: none; font-size: 1.1rem; }
.item-row.dragging { opacity: .4; background: #eef0fa; }
.badge.avg { background: #fff3d6; color: #7a5b1e; white-space: nowrap; }

/* ---------- question packs ---------- */
.badge.pack { background: #ece8f8; color: #4b3d8f; text-decoration: none; }
.pack-list { display: grid; gap: 6px; }
.pack-row { display: flex; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.pack-row > span { flex: 1; }
.pack-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.pack-card { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.pack-card .cover { height: 130px; background: #f0f1f7; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center; font-size: 2.6rem; }
.pack-card .cover img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- clip times ---------- */
.clip-times { display: grid; gap: 10px 18px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 14px; }
.clip-times .pair { display: flex; gap: 8px; align-items: end; }
.clip-times .pair > div { flex: 1; }
.clip-times .take { padding: 6px 8px; white-space: nowrap; }
.clip-player { margin-top: 10px; }
.clip-player audio, .clip-player video { width: 100%; max-width: 480px; max-height: 200px; }
