:root {
    color-scheme: dark;
    --bg: #071017;
    --panel: #102431;
    --text: #f3fbff;
    --muted: #adc4cf;
    --empty-a: #dff9ff;
    --empty-b: #94becd;
    --line: rgba(255, 255, 255, 0.15);
    --player-color: #00b4d8;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-y: auto;
}

body {
    position: relative;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    background:
        radial-gradient(circle at top, rgba(107, 228, 239, 0.16), transparent 30%),
        radial-gradient(circle at 80% 20%, rgba(240, 200, 92, 0.12), transparent 28%),
        linear-gradient(160deg, #121212 0%, #1d1d1d 48%, #101010 100%);
    color: var(--text);
    font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
    touch-action: pan-y;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
}

body::before {
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 0, rgba(255, 255, 255, 0.025) 1px, transparent 1px, transparent 72px),
        linear-gradient(rgba(255, 255, 255, 0.018) 0, rgba(255, 255, 255, 0.018) 1px, transparent 1px, transparent 72px);
    opacity: 0.28;
}

body::after {
    background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.28) 100%);
}

button {
    font: inherit;
}

.controlApp {
    min-height: 100vh;
    min-height: 100dvh;
}

.appShell {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100vw;
    min-height: 100vh;
    min-height: 100dvh;
    min-width: 0;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

#header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    flex-shrink: 0;
    padding: 16px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    background:
        linear-gradient(135deg, rgba(30, 30, 30, 0.94), rgba(18, 18, 18, 0.9)),
        linear-gradient(90deg, rgba(107, 228, 239, 0.1), rgba(240, 200, 92, 0.1));
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px);
}

.headerMain {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.appIconBadge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    flex: 0 0 72px;
    border-radius: 50%;
    overflow: hidden;
    background: #dff9ff;
    border: 1px solid rgba(255, 255, 255, 0.7);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.appIcon {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.headerCopy {
    max-width: 520px;
    min-width: 0;
}

.eyebrow {
    margin: 0 0 7px;
    color: #6be4ef;
    font-size: 10px;
    letter-spacing: 0.24em;
    text-transform: uppercase;
}

.headerCopy h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1;
    letter-spacing: 0.02em;
}

.headerCopy p {
    margin: 8px 0 0;
    max-width: 38ch;
    color: rgba(244, 239, 231, 0.76);
    font-size: 14px;
    line-height: 1.4;
}

#playerName {
    color: var(--text);
    font-weight: 800;
}

.headerActions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    align-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-left: auto;
}

.backToAppsButton,
#commsInfoDiv {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.84);
    font-size: 10px;
    letter-spacing: 0.04em;
}

.backToAppsButton {
    justify-content: center;
    padding: 0 10px;
    text-decoration: none;
}

#commsInfoDiv {
    gap: 7px;
    padding: 0 10px;
}

#commsInfo {
    color: inherit;
    text-decoration: none;
}

.backToAppsButton:focus-visible,
#commsInfo:focus-visible {
    outline: 3px solid rgba(107, 228, 239, 0.75);
    outline-offset: 3px;
}

.statusDot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #6be4ef;
    box-shadow: 0 0 16px rgba(107, 228, 239, 0.8);
}

.statusDot.statusDotConnected,
body.connected .statusDot {
    background: #59e189;
    box-shadow: 0 0 16px rgba(89, 225, 137, 0.8);
}

.statusDot.statusDotDisconnected {
    background: #ff4f4f;
    box-shadow: 0 0 16px rgba(255, 79, 79, 0.8);
}

.boardWrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 0;
}

.controlBar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.bubbleGrid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: clamp(0.35rem, 2vw, 0.7rem);
    width: min(100%, 31rem);
    aspect-ratio: 1;
    padding: clamp(0.45rem, 2.5vw, 0.8rem);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background:
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.05), transparent 32%),
        radial-gradient(circle at 80% 80%, rgba(107, 228, 239, 0.06), transparent 30%),
        linear-gradient(160deg, #1a1a1a, #111111 46%, #0a0a0a 100%);
    box-shadow:
        0 28px 60px rgba(0, 0, 0, 0.36),
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        inset 0 -24px 45px rgba(0, 0, 0, 0.22);
    touch-action: none;
    user-select: none;
}

.bubble {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 1;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    cursor: pointer;
    outline: none;
    touch-action: manipulation;
    user-select: none;
    -webkit-appearance: none;
    appearance: none;
}

.bubble:disabled {
    cursor: default;
}

.bubble::before {
    content: "";
    width: 90%;
    height: 90%;
    border-radius: 50%;
    background:
        radial-gradient(circle at 28% 23%, rgba(255, 255, 255, 0.98) 0 7%, rgba(255, 255, 255, 0.62) 8% 14%, transparent 15%),
        radial-gradient(circle at 38% 31%, rgba(255, 255, 255, 0.28), transparent 20%),
        radial-gradient(circle at 62% 74%, rgba(255, 255, 255, 0.12), transparent 34%),
        radial-gradient(circle at 48% 42%, var(--bubble-color, var(--empty-a)) 0 47%, var(--bubble-rim, var(--empty-b)) 76%, rgba(18, 55, 68, 0.42) 100%);
    box-shadow:
        inset -0.45rem -0.55rem 0.85rem rgba(4, 24, 34, 0.34),
        inset 0.28rem 0.34rem 0.82rem rgba(255, 255, 255, 0.5),
        inset 0 -0.1rem 0.25rem rgba(255, 255, 255, 0.18),
        0 0.48rem 0.95rem rgba(0, 0, 0, 0.3);
    transform: translateZ(0) scale(1);
    transform-origin: 50% 58%;
    transition: transform 180ms ease, filter 180ms ease, box-shadow 180ms ease;
    will-change: transform, filter;
}

.bubble::after {
    content: "";
    position: absolute;
    width: 58%;
    height: 44%;
    border-radius: 50%;
    background: radial-gradient(ellipse at 32% 30%, rgba(255, 255, 255, 0.62), rgba(255, 255, 255, 0.18) 34%, transparent 70%);
    filter: blur(0.02rem);
    opacity: 0.72;
    pointer-events: none;
    transform: translate(-10%, -18%) rotate(-16deg);
    transform-origin: center;
}

.bubble:focus,
.bubble:focus-visible,
.bubble:active {
    outline: none;
    box-shadow: none;
}

.bubble.owned::before {
    filter: saturate(1.18) brightness(1.04);
}

.bubble:active::before {
    transform: translateY(3%) scaleX(1.04) scaleY(0.82);
}

.bubble.popping::before {
    animation: bubblePop 620ms cubic-bezier(0.16, 0.9, 0.18, 1.12);
}

.bubble.popping::after {
    animation: bubbleShinePop 620ms ease;
}

@keyframes bubblePop {
    0% {
        transform: translateY(0) scale(1);
    }

    22% {
        transform: translateY(5%) scaleX(1.08) scaleY(0.28);
        filter: saturate(1.6) brightness(1.22);
        box-shadow:
            inset 0 -0.18rem 0.45rem rgba(4, 24, 34, 0.42),
            inset 0 0.18rem 0.35rem rgba(255, 255, 255, 0.32),
            0 0.12rem 0.28rem rgba(0, 0, 0, 0.28);
    }

    46% {
        transform: translateY(-2%) scaleX(0.86) scaleY(1.13);
        filter: saturate(1.28) brightness(1.12);
    }

    68% {
        transform: translateY(1%) scaleX(1.03) scaleY(0.96);
    }

    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes bubbleShinePop {
    0% {
        opacity: 0.72;
        transform: translate(-10%, -18%) rotate(-16deg) scale(1);
    }

    22% {
        opacity: 0.1;
        transform: translate(-12%, 10%) rotate(-16deg) scaleX(1.18) scaleY(0.32);
    }

    52% {
        opacity: 0.84;
        transform: translate(-10%, -22%) rotate(-16deg) scale(1.04);
    }

    100% {
        opacity: 0.72;
        transform: translate(-10%, -18%) rotate(-16deg) scale(1);
    }
}

.colorBadge {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 5px 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    color: #f8f3eb;
    font-size: 13px;
    font-weight: 800;
}

.colorSwatch {
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    background: var(--player-color);
    box-shadow: 0 0 1rem var(--player-color);
}

#resetButton {
    min-height: 40px;
    padding: 9px 13px;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, #f25f4c, #d9482f);
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 900;
    line-height: 1;
    box-shadow: 0 10px 25px rgba(242, 95, 76, 0.24);
    transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

#resetButton:active {
    transform: translateY(1px) scale(0.99);
}

@media (hover: hover) {
    #resetButton:hover {
        transform: translateY(-1px);
        filter: brightness(1.04);
    }
}

.status {
    flex-shrink: 0;
    min-height: 1.2rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.94rem;
    text-align: center;
}

@media (max-width: 760px) {
    .appShell {
        gap: 10px;
        padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }

    #header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px;
    }

    .headerMain {
        align-items: flex-start;
        width: 100%;
        gap: 12px;
    }

    .appIconBadge {
        width: 64px;
        height: 64px;
        flex-basis: 64px;
    }

    .headerCopy h1 {
        font-size: 30px;
    }

    .headerCopy p {
        max-width: none;
        font-size: 13px;
    }

    .headerActions {
        align-self: flex-end;
        margin-left: 0;
    }
}
