:root {
  --bg: #0f1b2d;
  --bg-2: #16263d;
  --card: #1d3150;
  --line: #2c4569;
  --text: #f3efe6;
  --muted: #a9b6c9;
  --gold: #e8b64c;
  --ok: #3fbf7f;
  --bad: #e5604f;
  --opt-0: #2f9e9a;
  --opt-1: #d98a2b;
  --opt-2: #c4566b;
  --opt-3: #6f63c9;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: radial-gradient(1200px 600px at 50% -10%, #23406a 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--gold); }

.wrap { max-width: 720px; margin: 0 auto; padding: 20px 16px 40px; }
.wrap.wide { max-width: 1100px; }

.brand {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-weight: 700; letter-spacing: .02em; color: var(--muted); font-size: 14px;
  margin-bottom: 18px;
}
.brand b { color: var(--gold); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}

h1 { font-size: 28px; margin: 0 0 8px; }
h2 { font-size: 22px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.hidden { display: none !important; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }

input[type=text], input[type=number], select {
  width: 100%;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  outline: none;
}
input:focus, select:focus { border-color: var(--gold); }
input.code { letter-spacing: .3em; text-align: center; font-weight: 700; font-size: 28px; }

button {
  font: inherit; font-weight: 700; font-size: 18px;
  border: 0; border-radius: 12px; padding: 14px 22px;
  background: var(--gold); color: #1b1405; cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
button:hover { filter: brightness(1.06); }
button:active { transform: scale(.98); }
button:disabled { opacity: .45; cursor: default; transform: none; }
button.ghost { background: transparent; color: var(--text); border: 2px solid var(--line); }
button.block { width: 100%; }

.error { color: var(--bad); min-height: 1.4em; font-weight: 600; }

/* ---------- options ---------- */
.options { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .options { grid-template-columns: 1fr 1fr; } }

.opt {
  display: flex; align-items: center; gap: 14px;
  text-align: left; color: #fff;
  min-height: 72px; padding: 14px 16px;
  border-radius: 14px; font-size: 19px;
  position: relative; overflow: hidden;
}
.opt .letter {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800;
  background: rgba(0,0,0,.22);
}
.opt[data-i="0"] { background: var(--opt-0); }
.opt[data-i="1"] { background: var(--opt-1); }
.opt[data-i="2"] { background: var(--opt-2); }
.opt[data-i="3"] { background: var(--opt-3); }
.opt.dim { opacity: .35; }
.opt.chosen { outline: 4px solid #fff; outline-offset: 2px; }
.opt.correct { outline: 4px solid var(--ok); outline-offset: 2px; opacity: 1; }
.opt .count {
  margin-left: auto; font-weight: 800; font-size: 22px;
  background: rgba(0,0,0,.25); padding: 2px 12px; border-radius: 999px;
}
.opt .bar {
  position: absolute; left: 0; bottom: 0; height: 6px; background: rgba(255,255,255,.65);
  transition: width .6s ease;
}

.question-text { font-size: 24px; font-weight: 700; }
.host .question-text { font-size: 34px; }
.host .opt { font-size: 24px; min-height: 90px; }

.pill {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); font-size: 14px; font-weight: 600;
}

/* ---------- feedback ---------- */
.result {
  border-radius: var(--radius); padding: 22px; text-align: center;
}
.result.ok { background: rgba(63,191,127,.18); border: 2px solid var(--ok); }
.result.bad { background: rgba(229,96,79,.15); border: 2px solid var(--bad); }
.result.none { background: var(--bg-2); border: 2px solid var(--line); }
.result .big { font-size: 30px; font-weight: 800; }

.explain {
  background: var(--bg-2); border-left: 4px solid var(--gold);
  border-radius: 12px; padding: 16px;
}
.explain .ref { font-weight: 800; color: var(--gold); }
.links { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.links a {
  text-decoration: none; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 15px;
}

.score-badge { font-size: 15px; color: var(--muted); }
.score-badge b { color: var(--gold); font-size: 20px; }

/* ---------- leaderboard ---------- */
.board { list-style: none; padding: 0; margin: 0; }
.board li {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 12px; background: var(--bg-2);
  border: 1px solid var(--line); margin-bottom: 8px; font-size: 18px;
}
.board li.me { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.board .pos { width: 34px; font-weight: 800; color: var(--muted); }
.board li:nth-child(-n+3) .pos { color: var(--gold); }
.board .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 800; }
.board .off { font-size: 12px; color: var(--muted); }

/* ---------- podium ---------- */
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin: 10px 0 20px; }
.podium .step {
  width: 30%; max-width: 180px; text-align: center; border-radius: 12px 12px 0 0;
  background: var(--card); border: 1px solid var(--line); padding: 12px 6px;
}
.podium .step .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.podium .step .medal { font-size: 34px; }
.podium .p1 { height: 190px; border-color: var(--gold); }
.podium .p2 { height: 150px; }
.podium .p3 { height: 120px; }

/* ---------- host lobby ---------- */
.lobby { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .lobby { grid-template-columns: 360px 1fr; } }
.qr { width: 100%; max-width: 320px; border-radius: 12px; background: #fff; padding: 8px; display: block; margin: 0 auto; }
.room-code { font-size: 64px; font-weight: 900; letter-spacing: .12em; color: var(--gold); line-height: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line);
  font-weight: 600; display: inline-flex; gap: 8px; align-items: center;
}
.chip.off { opacity: .5; }
.chip button { padding: 0 6px; font-size: 14px; background: transparent; color: var(--muted); }

.progress { height: 10px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--gold); transition: width .3s ease; }

.waiting-dot::after { content: '…'; animation: dots 1.5s steps(4) infinite; display: inline-block; width: 1em; text-align: left; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0 } 100% { width: 1em } }

/* ---------- timer ---------- */
.timer { display: flex; align-items: center; gap: 14px; }
.timer-num {
  flex: none; width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center; font-size: 24px; font-weight: 900;
  background: var(--bg-2); border: 3px solid var(--gold); color: var(--gold);
}
.timer-track { flex: 1; height: 12px; background: var(--bg-2); border-radius: 999px; overflow: hidden; }
.timer-bar { height: 100%; background: var(--gold); transition: width .1s linear; }
.timer.low .timer-num { border-color: var(--bad); color: var(--bad); animation: pulse 1s ease-in-out infinite; }
.timer.low .timer-bar { background: var(--bad); }
.host .timer-num { width: 84px; height: 84px; font-size: 38px; }
@keyframes pulse { 50% { transform: scale(1.08); } }

.timeup { text-align: center; font-weight: 800; font-size: 20px; color: var(--bad); }
.fastest { text-align: center; font-weight: 700; color: var(--gold); }

/* ---------- admin ---------- */
textarea {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; resize: vertical;
  border-radius: 12px; border: 2px solid var(--line); background: var(--bg-2); color: var(--text); outline: none;
}
textarea:focus { border-color: var(--gold); }
select:disabled { opacity: .6; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }

.admin { display: grid; gap: 24px; grid-template-columns: 1fr; align-items: start; }
@media (min-width: 980px) {
  .admin { grid-template-columns: 1fr 460px; }
  .admin-form { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
}
.admin-form input[type=text], .admin-form input[type=number], .admin-form select { font-size: 17px; padding: 11px 14px; }

.qlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.qlist li {
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
  padding: 12px 14px; border-radius: 12px; background: var(--bg-2); border: 1px solid var(--line);
}
.qlist li:hover, .qlist li:focus-visible { border-color: var(--muted); outline: none; }
.qlist li.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.qlist li.empty { cursor: default; color: var(--muted); justify-content: center; }
.qn { flex: none; width: 28px; color: var(--muted); font-weight: 800; text-align: right; }
.qbody { min-width: 0; }
.qtext { font-weight: 600; }
.qmeta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.qref { color: var(--gold); }

.opt-row { display: flex; gap: 10px; align-items: center; }
.opt-row + .opt-row { margin-top: 8px; }
.opt-correct { margin: 0; cursor: pointer; position: relative; }
.opt-correct input { position: absolute; opacity: 0; pointer-events: none; }
.opt-correct .letter {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center;
  font-weight: 800; color: #fff; opacity: .55; border: 3px solid transparent;
}
.opt-correct .letter[data-i="0"] { background: var(--opt-0); }
.opt-correct .letter[data-i="1"] { background: var(--opt-1); }
.opt-correct .letter[data-i="2"] { background: var(--opt-2); }
.opt-correct .letter[data-i="3"] { background: var(--opt-3); }
.opt-correct input:checked + .letter { opacity: 1; border-color: var(--ok); }
.opt-correct input:checked + .letter::after { content: '✓'; position: absolute; right: -6px; top: -6px; background: var(--ok); color: #fff; border-radius: 50%; width: 20px; height: 20px; font-size: 13px; display: grid; place-items: center; }
.opt-correct input:focus-visible + .letter { outline: 2px solid var(--gold); outline-offset: 2px; }

fieldset.ref { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px 14px; margin: 0; }
fieldset.ref legend { color: var(--muted); font-size: 14px; padding: 0 6px; }
.ref-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.ref-grid .span-2 { grid-column: 1 / -1; }
.ref-preview { margin-top: 10px; font-size: 15px; }

/* ---------- categorias e dificuldade ---------- */
.pill.diff-facil { color: #7fe0ad; border-color: rgba(63,191,127,.5); }
.pill.diff-medio { color: #f1c56b; border-color: rgba(232,182,76,.5); }
.pill.diff-dificil { color: #f08a7c; border-color: rgba(229,96,79,.5); }
.qtags { display: flex; gap: 6px; margin-bottom: 4px; }
.qtags .pill { font-size: 12px; padding: 2px 9px; }

.filters { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .filters { grid-template-columns: 1fr 190px 190px; } }
.filters input, .filters select { font-size: 16px; padding: 11px 14px; }

.class-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 520px) { .class-grid { grid-template-columns: 1fr 1fr; } }

.segmented { display: flex; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg { flex: 1; margin: 0; cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 11px 4px; font-weight: 700; color: var(--muted); background: var(--bg-2); }
.seg + .seg span { border-left: 1px solid var(--line); }
.seg.diff-facil input:checked + span { background: var(--ok); color: #062214; }
.seg.diff-medio input:checked + span { background: var(--gold); color: #1b1405; }
.seg.diff-dificil input:checked + span { background: var(--bad); color: #fff; }
.seg input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: -4px; }

.toggles { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { margin: 0; cursor: pointer; position: relative; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span {
  display: inline-block; padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: 15px;
  border: 2px solid var(--line); background: var(--bg-2); color: var(--muted);
}
.toggle small { opacity: .7; margin-left: 2px; }
.toggle input:checked + span { border-color: var(--gold); color: var(--text); background: rgba(232,182,76,.14); }
.toggle input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }

button.danger { color: var(--bad); border-color: var(--bad); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ok); color: #062214; font-weight: 800; padding: 10px 18px; border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
}

.conn { position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%); background: var(--bad); color: #fff; padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 700; }

.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin-top: 28px; }
