:root {
  --ink: #1E1E1E; --paper: #FFFFFF; --soft: #F4F4F1;
  --c0: #FED7D7; --c1: #C3ECF6; --c2: #FFE79C; --c3: #C1F8C0;
  --muted: #6B6B6B; --bad: #C62828; --good: #1B7F3B;
  --r: 22px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--ink); color: var(--ink); -webkit-font-smoothing: antialiased; }
main { min-height: 100vh; display: flex; flex-direction: column; gap: 14px; padding: 16px; max-width: 1400px; margin: 0 auto; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.15; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-weight: 600; min-height: 1.2em; }

.brand { display: flex; align-items: center; gap: 10px; color: var(--paper); font-weight: 700; font-size: 15px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; background: var(--c2); }

.card { background: var(--paper); border-radius: var(--r); padding: 22px; }
.center { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; }
.big { font-size: 64px; line-height: 1; margin-bottom: 10px; }
.card.good { background: var(--c3); }
.card.bad { background: var(--c0); }
.card.winner { background: var(--c2); }
.code { font: 700 44px/1 ui-monospace, "Roboto Mono", monospace; letter-spacing: 6px; background: var(--paper); padding: 14px 20px; border-radius: 14px; margin-top: 8px; }

.join { display: flex; flex-direction: column; gap: 12px; max-width: 420px; width: 100%; margin: 8vh auto 0; }
input { font: inherit; font-size: 20px; padding: 14px 16px; border-radius: 14px; border: 2px solid #D6D6D0; background: var(--soft); width: 100%; }
input:focus { outline: 3px solid var(--c1); border-color: var(--ink); }
.btn { font: inherit; font-weight: 700; font-size: 18px; border: 0; border-radius: 999px; padding: 14px 22px; cursor: pointer; background: var(--soft); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); }
.card .btn.primary { background: var(--ink); }
.btn.ghost { background: transparent; color: inherit; border: 2px solid currentColor; }
.btn.sm { font-size: 15px; padding: 9px 16px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .opt:focus-visible, .chip:focus-visible { outline: 3px solid var(--c2); outline-offset: 3px; }

.status { display: flex; justify-content: space-between; gap: 10px; color: var(--paper); font-weight: 600; }
.net { display: none; color: var(--c2); }
.net.show { display: inline; }
.bar { height: 10px; border-radius: 999px; background: #3A3A3A; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c2); transition: width .2s linear; }
.qmini { color: var(--paper); font-size: 15px; margin: 0; }
.secs { display: inline-block; min-width: 2ch; font-weight: 700; color: var(--c2); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; flex: 1; }
.grid.n2 { grid-template-columns: 1fr 1fr; }
.opt { border: 0; border-radius: var(--r); font: inherit; color: var(--ink); display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 120px; padding: 16px; cursor: pointer; position: relative; transition: transform .08s, opacity .2s; }
.opt:active { transform: scale(.97); }
.opt.c0 { background: var(--c0); } .opt.c1 { background: var(--c1); } .opt.c2 { background: var(--c2); } .opt.c3 { background: var(--c3); }
.opt .shape { font-size: 44px; line-height: 1; }
.opt:disabled { cursor: default; opacity: .35; }
.opt.picked { opacity: 1; outline: 4px solid var(--paper); }
.player .grid { min-height: 60vh; }

/* Host */
.host main { padding: 20px 28px; }
.hbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--paper); flex-wrap: wrap; }
.hpin { font-size: 18px; }
.hpin b { color: var(--c2); }
.hright { display: flex; gap: 10px; align-items: center; }
.pill { background: #333; padding: 8px 14px; border-radius: 999px; font-weight: 700; }
.lobby { background: var(--paper); border-radius: var(--r); padding: 32px; text-align: center; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.url { font-size: clamp(28px, 4vw, 52px); font-weight: 800; }
.pin { font: 800 clamp(64px, 11vw, 150px)/1 ui-monospace, "Roboto Mono", monospace; letter-spacing: .08em; background: var(--c2); border-radius: 26px; padding: 10px 30px; margin: 6px 0 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 1000px; margin-bottom: 18px; }
.chip { font: inherit; font-weight: 600; border: 0; background: var(--c1); padding: 8px 14px; border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--c0); text-decoration: line-through; }
.actions { display: flex; gap: 12px; }
.lobby .btn.ghost { color: var(--ink); }

.qwrap { background: var(--paper); border-radius: var(--r); padding: 26px 30px; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.qhead { display: flex; justify-content: space-between; align-items: center; }
.qn { font-weight: 700; color: var(--muted); }
.timer { font: 800 44px/1 ui-monospace, monospace; background: var(--c2); border-radius: 50%; width: 82px; height: 82px; display: grid; place-items: center; }
.qtext { font-size: clamp(26px, 3.2vw, 46px); }
.grid.big .opt { min-height: 110px; justify-content: flex-start; text-align: left; cursor: default; }
.grid.big .otext { font-size: clamp(18px, 1.9vw, 28px); font-weight: 650; flex: 1; }
.opt.dim { opacity: .35; }
.opt.right { outline: 5px solid var(--ink); }
.opt.right::after { content: "✔"; position: absolute; top: 10px; right: 16px; font-size: 28px; font-weight: 800; }
.count { display: flex; align-items: center; gap: 10px; min-width: 150px; }
.count i { display: block; height: 14px; border-radius: 999px; background: var(--ink); min-width: 4px; }
.count b { font-size: 24px; }
.explain { background: var(--soft); border-radius: 16px; padding: 14px 18px; font-size: 20px; }
.src { font-size: 14px; color: var(--muted); }

.board { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.board li { display: flex; align-items: center; gap: 14px; background: var(--soft); border-radius: 14px; padding: 12px 16px; font-size: 22px; }
.board li:nth-child(1) { background: var(--c2); } .board li:nth-child(2) { background: var(--c1); } .board li:nth-child(3) { background: var(--c0); }
.pos { font-weight: 800; width: 2ch; }
.nick { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pts { color: #444; font-size: 18px; }

.final { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; flex: 1; }
.final > div:first-child { background: var(--paper); border-radius: var(--r); padding: 26px 30px; }
.final .card { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.final label { font-size: 18px; display: flex; align-items: center; gap: 10px; }
.min { width: 90px; font-size: 20px; padding: 8px 10px; }
.raffle { width: 100%; min-height: 120px; display: flex; flex-direction: column; justify-content: center; }
.spin { font-size: clamp(32px, 4vw, 56px); font-weight: 800; background: var(--soft); border-radius: 18px; padding: 16px 20px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spin.win { background: var(--c2); animation: pop .5s ease-out; }
@keyframes pop { from { transform: scale(.8); } to { transform: scale(1); } }
.winners ol { margin: 4px 0 0; padding-left: 22px; font-size: 18px; }
code { font-family: ui-monospace, "Roboto Mono", monospace; font-weight: 700; }
.final .btn.ghost { color: var(--ink); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--c0); padding: 12px 18px; border-radius: 12px; font-weight: 600; }

@media (max-width: 900px) { .final { grid-template-columns: 1fr; } .grid.big { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.hbar .btn.primary { background: var(--c2); color: var(--ink); }

/* ---------- Laboratorio (celular) ---------- */
.lab main { max-width: 560px; }
.intro p { margin: 4px 0; }
.small { font-size: 14px; }
.mono { font-family: ui-monospace, "Roboto Mono", monospace; word-break: break-all; }
.lcard { border-radius: var(--r); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.lcard.c0 { background: var(--c0); } .lcard.c1 { background: var(--c1); } .lcard.c2 { background: var(--c2); } .lcard.c3 { background: var(--c3); }
.lhead { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lhead h2 { margin: 0; font-size: 20px; }
.ltag { font: 600 12px ui-monospace, monospace; background: var(--paper); border-radius: 999px; padding: 4px 10px; white-space: nowrap; }
.payload { display: block; background: var(--paper); border-radius: 12px; padding: 10px 12px; font-size: 15px; word-break: break-all; }
.lcard input { background: var(--paper); }
.result { background: var(--paper); border-radius: 14px; padding: 12px 14px; border-left: 8px solid #999; }
.result b { font-size: 17px; }
.result.ok { border-color: var(--good); } .result.blocked { border-color: var(--bad); } .result.limited { border-color: #E37400; }
.result p { margin: 4px 0; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; min-height: 18px; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: #999; }
.dot.ok { background: var(--good); } .dot.limited { background: #E37400; } .dot.blocked { background: var(--bad); }
.foot { color: #BDBDBD; text-align: center; }

/* ---------- Laboratorio (pantalla) ---------- */
.labgrid { display: grid; grid-template-columns: minmax(320px, 1fr) 2fr; gap: 18px; flex: 1; }
.qrbox { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.qr { width: min(340px, 100%); height: auto; image-rendering: pixelated; border-radius: 12px; }
.qrbox .url { font-size: clamp(20px, 2.2vw, 30px); margin-top: 10px; word-break: break-all; }
.counters { display: flex; flex-direction: column; gap: 10px; }
.cgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; flex: 1; }
.cnt { border-radius: 18px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; }
.cnt.c0 { background: var(--c0); } .cnt.c1 { background: var(--c1); } .cnt.c2 { background: var(--c2); } .cnt.c3 { background: var(--c3); }
.num { font: 800 clamp(40px, 5vw, 72px)/1 ui-monospace, monospace; }
.num.bump { animation: bump .5s ease-out; }
@keyframes bump { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
.clabel { font-weight: 700; font-size: 17px; margin-top: 8px; }
.stages { display: flex; gap: 6px; flex-wrap: wrap; }
.stage { font: inherit; font-weight: 700; border: 2px solid #555; background: transparent; color: var(--paper); border-radius: 999px; padding: 8px 14px; cursor: pointer; }
.stage.on { background: var(--c2); color: var(--ink); border-color: var(--c2); }
.counters .btn.ghost { color: var(--ink); align-self: flex-start; }
@media (max-width: 900px) { .labgrid { grid-template-columns: 1fr; } .cgrid { grid-template-columns: repeat(2, 1fr); } }

.result.preview { border-color: #E3B400; }
.envtag { display: inline-block; font: 700 12px ui-monospace, monospace; background: var(--soft); border-radius: 999px; padding: 2px 8px; margin-right: 8px; }
.out { display: flex; flex-direction: column; gap: 8px; }
.ctable { width: 100%; border-collapse: separate; border-spacing: 0 8px; }
.ctable th { text-align: left; font-size: 15px; color: var(--muted); padding: 0 12px; }
.ctable td { background: var(--soft); padding: 10px 12px; font-size: 18px; font-weight: 700; }
.ctable td:first-child { border-radius: 12px 0 0 12px; } .ctable td:last-child { border-radius: 0 12px 12px 0; }
.ctable td.n { font: 800 clamp(28px, 3.4vw, 48px)/1 ui-monospace, monospace; text-align: center; }
.ctable td.n.zero { color: var(--good); }
.ctable td.c0 { background: var(--c0); } .ctable td.c2 { background: var(--c2); } .ctable td.c3 { background: var(--c3); } .ctable td.c1 { background: var(--c1); }
.ctable td.n.bump { animation: bump .5s ease-out; }
.hsub { color: #BDBDBD; font-size: 15px; }
.labtitle { font-size: 22px; margin-bottom: 6px; }

/* Ráfaga por pulsaciones */
.tap { font-family: inherit; font-weight: 900; font-size: 30px; line-height: 1; letter-spacing: 3px; border: 0; border-radius: 22px; padding: 34px 0; background: var(--ink); color: var(--paper);
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; transition: transform .06s; }
.tap:active { transform: scale(.96); }
.tap:focus-visible { outline: 3px solid var(--c2); outline-offset: 3px; }
.tapsum { font-weight: 700; font-size: 15px; }
.tapok { background: var(--paper); border-radius: 12px; padding: 10px 12px; border-left: 6px solid #E37400; }
.ctable th.edgeh { color: var(--bad); }
.ctable td.n.edge { background: #fde3e1; color: var(--bad); }
