:root {
    color-scheme: dark;
    --bg: #071017;
    --panel: #102431;
    --panel-2: #173446;
    --text: #f3fbff;
    --muted: #a6bdc9;
    --empty-a: #dff9ff;
    --empty-b: #94becd;
    --line: rgba(255, 255, 255, 0.14);
    --shadow: rgba(0, 0, 0, 0.34);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    background:
        radial-gradient(circle at 12% 18%, rgba(92, 205, 224, 0.18), transparent 24rem),
        linear-gradient(135deg, #071017 0%, #173446 52%, #1f2d27 100%);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

button {
    font: inherit;
}

.screen {
    display: grid;
    grid-template-columns: clamp(17.5rem, 26vw, 22rem) minmax(0, 1fr);
    gap: clamp(1rem, 2vw, 2rem);
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding: clamp(0.75rem, 2dvh, 1.5rem);
}

.playArea {
    position: relative;
    display: grid;
    place-items: center;
    grid-column: 2;
    min-width: 0;
    min-height: 0;
}

.bubbleGrid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: clamp(0.45rem, 1.2vw, 0.9rem);
    width: min(78vmin, 100%);
    aspect-ratio: 1;
    padding: clamp(0.65rem, 1.8vw, 1.1rem);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.02)),
        rgba(6, 14, 20, 0.72);
    box-shadow: 0 1.2rem 4rem var(--shadow), inset 0 0 4rem rgba(255, 255, 255, 0.04);
    touch-action: none;
    user-select: none;
}

.bubble {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    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::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.05);
}

.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);
    }
}

.sidePanel {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 0.62rem;
    width: 100%;
    min-width: 0;
    overflow: hidden;
    padding: 0.85rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(9, 23, 31, 0.72);
    box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.2);
}

.eyebrow {
    margin: 0 0 0.18rem;
    color: #6be4ef;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1 {
    max-width: 100%;
    margin: 0;
    overflow-wrap: anywhere;
    cursor: pointer;
    font-size: clamp(1.55rem, 2.45vw, 2.15rem);
    line-height: 1;
}

h1:focus-visible {
    outline: 3px solid rgba(107, 228, 239, 0.75);
    outline-offset: 4px;
    border-radius: 6px;
}

.joinBlock {
    display: grid;
    gap: 0.45rem;
    justify-items: start;
}

.qrLink {
    display: grid;
    place-items: center;
    justify-self: start;
    width: clamp(7.25rem, min(13vw, 22dvh), 12rem);
    height: clamp(7.25rem, min(13vw, 22dvh), 12rem);
    padding: 0.65rem;
    border-radius: 8px;
    background: #ffffff;
}

.qrLink img,
.qrLink canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.badgeRow {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    width: 100%;
}

.infoBadge {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    max-width: 100%;
    min-height: 1.45rem;
    padding: 0 0.48rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--muted);
    font-size: 0.72rem;
    overflow-wrap: anywhere;
}

.status {
    margin: 0;
}

.scoreboard {
    display: flex;
    flex-direction: column;
    gap: 0.42rem;
    width: 100%;
    min-height: 0;
    overflow: auto;
}

.playerRow {
    display: grid;
    grid-template-columns: 0.78rem minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.42rem;
    width: 100%;
    min-width: 0;
    padding: 0.46rem 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
}

.playerSwatch {
    width: 0.78rem;
    height: 0.78rem;
    border-radius: 50%;
    background: var(--player-color);
    box-shadow: 0 0 1rem var(--player-color);
}

.playerName {
    overflow: hidden;
    color: var(--text);
    font-weight: 700;
    font-size: 0.92rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.playerScore {
    color: var(--muted);
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

.buttonRow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    gap: 0.45rem;
    width: 100%;
}

.soundButton,
.resetButton {
    width: 100%;
    min-width: 0;
    min-height: 2.15rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 800;
}

.soundButton {
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

.soundButton[aria-pressed="true"] {
    border-color: rgba(107, 228, 239, 0.58);
    background: rgba(107, 228, 239, 0.16);
}

.resetButton {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: linear-gradient(135deg, #ed5f5f, #f0c85c);
    color: #111817;
}

.winnerBanner {
    position: absolute;
    left: 50%;
    bottom: clamp(1rem, 3vw, 2.5rem);
    max-width: min(90%, 34rem);
    padding: 0.9rem 1.2rem;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    background: rgba(7, 16, 23, 0.84);
    box-shadow: 0 1rem 2.2rem rgba(0, 0, 0, 0.32);
    color: #ffffff;
    font-size: clamp(1.1rem, 2.4vw, 2rem);
    font-weight: 900;
    opacity: 0;
    text-align: center;
    transform: translate(-50%, 1rem);
    transition: opacity 200ms ease, transform 200ms ease;
    pointer-events: none;
}

.winnerBanner.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 820px) {
    body {
        overflow: hidden;
    }

    .screen {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
        align-content: start;
        gap: 0.65rem;
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
        padding: clamp(0.55rem, 2.3vw, 0.85rem);
    }

    .sidePanel {
        grid-column: 1;
        grid-row: 1;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-rows: auto auto auto auto;
        grid-template-areas:
            "title qr"
            "badges qr"
            "buttons buttons"
            "scores scores";
        gap: 0.45rem 0.65rem;
        align-items: center;
        padding: 0.62rem;
        overflow: visible;
        background: rgba(7, 18, 25, 0.86);
        box-shadow: 0 0.9rem 2rem rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    }

    .sidePanel header {
        grid-area: title;
        align-self: end;
    }

    .qrLink {
        justify-self: end;
        width: clamp(5.6rem, 25vw, 7.25rem);
        height: clamp(5.6rem, 25vw, 7.25rem);
        padding: 0.36rem;
    }

    .joinBlock {
        display: contents;
    }

    .joinBlock .qrLink {
        grid-area: qr;
    }

    .badgeRow {
        grid-area: badges;
        align-self: start;
        gap: 0.25rem;
    }

    .infoBadge {
        min-height: 1.22rem;
        padding: 0 0.38rem;
        font-size: 0.64rem;
    }

    .scoreboard {
        grid-area: scores;
        max-height: 4.8rem;
        overflow: auto;
    }

    .buttonRow {
        grid-area: buttons;
    }

    h1 {
        font-size: clamp(1.35rem, 5.6vw, 1.9rem);
    }

    .eyebrow {
        font-size: 0.6rem;
    }

    .playArea {
        grid-column: 1;
        grid-row: 2;
        min-height: 0;
        height: 100%;
        padding: 0;
    }

    .bubbleGrid {
        width: min(100%, 22rem, calc(100dvh - 15rem));
        max-width: 100%;
        max-height: 100%;
        gap: clamp(0.34rem, 2vw, 0.62rem);
        padding: clamp(0.44rem, 2.2vw, 0.72rem);
    }

    .buttonRow {
        gap: 0.35rem;
    }

    .soundButton,
    .resetButton {
        min-height: 1.9rem;
        font-size: 0.74rem;
    }

    .playerRow {
        padding: 0.34rem 0.42rem;
    }

    .playerName {
        font-size: 0.82rem;
    }

    .playerScore {
        font-size: 0.74rem;
    }

    .winnerBanner {
        bottom: 0.6rem;
        font-size: 1rem;
    }
}

@media (max-width: 820px) and (max-height: 700px) {
    .qrLink {
        width: 5.2rem;
        height: 5.2rem;
    }

    .scoreboard {
        max-height: 3.8rem;
    }

    .bubbleGrid {
        width: min(100%, 20rem, calc(100dvh - 13rem));
    }
}

@media (min-width: 821px) and (max-height: 760px) {
    .screen {
        gap: 0.75rem;
        padding: 0.55rem;
    }

    .sidePanel {
        gap: 0.38rem;
        padding: 0.55rem;
    }

    .qrLink {
        width: clamp(5.8rem, 16dvh, 7rem);
        height: clamp(5.8rem, 16dvh, 7rem);
        padding: 0.38rem;
    }

    h1 {
        font-size: clamp(1.25rem, 2vw, 1.7rem);
    }

    .eyebrow,
    .roomLine,
    .status {
        font-size: 0.68rem;
    }

    .playerRow {
        padding: 0.32rem 0.4rem;
    }

    .playerName {
        font-size: 0.78rem;
    }

    .playerScore {
        font-size: 0.7rem;
    }

    .soundButton,
    .resetButton {
        min-height: 1.72rem;
        font-size: 0.72rem;
    }

    .scoreboard {
        min-height: 0;
    }
}

@media (min-width: 821px) and (max-height: 620px) {
    .qrLink {
        width: 4.8rem;
        height: 4.8rem;
    }

    .scoreboard {
        max-height: 7rem;
    }
}
