:root {
  color-scheme: dark;
  --bg: #050711;
  --panel: rgba(18, 22, 43, .92);
  --text: #f8f9ff;
  --muted: #97a1c4;
  --blue: #2589ff;
  --red: #ff4966;
  --yellow: #ffd447;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 50%, rgba(37,137,255,.24), transparent 35rem),
    radial-gradient(circle at 90% 50%, rgba(255,73,102,.22), transparent 35rem),
    var(--bg);
}
button, input { font: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }

.screen-app { height: 100dvh; display: flex; flex-direction: column; padding: clamp(12px, 2vh, 24px) clamp(16px, 2vw, 36px); }
.screen-header { flex: 0 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 18px; margin-bottom: clamp(10px, 1.5vh, 18px); }
.screen-header p { margin: 0 0 3px; color: #65e6ff; font-size: clamp(.55rem, .75vw, .72rem); font-weight: 900; letter-spacing: .2em; }
.screen-header h1 { margin: 0; font-size: clamp(1.25rem, 2.4vw, 2.25rem); letter-spacing: -.04em; }
.screen-header h1 span { display: block; margin-top: 4px; font-size: .42em; letter-spacing: .18em; color: var(--muted); }
.screen-code { text-align: center; padding: 8px 20px; border-radius: 14px; background: var(--panel); border: 1px solid rgba(255,255,255,.1); }
.screen-code span { display: block; color: var(--muted); font-size: .58rem; font-weight: 900; letter-spacing: .14em; }
.screen-code strong { font-size: clamp(1.25rem, 2vw, 1.8rem); letter-spacing: .18em; color: var(--yellow); }
.screen-actions { display: flex; justify-content: flex-end; gap: 8px; }
.screen-actions button { min-height: 40px; padding: 0 13px; border-radius: 11px; color: var(--muted); background: var(--panel); border: 1px solid rgba(255,255,255,.1); font-size: .62rem; font-weight: 900; letter-spacing: .06em; }

.versus-stage { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 82px minmax(0, 1fr); align-items: center; gap: clamp(12px, 2vw, 28px); }
.arena { min-width: 0; height: 100%; display: flex; flex-direction: column; padding: clamp(10px, 1.4vw, 18px); border-radius: 24px; background: rgba(14,18,35,.9); border: 1px solid rgba(255,255,255,.1); box-shadow: 0 24px 80px rgba(0,0,0,.42); }
.blue-arena { box-shadow: 0 24px 80px rgba(0,0,0,.42), 0 0 55px rgba(37,137,255,.12); }
.red-arena { box-shadow: 0 24px 80px rgba(0,0,0,.42), 0 0 55px rgba(255,73,102,.12); }
.arena > header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.arena > header span { color: var(--muted); font-size: .57rem; font-weight: 900; letter-spacing: .14em; }
.arena > header h2 { margin: 0; font-size: clamp(1.25rem, 2.4vw, 2.3rem); line-height: 1; }
.blue-arena h2 { color: #73b5ff; }
.red-arena h2 { color: #ff879a; }
.arena > header > strong { font-size: clamp(2rem, 4vw, 4.6rem); line-height: .9; color: var(--yellow); }
.arena-body { flex: 1 1 auto; min-height: 0; display: flex; justify-content: center; align-items: center; gap: clamp(10px, 1.5vw, 20px); }
.arena-body > canvas { height: min(100%, calc((100vw - 260px) * .77)); width: auto; max-width: calc(100% - 116px); aspect-ratio: 1 / 2; border-radius: 16px; border: 1px solid rgba(255,255,255,.13); background: #070a15; image-rendering: pixelated; }
.arena-side { width: 96px; display: grid; gap: 10px; }
.arena-side > div { padding: 10px 6px; border-radius: 13px; text-align: center; background: var(--panel); border: 1px solid rgba(255,255,255,.08); }
.arena-side span { display: block; color: var(--muted); font-size: .52rem; font-weight: 900; letter-spacing: .1em; }
.arena-side strong { display: block; margin-top: 3px; font-size: 1.35rem; }
.next-box canvas { display: block; width: 78px; height: 78px; margin: 2px auto -4px; }
.arena > footer { flex: 0 0 auto; margin-top: 10px; min-height: 32px; display: grid; place-items: center; border-radius: 10px; color: var(--muted); background: rgba(255,255,255,.04); font-size: .62rem; font-weight: 900; letter-spacing: .1em; }
.blue-arena > footer.is-ready { color: #8bc1ff; background: rgba(37,137,255,.11); }
.red-arena > footer.is-ready { color: #ff9bab; background: rgba(255,73,102,.11); }
.arena > footer.is-out { color: #fff; background: rgba(255,255,255,.12); }

.versus-center { text-align: center; }
.versus-center strong { display: grid; place-items: center; width: 70px; height: 70px; margin: 0 auto; border-radius: 50%; color: #100d02; background: var(--yellow); font-size: 1.7rem; box-shadow: 0 0 45px rgba(255,212,71,.25); }
.versus-center p { margin: 14px -10px 0; color: var(--muted); font-size: .6rem; font-weight: 900; letter-spacing: .08em; line-height: 1.45; }

.screen-modal, .winner-modal { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(3,5,12,.86); backdrop-filter: blur(12px); }
.modal-card { width: min(460px, 100%); padding: 34px; border-radius: 24px; text-align: center; background: linear-gradient(180deg, rgba(26,31,59,.98), rgba(13,17,34,.98)); border: 1px solid rgba(255,255,255,.12); box-shadow: 0 28px 90px rgba(0,0,0,.56); }
.modal-card p, .winner-card p { margin: 0 0 8px; color: #65e6ff; font-size: .65rem; font-weight: 900; letter-spacing: .18em; }
.modal-card h2 { margin: 0 0 20px; font-size: 1.6rem; }
.modal-card input { width: 100%; height: 62px; border-radius: 14px; border: 1px solid rgba(255,255,255,.15); outline: 0; color: var(--text); background: rgba(4,7,16,.9); text-align: center; font-size: 1.8rem; font-weight: 950; letter-spacing: .24em; text-transform: uppercase; }
.modal-card input:focus { border-color: #65e6ff; box-shadow: 0 0 0 3px rgba(101,230,255,.12); }
.modal-card button { width: 100%; min-height: 50px; margin-top: 11px; border: 0; border-radius: 13px; color: #171203; background: var(--yellow); font-weight: 950; letter-spacing: .06em; }
.modal-card small { display: block; min-height: 1.3em; margin-top: 10px; color: #ff91a4; }
.modal-card a { display: inline-block; margin-top: 12px; color: var(--muted); text-decoration: none; font-size: .65rem; font-weight: 900; letter-spacing: .08em; }

.winner-modal { background: rgba(3,5,12,.74); }
.winner-card { min-width: min(560px, 90vw); padding: 42px; border-radius: 30px; text-align: center; background: rgba(15,19,38,.96); border: 1px solid rgba(255,255,255,.15); box-shadow: 0 30px 110px rgba(0,0,0,.65); }
.winner-card h2 { margin: 4px 0; font-size: clamp(2.7rem, 7vw, 6rem); line-height: 1; }
.winner-card h2.blue { color: #5faaff; text-shadow: 0 0 35px rgba(37,137,255,.38); }
.winner-card h2.red { color: #ff7189; text-shadow: 0 0 35px rgba(255,73,102,.38); }
.winner-card span { color: var(--yellow); font-size: clamp(.8rem, 1.4vw, 1.2rem); font-weight: 950; letter-spacing: .22em; }

@media (max-width: 1000px) {
  .screen-actions button:first-child { display: none; }
  .screen-header { grid-template-columns: 1fr auto auto; }
  .versus-stage { grid-template-columns: minmax(0,1fr) 58px minmax(0,1fr); gap: 10px; }
  .arena-side { width: 72px; }
  .arena-body > canvas { max-width: calc(100% - 84px); }
  .next-box canvas { width: 58px; height: 58px; }
  .versus-center strong { width: 52px; height: 52px; font-size: 1.25rem; }
}

@media (max-height: 700px) {
  .screen-app { padding-top: 8px; padding-bottom: 8px; }
  .screen-header { margin-bottom: 7px; }
  .screen-code { padding-block: 5px; }
  .arena { padding: 9px; border-radius: 18px; }
  .arena > header { margin-bottom: 5px; }
  .arena > footer { margin-top: 5px; min-height: 26px; }
  .arena-side { gap: 6px; }
  .arena-side > div { padding: 7px 4px; }
}

/* Detección automática de partida */
.auto-status {
  margin: -8px 0 18px;
  padding: 13px 15px;
  border-radius: 13px;
  color: var(--muted);
  background: rgba(101,230,255,.07);
  border: 1px solid rgba(101,230,255,.14);
  font-size: .82rem;
  line-height: 1.45;
}
.auto-status strong { color: #65e6ff; }
.manual-code { padding-top: 4px; border-top: 1px solid rgba(255,255,255,.08); }
.manual-code > span {
  display: block;
  margin: 15px 0 9px;
  color: var(--muted);
  font-size: .66rem;
  font-weight: 800;
  letter-spacing: .05em;
}
