:root {
    --red: #e10600;
    --red-dark: #8d0000;
    --gold: #ffe14a;
    --ink: #141414;
    --font-display: "Oswald", Impact, "Arial Narrow", sans-serif;
    --font-ui: "Barlow Condensed", "Arial Narrow", "Segoe UI", sans-serif;
    --row: 56px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; min-height: 100%; }

body {
    font-family: var(--font-ui);
    color: #fff;
    background: #070910;
}

button, input { font-family: inherit; }

button { cursor: pointer; }

.scene {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(0, 0, 0, .48) 0%, rgba(0, 0, 0, .22) 38%, rgba(0, 0, 0, .5) 100%),
        url("fondo.jpg") center center / cover no-repeat;
    background-color: #070910;
}

.scene::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0, 0, 0, .18), transparent 28%, rgba(0, 0, 0, .28));
}

.crowd {
    position: absolute;
    left: 0;
    right: 0;
    top: 46%;
    height: 16%;
    background-image:
        radial-gradient(circle at 8px 10px, #ff5a5a 1.6px, transparent 2.2px),
        radial-gradient(circle at 20px 16px, #ffd15a 1.6px, transparent 2.2px),
        radial-gradient(circle at 32px 8px, #6eb6ff 1.6px, transparent 2.2px),
        radial-gradient(circle at 14px 22px, #f3f3f3 1.4px, transparent 2px);
    background-size: 40px 30px;
    opacity: .45;
    mask-image: linear-gradient(180deg, transparent, #000 20%, #000 80%, transparent);
}

.lights::before,
.lights::after {
    content: "";
    position: absolute;
    top: -10%;
    width: 34%;
    height: 70%;
    background: linear-gradient(180deg, rgba(255, 244, 210, .2), transparent 72%);
    filter: blur(4px);
}

.lights::before { left: 8%; transform: skewX(-18deg); }
.lights::after { right: 8%; transform: skewX(18deg); }

.road {
    position: absolute;
    left: -20%;
    right: -20%;
    bottom: -30px;
    height: 190px;
    background: repeating-conic-gradient(#1a1a1a 0% 25%, #d9d9d9 0% 50%) 0 0 / 46px 46px;
    transform: perspective(520px) rotateX(58deg);
    transform-origin: center bottom;
    opacity: .55;
}

.hero-car {
    position: absolute;
    right: 2%;
    bottom: 18px;
    width: min(340px, 46vw);
    z-index: 1;
    filter: drop-shadow(0 16px 12px rgba(0, 0, 0, .45));
    pointer-events: none;
}

.crowd,
.lights,
.road,
.hero-car { display: none; }

.topbar, .flash, .toolbar, .panel, .board, .modal, .mute-btn, .confetti { position: relative; z-index: 2; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 112px;
    padding: 10px 150px;
    background: linear-gradient(180deg, rgba(0, 0, 0, .78), rgba(0, 0, 0, .42));
    border-bottom: 4px solid var(--red);
    overflow: hidden;
}

.flag {
    position: absolute;
    top: 0;
    width: 150px;
    height: 100%;
    background: repeating-conic-gradient(#111 0% 25%, #f4f4f4 0% 50%) 0 0 / 22px 22px;
}

.flag.left { left: 0; clip-path: polygon(0 0, 100% 0, 58% 100%, 0 100%); }
.flag.right { right: 0; clip-path: polygon(42% 0, 100% 0, 100% 100%, 0 100%); }

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1;
}

.logo-copa,
.logo-racing {
    margin: 0;
    font-family: var(--font-display);
    line-height: .82;
    letter-spacing: 1px;
}

.logo-copa {
    font-size: 46px;
    font-weight: 700;
    text-shadow: 0 3px 0 #000;
}

.logo-racing {
    font-size: 58px;
    color: #ff2a2a;
    font-style: italic;
    text-shadow: 0 4px 0 #6a0000, 0 10px 16px rgba(0, 0, 0, .45);
}

.gauge { width: 92px; height: 70px; margin-left: 6px; }

.flash {
    background: #4a0c0c;
    color: #fff;
    text-align: center;
    padding: 10px 16px;
    font-weight: 700;
    letter-spacing: .3px;
    border-bottom: 2px solid var(--red);
}

.panel {
    width: min(1040px, calc(100% - 28px));
    margin: 22px auto 48px;
    padding: 26px;
    background: rgba(8, 10, 18, .78);
    border: 2px solid rgba(255, 255, 255, .16);
    border-radius: 24px;
    box-shadow: 0 24px 50px rgba(0, 0, 0, .35);
    backdrop-filter: blur(8px);
}

.steps {
    display: flex;
    gap: 8px;
    list-style: none;
    margin: 0 0 22px;
    padding: 0;
}

.steps li {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .08);
    font-size: 14px;
    letter-spacing: .6px;
    text-transform: uppercase;
}

.steps li.is-on { background: var(--red); }
.steps li.is-current { box-shadow: inset 0 0 0 2px #fff; }

.admin-links {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin: 0 0 16px;
}

.login-form {
    display: grid;
    gap: 14px;
    max-width: 440px;
    margin: 8px auto 0;
}

.login-form label {
    display: grid;
    gap: 6px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: .4px;
}

.login-form input {
    border: 3px solid var(--red);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    font-size: 20px;
    font-weight: 700;
    padding: 12px 14px;
}

.panel h1, .side h1 {
    font-family: var(--font-display);
    font-size: 40px;
    margin: 0 0 6px;
    letter-spacing: .5px;
}

.lede {
    margin: 0 0 18px;
    font-size: 22px;
    color: rgba(255, 255, 255, .86);
}

.counter {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin: 10px 0 16px;
}

.step-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: linear-gradient(#ff3b30, #b00000);
    color: #fff;
    font-size: 40px;
    line-height: 1;
    box-shadow: 0 5px 0 var(--red-dark);
}

.step-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--red-dark); }

#countInput {
    width: 150px;
    border: 0;
    background: transparent;
    color: #fff;
    font-family: var(--font-display);
    font-size: 92px;
    text-align: center;
    line-height: .9;
}

#countInput:focus { outline: none; }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.presets, .actions, .plan, .toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.presets, .plan { justify-content: center; margin-bottom: 16px; }

.preset, .plan-pill, .btn {
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, .55);
    background: rgba(0, 0, 0, .35);
    color: #fff;
    font-weight: 700;
    letter-spacing: .4px;
}

.preset {
    padding: 8px 14px;
    font-size: 16px;
}

.preset.is-on, .plan-pill {
    background: var(--red);
    border-color: #fff;
}

.plan-pill {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 7px 12px;
    border-radius: 14px;
    line-height: 1.05;
}

.plan-pill small { color: var(--gold); font-size: 12px; }

.arrow { color: var(--gold); font-size: 22px; }

.hint {
    text-align: center;
    color: rgba(255, 255, 255, .8);
    margin: 0 0 18px;
    font-size: 18px;
}

.actions { justify-content: center; margin-top: 8px; }

.btn {
    border-radius: 14px;
    padding: 12px 18px;
    font-size: 18px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(#ff3b30, #c40000);
    border: 3px solid #fff;
    box-shadow: 0 6px 0 var(--red-dark), 0 12px 20px rgba(0, 0, 0, .28);
    text-transform: uppercase;
    font-family: var(--font-display);
    letter-spacing: 1px;
}

.btn-xl { min-width: 240px; min-height: 58px; font-size: 26px; padding: 12px 28px; }

.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--red-dark); }
.btn-primary:disabled { opacity: .65; cursor: wait; transform: none; }

.btn-ghost { background: rgba(0, 0, 0, .4); }

.btn:disabled { opacity: .45; cursor: not-allowed; }

.name-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.name-field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, .06);
    border-radius: 14px;
    padding: 6px;
}

.name-field .num {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    flex: 0 0 auto;
}

.name-field input {
    width: 100%;
    min-width: 0;
    border: 3px solid var(--red);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    font-size: 18px;
    font-weight: 700;
    padding: 10px 12px;
}

.roulette-layout {
    display: grid;
    grid-template-columns: minmax(260px, 460px) minmax(0, 1fr);
    gap: 28px;
    align-items: center;
}

.wheel-wrap {
    position: relative;
    width: min(460px, 100%);
    margin: 0 auto;
}

#wheel {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    display: block;
    filter: drop-shadow(0 16px 24px rgba(0, 0, 0, .45));
}

.pointer {
    position: absolute;
    top: -4px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    width: 0;
    height: 0;
    border-left: 14px solid transparent;
    border-right: 14px solid transparent;
    border-top: 28px solid #ff2a2a;
    filter: drop-shadow(0 2px 0 #fff);
}

.side h1 { font-size: 34px; }

.vs-list { max-height: 460px; overflow: auto; padding-right: 4px; }

.vs-card {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
    background: #fff;
    color: var(--ink);
    border: 3px solid var(--red);
    border-radius: 14px;
    padding: 8px 10px;
    margin-bottom: 8px;
}

.vs-card.bye { grid-template-columns: 1fr auto; border-style: dashed; border-color: var(--gold); }

.vs-card .car {
    font-family: var(--font-display);
    text-transform: uppercase;
    font-size: 18px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vs-card .car.right { text-align: right; }

.vs-card .badge {
    background: var(--red);
    color: #fff;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 13px;
    font-weight: 800;
}

.vs-card.bye .badge { background: #111; color: var(--gold); }

body.phase-bracket,
body.phase-bracket.is-pantalla {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    padding: 8px 14px;
    background: rgba(0, 0, 0, .45);
    flex-wrap: wrap;
}

.toolbar p { margin: 0; font-size: 18px; }

.live {
    display: inline-block;
    background: var(--red);
    border-radius: 999px;
    padding: 2px 8px;
    margin-right: 8px;
    font-size: 13px;
    letter-spacing: 1px;
}

.board {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 12px 16px 28px;
    background: rgba(0, 0, 0, .22);
}

.bracket {
    display: flex;
    align-items: flex-start;
    width: max-content;
    min-width: 100%;
    padding-bottom: 12px;
}

.round {
    width: 268px;
    flex: 0 0 268px;
    display: flex;
    flex-direction: column;
}

.round:first-child { width: 308px; flex-basis: 308px; }
.round.champion-round { width: 230px; flex-basis: 230px; }

.round-head-wrap {
    height: 86px;
    display: flex;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.round-head {
    flex: 1;
    min-width: 0;
    background: linear-gradient(#ff2d2d, #b40000);
    border: 3px solid #fff;
    border-radius: 14px;
    text-align: center;
    padding: 6px 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, .28);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.round.is-active .round-head { box-shadow: 0 0 0 3px var(--gold), 0 8px 16px rgba(0, 0, 0, .28); }

.round-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 15px;
    letter-spacing: .4px;
    line-height: 1.05;
}

.round-head .range {
    margin: 2px 0 0;
    color: var(--gold);
    font-weight: 800;
    font-size: 13px;
}

.round-head .sub {
    margin: 0;
    font-size: 11px;
    letter-spacing: .4px;
}

.arm-spacer { width: 34px; flex: 0 0 34px; }

.round-matches {
    height: max(340px, calc(var(--players) * var(--row)));
    display: flex;
    flex-direction: column;
}

.tie {
    flex: var(--w) 1 0%;
    display: flex;
    min-height: 0;
    min-width: 0;
}

.tie.is-spacer {
    visibility: hidden;
}

.tie-players {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.competitor {
    flex: var(--cw) 1 0%;
    display: flex;
    align-items: center;
    min-width: 0;
    min-height: 0;
}

.slot-line {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-width: 0;
}

.seed {
    width: 28px;
    flex: 0 0 28px;
    text-align: center;
    font-family: var(--font-display);
    font-size: 20px;
    text-shadow: 0 2px 2px rgba(0, 0, 0, .85);
}

.slot-form { flex: 1; min-width: 0; margin: 0; }

.slot {
    width: 100%;
    height: 44px;
    border: 3px solid var(--red);
    border-radius: 12px;
    background: #fff;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    text-align: left;
    box-shadow: 0 3px 0 rgba(0, 0, 0, .28);
    position: relative;
}

.slot .name {
    font-family: var(--font-display);
    text-transform: uppercase;
    font-size: 16px;
    letter-spacing: .2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--car, var(--red));
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .12);
    flex: 0 0 auto;
}

.slot.can-win { cursor: pointer; }
.slot.can-win:hover, .slot.is-picking {
    border-color: var(--gold);
    background: #fff8dc;
    transform: translateY(-1px);
}

.slot.is-winner {
    border-color: var(--gold);
    background: linear-gradient(#fff, #fff3bf);
}

.slot.is-loser {
    opacity: .4;
    filter: grayscale(.35);
    border-color: #777;
}

.slot.is-empty {
    background: rgba(255, 255, 255, .14);
    color: rgba(255, 255, 255, .88);
    border-style: dashed;
    box-shadow: none;
}

.slot .pase, .slot .tick {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    font-weight: 800;
    background: #111;
    color: var(--gold);
    border-radius: 999px;
    padding: 2px 6px;
}

.slot.has-pase .name, .slot.is-winner .name { padding-right: 46px; }

.arm {
    position: relative;
    width: 34px;
    flex: 0 0 34px;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .85));
}

.arm::before {
    content: "";
    position: absolute;
    left: -3px;
    width: 22px;
    top: calc(var(--c1) * 100%);
    height: calc((var(--c2) - var(--c1)) * 100%);
    border: 4px solid #fff;
    border-left: 0;
    border-radius: 0 12px 12px 0;
    box-sizing: border-box;
}

.arm::after {
    content: "";
    position: absolute;
    left: 17px;
    right: -3px;
    top: 50%;
    height: 4px;
    background: #fff;
    transform: translateY(-2px);
}

.arm.straight::before { display: none; }
.arm.straight::after { left: 0; }

.vs-float {
    position: absolute;
    top: 50%;
    left: -6px;
    transform: translateY(-50%);
    background: var(--red);
    color: #fff;
    border: 2px solid #fff;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    padding: 1px 5px;
    z-index: 2;
    pointer-events: none;
}

.champ-anchor { position: relative; width: 100%; }

.trophy-float {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: max-content;
    pointer-events: none;
}

.trophy {
    width: 148px;
    height: auto;
    filter: drop-shadow(0 10px 10px rgba(0, 0, 0, .45));
}

.champ-banner {
    margin-top: -8px;
    background: linear-gradient(#ff3b30, #a10000);
    color: #fff;
    border: 2px solid #fff;
    border-radius: 8px;
    padding: 3px 12px;
    font-family: var(--font-display);
    letter-spacing: 1px;
}

.champ-slot { justify-content: center; }
.champ-slot .name { text-align: center; }

.champion-round.has-champ .champ-slot {
    box-shadow: 0 0 0 3px rgba(255, 225, 74, .45), 0 3px 0 rgba(0, 0, 0, .28);
}

.class-wrap {
    width: min(720px, 100%);
    margin: 0 auto;
}

.class-wrap h1 {
    margin: 0 0 6px;
    font-family: var(--font-display);
    letter-spacing: .4px;
}

.class-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0 18px;
    background: rgba(0, 0, 0, .45);
    border-radius: 14px;
    overflow: hidden;
}

.class-table th,
.class-table td {
    padding: 8px 10px;
    text-align: left;
}

.class-table th {
    font-size: 12px;
    letter-spacing: .4px;
    color: var(--gold);
}

.class-table .is-in td:first-child { color: #b7f5c4; }
.class-table .is-out { opacity: .45; }

.class-wrap .vs-card {
    display: flex;
    align-items: center;
    gap: 8px;
}

.class-wrap .slot-form,
.class-wrap .slot { flex: 1; }

.third-under {
    margin: 16px 34px 0 0;
    padding: 10px 10px 12px;
    border: 3px solid #e8a15a;
    border-radius: 16px;
    background: rgba(8, 10, 16, .78);
}

.third-under h3 {
    margin: 0;
    text-align: center;
    font-family: var(--font-display);
    font-size: 16px;
    letter-spacing: .4px;
    color: #e8a15a;
}

.third-under p {
    margin: 2px 0 8px;
    text-align: center;
    font-size: 12px;
    line-height: 1.3;
    color: rgba(255, 255, 255, .82);
}

.third-under.is-ready {
    box-shadow: 0 0 0 3px rgba(232, 161, 90, .45);
}

.third-card,
.podium {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.podium-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.place-tag {
    width: 36px;
    flex: 0 0 36px;
    font-family: var(--font-display);
    font-size: 18px;
    text-align: center;
}

.place-1 .place-tag { color: #ffe14a; }
.place-2 .place-tag { color: #f2f2f2; }
.place-3 .place-tag { color: #e8a15a; }

.podium-row .slot { height: 40px; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(0, 0, 0, .68);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
}

.modal-card {
    width: min(480px, 100%);
    background: #141821;
    border: 3px solid var(--red);
    border-radius: 20px;
    padding: 22px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}

.modal-card::before {
    content: "";
    display: block;
    height: 16px;
    margin: -22px -22px 16px;
    border-radius: 16px 16px 0 0;
    background: repeating-conic-gradient(#111 0% 25%, #eee 0% 50%) 0 0 / 16px 16px;
}

.modal-kicker {
    margin: 0 0 8px;
    color: var(--gold);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 800;
}

#modalText {
    margin: 0 0 18px;
    font-size: 26px;
    line-height: 1.25;
    font-family: var(--font-display);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.spin-overlay {
    position: fixed;
    inset: 0;
    z-index: 35;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, .35);
    font-family: var(--font-display);
    font-size: 42px;
    letter-spacing: 1px;
    text-shadow: 0 4px 0 #000;
    pointer-events: none;
}

.mute-btn {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 30;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: rgba(0, 0, 0, .7);
    color: #fff;
    font-size: 20px;
}

.confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 45;
}

.confetti i {
    position: absolute;
    top: -12px;
    width: 8px;
    height: 14px;
    animation-name: fall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

@keyframes fall {
    to { transform: translateY(105vh) rotate(360deg); }
}

.board::-webkit-scrollbar { height: 12px; width: 12px; }
.board::-webkit-scrollbar-thumb { background: var(--red); border-radius: 99px; }
.board::-webkit-scrollbar-track { background: rgba(0, 0, 0, .35); }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

@media (max-width: 800px) {
    .flag { display: none; }
    .topbar { padding: 12px; min-height: 92px; }
    .logo-copa { font-size: 32px; }
    .logo-racing { font-size: 40px; }
    .gauge { width: 64px; }
    .name-grid, .roulette-layout { grid-template-columns: 1fr; }
    .panel h1 { font-size: 32px; }
    #countInput { font-size: 72px; }
    .toolbar { align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
    .slot.can-win:hover, .btn-primary:hover { transform: none; }
    .confetti { display: none; }
}

@media print {
    .scene, .toolbar, .mute-btn, .modal, .flash, .flag { display: none !important; }
    body { background: #fff; color: #000; }
    .slot { box-shadow: none; }
}
