:root {
  --bg: #0f0a1a;
  --bg2: #1a1129;
  --card: #221735;
  --card2: #2b1e43;
  --line: #3a2b57;
  --text: #f3ecff;
  --muted: #b3a5cc;
  --orange: #ff7a1a;
  --orange2: #ffb347;
  --purple: #9b5de5;
  --green: #4ade80;
  --red: #f87171;
  --star-off: #4a3a66;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(155, 93, 229, .35), transparent 45%),
    radial-gradient(circle at 110% 10%, rgba(255, 122, 26, .22), transparent 40%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.45;
}
a { color: var(--orange2); }
h1, h2, h3 { line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: clamp(1.6rem, 6vw, 2.3rem); }
h2 { font-size: 1.25rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 10, 26, .85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); text-decoration: none; font-weight: 800; display: flex; gap: 8px; align-items: center; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: flex; gap: 8px; flex-shrink: 0; }
.topnav a, .topnav button {
  font: inherit; font-size: .9rem; color: var(--muted); text-decoration: none;
  background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer;
}
.topnav a:hover, .topnav button:hover { color: var(--text); border-color: var(--purple); }

.wrap { max-width: 560px; margin: 0 auto; padding: 20px 16px 40px; }
.wrap.wide { max-width: 1100px; }
.foot { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; }

.card {
  background: linear-gradient(180deg, var(--card), var(--bg2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.eyebrow { text-transform: uppercase; letter-spacing: .12em; font-size: .75rem; color: var(--orange2); margin: 0 0 6px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--red); font-weight: 600; }
.big-emoji { font-size: 3.5rem; text-align: center; line-height: 1; margin-bottom: 8px; }

.flash { border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-weight: 600; }
.flash.ok { background: rgba(74, 222, 128, .12); border: 1px solid rgba(74, 222, 128, .4); color: var(--green); }
.flash.error { background: rgba(248, 113, 113, .12); border: 1px solid rgba(248, 113, 113, .4); color: var(--red); }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  border-radius: 12px; padding: 12px 18px; border: 1px solid var(--line);
  background: var(--card2); color: var(--text);
  transition: transform .08s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, var(--orange), #ff4d00); border: none; color: #1a0b00; }
.btn.primary:disabled { opacity: .4; cursor: not-allowed; }
.btn.danger { background: rgba(248, 113, 113, .15); border-color: rgba(248, 113, 113, .5); color: var(--red); }
.btn.sm { padding: 7px 11px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; padding: 16px; font-size: 1.1rem; }

/* Formularios */
label.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: .9rem; }
label.field input, label.field textarea, label.field select {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; /* evita zoom en iOS */
  color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px;
}
label.field input:focus, label.field textarea:focus, label.field select:focus { outline: 2px solid var(--purple); border-color: transparent; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-weight: 600; }
.check input { width: 22px; height: 22px; accent-color: var(--orange); }

/* Estrellas */
.stars { display: flex; justify-content: center; gap: 4px; margin: 18px 0 6px; user-select: none; }
.stars input { position: absolute; opacity: 0; pointer-events: none; }
.stars label {
  font-size: clamp(2.8rem, 14vw, 3.6rem); line-height: 1; cursor: pointer;
  color: var(--star-off); transition: transform .12s ease, color .12s ease, text-shadow .12s;
  padding: 2px; -webkit-tap-highlight-color: transparent;
}
.stars label.on { color: var(--orange); text-shadow: 0 0 18px rgba(255, 122, 26, .6); }
.stars label.pop { transform: scale(1.25); }
.stars input:focus-visible + label { outline: 2px solid var(--purple); border-radius: 8px; }
.stars.static span { font-size: 2.4rem; color: var(--star-off); }
.stars.static span.on { color: var(--orange); }
.rating-label { text-align: center; font-size: 1.15rem; font-weight: 700; min-height: 1.6em; margin: 0 0 16px; color: var(--orange2); }

.progress { margin-top: 8px; color: var(--muted); }
.progress-bar { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--purple), var(--orange)); }

/* Inicio */
.hero { text-align: center; padding: 30px 20px; }
.hero .big-emoji { font-size: 4.5rem; }
.steps { list-style: none; padding: 0; margin: 0; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.steps li::before {
  content: counter(s); flex: 0 0 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 800; background: var(--orange); color: #1a0b00;
}
.house-list { list-style: none; padding: 0; margin: 0; }
.house-list li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.house-list li:last-child { border-bottom: none; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 1.7rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.leader {
  text-align: center; padding: 24px 20px;
  background: linear-gradient(135deg, rgba(255, 122, 26, .22), rgba(155, 93, 229, .22));
  border: 1px solid rgba(255, 122, 26, .5);
}
.leader .trophy { font-size: 3.2rem; line-height: 1; }
.leader h2 { font-size: clamp(1.5rem, 6vw, 2.2rem); margin: 8px 0 4px; }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 8px; align-items: end; margin-bottom: 16px; }
.podium .p { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 14px 14px 6px 6px; padding: 12px 6px; min-width: 0; }
.podium .p .medal { font-size: 1.9rem; }
.podium .p .n { font-weight: 800; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.podium .p .v { color: var(--orange2); font-weight: 800; font-size: 1.2rem; margin-top: 4px; }
.podium .p1 { padding-top: 22px; padding-bottom: 26px; border-color: rgba(255, 179, 71, .6); }
.podium .p2 { padding-bottom: 16px; }

.tabs { display: flex; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; font: inherit; font-weight: 700; border: none; border-radius: 9px; padding: 10px; background: none; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--orange); color: #1a0b00; }

.rank { list-style: none; padding: 0; margin: 0; }
.rank li { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); }
.rank li:last-child { border-bottom: none; }
.rank .pos { font-weight: 800; font-size: 1.1rem; color: var(--muted); text-align: center; }
.rank .info { min-width: 0; }
.rank .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .sub { color: var(--muted); font-size: .8rem; }
.rank .score { text-align: right; font-weight: 800; font-size: 1.25rem; color: var(--orange2); }
.rank .score small { display: block; color: var(--muted); font-weight: 500; font-size: .72rem; }
.dist { display: flex; height: 6px; border-radius: 99px; overflow: hidden; margin-top: 6px; background: var(--card2); }
.dist i { display: block; height: 100%; }
.dist .d1 { background: #6b3fa0; } .dist .d2 { background: #9b5de5; } .dist .d3 { background: #c77dff; }
.dist .d4 { background: #ffb347; } .dist .d5 { background: #ff7a1a; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: .75rem; color: var(--muted); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; background: var(--c); }
.updated { color: var(--muted); font-size: .8rem; text-align: center; margin-top: 10px; }

/* Admin */
.grid2 { display: grid; gap: 16px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li { padding: 14px 0; border-bottom: 1px solid var(--line); }
.admin-list li:last-child { border-bottom: none; }
.admin-list .row { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.admin-list .nm { font-weight: 800; }
.admin-list .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.admin-list form { display: inline; }
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }
.pill.on { background: rgba(74, 222, 128, .15); color: var(--green); }
.pill.off { background: rgba(248, 113, 113, .15); color: var(--red); }
.kpis { display: flex; gap: 14px; font-size: .85rem; color: var(--muted); }
.kpis b { color: var(--text); }
.warn { background: rgba(255, 179, 71, .12); border: 1px solid rgba(255, 179, 71, .45); color: var(--orange2); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .9rem; }
details summary { cursor: pointer; font-weight: 700; }
code { background: var(--bg); padding: 2px 6px; border-radius: 6px; font-size: .85em; word-break: break-all; }
.qr-preview { background: #fff; border-radius: 12px; padding: 10px; width: 200px; max-width: 100%; display: block; margin: 10px auto; }

/* Multi-residencial */
.res-link { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); }
.res-link:hover b { color: var(--orange2); }
.inline-pwd { display: inline-flex !important; gap: 6px; align-items: center; }
.inline-pwd input { font: inherit; font-size: 16px; width: 170px; max-width: 45vw; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; }
@media (max-width: 560px) {
  .topnav .lbl { display: none; }
  .topnav { gap: 6px; }
  .topnav a, .topnav button { padding: 6px 10px; }
}

/* Fecha de votación */
.estado { border-radius: 12px; padding: 10px 14px; margin: 6px 0 12px; font-size: .9rem; border: 1px solid var(--line); background: var(--card); }
.estado-abierta { border-color: rgba(74, 222, 128, .45); }
.estado-pendiente { border-color: rgba(255, 179, 71, .45); }
.estado-terminada, .estado-cerrada { border-color: rgba(248, 113, 113, .4); }
.fecha-voto { font-size: 1.05rem; margin: 6px 0; }
.fecha-voto b { color: var(--orange2); }

/* Votos sospechosos */
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--red); color: #1a0505; font-size: .75rem; font-weight: 800; text-align: center; }
.btn.alerta { border-color: rgba(248, 113, 113, .6); }
.pill.warnpill { background: rgba(255, 179, 71, .15); color: var(--orange2); }
.chip { display: inline-block; background: var(--card2); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; margin: 2px 4px 2px 0; font-size: .78rem; }
.chip.anul { color: var(--red); border-color: rgba(248, 113, 113, .4); }
.tvotos { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: .82rem; }
.tvotos th, .tvotos td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tvotos input { width: 18px; height: 18px; accent-color: var(--red); }
.tvotos tr.anulado td { opacity: .5; text-decoration: line-through; }
.tvotos tr.anulado td:first-child, .tvotos tr.anulado td:last-child { text-decoration: none; }
.grupo details { overflow-x: auto; }
