:root {
    /* ========================================================
       TEXT SCALE
       Every text size, and the spacing around text, is written as
       a multiple of --u ("one HUD pixel"), so the whole interface
       grows and shrinks together, keeping its proportions:
         - phones (up to 600 px wide): about 1.4-1.5x the original
         - laptops and 1080p screens: about 1.35-1.45x
         - 1440p: about 1.8x;  4K: about 2.5x (the most)
       It follows the screen's shorter side, so a big monitor gets
       big text and a phone held sideways stays compact. (Media
       queries further down set it for phones and short screens.)
       ======================================================== */
    --u: clamp(1.35px, calc(0.55px + 0.095vmin), 2.6px);

    --cyan: #42f5f2;
    --pink: #ff3f9f;
    --yellow: #ffe66d;
    --background: #050713;
    --panel: rgba(7, 12, 35, 0.92);
}

* {
    box-sizing: border-box;
}

/* ============================================================
   NO ACCIDENTAL COPY / PASTE ON PHONES
   Long-pressing or double-tapping during play would otherwise
   select HUD text and pop up the copy / paste / look-up menu.
   ============================================================ */

html,
body,
body * {
    /* No text selection (and so no copy / paste handles). */
    -webkit-user-select: none;
    user-select: none;

    /* No iOS long-press callout (copy, look up, save image). */
    -webkit-touch-callout: none;

    /* No grey flash over tapped elements on Android / iOS. */
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    /* No pinch-zoom, double-tap zoom or pull-to-refresh while
       playing. The game canvas already sets this for itself. */
    touch-action: none;
    overscroll-behavior: none;

    /* Stops iOS enlarging text after rotating the phone. */
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* The start and game-over panels scroll on short screens, so they
   still allow vertical swipes; buttons must still respond to taps. */
#start-screen,
#game-over,
#round-results {
    touch-action: pan-y;
}

.arcade-button {
    touch-action: manipulation;
}

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--background);
    color: white;
    font-family: "Press Start 2P", monospace;
}

#game-container {
    position: fixed;
    inset: 0;
}

#game-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* ============================================================ TOP HUD ============================================================ */

#hud { position: fixed; top: 0; left: 0; right: 0; z-index: 2;

display: grid;
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: start;
gap: calc(12 * var(--u));

padding: calc(18 * var(--u)) calc(24 * var(--u));
pointer-events: none;


}

/* ============================================================ BOTTOM HUD ============================================================ */

#bottom-hud { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2;

display: grid;
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
align-items: end;
gap: calc(12 * var(--u));

padding: calc(18 * var(--u)) calc(24 * var(--u));
pointer-events: none;


}

/* ============================================================ HUD ELEMENTS ============================================================ */

.hud-block { min-width: 0; }

.hud-center { text-align: center; justify-self: center; }

.hud-right { text-align: right; justify-self: end; }

.hud-label { margin-bottom: calc(8 * var(--u)); color: var(--cyan); font-size: calc(9 * var(--u)); line-height: 1.6; }

/* SYSTEM STATUS, the status message, warp and the clock sit closer together. */
#bottom-hud .hud-center .hud-label { margin-bottom: calc(4 * var(--u)); }

.hud-value, .lives-value { font-size: calc(13 * var(--u)); line-height: 1.6; }

.lives-value { color: var(--pink); white-space: nowrap; }

/* ============================================================
   HULL BAR (replaces the hearts)
   The fill is drawn in the bar's current color (set by game.js:
   green → yellow → red), glows in it, and is split into one segment
   per hull point. Width and color animate on every hit or repair.
   ============================================================ */

.hull-bar {
    position: relative;
    width: calc(120 * var(--u));
    height: calc(12 * var(--u));
    padding: calc(2 * var(--u));
    border: 1px solid currentColor;
    background: rgba(5, 7, 19, 0.65);
    box-shadow: 0 0 8px currentColor, inset 0 0 6px rgba(0, 0, 0, 0.6);
    color: #3dff8b;
    transition: color 0.45s ease, box-shadow 0.45s ease;
}

.hull-fill {
    width: 100%;
    height: 100%;
    /* Plain color first, for browsers without color-mix(). */
    background: currentColor;
    background: linear-gradient(90deg, currentColor, color-mix(in srgb, currentColor 60%, white));
    box-shadow: 0 0 10px currentColor, 0 0 18px currentColor;
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Segment dividers: one segment per hull point. */
.hull-bar::after {
    content: "";
    position: absolute;
    inset: 2px;
    background: linear-gradient(
        90deg,
        transparent calc(33.333% - 1px),
        rgba(5, 7, 19, 0.9) calc(33.333% - 1px),
        rgba(5, 7, 19, 0.9) calc(33.333% + 1px),
        transparent calc(33.333% + 1px),
        transparent calc(66.667% - 1px),
        rgba(5, 7, 19, 0.9) calc(66.667% - 1px),
        rgba(5, 7, 19, 0.9) calc(66.667% + 1px),
        transparent calc(66.667% + 1px)
    );
    pointer-events: none;
}

/* Last hull point: an urgent pulse. */
.hull-bar[data-hull="1"] { animation: hull-critical 0.55s ease-in-out infinite alternate; }

@keyframes hull-critical {
    from { box-shadow: 0 0 4px currentColor, inset 0 0 6px rgba(0, 0, 0, 0.6); }
    to { box-shadow: 0 0 16px currentColor, inset 0 0 6px rgba(0, 0, 0, 0.6); }
}

/* Destroyed: an empty, dim frame. */
.hull-bar[data-hull="0"] { box-shadow: none; opacity: 0.7; }

.game-logo { font-size: clamp(calc(12 * var(--u)), 1.8vw, calc(20 * var(--u))); line-height: 1.6; white-space: nowrap; text-shadow: 0 0 12px var(--cyan); }

.game-logo span { color: var(--pink); }

.hud-subtitle { margin-top: calc(4 * var(--u)); color: var(--cyan); font-size: calc(8 * var(--u)); line-height: 1.6; letter-spacing: calc(0.5 * var(--u)); }

#message { max-width: calc(300 * var(--u)); color: var(--yellow); font-size: calc(9 * var(--u)); line-height: 1.5; overflow-wrap: anywhere; text-shadow: 0 0 12px var(--yellow); }

/* Moved out of the max-width: 360px media query, where it only
   applied on the very smallest phones. */
#warp-status { color: #65f5ff; font-family: monospace; font-size: calc(14 * var(--u)); font-weight: bold; text-shadow: 0 0 8px #00cfff; margin-top: calc(4 * var(--u)); }

/* Match clock: time left in the 5-minute match. */
#match-clock { margin-top: calc(4 * var(--u)); color: var(--cyan); font-size: calc(9 * var(--u)); line-height: 1.6; white-space: nowrap; text-shadow: 0 0 10px var(--cyan); }

#match-time { color: white; }

/* The last 30 seconds glow warmer and pulse. */
#match-clock.final { color: var(--yellow); text-shadow: 0 0 12px var(--yellow); animation: match-clock-pulse 1s ease-in-out infinite alternate; }

@keyframes match-clock-pulse {
    from { opacity: 0.75; }
    to { opacity: 1; }
}

/* ============================================================
   LOBBY LEADERBOARD (top right, online only)
   ============================================================ */

.leaderboard { margin: calc(8 * var(--u)) 0 0; padding: 0; list-style: none; font-size: calc(8.5 * var(--u)); line-height: 1.8; text-align: right; }

.leaderboard[hidden] { display: none; }

.leaderboard li { display: flex; justify-content: flex-end; gap: calc(6 * var(--u)); white-space: nowrap; opacity: 0.95; }

.leaderboard .lb-rank { color: var(--cyan); }

.leaderboard .lb-name { max-width: 14ch; overflow: hidden; text-overflow: ellipsis; }

.leaderboard .lb-score { min-width: 7ch; color: white; }

/* A pilot's rank (a new one every 10,000 points), boxed beside the name. */
.leaderboard .lb-lvl { min-width: 2.2ch; padding: 0 0.35em; border: 1px solid currentColor; border-radius: 2px; line-height: 1.35; align-self: center; text-align: center; color: var(--cyan); font-size: 0.85em; }

.leaderboard .lb-me { opacity: 1; text-shadow: 0 0 8px rgba(255, 255, 255, 0.5); }

.leaderboard .lb-gap { justify-content: flex-end; color: var(--cyan); }

/* ============================================================
   GAME LOG (top left, under the score, online only)
   Each line flashes in, stays a few seconds, then fades (game.js
   removes it); the newest is on top. A long one wraps onto a second
   row (indented) rather than being cut off; names stay in one piece.
   ============================================================ */

.game-log { margin: calc(8 * var(--u)) 0 0; padding: 0; list-style: none; max-width: 100%; font-size: calc(8 * var(--u)); line-height: 1.8; text-align: left; }

.game-log[hidden] { display: none; }

.game-log li { margin-bottom: calc(3 * var(--u)); padding-left: 2ch; text-indent: -2ch; animation: game-log-line 5s ease-out forwards; }

/* (Only a name too long for the whole width is shortened.) */
.game-log .log-name { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-indent: 0; vertical-align: bottom; }

.game-log .log-weapon { color: var(--cyan); white-space: nowrap; }

@keyframes game-log-line {
    0% { opacity: 0; text-shadow: 0 0 14px white; }
    4% { opacity: 1; text-shadow: 0 0 14px white; }
    20% { opacity: 1; text-shadow: 0 0 0 transparent; }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .game-log li { animation: none; }
}

/* ============================================================
   WEAPON SWITCH (bottom left, under the hull display)
   Hidden until a second weapon unlocks; tap to cycle.
   ============================================================ */

.weapon-switch {
    margin-top: calc(8 * var(--u));
    padding: calc(7 * var(--u)) calc(10 * var(--u));
    min-height: calc(32 * var(--u));
    border: 1px solid var(--cyan);
    background: rgba(7, 12, 35, 0.6);
    color: white;
    font-family: inherit;
    font-size: calc(8 * var(--u));
    letter-spacing: calc(1 * var(--u));
    cursor: pointer;

    /* The HUD itself ignores the pointer; this button doesn't. */
    pointer-events: auto;
    touch-action: manipulation;
}

.weapon-switch[hidden] { display: none; }

.weapon-switch .weapon-cycle { margin-left: calc(6 * var(--u)); color: var(--cyan); }

.weapon-switch[data-weapon="laser"] { border-color: #ff4f6d; box-shadow: 0 0 8px rgba(255, 79, 109, 0.4); }

.weapon-switch[data-weapon="rockets"] { border-color: var(--yellow); box-shadow: 0 0 8px rgba(255, 230, 109, 0.4); }

.weapon-switch.switched { animation: weapon-switched 300ms ease-out; }

/* The weapon and cloak buttons side by side. */
.hud-buttons { display: flex; flex-wrap: wrap; gap: 0 calc(6 * var(--u)); align-items: flex-start; }

/* The cloak button: icy blue; shimmering while cloaked. */
.cloak-toggle { border-color: #5ac8ff; color: #bfe9ff; }

.cloak-toggle[aria-pressed="true"] {
    background: rgba(40, 120, 200, 0.35);
    color: white;
    box-shadow: 0 0 10px rgba(90, 200, 255, 0.7), inset 0 0 8px rgba(90, 200, 255, 0.5);
    animation: cloak-shimmer 1.6s ease-in-out infinite;
}

@keyframes cloak-shimmer {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes weapon-switched {
    from { transform: scale(1.12); }
    to { transform: scale(1); }
}

/* ============================================================
   ROUND RESULTS (online)
   ============================================================ */

#round-results {
    position: fixed;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    overflow-y: auto;
    padding: calc(24 * var(--u));
    text-align: center;

    /* Scrollable when it doesn't fit (a phone held sideways). */
    pointer-events: auto;

    /* Translucent, so the black hole stays visible behind it. */
    background: radial-gradient(circle, rgba(3, 5, 20, 0.35) 0%, rgba(3, 5, 20, 0.8) 75%);
}

.results-title { color: #66ffff; font-size: clamp(calc(24 * var(--u)), 6vw, calc(48 * var(--u))); letter-spacing: 0.1em; text-shadow: 0 0 10px #00ffff, 0 0 30px #00ffff; }

.results-winner { margin-top: calc(18 * var(--u)); font-size: clamp(calc(10 * var(--u)), 2.4vw, calc(16 * var(--u))); line-height: 1.6; }

.results-you { color: var(--yellow); text-shadow: 0 0 12px var(--yellow); }

.results-list { margin: calc(22 * var(--u)) 0 0; padding: 0; list-style: none; font-size: clamp(calc(8 * var(--u)), 1.8vw, calc(11 * var(--u))); line-height: 2.2; }

.results-list li { display: grid; grid-template-columns: 3ch minmax(0, 16ch) 10ch 6ch; gap: calc(10 * var(--u)); text-align: left; }

.results-list .results-me { text-shadow: 0 0 10px rgba(255, 255, 255, 0.6); }

.results-rank { color: var(--cyan); }

.results-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.results-score { text-align: right; color: white; }

.results-kills { text-align: right; color: #8f93b8; }

.results-next { margin-top: calc(22 * var(--u)); color: var(--cyan); font-size: calc(8 * var(--u)); }

/* ============================================================
   ALL-TIME LEADERBOARD (from the server)
   ============================================================ */

.all-time-best { margin-top: calc(4 * var(--u)); color: var(--yellow); font-size: calc(8.5 * var(--u)); line-height: 1.6; white-space: nowrap; opacity: 1; }

.all-time-best[hidden] { display: none; }

.all-time-best span { color: white; }

/* Your score has passed the all-time record (official at round end). */
.all-time-best.live { color: #7dff6b; text-shadow: 0 0 10px rgba(125, 255, 107, 0.7); animation: match-clock-pulse 0.6s ease-in-out infinite alternate; }

.all-time-best.live::after { content: " NEW RECORD!"; }

.records { margin-top: calc(14 * var(--u)); width: min(calc(320 * var(--u)), 100%); }

.records[hidden] { display: none; }

.records-title { margin-bottom: calc(6 * var(--u)); color: var(--yellow); font-size: calc(8 * var(--u)); letter-spacing: calc(1 * var(--u)); }

.records-list { margin: 0; padding: 0; list-style: none; font-size: calc(8 * var(--u)); line-height: 2; }

.records-list li { display: grid; grid-template-columns: 3ch minmax(0, 1fr) auto; gap: calc(8 * var(--u)); text-align: left; }

.records-list .rec-rank { color: var(--cyan); }

.records-list .rec-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.records-list .rec-score { text-align: right; color: white; }

.records-list .rec-you { text-shadow: 0 0 10px rgba(255, 255, 255, 0.7); }

.records-list .rec-you .rec-score { color: var(--yellow); }

#round-results .records { margin-top: calc(18 * var(--u)); }

/* While the round results are up, the HUD steps aside (it would show
   through the see-through panel, doubling up scores and the clock). */
body.results-open #hud,
body.results-open #bottom-hud {
    visibility: hidden;
}

.results-record { margin-top: calc(14 * var(--u)); color: var(--yellow); font-size: clamp(calc(9 * var(--u)), 2vw, calc(13 * var(--u))); text-shadow: 0 0 12px var(--yellow); animation: match-clock-pulse 0.8s ease-in-out infinite alternate; }

.results-record[hidden] { display: none; }

/* ============================================================
   CALLSIGN (your name online)
   ============================================================ */

.callsign {
    margin-top: calc(6 * var(--u));
    padding: calc(4 * var(--u)) calc(8 * var(--u));
    border: 1px solid rgba(66, 245, 242, 0.45);
    background: rgba(7, 12, 35, 0.55);
    color: white;
    font-family: inherit;
    font-size: calc(7 * var(--u));
    letter-spacing: calc(1 * var(--u));
    cursor: pointer;

    /* The HUD itself ignores the pointer; this button doesn't. */
    pointer-events: auto;
    touch-action: manipulation;
}

.callsign[hidden] { display: none; }

.callsign .callsign-edit { margin-left: calc(4 * var(--u)); color: var(--cyan); }

.callsign-dialog {
    position: fixed;
    inset: 0;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(16 * var(--u));
    background: rgba(2, 3, 15, 0.75);
}

.callsign-box {
    width: min(calc(340 * var(--u)), 100%);
    padding: calc(20 * var(--u));
    border: 2px solid var(--cyan);
    background: var(--panel);
    text-align: center;
}

.callsign-title { display: block; margin-bottom: calc(14 * var(--u)); color: var(--cyan); font-size: calc(10 * var(--u)); }

.callsign-input {
    width: 100%;
    padding: calc(12 * var(--u));
    border: 1px solid var(--pink);
    background: rgba(255, 63, 159, 0.08);
    color: white;
    font-family: inherit;
    font-size: calc(14 * var(--u));
    text-align: center;
    text-transform: uppercase;
    letter-spacing: calc(1 * var(--u));
    outline: none;

    /* Typing and selecting must work here, unlike the rest of the page. */
    -webkit-user-select: text;
    user-select: text;
    touch-action: manipulation;
}

.callsign-input:focus { box-shadow: 0 0 10px rgba(255, 63, 159, 0.6); }

.callsign-hint { margin-top: calc(10 * var(--u)); color: var(--cyan); font-size: calc(7 * var(--u)); line-height: 1.7; opacity: 0.85; }

/* Under the callsign box: don't use your real name. */
.callsign-warning { margin-top: calc(10 * var(--u)); color: var(--yellow); font-size: calc(7 * var(--u)); line-height: 1.7; }

/* The link to privacy.html (start screen, callsign box). */
.privacy-link { color: inherit; text-decoration: underline; text-underline-offset: 0.25em; pointer-events: auto; }

.privacy-link:hover, .privacy-link:focus-visible { color: white; }

.callsign-error { min-height: 2.4em; margin-top: calc(10 * var(--u)); color: var(--yellow); font-size: calc(8 * var(--u)); line-height: 1.6; }

.callsign-buttons { display: flex; gap: calc(10 * var(--u)); margin-top: calc(6 * var(--u)); }

.callsign-button {
    flex: 1;
    padding: calc(12 * var(--u)) calc(8 * var(--u));
    border: 1px solid var(--cyan);
    background: transparent;
    color: white;
    font-family: inherit;
    font-size: calc(9 * var(--u));
    cursor: pointer;
    touch-action: manipulation;
}

.callsign-button.primary { border-color: var(--pink); background: rgba(255, 63, 159, 0.15); }

/* Multiplayer connection status, under the logo. */
#net-status { margin-top: calc(6 * var(--u)); font-size: calc(7 * var(--u)); line-height: 1.6; letter-spacing: calc(0.5 * var(--u)); white-space: nowrap; color: var(--cyan); opacity: 0.9; }

#net-status[data-state="online"] { color: #7dff6b; text-shadow: 0 0 8px rgba(125, 255, 107, 0.6); }

#net-status[data-state="connecting"] { color: var(--yellow); animation: match-clock-pulse 0.8s ease-in-out infinite alternate; }

#net-status[data-state="offline"] { color: #8f93b8; }

.mission-goal { margin: calc(4 * var(--u)) 0 0; color: var(--cyan); font-size: calc(8 * var(--u)); line-height: 2; overflow-wrap: anywhere; }

/* ============================================================
   RADAR (bottom right, online)
   ============================================================ */

.radar {
    display: block;
    width: calc(104 * var(--u));
    height: calc(104 * var(--u));
    margin: 0 0 calc(8 * var(--u)) auto;
    border-radius: 50%;
    box-shadow: 0 0 calc(10 * var(--u)) rgba(57, 255, 122, 0.25);
}

.radar[hidden] { display: none; }

/* ============================================================
   SHIP PICKER (title and game-over screens)
   ============================================================ */

.ship-picker {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(10 * var(--u));
    margin-top: calc(12 * var(--u));
}

.ship-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: calc(120 * var(--u));
}

.ship-image {
    width: calc(84 * var(--u));
    height: calc(84 * var(--u));
    object-fit: contain;
    filter: drop-shadow(0 0 calc(6 * var(--u)) rgba(66, 245, 242, 0.35));
    pointer-events: none;
}

.ship-name {
    margin-top: calc(4 * var(--u));
    font-size: calc(9 * var(--u));
    letter-spacing: calc(1 * var(--u));
    text-shadow: 0 0 10px currentColor;
    white-space: nowrap;
}

.ship-arrow {
    min-width: calc(36 * var(--u));
    min-height: calc(36 * var(--u));
    padding: 0;
    border: 1px solid var(--cyan);
    background: rgba(7, 12, 35, 0.6);
    color: var(--cyan);
    font-family: inherit;
    font-size: calc(10 * var(--u));
    cursor: pointer;
    touch-action: manipulation;
}

.ship-arrow:hover { background: var(--cyan); color: #080716; }

/* ============================================================ GAME SCREENS ============================================================ */

.hidden { display: none !important; }

#start-screen, #game-over { position: fixed; inset: 0; z-index: 5;

display: flex;
flex-direction: column;
align-items: center;
justify-content: center;

/* Centered when it fits; when it's taller than the screen (a phone
   held sideways), it starts at the top and scrolls, instead of the
   top being cut off out of reach. */
justify-content: safe center;

overflow-y: auto;
padding: calc(24 * var(--u));

text-align: center;
background: rgba(2, 3, 15, 0.92);


}

#start-screen.hidden, #game-over.hidden { display: none !important; }

#start-screen h1, #game-over h2 { margin: calc(16 * var(--u)) 0; line-height: 1.5; }

#start-screen h1 { font-size: clamp(calc(30 * var(--u)), 7vw, calc(56 * var(--u))); letter-spacing: calc(-2 * var(--u)); text-shadow: 4px 4px 0 #4031a3; }

#start-screen h1 span, #game-over h2 span { color: var(--pink); }

.title-description { max-width: 100%; font-size: calc(9 * var(--u)); line-height: 2; overflow-wrap: anywhere; }

.arcade-button { width: min(calc(320 * var(--u)), 100%); margin: calc(16 * var(--u)) 0; padding: calc(16 * var(--u)); border: 2px solid var(--pink); background: rgba(255, 63, 159, 0.09); color: white; font-family: inherit; font-size: calc(10 * var(--u)); cursor: pointer; }

.arcade-button:hover { background: var(--pink); color: #080716; }

.controls { margin-top: calc(20 * var(--u)); font-size: calc(8 * var(--u)); line-height: 2.2; }

.controls-heading { margin-bottom: calc(10 * var(--u)); color: var(--cyan); }

.control-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: calc(6 * var(--u)); }

.control-description { margin-left: calc(6 * var(--u)); }

.keycap { color: var(--yellow); }

.panel-topline, .panel-bottomline { max-width: 100%; color: var(--cyan); font-size: calc(7 * var(--u)); line-height: 2; overflow-wrap: anywhere; }

.panel-bottomline { margin-top: calc(20 * var(--u)); }

.insert-coin { margin: calc(12 * var(--u)) 0; color: var(--yellow); font-size: calc(9 * var(--u)); }

.final-score { margin: calc(18 * var(--u)) 0; color: var(--yellow); font-size: clamp(calc(22 * var(--u)), 5vw, calc(34 * var(--u))); }

.final-score-label { margin-top: calc(20 * var(--u)); color: var(--cyan); font-size: calc(9 * var(--u)); }

.game-over-icon { margin: calc(12 * var(--u)) 0; color: var(--cyan); font-size: calc(36 * var(--u)); }

/* ============================================================ DAMAGE FLASH ============================================================ */

#flash { position: fixed; inset: 0; z-index: 4; pointer-events: none; background: white; opacity: 0; }

/* ============================================================ MOBILE HUD ============================================================ */

/* Phones, upright or held sideways (short screens): the compact
   layout, its text scaled by the screen's shorter side. */
@media (max-width: 600px), (max-height: 500px) { :root { --u: clamp(1.4px, calc(0.45px + 0.25vmin), 1.7px); }

#hud { padding: calc(12 * var(--u)) calc(8 * var(--u)); gap: calc(4 * var(--u)); }

#bottom-hud {
    padding: calc(12 * var(--u)) calc(8 * var(--u));
    gap: calc(4 * var(--u));
}

#hud .hud-center,
#bottom-hud .hud-center {
    width: 100%;
    max-width: 40vw;
    justify-self: center;
    text-align: center;
}

#hud .hud-right,
#bottom-hud .hud-right {
    justify-self: end;
    text-align: right;
}

.game-logo {
    font-size: clamp(calc(9 * var(--u)), 3vw, calc(13 * var(--u)));
    letter-spacing: 0;
}

.hud-subtitle {
    max-width: 40vw;
    margin: calc(3 * var(--u)) auto 0;
    font-size: calc(6 * var(--u));
    line-height: 1.6;
    letter-spacing: 0;
    overflow-wrap: anywhere;
}

.hud-label {
    margin-bottom: calc(4 * var(--u));
    font-size: calc(7 * var(--u));
    line-height: 1.5;
}

.hud-value,
.lives-value {
    font-size: calc(10 * var(--u));
}

.hull-bar {
    width: calc(72 * var(--u));
    height: calc(10 * var(--u));
}

#message {
    max-width: 40vw;
    font-size: calc(7 * var(--u));
    line-height: 1.4;
    overflow-wrap: anywhere;
}

#match-clock {
    font-size: calc(7 * var(--u));
    margin-top: calc(4 * var(--u));
}

#net-status {
    font-size: calc(6 * var(--u));
    margin-top: calc(3 * var(--u));
}

.callsign {
    font-size: calc(6 * var(--u));
    padding: calc(5 * var(--u)) calc(7 * var(--u));
}

.all-time-best {
    font-size: calc(7.5 * var(--u));
}

.records-list {
    font-size: calc(7 * var(--u));
}

.leaderboard {
    font-size: calc(7.5 * var(--u));
    line-height: 1.7;
}

.leaderboard .lb-name {
    max-width: 9ch;
}

/* Upright phones: the top right is narrow, so the all-time score
   takes two lines (label, then score), and the lobby's top 5 sits
   just below the top HUD on the right, where it has room, instead of
   squeezing into the column beside the title. */
@media (max-width: 600px) {
    .all-time-best span {
        display: block;
    }

    #hud .leaderboard {
        position: absolute;
        top: 100%;
        right: calc(8 * var(--u));
        margin-top: 0;
    }

    /* Likewise the game log, on the left. */
    #hud .game-log {
        position: absolute;
        top: 100%;
        left: calc(8 * var(--u));
        /* (Leaves the right side to the leaderboard.) */
        max-width: 46vw;
        margin-top: 0;
        font-size: calc(7 * var(--u));
    }
}

.radar {
    width: calc(72 * var(--u));
    height: calc(72 * var(--u));
    margin-bottom: calc(5 * var(--u));
}

.weapon-switch {
    font-size: calc(7 * var(--u));
    padding: calc(8 * var(--u)) calc(9 * var(--u));
    min-height: calc(34 * var(--u));
}

#start-screen,
#game-over {
    padding: calc(16 * var(--u));
}

.controls {
    font-size: calc(7 * var(--u));
}

.title-description {
    font-size: calc(8 * var(--u));
}


}

/* ============================================================ EXTRA-SMALL PHONES ============================================================ */

@media (max-width: 360px) { #hud, #bottom-hud { padding-left: calc(5 * var(--u)); padding-right: calc(5 * var(--u)); gap: calc(3 * var(--u)); }

#hud .leaderboard {
    right: calc(5 * var(--u));
}

#hud .game-log {
    left: calc(5 * var(--u));
}

.game-logo {
    font-size: calc(9 * var(--u));
}

.hud-subtitle {
    font-size: calc(5.5 * var(--u));
}

.hud-label {
    font-size: calc(6 * var(--u));
}

.hud-value,
.lives-value {
    font-size: calc(9 * var(--u));
}

.hull-bar {
    width: calc(64 * var(--u));
    height: calc(9 * var(--u));
}

#message {
    font-size: calc(6 * var(--u));
}

}

/* ============================================================ SHORT SCREENS (phones held sideways) ============================================================ */

/* Little height to spare: the start and game-over screens tighten up
   so the INSERT COIN / PLAY AGAIN button is on screen without
   scrolling. (The rest scrolls.) */
@media (max-height: 500px) {
    /* Height is the tight dimension here: a little less growth. */
    :root { --u: clamp(1.3px, calc(0.4px + 0.24vmin), 1.4px); }

    #start-screen h1,
    #game-over h2 {
        margin: calc(6 * var(--u)) 0;
    }

    #start-screen h1 {
        font-size: min(clamp(calc(30 * var(--u)), 7vw, calc(56 * var(--u))), 12vh);
    }

    /* The decorative stars in a row instead of a column. */
    .title-art {
        display: flex;
        justify-content: center;
        gap: calc(14 * var(--u));
    }

    .insert-coin,
    .game-over-icon {
        margin: calc(6 * var(--u)) 0;
    }

    .final-score-label {
        margin-top: calc(8 * var(--u));
    }

    .final-score {
        margin: calc(8 * var(--u)) 0;
    }

    .arcade-button {
        margin: calc(10 * var(--u)) 0;
        padding: calc(12 * var(--u));
    }

    /* The round results, tightened to fit. */
    .results-title {
        font-size: min(clamp(calc(24 * var(--u)), 6vw, calc(48 * var(--u))), 11vh);
    }

    .results-winner { margin-top: calc(6 * var(--u)); }
    .results-list { margin-top: calc(8 * var(--u)); line-height: 1.7; }
    .results-record { margin-top: calc(6 * var(--u)); }
    #round-results .records { margin-top: calc(8 * var(--u)); }
    .results-next { margin-top: calc(8 * var(--u)); }

    /* The ship picker moves just below the button (so the button is
       on screen without scrolling), the name beside the picture. */
    .ship-picker {
        order: 1;
        margin-top: 0;
    }

    #start-screen .records,
    #start-screen .controls,
    #start-screen .panel-bottomline,
    #game-over .records,
    #game-over .panel-bottomline {
        order: 2;
    }

    .ship-card {
        flex-direction: row;
        gap: calc(8 * var(--u));
        width: auto;
        min-width: calc(150 * var(--u));
        justify-content: center;
    }

    .ship-image {
        width: calc(44 * var(--u));
        height: calc(44 * var(--u));
    }

    .ship-name {
        margin-top: 0;
    }
}
