:root {
    --amb: #5dff7a;
    --gold: #a6ffb8;
    --ink: #e8fff0;
    --dim: #8db5a0;
    --glass: rgba(5, 10, 12, .66);
    --bd: rgba(93, 255, 122, .25);
    --bad: #ef476f;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box
}

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background: #05070f;
    color: var(--ink);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none
}

canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
    display: block
}

.vig {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, .82) 100%)
}

.hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(12px + env(safe-area-inset-left, 0px));
    background: var(--glass);
    border-bottom: 1px solid var(--bd);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px)
}

.hud-l,
.hud-r {
    display: flex;
    gap: 8px;
    min-width: 84px
}

.hud-r {
    justify-content: flex-end
}

.hud-c {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center
}

.lbl {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--dim)
}

.val {
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 12px rgba(93, 255, 122, .45)
}

.ib {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(93, 255, 122, .1);
    border: 1px solid var(--bd);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none
}

.ib:hover {
    background: rgba(93, 255, 122, .22)
}

.ib.confirm {
    background: var(--bad);
    border-color: transparent
}

.toast {
    position: fixed;
    top: calc(64px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    z-index: 101;
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--bad);
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s
}

.toast.on {
    opacity: 1
}

.boost {
    position: fixed;
    z-index: 90;
    right: calc(28px + env(safe-area-inset-right, 0px));
    bottom: calc(28px + env(safe-area-inset-bottom, 0px));
    width: 76px;
    height: 76px;
    min-width: 64px;
    min-height: 64px;
    border-radius: 50%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font: 700 11px system-ui, sans-serif;
    letter-spacing: .5px;
    color: #04120a;
    background: radial-gradient(circle at 35% 30%, var(--gold), var(--amb));
    border: 0;
    box-shadow: 0 0 22px rgba(93, 255, 122, .45);
    touch-action: none
}

.boost:active {
    transform: scale(.94)
}

@media (hover:none),
(pointer:coarse) {
    body[data-s=playing] .boost {
        display: flex
    }
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(2, 3, 8, .82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px)
}

.overlay.open {
    display: flex
}

.modal {
    position: relative;
    width: 100%;
    max-width: 380px;
    max-height: 88vh;
    overflow-y: auto;
    touch-action: pan-y;
    padding: 28px 24px;
    border-radius: 22px;
    text-align: center;
    background: linear-gradient(160deg, #0c1814, #04080a);
    border: 1px solid var(--bd);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7)
}

.modal h2 {
    font-size: 24px;
    margin-bottom: 16px;
    color: var(--gold)
}

.title {
    font-size: 42px !important;
    letter-spacing: 2px;
    text-shadow: 0 0 22px rgba(93, 255, 122, .5)
}

.txt {
    color: var(--dim);
    margin-bottom: 16px;
    line-height: 1.4
}

input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 12px;
    text-align: center;
    font: 600 16px system-ui, sans-serif;
    color: var(--ink);
    background: rgba(255, 255, 255, .06);
    border: 1px solid var(--bd);
    outline: 0;
    user-select: text;
    -webkit-user-select: text
}

input:focus {
    border-color: var(--amb)
}

.row {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 16px
}

.chip {
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    font: 600 13px system-ui, sans-serif;
    color: var(--dim);
    background: transparent;
    border: 1px solid var(--bd)
}

.chip.on {
    color: #04120a;
    background: var(--amb);
    border-color: var(--amb)
}

.menu {
    display: flex;
    flex-direction: column;
    gap: 10px
}

.btn {
    display: block;
    width: 100%;
    padding: 13px;
    border-radius: 14px;
    cursor: pointer;
    text-decoration: none;
    font: 700 16px system-ui, sans-serif;
    color: #04120a;
    background: linear-gradient(135deg, var(--gold), var(--amb));
    border: 1px solid transparent;
    box-shadow: 0 6px 18px rgba(93, 255, 122, .25)
}

.btn.alt {
    color: var(--ink);
    background: rgba(93, 255, 122, .1);
    border-color: var(--bd);
    box-shadow: none
}

.btn.danger {
    color: #ffb3c4;
    border-color: rgba(239, 71, 111, .35)
}

.btn.danger.confirm {
    color: #fff;
    background: linear-gradient(135deg, #c1274d, #8f1636);
    border-color: transparent
}

.x {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--ink);
    background: transparent;
    border: 0;
    font-size: 18px
}

ul {
    list-style: none;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: var(--ink);
    line-height: 1.4
}

li::before {
    content: '›  ';
    color: var(--amb)
}

.badge {
    margin-bottom: 12px;
    font-weight: 700;
    color: var(--gold)
}

.stats {
    margin-bottom: 16px;
    border-top: 1px solid var(--bd)
}

.stats div {
    display: flex;
    justify-content: space-between;
    padding: 9px 2px;
    border-bottom: 1px solid var(--bd);
    color: var(--dim)
}

.stats b {
    color: var(--ink)
}

@media (max-height:480px) {
    .modal {
        padding: 16px 20px
    }

    .overlay {
        padding: 8px
    }
}

.lb {
    position: fixed;
    z-index: 95;
    top: calc(64px + env(safe-area-inset-top, 0px));
    left: calc(12px + env(safe-area-inset-left, 0px));
    width: 176px;
    padding: 6px 8px;
    border-radius: 12px;
    background: var(--glass);
    border: 1px solid var(--bd);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: none;
    font: 600 14px/20px system-ui, sans-serif;
    color: var(--ink);
    font-variant-numeric: tabular-nums
}

.lb div {
    display: flex;
    gap: 6px;
    white-space: nowrap
}

.lb i {
    font-style: normal;
    width: 22px;
    text-align: right;
    color: var(--dim)
}

.lb span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis
}

.lb b {
    font-weight: 700
}

.lb .me {
    color: #3dff7a;
    font-weight: 800
}

.lb .me i {
    color: #3dff7a
}

@media (max-height:480px) {
    .lb {
        width: 164px;
        font-size: 13px;
        line-height: 17px;
        padding: 4px 7px
    }
}

.toast.ad {
    z-index: 500;
    top: max(20px, env(safe-area-inset-top));
    left: 50%;
    display: flex;
    align-items: center;
    gap: 12px;
    width: max-content;
    max-width: calc(100vw - 32px);
    padding: 13px 20px;
    color: #fff;
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    text-align: left;
    background: linear-gradient(135deg, rgba(30, 33, 65, .94), rgba(72, 48, 112, .94));
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 18px;
    box-shadow: 0 12px 36px rgba(20, 15, 50, .32), 0 0 22px rgba(240, 147, 251, .14), inset 0 1px 0 rgba(255, 255, 255, .12);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transform: translateX(-50%);
    animation: toastEnter .35s cubic-bezier(.16, 1, .3, 1) both
}

.toast.ad::before {
    content: '↻';
    display: grid;
    place-items: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    color: #fff;
    font-size: 19px;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 50%;
    box-shadow: 0 3px 12px rgba(102, 126, 234, .35)
}

.toast.ad.ok::before {
    content: '✓';
    background: linear-gradient(135deg, #51cf66, #20a85a);
    box-shadow: 0 3px 12px rgba(81, 207, 102, .35)
}

@keyframes toastEnter {
    from {
        opacity: 0;
        transform: translate(-50%, -14px) scale(.96)
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0) scale(1)
    }
}

@media (max-width:480px) {
    .toast.ad {
        top: max(12px, env(safe-area-inset-top));
        max-width: calc(100vw - 24px);
        padding: 11px 16px;
        border-radius: 16px;
        font-size: 13px
    }
}

@media (prefers-reduced-motion:reduce) {
    .toast.ad {
        animation: none
    }
}

.mg-ad-overlay {
    position: fixed;
    inset: 0;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(2, 3, 8, .92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px)
}

.mg-ad-dialog {
    position: relative;
    width: 100%;
    max-width: 720px;
    max-height: 94vh;
    overflow-y: auto;
    padding: 18px;
    border-radius: 22px;
    background: linear-gradient(160deg, #0c1814, #04080a);
    border: 1px solid var(--bd);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .7)
}

.mg-ad-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    text-align: left
}

.mg-ad-title {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
    color: var(--gold)
}

.mg-ad-desc {
    margin: 0;
    font-size: 14px;
    line-height: 1.4;
    color: var(--dim)
}

.mg-ad-side {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0
}

.mg-ad-timer {
    min-width: 36px;
    text-align: right;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    color: #ffd166
}

.mg-ad-x {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    cursor: pointer;
    color: var(--ink);
    background: rgba(93, 255, 122, .1);
    border: 1px solid var(--bd)
}

.mg-ad-player {
    position: relative;
    width: 100%;
    aspect-ratio: 16/9;
    overflow: hidden;
    border-radius: 12px;
    background: #000
}

.mg-ad-player video {
    width: 100%;
    height: 100%;
    background: #000
}

.mg-ad-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    font-size: 14px;
    color: var(--dim)
}

.mg-ad-quit {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 20;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    border-radius: 22px;
    background: rgba(3, 6, 8, .95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px)
}

.mg-ad-quit.on {
    display: flex
}

.mg-ad-quit .menu {
    width: 100%;
    max-width: 300px;
    margin-top: 4px
}

.btn.gold {
    color: #ffd43b;
    background: rgba(255, 212, 59, .12);
    border-color: rgba(255, 212, 59, .55)
}

.btn.gold:hover {
    background: rgba(255, 212, 59, .24)
}
[hidden] { display: none !important }
.records-title { font-size: 26px !important; margin-bottom: 24px !important }
.records-section { padding: 16px; text-align: left; border-radius: 16px; background: rgba(93, 255, 122, .04); border: 1px solid var(--bd) }
.records-section h3 { margin-bottom: 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim) }
.rank-list { display: flex; flex-direction: column; gap: 6px }
.rank-row { display: grid; grid-template-columns: 30px 84px 1fr; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; font-size: 14px; background: rgba(255, 255, 255, .05); border: 1px solid transparent }
.rank-row .rk { text-align: center; font-weight: 700; color: var(--dim) }
.rank-row .rv { font-weight: 800; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums }
.rank-row .rm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-style: italic; color: var(--dim) }
.rank-row.me { background: rgba(93, 255, 122, .18); border-color: var(--amb) }
.rank-sep { height: 1px; margin: 4px 0; background: rgba(255, 255, 255, .1) }
.connection-status { margin-top: 12px; text-align: center; font-size: 11px; font-style: italic; opacity: .7; color: var(--dim) }

.wr-box { margin-bottom: 16px }
.message-input-wrapper { position: relative; margin-bottom: 28px }
.message-input-wrapper input { margin-bottom: 0 }
.char-counter { position: absolute; right: 8px; bottom: -20px; font-size: 11px; font-weight: 600; color: var(--dim) }
#msgOverlay { z-index: 350 }
