* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin:0;font-family: Lato,sans-serif;
    background:
        radial-gradient(circle at top, rgba(0,255,247,.08), transparent 34%),
        linear-gradient(180deg, #051312 0%, #071918 42%, #04100f 100%);
    min-height:100svh;
    overflow-x: hidden;
    overflow-y: auto;
    color: #dffcff
}

#wrap {
    min-height: 100svh;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 12px 20px;
}

#hud {
    width: min(980px,95vw);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.hud-group {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.hud-meta {
    flex: 1 1 420px;
    flex-wrap: wrap;
}

.hud-actions {
    flex: 0 0 auto;
    margin-left: auto;
    justify-content: flex-end;
}

.badge {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1px solid rgba(0,255,247,.35);
    border-radius: 12px;
    background:rgba(0,255,247,.06); box-shadow: 0 0 25px rgba(0,255,247,.15);
    white-space: nowrap;
}

#status {
    opacity: 0.9;
    min-width: 130px;
    text-align: center;
}

#score {
    min-width: 64px;
    text-align: center;
}

.arena-shell {
    position: relative;
    width: min(980px, 95vw);
    display: flex;
    justify-content: center;
    align-items: center;
    isolation: isolate;
    padding: 20px 0;
}

.arena-decor {
    position: absolute;
    inset: -12px -28px;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.arena-decor-item {
    position: absolute;
    display: block;
    font-size: clamp(24px, 3.8vw, 42px);
    opacity: .18;
    filter: grayscale(1) brightness(.42) drop-shadow(0 10px 22px rgba(0, 0, 0, .38));
    animation: arenaFloat 16s ease-in-out infinite;
    transform: translate3d(0, 0, 0);
    user-select: none;
}

.arena-decor-item.item-1 { top: 10%; left: 4%; animation-duration: 18s; }
.arena-decor-item.item-2 { top: 20%; left: 15%; animation-duration: 14s; animation-delay: -6s; }
.arena-decor-item.item-3 { top: 72%; left: 10%; animation-duration: 17s; animation-delay: -9s; }
.arena-decor-item.item-4 { top: 8%; right: 8%; animation-duration: 19s; animation-delay: -4s; }
.arena-decor-item.item-5 { top: 58%; right: 4%; animation-duration: 15s; animation-delay: -7s; }
.arena-decor-item.item-6 { bottom: 12%; right: 16%; animation-duration: 20s; animation-delay: -11s; }
.arena-decor-item.item-7 { bottom: 18%; left: 22%; animation-duration: 13s; animation-delay: -5s; }
.arena-decor-item.item-8 { top: 46%; left: 50%; animation-duration: 21s; animation-delay: -10s; }

#canvas {
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    max-height: min(560px, 68svh);
    display: block;
    border-radius: 18px;
    border: 2px solid rgba(0,255,247,.35);
    box-shadow: 0 0 60px rgba(0,255,247,.25),
    inset 0 0 40px rgba(0,255,247,.06); 
    background:#0a0a0a;
    position: relative;
    z-index: 1;
}

#overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(1,8,8,.72);
    backdrop-filter: blur(14px);
    z-index: 50;
}

.panel {
    width: min(640px, 92vw);
    border-radius: 28px;
    border: 1px solid rgba(115,255,244,.22);
    background:
        radial-gradient(circle at top left, rgba(0,255,247,.12), transparent 34%),
        linear-gradient(180deg, rgba(8,28,27,.96) 0%, rgba(4,14,14,.98) 100%);
    padding: 30px 28px 24px;
    box-shadow:
        0 24px 80px rgba(0,0,0,.45),
        0 0 0 1px rgba(255,255,255,.03) inset,
        0 0 50px rgba(0,255,247,.09);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.panel::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(115,255,244,.72), transparent);
    pointer-events: none;
}
.panel > * {
    position: relative;
    z-index: 1;
}
.h1 {
    font-size: clamp(28px, 4vw, 36px);
    line-height: 1.05;
    margin: 0;
    color: #00fff7;
    text-shadow: 0 0 22px rgba(0,255,247,.22);
    letter-spacing: -.03em;
    max-width: 12ch;
}
.p {
    margin: 0;
    opacity: .92;
    line-height: 1.6;
    white-space: pre-line;
    font-size: 16px;
    color: rgba(223,252,255,.9);
    width: 100%;
    max-width: none;
}
.overlay-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
    min-height: 32px;
    padding: 6px 12px;
    margin-bottom: 2px;
    border-radius: 999px;
    border: 1px solid rgba(115,255,244,.2);
    background: rgba(115,255,244,.08);
    color: #8bfef4;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    box-shadow: 0 0 20px rgba(0,255,247,.08);
}
.overlay-stage {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,.04);
    border: 1px solid rgba(255,255,255,.08);
    color: rgba(223,252,255,.88);
    font-size: 13px;
    letter-spacing: .04em;
}
.overlay-hero {
    display: grid;
    grid-template-columns: minmax(112px, 140px) 1fr;
    gap: 18px;
    align-items: center;
    margin-top: 4px;
}
.overlay-hero-number {
    min-height: 112px;
    min-width: 112px;
    display: grid;
    place-items: center;
    border-radius: 26px;
    font-size: clamp(44px, 9vw, 72px);
    font-weight: 900;
    line-height: 1;
    color: #04100f;
    background: linear-gradient(135deg, #00fff7 0%, #17a8ff 100%);
    box-shadow: 0 18px 50px rgba(0,255,247,.22);
    animation: overlayPulse 1s ease-in-out infinite;
}
.overlay-hero-label {
    font-size: 15px;
    line-height: 1.7;
    color: rgba(223,252,255,.88);
}
.overlay-progress {
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.06);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.08);
}
.overlay-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #00fff7 0%, #17a8ff 48%, #ffd60a 100%);
    box-shadow: 0 0 30px rgba(0,255,247,.22);
    transition: width .18s linear;
}
.overlay-progress[data-indeterminate="true"] .overlay-progress-bar {
    width: 46%;
    animation: overlaySweep 1.15s ease-in-out infinite;
}
.overlay-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.overlay-card {
    padding: 14px 15px;
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,.08);
    background: rgba(255,255,255,.03);
    min-height: 86px;
}
.overlay-card-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: rgba(223,252,255,.62);
    margin-bottom: 8px;
}
.overlay-card-value {
    font-size: 17px;
    line-height: 1.45;
    color: #efffff;
}
.overlay-card.tone-blue {
    background: linear-gradient(180deg, rgba(23,168,255,.12) 0%, rgba(23,168,255,.04) 100%);
    border-color: rgba(23,168,255,.24);
}
.overlay-card.tone-pink {
    background: linear-gradient(180deg, rgba(255,0,110,.14) 0%, rgba(255,0,110,.05) 100%);
    border-color: rgba(255,0,110,.26);
}
.overlay-card.tone-gold {
    background: linear-gradient(180deg, rgba(255,214,10,.14) 0%, rgba(255,214,10,.05) 100%);
    border-color: rgba(255,214,10,.24);
}
#overlay[data-mode="countdown"] .panel {
    box-shadow:
        0 24px 80px rgba(0,0,0,.45),
        0 0 0 1px rgba(255,255,255,.03) inset,
        0 0 70px rgba(0,255,247,.14);
}
#overlay[data-mode="countdown"] .overlay-badge {
    background: rgba(0,255,247,.15);
    color: #00fff7;
}
#overlay[data-mode="countdown"] .overlay-hero-number {
    background: linear-gradient(135deg, #00fff7 0%, #17a8ff 100%);
}
#overlay[data-mode="victory"] .panel {
    width: min(920px, 96vw);
    padding: 24px 24px 20px;
    gap: 10px;
    border-color: rgba(0,255,247,.55);
    box-shadow: 0 24px 80px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.04), 0 0 60px rgba(0,255,247,.16);
}
#overlay[data-mode="victory"] .overlay-badge {
    background: rgba(0,255,247,.12);
    color: #00fff7;
}
#overlay[data-mode="victory"] .overlay-hero-number {
    background: linear-gradient(135deg, #00fff7 0%, #69ff9a 100%);
}
#overlay[data-mode="defeat"] .panel {
    width: min(920px, 96vw);
    padding: 24px 24px 20px;
    gap: 10px;
    border-color: rgba(255,0,110,.45);
    box-shadow: 0 24px 80px rgba(0,0,0,.45), inset 0 0 0 1px rgba(255,255,255,.04), 0 0 60px rgba(255,0,110,.12);
}
#overlay[data-mode="defeat"] .overlay-badge {
    background: rgba(255,0,110,.12);
    color: #ff4b9c;
}
#overlay[data-mode="defeat"] .overlay-hero-number {
    background: linear-gradient(135deg, #ff7a59 0%, #ff006e 100%);
}
#overlay[data-mode="victory"] .h1,
#overlay[data-mode="defeat"] .h1 {
    max-width: none;
}
#overlay[data-mode="victory"] .overlay-hero,
#overlay[data-mode="defeat"] .overlay-hero {
    grid-template-columns: minmax(120px, 156px) 1fr;
    gap: 14px;
    margin-top: 0;
}
#overlay[data-mode="victory"] .overlay-hero-number,
#overlay[data-mode="defeat"] .overlay-hero-number {
    min-width: 92px;
    min-height: 92px;
    border-radius: 22px;
    font-size: clamp(34px, 6vw, 54px);
}
#overlay[data-mode="victory"] .overlay-grid,
#overlay[data-mode="defeat"] .overlay-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}
#overlay[data-mode="victory"] .overlay-card,
#overlay[data-mode="defeat"] .overlay-card {
    min-height: 64px;
    padding: 12px 12px;
    border-radius: 16px;
}
#overlay[data-mode="victory"] .overlay-card-label,
#overlay[data-mode="defeat"] .overlay-card-label {
    margin-bottom: 6px;
    font-size: 11px;
}
#overlay[data-mode="victory"] .overlay-card-value,
#overlay[data-mode="defeat"] .overlay-card-value {
    font-size: 15px;
    line-height: 1.35;
}
#overlay[data-mode="victory"] .small,
#overlay[data-mode="defeat"] .small {
    margin-top: 2px !important;
}
#overlay[data-mode="rewards"] .overlay-badge {
    background: rgba(255,214,10,.14);
    color: #ffd60a;
}
.btnrow {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 6px;
}
.btn {
    appearance: none;
    border: 1px solid rgba(0,255,247,.3);
    background: linear-gradient(135deg, #00d8ff 0%, #17a8ff 100%);
    color: #0a0a0a;
    font-weight: 800;
    padding: 12px 18px;
    min-height: 52px;
    min-width: 132px;
    border-radius: 16px;
    cursor: pointer;
    transition: transform .15s ease, filter .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.btn:hover {
    filter: brightness(1.04);
    box-shadow: 0 14px 30px rgba(0,128,255,.18);
}
.btn:active{transform:translateY(1px)}
.btn.secondary{
    background: rgba(255,255,255,.02);
    color:#dffcff;
    border-color: rgba(223,252,255,.16);
}
.btn.secondary:hover {
    border-color: rgba(115,255,244,.3);
    box-shadow: none;
}
.spinner{width:20px;height:20px;border-radius:50%;border:3px solid rgba(0,255,247,.25);border-top-color:#00fff7;animation:spin 1s linear infinite;display:inline-block;vertical-align:-4px;margin-right:10px}
@keyframes spin{to{transform:rotate(360deg)}}
.rewardline{display:flex;justify-content:space-between;padding:10px 12px;border:1px solid rgba(0,255,247,.2);border-radius:14px;background:rgba(0,255,247,.05);margin-top:10px}
.small{
    font-size:12px;
    opacity:.7;
    color: rgba(223,252,255,.78);
}

@keyframes overlayPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 18px 50px rgba(0,255,247,.22); }
    50% { transform: scale(1.03); box-shadow: 0 24px 65px rgba(0,255,247,.34); }
}

@keyframes arenaFloat {
    0%, 100% {
        transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
    }
    25% {
        transform: translate3d(12px, -18px, 0) rotate(5deg) scale(1.08);
    }
    50% {
        transform: translate3d(-10px, 12px, 0) rotate(-4deg) scale(.94);
    }
    75% {
        transform: translate3d(18px, 8px, 0) rotate(3deg) scale(1.03);
    }
}

@keyframes overlaySweep {
    0% { transform: translateX(-115%); }
    100% { transform: translateX(240%); }
}

@media (max-width: 760px) {
    #wrap {
        justify-content: flex-start;
        padding: 14px 10px 18px;
    }

    #hud {
        align-items: stretch;
    }

    .hud-meta,
    .hud-actions {
        flex: 1 1 100%;
        margin-left: 0;
    }

    .hud-actions {
        justify-content: stretch;
    }

    .hud-actions .btn {
        flex: 1 1 160px;
    }

    #status {
        min-width: 0;
        flex: 1 1 140px;
    }

    #canvas {
        max-height: min(72svh, 78vw, 560px);
    }

    .arena-shell {
        width: min(95vw, 620px);
        padding: 14px 0;
    }

    .arena-decor {
        inset: -4px -10px;
    }

    .arena-decor-item {
        font-size: clamp(20px, 6vw, 32px);
        opacity: .14;
    }

    .panel {
        padding: 24px 20px 20px;
        border-radius: 24px;
    }

    .overlay-hero {
        grid-template-columns: 1fr;
    }

    .overlay-hero-number {
        min-width: 100px;
        min-height: 100px;
        justify-self: start;
    }

    .overlay-grid {
        grid-template-columns: 1fr;
    }

    #overlay[data-mode="victory"] .panel,
    #overlay[data-mode="defeat"] .panel {
        width: min(96vw, 680px);
        padding: 22px 18px 18px;
    }

    #overlay[data-mode="victory"] .overlay-grid,
    #overlay[data-mode="defeat"] .overlay-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .h1,
    .p {
        max-width: none;
    }
}

@media (max-width: 520px) {
    .hud-meta {
        gap: 8px;
    }

    .badge {
        min-height: 44px;
        padding: 8px 12px;
    }

    .btn {
        min-height: 48px;
        padding: 10px 14px;
    }
}
