/* The look of the page and of the HTML parts of the game (the words and
   buttons). The space scene itself is drawn on the canvas by game.js.

   Sizes use "cqw": 1cqw is 1% of the game box's width. The game box is 1600
   game pixels wide, so 1cqw = 16 game pixels. That way the words and buttons
   grow and shrink together with the game when the browser window changes size. */

html, body {
    margin: 0;
    height: 100%;
    background: #111;
    overflow: hidden;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: "Segoe UI", system-ui, sans-serif;
    user-select: none;          /* no text highlighting while playing */
}

/* The game box: as big as fits in the window, always 16 by 9. */
#game {
    position: relative;
    width: min(100vw, calc(100vh * 16 / 9));
    aspect-ratio: 16 / 9;
    background: black;
    container-type: inline-size;   /* lets everything inside use cqw */
    overflow: hidden;
    touch-action: none;            /* fingers steer the ship instead of scrolling the page */
}

#screen {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

/* Top left: 10 game pixels in from the corner, 10-point text in the ship's color. */
#info {
    position: absolute;
    left: 0.625cqw;
    top: 0.625cqw;
    font-size: 1.04cqw;
    white-space: pre;
    pointer-events: none;
}

/* Top right: the button, then the three lines, side by side. */
#scoreboard {
    position: absolute;
    top: 0.5cqw;
    right: 0.75cqw;
    display: flex;
    align-items: center;
    gap: 0.75cqw;
    font-size: 1.67cqw;          /* 16 point, like Score in the C# version */
    font-weight: bold;
}

/* Score, Lives and Shields: left-justified, in a column wide enough for
   its longest line, so nothing jumps sideways when the numbers change. */
#lines {
    width: 15cqw;
    line-height: 1.2;
    color: white;
    pointer-events: none;
}
#lines div { white-space: pre; }   /* keep the spaces in "Shields: 2   ON: 6s" */

#lives.last-life { color: rgb(255, 90, 90); }
#shields         { color: rgb(70, 150, 255); }
#shields.none    { color: gray; }

/* START / RESET: a rectangle with rounded corners, in the same font as Score. */
#start {
    width: 7.1cqw;
    height: 3.2cqw;
    font: inherit;
    color: white;
    border-radius: 0.4cqw;
    border: 0.13cqw solid;
    cursor: pointer;
}
.start       { background: rgba(40, 150, 70, 0.82);  border-color: rgb(90, 200, 120); }
.reset       { background: rgba(200, 40, 40, 0.82);  border-color: rgb(240, 110, 110); }
#start:active { filter: brightness(1.25); }

/* The gray ship buttons at the bottom left, just above the ground, in rows
   of 3 to leave room for the launch pad. */
#ship-buttons {
    position: absolute;
    left: 0.75cqw;
    bottom: 2.9cqw;
    display: grid;
    grid-template-columns: repeat(3, 10.625cqw);
    gap: 0.625cqw;
}
#ship-buttons[hidden] { display: none; }

.ship-button {
    width: 10.625cqw;
    height: 3cqw;
    padding: 0 0 0 0.375cqw;
    display: flex;
    align-items: center;
    gap: 0.5cqw;
    background: rgb(90, 90, 90);
    color: white;
    border: 0.1cqw solid rgb(130, 130, 130);
    border-radius: 0.5cqw;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.ship-button canvas {
    width: 2.375cqw;
    height: 2.375cqw;
    background: black;
    flex: none;
}
.ship-button .number { display: block; font-size: 0.83cqw; }
.ship-button .name   { display: block; font-size: 0.94cqw; font-weight: bold; }

/* The chosen ship: lighter gray, black writing, a border in the ship's own
   color (game.js sets that color). */
.ship-button.chosen {
    background: rgb(150, 150, 150);
    color: black;
    border-width: 0.19cqw;
}

/* Bottom: which keys do what. */
#keys {
    position: absolute;
    left: 0.625cqw;
    bottom: 0.4cqw;
    font-size: 1.04cqw;
    white-space: pre;
    pointer-events: none;
}

/* BATTLE OVER: a dark red box across the middle. */
#banner {
    position: absolute;
    left: 20%;
    top: 38%;
    width: 60%;
    height: 24%;
    box-sizing: border-box;
    background: rgba(40, 0, 0, 0.78);
    border: 0.25cqw solid rgb(255, 60, 60);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
#banner[hidden] { display: none; }
#banner .big   { font-size: 5.6cqw; font-weight: bold; line-height: 1.1; }
#banner .small { font-size: 1.67cqw; white-space: pre; }
#banner.win    { background: rgba(0, 50, 10, 0.8); border-color: rgb(80, 220, 110); }

/* The friend's line under Shields (2 players only). */
#other { color: rgb(255, 200, 90); font-size: 0.8em; }

/* Top middle: HOST / JOIN, and messages about the connection. */
#versus {
    position: absolute;
    top: 0.5cqw;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3cqw;
    font-size: 1.04cqw;
    color: rgb(255, 200, 90);
}
#versus[hidden] { display: none; }
#versus-buttons { display: flex; align-items: center; gap: 0.5cqw; }
#versus .or[hidden], #versus input[hidden] { display: none; }
#versus-buttons[hidden] { display: none; }
#versus button {
    font: bold 1.04cqw "Segoe UI", system-ui, sans-serif;
    padding: 0.3cqw 0.8cqw;
    color: white;
    background: rgb(150, 100, 20);
    border: 0.1cqw solid rgb(255, 200, 90);
    border-radius: 0.4cqw;
    cursor: pointer;
}
#versus button[hidden] { display: none; }
#versus input {
    width: 4.5cqw;
    font: bold 1.04cqw "Segoe UI", system-ui, sans-serif;
    padding: 0.25cqw 0.4cqw;
    text-align: center;
    border-radius: 0.3cqw;
    border: 0.1cqw solid rgb(255, 200, 90);
    background: black;
    color: white;
}
#versus-status { white-space: pre; text-align: center; }

/* START while waiting for the other player. */
.ready { background: rgba(40, 110, 60, 0.6); border-color: rgb(120, 170, 130); }

/* The INSTRUCTIONS button, next to the control pad. game.js sets its left
   and top (in %) each frame so it follows the pad. Same blue as the pad. */
#instructions-button {
    position: absolute;
    width: 9.375cqw;            /* 150 game pixels */
    height: 2.75cqw;            /* 44 game pixels */
    font: bold 0.95cqw "Segoe UI", system-ui, sans-serif;
    color: white;
    background: rgba(40, 90, 170, 0.82);
    border: 0.13cqw solid rgb(150, 200, 255);
    border-radius: 0.625cqw;
    box-shadow: 0.25cqw 0.4cqw 0 rgba(0, 0, 0, 0.35);   /* floats like the pad */
    cursor: pointer;
}
#instructions-button:active { filter: brightness(1.35); }
#instructions-button[hidden] { display: none; }

/* The instructions: a dark box with a blue border in the middle of the
   game. Only the box scrolls, not the page. */
#instructions {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 47.5cqw;             /* 760 game pixels */
    max-height: 37.5cqw;        /* 600 game pixels */
    box-sizing: border-box;
    display: flex;              /* version 37: the top bar, then the words that scroll */
    flex-direction: column;
    background: rgb(8, 14, 35);
    border: 0.19cqw solid rgb(70, 150, 255);
    color: white;
    font-size: 1.2cqw;
    line-height: 1.35;
    user-select: text;
}
#instructions[hidden] { display: none; }

/* Version 37: the top bar with the title and the red CLOSE button. It does not scroll. */
#instructions-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1cqw;
    padding: 0.6cqw 1.6cqw;
    border-bottom: 0.13cqw solid rgba(70, 150, 255, 0.5);
}
#instructions-close {
    flex: none;
    font: bold 1.2cqw "Segoe UI", system-ui, sans-serif;
    padding: 0.5cqw 1.4cqw;
    color: white;
    background: rgba(200, 40, 40, 0.9);
    border: 0.13cqw solid rgb(240, 110, 110);
    border-radius: 0.5cqw;
    cursor: pointer;
}
#instructions-close:active { filter: brightness(1.3); }

/* The words: only this part scrolls. */
#instructions-text {
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;        /* a finger can scroll it */
    padding: 0.2cqw 1.6cqw 1.2cqw;
}

#instructions h1 { color: yellow; font-size: 2.1cqw; margin: 0.4cqw 0; }
#instructions h2 { color: rgb(120, 190, 255); font-size: 1.4cqw; margin: 1.3cqw 0 0.2cqw; }
#instructions p  { margin: 0.3cqw 0; }

/* Version 39: the VOICE button at the top left, under the top line.
   Green while the crew talks, gray when the voice is off. */
#voice-button {
    position: absolute;
    left: 0.625cqw;
    top: 2.2cqw;
    font: bold 0.9cqw "Segoe UI", system-ui, sans-serif;
    padding: 0.35cqw 0.8cqw;
    color: white;
    background: rgba(40, 150, 70, 0.82);
    border: 0.13cqw solid rgb(90, 200, 120);
    border-radius: 0.4cqw;
    cursor: pointer;
}
#voice-button.off { background: rgba(90, 90, 90, 0.82); border-color: rgb(150, 150, 150); }
#voice-button:active { filter: brightness(1.3); }
#voice-button[hidden] { display: none; }

/* Version 41: PAUSED, over the whole game, after the player left it. */
#pause {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1cqw;
    background: rgba(0, 0, 20, 0.6);
    color: white;
    cursor: pointer;
}
#pause[hidden] { display: none; }
#pause .big   { font-size: 7cqw; font-weight: bold; color: rgb(255, 220, 120); letter-spacing: 0.1em; }
#pause .small { font-size: 2.2cqw; }

/* ================================================================
   Version 36: phones and tablets (a touch screen with no mouse).
   Everything here is bigger so a finger can hit it. On a computer
   none of this is used, so the game looks the same as before.
   ================================================================ */
@media (pointer: coarse) {
    /* "dvh" is the height you can really see, without the phone's address bar */
    html, body { height: 100dvh; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
    #game { width: min(100vw, calc(100dvh * 16 / 9)); }

    #info { font-size: 1.6cqw; }
    #scoreboard { font-size: 2.4cqw; gap: 1cqw; }
    #lines { width: 21cqw; }
    #start { width: 11cqw; height: 5cqw; border-radius: 0.8cqw; }

    #ship-buttons { grid-template-columns: repeat(3, 14cqw); gap: 0.8cqw; }
    .ship-button { width: 14cqw; height: 4.6cqw; border-radius: 0.8cqw; }
    .ship-button canvas { width: 3.6cqw; height: 3.6cqw; }
    .ship-button .number { font-size: 1.2cqw; }
    .ship-button .name   { font-size: 1.35cqw; }

    #keys { display: none; }   /* the keyboard help is no use on a phone */
    #voice-button { top: 3.2cqw; font-size: 1.5cqw; padding: 0.8cqw 1.6cqw; border-radius: 0.7cqw; }   /* version 39 */

    /* HOST / JOIN move down a little, under the START button's height */
    #versus { top: 6cqw; }
    #versus, #versus button, #versus input { font-size: 1.45cqw; }
    #versus button { padding: 0.6cqw 1.2cqw; }
    #versus input { width: 7cqw; padding: 0.5cqw; }

    #instructions-button { width: 14cqw; height: 4.25cqw; font-size: 1.45cqw; border-radius: 0.9cqw; }

    #instructions { width: 72cqw; max-height: 50cqw; font-size: 1.9cqw; }
    #instructions-top { padding: 1cqw 2.4cqw; }
    #instructions-text { padding: 0.4cqw 2.4cqw 2cqw; }
    #instructions-close { font-size: 1.9cqw; padding: 0.9cqw 2.4cqw; border-radius: 0.8cqw; }
    #instructions h1 { font-size: 3cqw; }
    #instructions h2 { font-size: 2.2cqw; }

    #banner .small { font-size: 2.4cqw; }
}

/* A phone held upright: ask for it to be turned sideways. */
#turn-phone { display: none; }
@media (pointer: coarse) and (orientation: portrait) {
    #turn-phone {
        position: fixed;
        inset: 0;
        z-index: 100;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 6vw;
        background: #0a0e20;
        color: rgb(255, 220, 120);
        font: bold 6vw "Segoe UI", system-ui, sans-serif;
        text-align: center;
    }
    #turn-phone .phone-icon { font-size: 22vw; animation: turn 2s ease-in-out infinite; }
    /* Version 37: the "Tap here to play" button and the auto-rotate hint */
    #turn-play {
        font: bold 6vw "Segoe UI", system-ui, sans-serif;
        padding: 3.5vw 8vw;
        color: white;
        background: linear-gradient(#50d264, #1e8c3c);
        border: 0.6vw solid #c8ffc8;
        border-radius: 4vw;
    }
    #turn-phone .turn-hint { font-size: 4vw; font-weight: normal; color: #b4c8ff; max-width: 84vw; line-height: 1.45; }
    #turn-phone .turn-hint b { color: rgb(255, 220, 120); }
    @keyframes turn { 0%, 30% { transform: rotate(0); } 60%, 100% { transform: rotate(-90deg); } }
}
