* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); font-family: var(--font-body);
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(122, 90, 48, .45), transparent),
    radial-gradient(800px 500px at 100% 10%, rgba(176, 48, 42, .16), transparent),
    var(--felt-deep);
}
button, input { font: inherit; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 1500px; margin: 0 auto; padding: 18px 24px 8px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .logo { width: 50px; height: 50px; display: block; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5)); }
.brand .logo svg { width: 100%; height: 100%; }
.brand b { display: block; font: 900 28px/1 var(--font-display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.brand small { display: block; font-size: 13px; letter-spacing: .5em; text-transform: uppercase; color: var(--muted); margin-top: 3px; }
.pills { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12); }
.pill::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #777; }
.pill.on::before { background: #37d67a; box-shadow: 0 0 8px #37d67a; }
.pill.off::before { background: #e5484d; }
.pill.warn::before { background: var(--gold); }
.icon-btn { border: 1px solid rgba(255, 255, 255, .18); background: rgba(255, 255, 255, .07); color: var(--ink); border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer; }
.icon-btn:hover { background: rgba(255, 255, 255, .14); }

/* ---------- Distribucion ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; max-width: 1760px; margin: 0 auto; padding: 10px 24px 48px; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }
.top { max-width: 1760px; }

.screen-frame {
  padding: 8px; border-radius: 26px; background: linear-gradient(160deg, var(--gold-light), var(--gold) 40%, var(--gold-dark));
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55), 0 0 0 1px rgba(0, 0, 0, .4);
}
#screen { aspect-ratio: 16 / 9; width: 100%; border-radius: 19px; overflow: hidden; }

.controls { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 18px; }
.btn { border: 2px solid var(--gold-dark); border-radius: 14px; padding: 12px 22px; font-weight: 800; font-size: 16px; cursor: pointer; transition: transform .12s, filter .12s, box-shadow .12s; }
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.gold { background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, var(--gold-dark)); color: #2a1d00; }
.btn.ghost { background: rgba(255, 255, 255, .06); color: var(--ink); border-color: rgba(255, 255, 255, .22); }
.btn.go { background: linear-gradient(180deg, #ff5a63, var(--red) 60%, #8c1418); color: #fff; border-color: #ffb3b7; font-size: 20px; letter-spacing: .1em; padding: 12px 40px; margin-left: auto; box-shadow: 0 0 26px rgba(230, 57, 70, .45); }
.btn.go:disabled { box-shadow: none; }
.btn.small { padding: 7px 14px; font-size: 14px; border-radius: 10px; }
.note { min-height: 24px; margin-top: 10px; font-size: 15px; color: var(--gold); }
.how { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.how b { color: var(--ink); }

/* ---------- Panel lateral ---------- */
.side { display: grid; gap: 14px; }
.panel { background: rgba(255, 255, 255, .045); border: 1px solid rgba(245, 197, 66, .22); border-radius: 18px; padding: 16px 18px; backdrop-filter: blur(6px); }
.panel h2 { margin: 0 0 12px; font-size: 13px; letter-spacing: .28em; text-transform: uppercase; color: var(--gold); display: flex; align-items: center; gap: 10px; }
.badge { background: var(--gold); color: #2a1d00; border-radius: 999px; padding: 1px 10px; font-size: 12px; letter-spacing: 0; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.phead-btn { margin-left: auto; padding: 4px 12px; font-size: 12px; letter-spacing: 0; text-transform: none; }

.games { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.game {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px 12px;
  border-radius: 14px; border: 2px solid rgba(255, 255, 255, .12); background: rgba(0, 0, 0, .25); color: var(--muted); cursor: pointer; font-weight: 700; font-size: 14px;
  transition: border-color .15s, background .15s, color .15s;
}
.game svg.ic { width: 46px; height: 46px; opacity: .55; transition: opacity .15s; }
.game[aria-pressed="true"] { border-color: var(--gold); background: rgba(245, 197, 66, .1); color: var(--ink); }
.game[aria-pressed="true"] svg.ic { opacity: 1; }
.game:hover:not(:disabled) { background: rgba(255, 255, 255, .09); }
.game:disabled { cursor: not-allowed; opacity: .6; }
.game .demo {
  position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; cursor: pointer; padding: 0;
  background: rgba(255, 255, 255, .12); color: var(--ink); display: grid; place-items: center;
}
.game .demo:hover:not(:disabled) { background: var(--gold); color: #2a1d00; }
.game .demo:disabled { opacity: .35; cursor: not-allowed; }
.game .demo svg { width: 12px; height: 12px; fill: currentColor; margin-left: 2px; }

.stepper { display: inline-flex; align-items: center; border: 2px solid var(--gold-dark); border-radius: 14px; overflow: hidden; }
.stepper button { width: 48px; height: 44px; border: 0; background: rgba(245, 197, 66, .15); color: var(--gold); font-size: 24px; font-weight: 800; cursor: pointer; }
.stepper button:hover:not(:disabled) { background: rgba(245, 197, 66, .3); }
.stepper button:disabled { opacity: .35; cursor: not-allowed; }
.stepper output { min-width: 64px; text-align: center; font: 900 26px var(--font-display); color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow: auto; }
.chip { background: rgba(255, 255, 255, .1); border-radius: 999px; padding: 3px 12px; font-size: 13px; }
.chip.test { border: 1px dashed var(--gold); }
.empty { color: var(--muted); font-size: 14px; }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history li { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.history time { color: var(--muted); font-variant-numeric: tabular-nums; }
.history b { color: var(--gold); }
.history small { grid-column: 2; color: var(--muted); }
.history li { display: block; padding: 8px 0; border-top: 1px solid rgba(255, 255, 255, .07); }
.history li:first-child { border-top: 0; padding-top: 0; }
.history li.empty { color: var(--muted); }
.history time { display: block; font-size: 12px; margin-bottom: 4px; }
.history .hw { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.history .hw b { font-size: 15px; }
.history .hw i { font-style: normal; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 8px; border-radius: 99px; }
.history .hw i.ok { background: rgba(64, 192, 96, .18); color: #60e080; }
.history .hw i.no { background: rgba(255, 80, 80, .16); color: #ff7060; }
.history .paid { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.history .paid input { accent-color: #40c060; }
.history li > small { display: block; margin-top: 3px; font-size: 12px; line-height: 1.4; }
.history li > small b { color: var(--ink); font-weight: 700; }
.rk-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 3px; margin-bottom: 8px; border-radius: 10px; background: rgba(0, 0, 0, .3); }
.rk-tabs button { padding: 6px 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.rk-tabs button.on { background: var(--gold); color: #1a1208; }
.rk-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.rk-nav b { color: var(--ink); text-align: center; }
.rk-nav button { width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(245, 197, 66, .3); background: rgba(0, 0, 0, .3); color: var(--gold); font-size: 20px; line-height: 1; cursor: pointer; }
.rk-nav button:disabled { opacity: .3; cursor: default; }
.hint.warn { color: #ffb070; }
.field { display: grid; gap: 6px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.field input, .field select { width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid rgba(245, 197, 66, .3); background: rgba(0, 0, 0, .35); color: var(--ink); font: inherit; font-size: 14px; }
.field select option { background: #1a1220; }


.tools summary { cursor: pointer; font-size: 13px; letter-spacing: .28em; text-transform: uppercase; color: var(--gold); font-weight: 700; }
.tools-body { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; }
input { background: rgba(0, 0, 0, .35); border: 2px solid rgba(255, 255, 255, .18); color: var(--ink); border-radius: 10px; padding: 9px 12px; min-width: 0; }
input:focus { outline: none; border-color: var(--gold); }
#obs-url { flex: 1; font-size: 13px; }

/* ---------- Ventana de clave ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(0, 0, 0, .7); backdrop-filter: blur(4px); padding: 16px; }
.modal-box { width: min(420px, 100%); background: #180a3a; border: 2px solid var(--gold); border-radius: 20px; padding: 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, .7); }
.modal-box h2 { margin: 0 0 6px; font: 900 26px var(--font-display); color: var(--gold); }
.modal-box input { width: 100%; margin-top: 14px; }
code { background: rgba(255, 255, 255, .1); padding: 1px 6px; border-radius: 6px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); border: 2px solid var(--gold-dark); border-radius: 14px; overflow: hidden; }
.seg button { border: 0; padding: 11px 4px; background: rgba(255, 255, 255, .05); color: var(--muted); font-weight: 800; cursor: pointer; border-right: 1px solid rgba(245, 197, 66, .25); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: linear-gradient(180deg, var(--gold-light), var(--gold) 55%, var(--gold-dark)); color: #2a1d00; }
.seg button:disabled { opacity: .45; cursor: not-allowed; }
.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: r; }
.ranking li { counter-increment: r; display: grid; grid-template-columns: 26px 1fr auto auto; gap: 10px; align-items: baseline; font-size: 14px; }
.ranking li::before { content: counter(r); color: var(--muted); font-weight: 800; text-align: right; }
.ranking li b { color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking li span { font-variant-numeric: tabular-nums; color: var(--ink); }
.ranking li.empty { display: block; color: var(--muted); }
.ranking li.empty::before { content: none; }
.chip.new { animation: chipNew 1.6s ease-out; }
@keyframes chipNew { 0% { background: rgba(96, 224, 128, .7); transform: scale(1.15); } 100% { background: rgba(255, 255, 255, .1); transform: scale(1); } }
/* podio del ranking */
.ranking li:nth-child(1)::before { content: '1'; color: #1a1208; background: #f0c040; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; justify-self: end; }
.ranking li:nth-child(2)::before { content: '2'; color: #1a1208; background: #c8ccd4; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; justify-self: end; }
.ranking li:nth-child(3)::before { content: '3'; color: #1a1208; background: #d08a4a; border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; justify-self: end; }
.ranking li.empty::before { content: none !important; }
/* barra de estado grande */
.status-bar { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; padding: 14px 22px; border-radius: 16px; border: 2px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .05); transition: background .3s, border-color .3s; }
.status-bar .sb-dot { width: 16px; height: 16px; border-radius: 50%; background: #888; flex: none; }
.status-bar .sb-text { display: grid; gap: 4px; }
.status-bar .sb-text b { font-size: 22px; letter-spacing: .06em; text-transform: uppercase; }
.status-bar .sb-text small { color: var(--muted); font-size: 14px; }
.status-bar .sb-count { margin-left: auto; text-align: right; display: grid; }
.status-bar .sb-count strong { font-size: 40px; line-height: 1; color: var(--gold); display: inline-block; }
.status-bar .sb-count strong.bump { animation: sbBump .45s cubic-bezier(.2, 1.6, .4, 1); }
.status-bar .sb-count small { color: var(--muted); font-size: 12px; letter-spacing: .2em; text-transform: uppercase; }
.status-bar.open { background: rgba(60, 200, 110, .14); border-color: rgba(60, 200, 110, .6); }
.status-bar.open .sb-dot { background: #3cd070; box-shadow: 0 0 0 0 rgba(60, 208, 112, .7); animation: sbPing 1.4s infinite; }
.status-bar.draw { background: rgba(230, 57, 70, .16); border-color: rgba(230, 57, 70, .7); }
.status-bar.draw .sb-dot { background: #ff4a55; animation: sbPing 0.9s infinite; }
@keyframes sbPing { 0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .55); } 100% { box-shadow: 0 0 0 14px rgba(255, 255, 255, 0); } }
@keyframes sbBump { 40% { transform: scale(1.35); } }
/* SORTEAR late cuando se puede usar */
.btn.go:not(:disabled) { animation: goPulse 1.6s ease-in-out infinite; }
@keyframes goPulse { 50% { box-shadow: 0 0 44px rgba(255, 90, 99, .85); transform: translateY(-1px) scale(1.03); } }
/* ranking: el primero con corona y fila dorada */
.ranking li.top1 { padding: 8px 10px; margin: -2px -6px 4px; border-radius: 10px; background: linear-gradient(90deg, rgba(240, 192, 64, .28), rgba(240, 192, 64, .05)); font-size: 16px; }
.ranking li.top1 b::before { content: ''; display: inline-block; width: 18px; height: 14px; margin-right: 6px; vertical-align: -1px;
  background: #f0c040; clip-path: polygon(0 100%, 0 20%, 25% 55%, 50% 0, 75% 55%, 100% 20%, 100% 100%); }
