:root {
  --bg: #f4f2fb;
  --surface: #ffffff;
  --surface-2: #eeebf7;
  --text: #1d1730;
  --muted: #625b78;
  --border: #d9d4e8;
  --primary: #46178f;
  --primary-2: #6a2bd1;
  --on-primary: #ffffff;
  --ok: #1f8a3b;
  --bad: #c62839;
  --warn: #b87700;
  --o0: #e21b3c;
  --o1: #1368ce;
  --o2: #c98f00;
  --o3: #26890c;
  --o4: #864cbf;
  --o5: #0a8a8a;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30, 20, 60, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15111f;
    --surface: #211b30;
    --surface-2: #2b2440;
    --text: #f1edfa;
    --muted: #b3aac8;
    --border: #3b3354;
    --primary: #8b5cf6;
    --primary-2: #a57bff;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  min-height: 100vh;
}
a { color: var(--primary-2); }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .5em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: .75rem; }
.grow { flex: 1 1 auto; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 460px; margin: 0 auto; padding: 16px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

button, .btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  padding: .6em 1.1em;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .4em;
  justify-content: center;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
button.danger { background: transparent; color: var(--bad); border-color: var(--bad); }
button.ghost { background: transparent; }
button.big { font-size: 1.25rem; padding: .8em 1.4em; }
button.icon { padding: .4em .6em; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .6em .8em;
  width: 100%;
}
textarea { resize: vertical; min-height: 3em; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 3px solid var(--primary-2); outline-offset: 1px; }
label { display: block; font-weight: 600; margin-bottom: .3em; }
label.inline { display: inline-flex; align-items: center; gap: .4em; font-weight: 500; margin: 0; }
label.inline input { width: auto; }

.topbar {
  background: var(--primary);
  color: var(--on-primary);
  padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.topbar .brand { font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; }
.topbar a, .topbar button { color: var(--on-primary); }
.topbar button { background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.3); }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 700;
  padding: .15em .6em; border-radius: 999px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
}
.badge.quiz { color: var(--primary-2); }
.badge.survey { color: var(--o5); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .7em 1.2em; border-radius: 10px;
  z-index: 1000; max-width: calc(100vw - 32px); box-shadow: var(--shadow);
}
.toast.error { background: var(--bad); color: #fff; }

/* ---------- Colores de opciones ---------- */
.opt-0 { --oc: var(--o0); } .opt-1 { --oc: var(--o1); } .opt-2 { --oc: var(--o2); }
.opt-3 { --oc: var(--o3); } .opt-4 { --oc: var(--o4); } .opt-5 { --oc: var(--o5); }
.shape { font-size: 1.1em; line-height: 1; }

/* ---------- Alumno ---------- */
.player { min-height: 100vh; display: flex; flex-direction: column; }
.player header {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.player main { flex: 1; display: flex; flex-direction: column; padding: 16px; gap: 16px; }
.player .logo { font-size: 2.2rem; font-weight: 900; color: var(--primary-2); text-align: center; margin: 24px 0 8px; }
.pin-input { font-size: 1.8rem; text-align: center; letter-spacing: .25em; font-weight: 800; }
.answer-grid {
  flex: 1; display: grid; gap: 12px;
  grid-template-columns: 1fr 1fr; grid-auto-rows: minmax(110px, 1fr);
}
.answer-grid.one-col { grid-template-columns: 1fr; grid-auto-rows: minmax(70px, auto); }
.answer-btn {
  background: var(--oc); color: #fff; border: none; border-radius: var(--radius);
  font-size: 1.1rem; font-weight: 700; padding: 12px; flex-direction: column; gap: 8px;
  text-align: center; box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.answer-btn .shape { font-size: 2rem; }
.answer-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.answer-btn.chosen { outline: 4px solid var(--text); outline-offset: 3px; }
.answer-btn.dim { opacity: .35; }
.status-screen {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 14px; padding: 20px;
}
.status-screen .big-emoji { font-size: 4rem; line-height: 1; }
.status-screen.correct { background: var(--ok); color: #fff; border-radius: var(--radius); }
.status-screen.wrong { background: var(--bad); color: #fff; border-radius: var(--radius); }
.status-screen.neutral { background: var(--primary); color: #fff; border-radius: var(--radius); }
.status-screen h2 { font-size: 1.8rem; margin: 0; }
.player-question { font-size: 1.15rem; font-weight: 700; text-align: center; }
.timer-pill {
  background: var(--primary); color: #fff; border-radius: 999px; padding: .2em .8em; font-weight: 800;
  min-width: 3em; text-align: center;
}
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 5px solid rgba(255,255,255,.35); border-top-color: currentColor;
  animation: spin 1s linear infinite;
}
.status-screen:not(.neutral):not(.correct):not(.wrong) .spinner { border-color: var(--border); border-top-color: var(--primary-2); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pantalla del formador / proyección ---------- */
.stage { min-height: 100vh; display: flex; flex-direction: column; }
.stage-main { flex: 1; display: flex; flex-direction: column; padding: 20px clamp(16px, 3vw, 48px); gap: 20px; }
.stage-controls {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 16px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; z-index: 10;
}
.stage-controls .info { color: var(--muted); font-weight: 600; }
body.presenting .stage-controls { opacity: .15; transition: opacity .2s; }
body.presenting .stage-controls:hover, body.presenting .stage-controls:focus-within { opacity: 1; }

.lobby { display: grid; grid-template-columns: minmax(240px, 380px) 1fr; gap: 28px; align-items: start; }
.join-box { text-align: center; }
.join-box img { width: 100%; max-width: 340px; background: #fff; border-radius: 12px; padding: 8px; }
.join-box .url { font-size: clamp(1rem, 1.6vw, 1.4rem); font-weight: 700; word-break: break-all; }
.join-box .pin { font-size: clamp(2.4rem, 4.6vw, 4.4rem); font-weight: 900; letter-spacing: .04em; color: var(--primary-2); line-height: 1; }
.lobby-title { font-size: clamp(1.6rem, 3vw, 2.6rem); }
.player-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: .4em .9em; font-weight: 700; font-size: 1.05rem; display: inline-flex; gap: .4em; align-items: center;
}
.chip.off { opacity: .45; }
.chip button { padding: 0 .3em; border: none; background: none; color: var(--muted); font-size: 1rem; }
.count-big { font-size: 2rem; font-weight: 900; }

.q-head { display: flex; align-items: center; gap: 16px; justify-content: space-between; }
.q-text {
  font-size: clamp(1.5rem, 3.2vw, 3rem); font-weight: 800; text-align: center;
  background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.q-image { max-height: 32vh; max-width: 100%; object-fit: contain; align-self: center; border-radius: 10px; }
.q-middle { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.timer-circle {
  width: clamp(80px, 9vw, 130px); height: clamp(80px, 9vw, 130px); border-radius: 50%;
  background: var(--primary); color: #fff; display: grid; place-items: center;
  font-size: clamp(2rem, 4vw, 3.4rem); font-weight: 900; flex: none;
}
.timer-circle.low { background: var(--bad); }
.answers-count { text-align: center; font-weight: 800; }
.answers-count .n { font-size: clamp(2rem, 4vw, 3.4rem); display: block; line-height: 1; }
.stage-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.stage-option {
  background: var(--oc); color: #fff; border-radius: var(--radius);
  padding: 18px 20px; font-size: clamp(1.1rem, 2.2vw, 1.9rem); font-weight: 700;
  display: flex; align-items: center; gap: 14px; min-height: 80px;
}
.stage-option .shape { font-size: 1.4em; }
.stage-option.wrong { opacity: .3; }
.stage-options.compact { gap: 10px; }
.stage-options.compact .stage-option { min-height: 0; padding: 10px 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); }
.chart.compact { height: 26vh; min-height: 140px; }
.stage-option .tick { margin-left: auto; font-size: 1.4em; }

.chart { display: flex; align-items: flex-end; justify-content: center; gap: 18px; height: 34vh; min-height: 180px; }
.chart .bar-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; width: min(140px, 18%); gap: 6px; }
.chart .bar { width: 100%; background: var(--oc); border-radius: 10px 10px 0 0; min-height: 6px; transition: height .6s ease; }
.chart .bar.wrong { opacity: .35; }
.chart .bar-label { font-weight: 900; font-size: clamp(1.1rem, 2vw, 1.8rem); }
.chart .bar-foot { color: #fff; background: var(--oc); width: 100%; text-align: center; border-radius: 0 0 10px 10px; padding: 4px 0; }

.explanation {
  background: var(--surface); border-left: 6px solid var(--primary-2); border-radius: 10px;
  padding: 14px 18px; font-size: clamp(1rem, 1.6vw, 1.35rem);
}
.explanation strong { color: var(--primary-2); }

.cloud { display: flex; flex-wrap: wrap; gap: 8px 22px; justify-content: center; align-items: center; padding: 20px; min-height: 30vh; }
.cloud span { font-weight: 800; line-height: 1.1; }

.leaderboard { max-width: 800px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.lb-row {
  display: flex; align-items: center; gap: 14px; background: var(--surface); border-radius: 12px;
  padding: 12px 18px; font-size: clamp(1.1rem, 2vw, 1.6rem); font-weight: 700; box-shadow: var(--shadow);
}
.lb-row .pos { width: 2em; color: var(--muted); }
.lb-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .streak { font-size: .8em; color: var(--warn); }

.podium { display: flex; justify-content: center; align-items: flex-end; gap: 16px; margin: 10px 0 20px; }
.podium .step { text-align: center; width: min(220px, 30%); }
.podium .block { border-radius: 12px 12px 0 0; color: #fff; font-weight: 900; font-size: 2.4rem; display: grid; place-items: center; }
.podium .p1 .block { background: #d4a106; height: 200px; }
.podium .p2 .block { background: #8e9aa6; height: 150px; }
.podium .p3 .block { background: #b8733b; height: 110px; }
.podium .pname { font-weight: 800; font-size: clamp(1rem, 2vw, 1.6rem); margin-bottom: 6px; word-break: break-word; }
.podium .pscore { color: var(--muted); font-weight: 700; margin-bottom: 6px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button[aria-selected="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }

.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.summary-item h4 { margin: 0 0 .5em; font-size: 1.05rem; }
.mini-bars { display: flex; flex-direction: column; gap: 6px; }
.mini-bar { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: .9rem; }
.mini-bar .track { grid-column: 1 / -1; height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.mini-bar .fill { height: 100%; background: var(--oc); }
.mini-bar.correct .lbl::after { content: " ✓"; color: var(--ok); font-weight: 900; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; }
.kpi .v { font-size: 2rem; font-weight: 900; color: var(--primary-2); }
.kpi .l { color: var(--muted); font-weight: 600; font-size: .9rem; }
.pct { font-weight: 900; }
.pct.good { color: var(--ok); } .pct.mid { color: var(--warn); } .pct.low { color: var(--bad); }
.conclusions-text { font-size: clamp(1.05rem, 1.8vw, 1.5rem); white-space: pre-wrap; }

/* ---------- Editor ---------- */
.quiz-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.quiz-card { display: flex; flex-direction: column; gap: 8px; }
.quiz-card h3 { margin: 0; font-size: 1.15rem; }
.quiz-card .actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.q-editor { border-left: 6px solid var(--primary-2); }
.q-editor .opt-row { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.q-editor .opt-swatch { width: 30px; height: 30px; border-radius: 8px; background: var(--oc); color: #fff; display: grid; place-items: center; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table-wrap { overflow-x: auto; }

@media (max-width: 760px) {
  .lobby { grid-template-columns: 1fr; }
  .stage-options { grid-template-columns: 1fr; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .chart { gap: 8px; }
  .q-middle { flex-wrap: wrap; justify-content: center; }
}
