:root {
    --ink: #e8f1f7;
    --muted: #9fbcd0;
    --accent: #7ff3ff;
    --friendly: #6be585;
    --panel: rgba(10, 33, 52, 0.72);
    --panel-border: rgba(127, 200, 240, 0.22);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, sans-serif;
    color: var(--ink);
    background: #06141f radial-gradient(ellipse at 30% 0%, #143f60 0%, #0a2235 45%, #06141f 100%) fixed;
}

main {
    max-width: 44rem;
    margin: 3rem auto;
    padding: 0 1rem;
}

a {
    color: #7cc4ef;
}

h2 {
    font-size: 1.2rem;
    margin-top: 2rem;
}

h3 {
    font-size: 1rem;
    margin: 1.5rem 0 0.5rem;
}

[hidden] {
    display: none !important;
}

.status {
    color: #9fbcd0;
}

.error {
    color: #ff9b8f;
}

/* ---- Forms (login and register pages) ---- */

form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 20rem;
}

input,
button {
    font: inherit;
    padding: 0.4rem 0.6rem;
}

label {
    margin-top: 0.5rem;
}

button {
    background: #12415e;
    color: #e8f1f7;
    border: 1px solid #2f6f96;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

button:hover:not(:disabled) {
    background: #185577;
}

button:disabled {
    opacity: 0.45;
    cursor: default;
}

button.active {
    background: #2f7a4a;
    border-color: #6be585;
}

button.link {
    background: none;
    border: none;
    color: #7cc4ef;
    padding: 0;
}

a.button {
    display: inline-block;
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    border: 1px solid #2f6f96;
    background: #12415e;
    color: var(--ink);
    font-weight: 600;
    text-decoration: none;
}

a.button.primary {
    background: #1d6f80;
    border-color: var(--accent);
}

a.button:hover {
    filter: brightness(1.2);
}

/* ---- Home page: title, globe, lobby ---- */

.home {
    max-width: 72rem;
    margin: 2rem auto;
}

.hero {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2.2rem, 6vw, 3.4rem);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    background: linear-gradient(90deg, #e8f1f7, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.tagline {
    margin: 0.3rem 0 0;
    color: var(--muted);
    letter-spacing: 0.04em;
}

.account {
    margin: 0;
    color: var(--muted);
}

.account strong {
    color: var(--ink);
}

.lobby-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.globe-panel {
    position: sticky;
    top: 1rem;
    aspect-ratio: 1;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    background: radial-gradient(circle at 50% 45%, #0f2c47 0%, #061420 70%);
}

#globe {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

/* The name of the sea the globe is showing. */
.globe-label {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1rem;
    text-align: center;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    text-shadow: 0 0 12px rgba(127, 243, 255, 0.6);
    pointer-events: none;
}

.lobby h2 {
    margin-top: 0;
    font-size: 1.5rem;
}

.lobby .link {
    margin-bottom: 0.6rem;
}

.cta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

/* ---- Choosing a sea ---- */

.sea-list {
    display: grid;
    gap: 0.7rem;
}

.sea-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name pills" "area pills";
    align-items: center;
    gap: 0.15rem 1rem;
    padding: 0.9rem 1.1rem;
    text-align: left;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
}

.sea-card:hover:not(:disabled),
.sea-card:focus-visible {
    background: var(--panel);
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), 0 0 24px rgba(127, 243, 255, 0.18);
    transform: translateX(3px);
    outline: none;
}

.sea-name {
    grid-area: name;
    font-size: 1.15rem;
    font-weight: 700;
}

.sea-area {
    grid-area: area;
    color: var(--muted);
    font-size: 0.85rem;
}

.sea-card .pills {
    grid-area: pills;
    flex-direction: column;
    align-items: flex-end;
}

.pills {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.pill {
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.06);
    color: var(--muted);
    font-size: 0.75rem;
}

.pill.active {
    border-color: var(--friendly);
    background: var(--friendly);
    color: #04131c;
    font-weight: 600;
}

/* ---- Choosing a team and a ship ---- */

.my-team {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    border: 1px solid rgba(107, 229, 133, 0.5);
    background: rgba(107, 229, 133, 0.08);
}

.my-team button {
    align-self: flex-start;
}

.team-grid {
    display: grid;
    gap: 0.8rem;
}

.team-card {
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    border-top: 3px solid var(--team-color, var(--accent));
    background: var(--panel);
}

.team-card.mine {
    box-shadow: 0 0 0 1px var(--friendly), 0 0 20px rgba(107, 229, 133, 0.15);
}

.team-heading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.05rem;
}

.team-dot {
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    background: var(--team-color, var(--accent));
    box-shadow: 0 0 8px var(--team-color, var(--accent));
}

.countdown {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0.4rem 0 0.5rem;
    color: var(--muted);
    font-size: 0.8rem;
}

.countdown-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.countdown-bar {
    height: 100%;
    background: linear-gradient(90deg, #ffb238, #ffe066);
    transition: width 0.2s linear;
}

.team-slot {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.slot-about {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.slot-class {
    font-weight: 600;
}

.captain {
    color: var(--friendly);
    font-weight: 600;
}

.ship-icon {
    width: 64px;
    height: 20px;
    fill: #a9c4d6;
}

.class-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    gap: 0.7rem;
}

.class-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.9rem;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
}

.class-card .ship-icon {
    width: 100%;
    height: 34px;
    fill: #cfe3f0;
}

.class-card button {
    margin-top: auto;
}

/* Speed and armor bars. */
.ship-stats {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 7rem;
}

.stat {
    display: grid;
    grid-template-columns: 3.2rem 1fr;
    align-items: center;
    gap: 0.4rem;
    color: var(--muted);
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.stat-track {
    height: 5px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.stat-fill {
    display: block;
    height: 100%;
    background: var(--accent);
}

.how-to-play {
    margin: 2rem 0;
    padding: 0.8rem 1.1rem;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    background: var(--panel);
}

.how-to-play summary {
    cursor: pointer;
    font-weight: 700;
}

.help {
    color: #c3d6e3;
    line-height: 1.5;
    padding-left: 1.2rem;
}

@media (max-width: 860px) {
    .lobby-layout {
        grid-template-columns: 1fr;
    }

    .globe-panel {
        position: relative;
        top: 0;
        width: 100%;
        max-width: min(460px, 75vw);   /* leave room for the sea list on phones */
        margin: 0 auto;
    }
}

/* ---- The battle: 3D view on top, console below ---- */

#game {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #161d23;
}

.bridge {
    position: relative;
    flex: 1 1 auto;
    min-height: 40%;
}

#view {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;   /* taps and drags go to the game, not page scrolling */
    cursor: crosshair;
}

.bridge-top {
    position: absolute;
    top: 14px;
    left: 18px;
    right: 18px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.bridge-top button {
    pointer-events: auto;
}

.team-name {
    color: #6be585;
}

.feed {
    flex-basis: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    font-size: 0.9rem;
}

.feed div {
    background: rgba(6, 20, 31, 0.75);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

/* Warnings like "AGROUND", on their own line under the sea name, clear of your ship. */
.banner {
    flex-basis: 100%;
    color: #ffdd57;
    font-weight: 600;
    text-shadow: 0 1px 3px #000, 0 0 8px #000;
}

.console {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(170px, 240px) repeat(3, minmax(0, 1fr));
    gap: 0.6rem;
    padding: 0.6rem;
    background: #1b232a;
    border-top: 3px solid #2b3740;
    max-height: 55vh;
    overflow-y: auto;
}

.panel {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-width: 0;   /* let panels shrink on narrow screens instead of overflowing */
    padding: 0.5rem;
    background: #10171c;
    border: 1px solid #2b3740;
    border-radius: 6px;
}

.panel .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
}

.panel .row button {
    flex: 1 1 0;
}

.label {
    color: #8aa3b4;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.readout {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    color: #9be7a8;
}

.readout.warning {
    color: #ff9b8f;
}

#radar {
    width: 100%;
    aspect-ratio: 1;
    touch-action: none;
    cursor: crosshair;
}

#rudder-left,
#rudder-right {
    padding: 0.7rem 0.4rem;
    user-select: none;
}

.meter {
    height: 6px;
    background: #2b3740;
    border-radius: 3px;
    overflow: hidden;
}

.meter > div {
    height: 100%;
    width: 100%;
    background: #8aa3b4;   /* reload */
}

.range-meter {
    height: 10px;
}

.range-meter > div {
    width: 0;
    background: #ffe066;   /* how far the missile will fly */
}

/* Where the guns point: the middle of the 3D view. */
.crosshair {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 2px solid rgba(255, 224, 102, 0.85);
    border-radius: 50%;
    pointer-events: none;
}

.crosshair::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 4px;
    height: 4px;
    margin: -2px 0 0 -2px;
    border-radius: 50%;
    background: rgba(255, 224, 102, 0.95);
}

button.fire {
    padding: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    background: #8f2a1f;
    border-color: #ff6b5b;
    /* Holding it shouldn't select text or open a menu on phones. */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

button.fire:hover:not(:disabled) {
    background: #a83325;
}

#crew {
    margin: 0;
    padding-left: 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* After your ship sinks, the helm and weapons go dark. */
#game.sunk .helm,
#game.sunk .weapons {
    opacity: 0.35;
    pointer-events: none;
}

.results {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    min-width: 17rem;
    padding: 1rem 1.5rem;
    background: rgba(6, 20, 31, 0.95);
    border: 1px solid #2f6f96;
    border-radius: 8px;
}

.results h2 {
    margin-top: 0;
}

.results dl {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0.3rem 1rem;
}

.results dd {
    margin: 0;
    text-align: right;
}

/* Phones: radar and helm side by side, weapons and crew below, everything smaller. */
@media (max-width: 760px) {
    .bridge {
        min-height: 42%;
    }

    .console {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 0.4rem;
        padding: 0.4rem;
        max-height: 58vh;
    }

    .panel {
        gap: 0.3rem;
        padding: 0.35rem;
    }

    .console button {
        padding: 0.4rem 0.3rem;
        font-size: 0.85rem;
    }

    #rudder-left,
    #rudder-right {
        padding: 0.6rem 0.3rem;
        font-size: 1.1rem;
    }

    .console button.fire {
        padding: 0.8rem 0.3rem;
    }

    .word {
        display: none;   /* just the arrows on the rudder buttons */
    }

    .readout {
        font-size: 0.85rem;
    }

    .label {
        font-size: 0.65rem;
    }

    #crew {
        font-size: 0.75rem;
        padding-left: 0.8rem;
    }

    .bridge-top {
        font-size: 0.85rem;
    }
}
