body {
    margin: 0;
    padding: 0;
    color: rgba(255, 255, 255, 0.87);
    background-color: #000000;
}

#app {
    width: 100%;
    height: 100vh;
    /* The visible height on mobile, where 100vh includes the collapsed URL bar
       and pushes the bottom HUD off screen. */
    height: 100dvh;
    /* The arena takes every gesture: no pan, no pinch-zoom, no pull-to-refresh,
       no long-press menu or text selection under a held thumb. The name gate
       sits outside #app, so its form still scrolls. */
    touch-action: none;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* The wall. The arena is already swimming behind it, dimmed and slightly
   softened so it reads as the background it is: something to be earned, not
   the page itself. It sits above every other overlay and is the only thing on
   screen that takes clicks. `#name-gate.name-gate-opaque` is the `?attract=0`
   fallback for a machine that cannot afford the water running while idle. */
#name-gate {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    background-color: rgba(3, 8, 18, 0.5);
    font-family: system-ui, sans-serif;
    z-index: 100;
    transition: opacity 650ms ease-out;
}

#name-gate.name-gate-opaque {
    background-color: #05080c;
}

#name-gate.name-gate-leaving {
    opacity: 0;
}

.name-gate-dialog {
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 48px));
    /* Wide screens get two columns — the form and the how-to-play side by
       side — so the card stays short enough to fit a laptop without a
       scroll; below 720px it stacks and Play stays above the fold. */
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 32px);
    box-sizing: border-box;
    margin: 16px 0;
    padding: 28px 28px 20px;
    background-color: rgba(8, 12, 20, 0.78);
    border: 1px solid rgba(160, 200, 255, 0.18);
    border-radius: 12px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(0, 0, 0, 0.4);
    /* Blur only the card's footprint, not the whole screen: a full-screen
       backdrop blur re-filters every canvas frame and shows up on a laptop. */
    backdrop-filter: blur(10px) saturate(0.85);
    -webkit-backdrop-filter: blur(10px) saturate(0.85);
    transition: transform 650ms ease-out;
}

.name-gate-leaving .name-gate-dialog {
    transform: translateY(-12px) scale(0.98);
}

.name-gate-title {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.2em;
    text-align: center;
    color: #ffd25a;
    text-shadow: 0 0 18px rgba(255, 210, 90, 0.35);
}

.name-gate-pitch {
    margin: 0 0 22px;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    color: rgba(255, 255, 255, 0.72);
}

.name-gate-pitch strong {
    color: #ff9ac4;
    font-weight: 600;
}

.name-gate-label {
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 6px;
}

.name-gate-input {
    padding: 10px 12px;
    font-family: inherit;
    font-size: 16px;
    color: inherit;
    background-color: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
}

.name-gate-input:focus {
    outline: none;
    border-color: #ffd25a;
}

.name-gate-hint {
    margin: 6px 0 16px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.45);
}

.name-gate-play {
    padding: 12px;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #0b0f14;
    background-color: #ffd25a;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 0 22px rgba(255, 210, 90, 0.25);
}

.name-gate-play:hover:not(:disabled) {
    background-color: #ffdc7a;
}

.name-gate-play:disabled {
    color: rgba(255, 255, 255, 0.35);
    background-color: rgba(255, 255, 255, 0.1);
    box-shadow: none;
    cursor: not-allowed;
}

/* The how-to-play, below the button so Play stays above the fold on a phone.
   Also the crawlable copy; it is the same words the game would use. */
.name-gate-main {
    display: flex;
    flex-direction: column;
}

.name-gate-how {
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12.5px;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.58);
}

.name-gate-how h2 {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
}

.name-gate-how ul {
    margin: 0;
    padding-left: 1.1em;
}

.name-gate-how li {
    margin-bottom: 5px;
}

.name-gate-how b {
    color: rgba(255, 255, 255, 0.85);
    font-weight: 600;
}

@media (min-width: 720px) {
    .name-gate-dialog {
        display: grid;
        grid-template-columns: 1fr 1fr;
        column-gap: 32px;
        width: min(720px, calc(100vw - 48px));
        padding: 28px 32px 24px;
    }

    .name-gate-title {
        grid-column: 1 / -1;
        margin-bottom: 18px;
    }

    .name-gate-how {
        margin-top: 0;
        padding-top: 0;
        padding-left: 28px;
        border-top: none;
        border-left: 1px solid rgba(255, 255, 255, 0.1);
        font-size: 13px;
    }

    .name-gate-pitch {
        text-align: left;
    }
}

/* A HUD panel your own blob has wandered under. Faded rather than hidden: the
   leaderboard is still readable at a glance through it, and a panel that
   vanished outright would read as a bug. See ui/overlayFade.ts. */
.hud-panel-dimmed {
    opacity: 0.2;
}

#rank-table,
#radar,
#sucker-status {
    transition: opacity 180ms ease-out;
}

#rank-table {
    position: fixed;
    top: 12px;
    left: 12px;
    width: 220px;
    padding: 10px 12px;
    background-color: rgba(11, 15, 20, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-family: system-ui, sans-serif;
    font-size: 13px;
    pointer-events: none;
    z-index: 10;
}

.rank-table-title {
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 6px;
}

#rank-table ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

#rank-table li {
    display: flex;
    align-items: center;
    padding: 2px 4px;
    border-radius: 4px;
}

.rank-table-rank {
    width: 1.5em;
    color: rgba(255, 255, 255, 0.5);
}

.rank-table-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.rank-table-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-table-mass {
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.75);
}

.rank-table-self {
    background-color: rgba(255, 210, 90, 0.22);
    font-weight: 600;
}

.rank-table-self .rank-table-mass,
.rank-table-self .rank-table-rank {
    color: #ffd25a;
}

#radar {
    position: fixed;
    bottom: 12px;
    left: 12px;
    padding: 8px;
    background-color: rgba(11, 15, 20, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    pointer-events: none;
    z-index: 10;
}

#radar canvas {
    display: block;
    border-radius: 3px;
}

#sucker-status {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 18px;
    padding: 8px 16px;
    background-color: rgba(11, 15, 20, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    font-family: system-ui, sans-serif;
    font-size: 13px;
    pointer-events: none;
    z-index: 10;
}

.sucker-status-stat {
    display: flex;
    align-items: baseline;
    gap: 6px;
    white-space: nowrap;
}

/* Separates the session total from the three live swarm counts beside it. */
.sucker-status-divided {
    padding-left: 18px;
    border-left: 1px solid rgba(255, 255, 255, 0.14);
}

.sucker-status-count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 16px;
    min-width: 1.2em;
    text-align: right;
}

.sucker-status-label {
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 11px;
}

.sucker-status-mass {
    font-variant-numeric: tabular-nums;
    color: #ffd25a;
    font-size: 12px;
}

/* Connection status: hidden while a healthy game is in progress, and the
   loudest thing on screen when it isn't. Sits top-centre because the empty
   arena it explains has nothing else in it to look at. */
#connection-status {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background-color: rgba(11, 15, 20, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    font-family: system-ui, sans-serif;
    font-size: 13px;
    pointer-events: none;
    z-index: 20;
}

.connection-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
    background-color: #8a94a0;
}

.connection-status-label {
    font-weight: 600;
    white-space: nowrap;
}

.connection-status-detail {
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
}

#connection-status[data-phase="live"] .connection-status-dot {
    background-color: #4ade80;
}

#connection-status[data-phase="connecting"] .connection-status-dot {
    background-color: #facc15;
    animation: connection-pulse 1s ease-in-out infinite;
}

#connection-status[data-phase="stalled"] .connection-status-dot {
    background-color: #fb923c;
}

#connection-status[data-phase="offline"] .connection-status-dot,
#connection-status[data-phase="incompatible"] .connection-status-dot {
    background-color: #f87171;
}

#connection-status[data-phase="offline"],
#connection-status[data-phase="incompatible"] {
    border-color: rgba(248, 113, 113, 0.55);
}

@keyframes connection-pulse {
    50% { opacity: 0.3; }
}

/* Knocked out by an EMP: the game is not taking input, and the cursor is the
   one place a player looks when nothing responds. Same shape the disabled
   Play button uses, for the same reason. */
body.knocked-out {
    cursor: not-allowed;
}

/* How-to-play: mouse wording unless the device has no hovering pointer. A
   Surface with its keyboard off still reports a mouse-capable pointer, and
   gets the desktop text; its touch controls explain themselves. */
.how-touch {
    display: none;
}

@media (hover: none) and (pointer: coarse) {
    .how-mouse {
        display: none;
    }

    .how-touch {
        display: list-item;
    }
}

/* ---- Touch controls (ui/touchControls.ts), shown while touch is the live input. */

#touch-controls {
    display: none;
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 20;
    font-family: system-ui, sans-serif;
}

body.touch-mode #touch-controls {
    display: block;
}

.touch-stick-base {
    position: absolute;
    left: -56px;
    top: -56px;
    width: 112px;
    height: 112px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.22);
    background-color: rgba(255, 255, 255, 0.05);
    visibility: hidden;
}

.touch-stick-active .touch-stick-base {
    visibility: visible;
}

.touch-stick-knob {
    position: absolute;
    left: 32px;
    top: 32px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.3);
}

.touch-buttons {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 184px;
    height: 184px;
}

.touch-button {
    --accent: 120, 220, 255;
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(var(--accent), 0.5);
    background: radial-gradient(
        circle at 50% 35%,
        rgba(var(--accent), 0.22),
        rgba(8, 14, 22, 0.7) 70%
    );
    box-shadow:
        0 0 14px rgba(var(--accent), 0.25),
        inset 0 0 10px rgba(var(--accent), 0.15);
    color: rgb(var(--accent));
    font: 600 10px system-ui, sans-serif;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition:
        opacity 160ms ease-out,
        filter 160ms ease-out,
        box-shadow 160ms ease-out;
}

/* Release is the one pressed constantly, so it is the big one in the corner;
   the other three arc around it within the same thumb's reach. */
.touch-button-release {
    --accent: 120, 220, 255;
    right: 0;
    bottom: 0;
    width: 88px;
    height: 88px;
    font-size: 11px;
}

.touch-button-boost,
.touch-button-recall,
.touch-button-emp {
    width: 58px;
    height: 58px;
}

.touch-button-boost {
    --accent: 130, 255, 190;
    right: 104px;
    bottom: 4px;
}

.touch-button-recall {
    --accent: 200, 165, 255;
    right: 88px;
    bottom: 84px;
}

.touch-button-emp {
    --accent: 255, 210, 90;
    right: 8px;
    bottom: 110px;
}

.touch-button-icon {
    width: 40%;
    height: 40%;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 3px rgba(var(--accent), 0.8));
}

.touch-button-emp .touch-button-icon {
    fill: currentColor;
    fill-opacity: 0.35;
}

.touch-button-label {
    color: rgba(255, 255, 255, 0.8);
}

/* Held down: lit from inside. */
.touch-button:active {
    background: radial-gradient(
        circle at 50% 45%,
        rgba(var(--accent), 0.55),
        rgba(8, 14, 22, 0.7) 80%
    );
    box-shadow:
        0 0 26px rgba(var(--accent), 0.6),
        inset 0 0 16px rgba(var(--accent), 0.4);
}

/* The progress ring just inside the rim: recharge, charge, or boost left. */
.touch-button-ring {
    --p: 0;
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: conic-gradient(
        rgba(var(--accent), 0.9) calc(var(--p) * 1turn),
        transparent 0
    );
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 4px), #000 calc(100% - 3.5px));
    opacity: 0;
    pointer-events: none;
}

.touch-button[data-state="cooling"] .touch-button-ring,
.touch-button[data-state="active"] .touch-button-ring {
    opacity: 1;
}

.touch-button[data-state="cooling"] .touch-button-ring {
    background: conic-gradient(
        rgba(var(--accent), 0.45) calc(var(--p) * 1turn),
        transparent 0
    );
}

.touch-button[data-state="cooling"],
.touch-button[data-state="blocked"] {
    opacity: 0.45;
    filter: saturate(0.4);
    box-shadow: none;
}

/* Boosting or charging: the button breathes for as long as it lasts. */
.touch-button[data-state="active"] {
    animation: touch-button-breathe 0.6s ease-in-out infinite alternate;
}

@keyframes touch-button-breathe {
    from { box-shadow: 0 0 12px rgba(var(--accent), 0.4); }
    to { box-shadow: 0 0 30px rgba(var(--accent), 0.85); }
}

/* Every press pops and throws a ring outward. */
.touch-button::after {
    content: "";
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    border: 2px solid rgba(var(--accent), 0.9);
    opacity: 0;
    pointer-events: none;
}

.touch-button-pop {
    animation: touch-button-pop 260ms cubic-bezier(0.3, 1.6, 0.5, 1);
}

.touch-button-pop::after {
    animation: touch-button-ripple 420ms ease-out;
}

@keyframes touch-button-pop {
    0% { transform: scale(0.84); }
    100% { transform: scale(1); }
}

@keyframes touch-button-ripple {
    0% { transform: scale(1); opacity: 0.9; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Pressed while it cannot fire: a short no-shake instead of the pop. */
.touch-button-deny {
    animation: touch-button-deny 280ms ease-in-out;
}

@keyframes touch-button-deny {
    0%, 100% { translate: 0; }
    20% { translate: -5px; }
    40% { translate: 5px; }
    60% { translate: -3px; }
    80% { translate: 3px; }
}

/* Just came off cooldown. */
.touch-button-ready::after {
    animation: touch-button-ripple 520ms ease-out;
}

.touch-button-ready {
    animation: touch-button-flash 520ms ease-out;
}

@keyframes touch-button-flash {
    0% { box-shadow: 0 0 36px rgba(var(--accent), 1), inset 0 0 20px rgba(var(--accent), 0.8); }
    100% { box-shadow: 0 0 14px rgba(var(--accent), 0.25), inset 0 0 10px rgba(var(--accent), 0.15); }
}

.touch-button-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    padding: 0 4px;
    border-radius: 9px;
    background-color: rgba(120, 220, 255, 0.85);
    color: #05080c;
    font-size: 11px;
    line-height: 18px;
}

.touch-button-badge:empty {
    display: none;
}

/* ---- Small screens: a phone has room for the arena and the controls, not
   the full HUD. The rank table collapses to one line; the radar and the
   status panel go (the Sucker count rides on the Recall button). Sized by the
   screen, not the input, so a touch-only Surface keeps the whole HUD. */

#rank-compact {
    display: none;
}

@media (max-width: 720px), (max-height: 500px) {
    #rank-table,
    #radar,
    #sucker-status {
        display: none;
    }

    #rank-compact {
        display: block;
        position: fixed;
        top: max(8px, env(safe-area-inset-top));
        left: max(8px, env(safe-area-inset-left));
        padding: 4px 10px;
        background-color: rgba(11, 15, 20, 0.6);
        border: 1px solid rgba(255, 255, 255, 0.12);
        border-radius: 6px;
        font: 13px system-ui, sans-serif;
        pointer-events: none;
        z-index: 10;
    }
}
