:root {
  --bg: #f4f2fb;
  --surface: #ffffff;
  --surface-2: #f8f7fd;
  --ink: #1b1035;
  --ink-2: #4d4766;
  --muted: #8a85a3;
  --line: #e6e3f2;
  --brand: #6c3cf0;
  --brand-2: #4b1fc7;
  --good: #1f8a3a;
  --bad: #c62839;
  --warn: #b77900;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 16, 53, .06), 0 6px 24px rgba(27, 16, 53, .06);
  --a0: #e21b3c; --a1: #1368ce; --a2: #d89e00; --a3: #26890c; --a4: #864cbf; --a5: #0a8f8f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #120c22; --surface: #1c1533; --surface-2: #231b3e; --ink: #f1eefb; --ink-2: #c9c3e0;
    --muted: #8f88ad; --line: #30284d; --brand: #8b63ff; --brand-2: #a688ff;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 24px rgba(0,0,0,.25); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.hidden { display: none !important; }

/* ── Layout ─────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 12px 24px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap;
}
.logo { font-weight: 800; font-size: 1.2rem; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.logo b { background: var(--brand); color: #fff; border-radius: 8px; padding: 2px 8px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 10px; color: var(--ink-2); font-weight: 500; }
.nav a.active, .nav a:hover { background: var(--surface-2); color: var(--ink); }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: .9rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.section { margin-top: 28px; }

/* ── Controls ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  cursor: pointer; transition: transform .05s, background .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 6px 10px; font-size: .85rem; border-radius: 8px; }
.btn.lg { padding: 14px 26px; font-size: 1.1rem; border-radius: 12px; }
.btn.ghost { background: transparent; border-color: transparent; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; font-weight: 600; font-size: .85rem; color: var(--ink-2); margin: 10px 0 4px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }

/* ── KPI ─────────────────────────────── */
.kpi .label { color: var(--muted); font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 2rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: .8rem; }

/* ── Tables ─────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.badge.live { color: #fff; background: var(--bad); border-color: var(--bad); }
.badge.run { color: #fff; background: var(--good); border-color: var(--good); }
.badge.done { color: var(--muted); }

/* ── Quiz cards ─────────────────────── */
.quiz-card { display: flex; flex-direction: column; gap: 10px; padding: 0; overflow: hidden; }
.quiz-card .cover { height: 70px; display: flex; align-items: flex-end; padding: 10px 14px; color: #fff; font-weight: 800; font-size: 1.05rem; }
.quiz-card .body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.quiz-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }

/* ── Modal ─────────────────────────── */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 5, 25, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 18px; padding: 22px; width: min(520px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.share-qr { width: 100%; max-width: 280px; display: block; margin: 8px auto; border-radius: 12px; background: #fff; padding: 8px; }
.pin-big { font-size: 2.2rem; font-weight: 900; letter-spacing: .12em; text-align: center; font-variant-numeric: tabular-nums; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: .85rem; }

/* ── Toast ─────────────────────────── */
#toasts { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; max-width: 340px; }
.toast.error { background: var(--bad); color: #fff; }

/* ── Editor ────────────────────────── */
.q-card { position: relative; }
.q-card .q-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.q-num { background: var(--brand); color: #fff; border-radius: 8px; padding: 2px 10px; font-weight: 800; }
.ans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; margin-top: 8px; }
.ans-edit { display: flex; align-items: center; gap: 8px; border-radius: 10px; padding: 6px 8px 6px 6px; color: #fff; }
.ans-edit input[type=text] { background: rgba(255,255,255,.95); color: #1b1035; border: 0; }
.ans-edit .shape { width: 34px; text-align: center; font-size: 1.2rem; }
.ans-edit .correct { display: flex; align-items: center; gap: 4px; font-size: .9rem; font-weight: 700; cursor: pointer; white-space: nowrap; margin: 0; color: #fff; }
.ans-edit .correct input { width: 18px; height: 18px; accent-color: #fff; }
.ans-edit .x { background: transparent; border: 0; color: #fff; cursor: pointer; font-size: 1.1rem; }
.sticky-actions { position: sticky; top: 62px; z-index: 10; background: var(--bg); padding: 10px 0; }

/* ── Game screens (anfitrión y jugador) ─────────────────────── */
body.game { background: linear-gradient(160deg, #2a0f6b 0%, #4b1fc7 55%, #6c3cf0 100%); color: #fff; min-height: 100vh; }
body.game .card { background: rgba(255,255,255,.96); color: #1b1035; border: 0; }
.game-top { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; gap: 12px; flex-wrap: wrap; }
.game-top .btn { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; }
.game-top .btn:hover { background: rgba(255,255,255,.25); }
.stage { max-width: 1200px; margin: 0 auto; padding: 8px 16px 40px; }
.lobby { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .lobby { grid-template-columns: 1fr; } }
.join-box { text-align: center; }
.join-box .pin { font-size: 3.4rem; font-weight: 900; letter-spacing: .1em; color: #1b1035; line-height: 1; font-variant-numeric: tabular-nums; }
.join-box img { width: 100%; max-width: 260px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: rgba(255,255,255,.95); color: #1b1035; padding: 8px 14px; border-radius: 99px; font-weight: 700; animation: pop .25s ease-out; cursor: default; }
.chip.off { opacity: .45; }
.chip.kick:hover { background: #ffd5da; text-decoration: line-through; cursor: pointer; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.q-text { background: #fff; color: #1b1035; border-radius: 14px; padding: 18px 22px; font-size: clamp(1.3rem, 3vw, 2.2rem); font-weight: 800; text-align: center; box-shadow: var(--shadow); }
.q-mid { display: grid; grid-template-columns: 110px 1fr 110px; align-items: center; gap: 16px; margin: 18px 0; min-height: 140px; }
.q-mid img { max-height: 280px; max-width: 100%; border-radius: 12px; justify-self: center; }
.timer { width: 96px; height: 96px; border-radius: 50%; background: #fff; color: #1b1035; display: grid; place-items: center; font-size: 2.2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.timer.low { background: #ffd5da; color: var(--bad); }
.counter { text-align: center; font-weight: 800; font-size: 1.6rem; }
.counter small { display: block; font-size: .8rem; font-weight: 600; opacity: .8; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; align-items: center; gap: 14px; padding: 18px 20px; border-radius: 12px; color: #fff; font-weight: 800;
  font-size: clamp(1rem, 2vw, 1.5rem); min-height: 80px; border: 0; text-align: left; box-shadow: inset 0 -5px 0 rgba(0,0,0,.18);
  font-family: inherit; transition: opacity .2s, transform .1s;
}
.tile .shape { font-size: 1.6em; width: 1.3em; text-align: center; flex: none; }
.tile .txt { flex: 1; }
.tile .cnt { background: rgba(0,0,0,.2); border-radius: 8px; padding: 2px 10px; font-variant-numeric: tabular-nums; }
.tile.dim { opacity: .3; }
.tile .ok { font-size: 1.4em; }
button.tile { cursor: pointer; }
button.tile:hover { transform: scale(1.015); }
.bars { display: flex; align-items: flex-end; justify-content: center; gap: 14px; height: 170px; }
.bar { width: 64px; border-radius: 8px 8px 0 0; position: relative; min-height: 6px; transition: height .5s ease-out; }
.bar span { position: absolute; top: -26px; left: 0; right: 0; text-align: center; font-weight: 800; }
.bar.dim { opacity: .35; }
.lb { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.lb-row { display: flex; align-items: center; gap: 12px; background: #fff; color: #1b1035; border-radius: 12px; padding: 12px 18px; font-weight: 700; font-size: 1.15rem; animation: pop .3s ease-out; }
.lb-row .pos { width: 34px; font-weight: 900; color: var(--brand); }
.lb-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sc { font-variant-numeric: tabular-nums; }
.podium { display: flex; justify-content: center; align-items: flex-end; gap: 12px; margin: 30px 0; }
.podium .step { width: min(200px, 30vw); text-align: center; }
.podium .block { background: #fff; color: #1b1035; border-radius: 12px 12px 0 0; display: grid; place-items: center; font-size: 2.4rem; font-weight: 900; }
.podium .who { font-weight: 800; font-size: 1.2rem; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .pts { opacity: .85; font-weight: 600; margin-bottom: 8px; }
.center-msg { text-align: center; padding: 40px 16px; }
.center-msg .big { font-size: clamp(1.6rem, 6vw, 2.6rem); font-weight: 900; margin: 10px 0; }
.result-banner { border-radius: 16px; padding: 30px 16px; text-align: center; font-weight: 900; font-size: 2rem; }
.result-banner.ok { background: var(--good); }
.result-banner.bad { background: var(--bad); }
.result-banner.neutral { background: rgba(255,255,255,.18); }
.player-bar { display: flex; justify-content: space-between; align-items: center; background: rgba(0,0,0,.2); padding: 10px 16px; font-weight: 700; position: fixed; bottom: 0; left: 0; right: 0; }
.player-bar .sc { background: #fff; color: #1b1035; border-radius: 8px; padding: 2px 10px; }
.play-wrap { max-width: 720px; margin: 0 auto; padding: 16px 16px 80px; }
.play-q { font-size: 1.25rem; font-weight: 800; text-align: center; margin: 8px 0 16px; }
.progress { height: 8px; background: rgba(255,255,255,.2); border-radius: 99px; overflow: hidden; margin-bottom: 12px; }
.progress > div { height: 100%; background: #fff; transition: width .25s linear; }
@media (max-width: 560px) {
  .tiles { grid-template-columns: 1fr; }
  .play-wrap .tiles { grid-template-columns: 1fr 1fr; }
  .play-wrap .tile { min-height: 110px; flex-direction: column; justify-content: center; text-align: center; font-size: 1rem; }
  .q-mid { grid-template-columns: 70px 1fr 70px; }
  .timer { width: 64px; height: 64px; font-size: 1.5rem; }
  .bar { width: 40px; }
}

/* ── Landing ─────────────────────── */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.hero-card { width: min(420px, 100%); text-align: center; }
.hero-card h1 { font-size: 2.6rem; font-weight: 900; color: #fff; margin-bottom: 18px; }
.hero-card input { text-align: center; font-size: 1.3rem; font-weight: 800; padding: 14px; }
.hero-card .btn { width: 100%; margin-top: 10px; }

/* Chart containers */
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.data-table { margin-top: 8px; }
.data-table summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
