:root {
  --bg: #0b1020;
  --bg-elev: #141a2f;
  --bg-elev-2: #1b2341;
  --border: #262e52;
  --text: #e8ecf7;
  --text-dim: #9aa3c7;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
  --gold: #fbbf24;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 10px 30px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(180deg, #0a0f1f 0%, #0b1020 100%);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: rgba(10,14,30,0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar .brand {
  font-weight: 700;
  letter-spacing: 0.3px;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar .brand .logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 900;
  color: #0a0f1f;
}
.nav { display: flex; gap: 6px; }
.nav a {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
}
.nav a.active, .nav a:hover { background: var(--bg-elev); color: var(--text); text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }
.container.wide { max-width: 1600px; }

h1 { font-size: 28px; margin: 0 0 4px; }
h2 { font-size: 20px; margin: 0 0 8px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--text-dim); font-size: 14px; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, transform 60ms;
  font-weight: 500;
}
.btn:hover { background: #232b50; border-color: #37437a; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b3dff); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ok { background: var(--ok); border-color: transparent; color: #052016; }
.btn.warn { background: var(--warn); border-color: transparent; color: #2a1a00; }
.btn.danger { background: var(--err); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.lg { padding: 12px 20px; font-size: 15px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.input, .select, .textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
}
.textarea { resize: vertical; min-height: 70px; }

label.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--text-dim); }
label.field > span { display: block; margin-bottom: 4px; }
label.field.row-inline { display: flex; align-items: center; gap: 8px; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--bg-elev-2); color: var(--text-dim);
  font-size: 11px; letter-spacing: 0.3px;
}
.badge.ok { background: rgba(34,197,94,0.18); color: #4ade80; }
.badge.warn { background: rgba(245,158,11,0.18); color: #fbbf24; }
.badge.accent { background: rgba(124,92,255,0.22); color: #c7bbff; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--bg-elev-2); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.list li .meta { color: var(--text-dim); font-size: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--bg-elev-2);
  border: 1px solid var(--border); font-size: 12px; color: var(--text-dim);
}

.modal-backdrop { position: fixed; inset: 0; background: rgba(5,8,20,0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 500; }
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 720px;
  width: calc(100% - 40px);
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding: 22px;
}
.modal h2 { margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; opacity: 0; transition: opacity 200ms;
  z-index: 1000;
}
.toast.show { opacity: 1; }
.toast.err { border-color: var(--err); }

.media-thumb {
  width: 60px; height: 60px; object-fit: cover; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--border);
}

.q-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  gap: 14px;
  cursor: grab;
}
.q-card.dragging { opacity: 0.4; }
.q-card .q-num {
  min-width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}
.q-card .q-body { flex: 1; min-width: 0; }
.q-card .q-text { font-size: 14px; margin-bottom: 6px; word-break: break-word; }
.q-card .q-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 8px; flex-wrap: wrap; }
.q-card .q-answer { font-size: 12px; color: #a7d7a7; margin-top: 4px; }
.q-card .q-actions { display: flex; gap: 6px; align-items: flex-start; }
.q-card.child { margin-left: 32px; background: rgba(27,35,65,0.6); }

.section-block { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 16px; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  cursor: grab;
}
.section-body { padding: 14px 18px; }

.empty { padding: 40px; text-align: center; color: var(--text-dim); }

.header-flex { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
.table th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

.score-badge {
  padding: 4px 10px; border-radius: 999px; font-weight: 700;
  background: rgba(124,92,255,0.18); color: #c7bbff;
  font-size: 13px;
}

/* Host console */
.host-layout { display: grid; grid-template-columns: 300px 1fr 300px; height: calc(100vh - 60px); }
.host-sidebar { background: var(--bg-elev); border-right: 1px solid var(--border); overflow-y: auto; padding: 14px; }
.host-sidebar.right { border-right: 0; border-left: 1px solid var(--border); }
.host-main { padding: 20px; overflow-y: auto; }
.host-section-list .sec { padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim); font-size: 13px; }
.host-section-list .sec.active { background: var(--accent); color: #fff; }
.host-section-list .sec:hover:not(.active) { background: var(--bg-elev-2); color: var(--text); }
.host-q-list .q { padding: 10px; border-radius: var(--radius-sm); margin-bottom: 4px; cursor: pointer; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.host-q-list .q.active { background: var(--accent); color: #fff; }
.host-q-list .q:hover:not(.active) { background: var(--bg-elev-2); }
.host-q-list .q.scored { opacity: 0.65; }

.host-stage {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
}
.host-stage .q-text { font-size: 20px; line-height: 1.5; margin-bottom: 14px; }
.host-stage img, .host-stage video { max-width: 100%; max-height: 280px; border-radius: var(--radius-sm); }
.host-stage .answer-box { background: rgba(34,197,94,0.1); border: 1px solid rgba(34,197,94,0.4); padding: 14px; border-radius: var(--radius-sm); margin-top: 12px; }

.timer-ring {
  width: 120px; height: 120px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--accent) 0%, var(--bg-elev-2) 0%);
  position: relative;
}
.timer-ring .inner { width: 100px; height: 100px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 28px; }
.timer-ring.warn { background: conic-gradient(var(--warn) 0%, var(--bg-elev-2) 0%); }
.timer-ring.err { background: conic-gradient(var(--err) 0%, var(--bg-elev-2) 0%); }

.team-score-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2); margin-bottom: 6px;
  border-left: 4px solid var(--accent);
}
.team-score-row .nm { font-weight: 600; }
.team-score-row .sc { font-weight: 700; color: var(--gold); }

.team-award {
  display: flex; align-items: center; gap: 8px;
  padding: 10px; margin-bottom: 8px; border-radius: var(--radius-sm);
  background: var(--bg-elev-2); border-left: 4px solid var(--accent);
}
.team-award input { width: 80px; }

/* Display screen */
.display-root {
  min-height: 100vh; display: flex; flex-direction: column;
}
.display-screen {
  flex: 1;
  display: flex; flex-direction: column;
  padding: 48px 72px;
  position: relative;
}
.display-section { font-size: 20px; color: var(--accent-2); text-transform: uppercase; letter-spacing: 2px; margin-bottom: 8px; }
.display-q-num { font-size: 16px; color: var(--text-dim); margin-bottom: 20px; }
.display-q-text {
  font-size: 48px; line-height: 1.3; font-weight: 500; margin-bottom: 32px;
  color: var(--text);
}
.display-media img, .display-media video { max-width: 100%; max-height: 400px; border-radius: 12px; object-fit: contain; }
.display-footer {
  padding: 20px 72px;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.display-timer {
  font-size: 72px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.display-timer.warn { color: var(--warn); }
.display-timer.err { color: var(--err); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.display-marks { font-size: 24px; color: var(--gold); font-weight: 700; }

.display-answer {
  background: rgba(34,197,94,0.12);
  border: 2px solid rgba(34,197,94,0.5);
  padding: 32px; border-radius: 12px; margin-top: 20px;
}
.display-answer .label { font-size: 20px; color: var(--ok); text-transform: uppercase; letter-spacing: 2px; margin-bottom: 12px; }
.display-answer .text { font-size: 32px; line-height: 1.4; }
.display-answer .expl { font-size: 20px; color: var(--text-dim); margin-top: 12px; line-height: 1.4; }

.display-scoreboard {
  padding: 48px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}
.display-team {
  background: var(--bg-elev);
  padding: 24px;
  border-radius: 14px;
  border-top: 6px solid var(--accent);
  text-align: center;
}
.display-team .nm { font-size: 24px; margin-bottom: 10px; font-weight: 600; }
.display-team .sc { font-size: 48px; font-weight: 800; color: var(--gold); }

.display-waiting {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.display-waiting h1 { font-size: 72px; margin-bottom: 20px; }
.display-waiting .sub { font-size: 24px; color: var(--text-dim); }

.flash-correct { animation: flash-ok 1s; }
@keyframes flash-ok { 0% { background: rgba(34,197,94,0.4); } 100% { background: transparent; } }
.flash-wrong { animation: flash-err 1s; }
@keyframes flash-err { 0% { background: rgba(239,68,68,0.4); } 100% { background: transparent; } }

@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .host-layout { grid-template-columns: 1fr; height: auto; }
  .host-sidebar { max-height: 240px; }
  .display-q-text { font-size: 32px; }
  .display-screen { padding: 24px; }
  .display-footer { padding: 16px 24px; }
}
