* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
}

body {
    overflow: hidden;
    background: #000;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    color: #dbe8f6;
}

:root {
    --touch-overlay-scale: 1;
    --touch-overlay-opacity: 1;
    --app-vw: 100vw;
    --app-vh: 100vh;
    --app-safe-vh: 100vh;
}

html.touch-capable-device,
body.touch-capable-device {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body.touch-ui-active-device {
    overscroll-behavior: none;
}

body.touch-ui-active-device #game {
    width: var(--app-vw) !important;
    height: var(--app-vh) !important;
}

html.overlay-fullscreen,
body.overlay-fullscreen {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

canvas {
    display: block;
}

body.overlay-fullscreen #game {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    height: 100dvh !important;
}

#fullscreen-fallback-hint {
    position: fixed;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(8, 18, 30, 0.8);
    border: 1px solid rgba(125, 189, 255, 0.45);
    color: #b9dcff;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 11px;
    letter-spacing: 0.04em;
    z-index: 690;
    pointer-events: none;
}

#btn-fullscreen-retry {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 10px;
    z-index: 691;
    min-height: 34px;
    padding: 8px 12px;
    letter-spacing: 0.08em;
    font-size: 11px;
}

#touch-debug-indicator {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    z-index: 900;
    background: rgba(8, 14, 24, 0.82);
    border: 1px solid rgba(122, 188, 255, 0.58);
    color: #bfe4ff;
    border-radius: 6px;
    padding: 5px 8px;
    font-family: "Courier New", monospace;
    font-size: 10px;
    letter-spacing: 0.03em;
    line-height: 1.25;
    pointer-events: none;
}

#btn-version-info {
    position: fixed;
    left: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 692;
    min-height: 30px;
    padding: 6px 10px;
    font-size: 10px;
    letter-spacing: 0.06em;
    opacity: 0.9;
}

#btn-weapon-credits-inline {
    min-height: 24px;
    min-width: 62px;
    padding: 4px 8px;
    font-size: 9px;
    letter-spacing: 0.06em;
}

#btn-important-notice {
    position: fixed;
    left: 10px;
    bottom: calc(46px + env(safe-area-inset-bottom, 0px));
    z-index: 692;
    min-height: 30px;
    padding: 6px 10px;
    font-size: 10px;
    letter-spacing: 0.06em;
    color: #ff5a5a;
    border-color: rgba(255, 120, 120, 0.6);
    text-shadow: 0 0 8px rgba(255, 60, 60, 0.45);
    animation: important-pulse 2.1s ease-in-out infinite;
}

@keyframes important-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.42; }
}

/* ---- Start Screen ---- */

#blocker {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background:
        linear-gradient(rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.88)),
        url('/assets/ui-ref/robot-reference.png') center center / cover no-repeat,
        rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: default;
}

#instructions {
    text-align: center;
    color: #fff;
}

#mp-pause-menu {
    display: none;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    justify-content: center;
    z-index: 102;
}

#instructions h1 {
    font-size: 4.5em;
    color: #8ed0ff;
    text-shadow: 0 0 26px rgba(92, 174, 255, 0.55), 0 0 70px rgba(20, 70, 122, 0.5);
    letter-spacing: 0.12em;
    margin-bottom: 0.05em;
}

#instructions .subtitle {
    font-size: 0.9em;
    color: #6e89a9;
    display: block;
    margin-bottom: 0.85em;
    letter-spacing: 0.3em;
}

#title-subtitle {
    display: none !important;
}

#instructions .author-credit {
    font-size: 0.98em;
    font-weight: 800;
    color: #9cc6e8;
    letter-spacing: 0.08em;
    white-space: nowrap;
    margin-top: -1.05em;
    margin-bottom: 1.2em;
    text-shadow: 0 0 10px rgba(156, 198, 232, 0.55), 0 0 26px rgba(66, 150, 220, 0.28);
    animation: author-credit-fade-soft 3.2s ease-in-out infinite;
}

@keyframes author-credit-fade-soft {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

#instructions p {
    font-size: 1.4em;
    color: #aaa;
    margin-bottom: 1.8em;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

#instructions .controls span {
    color: #8ec6ff;
    font-weight: bold;
}

.rules-text {
    position: fixed;
    right: 14px;
    bottom: 56px;
    z-index: 430;
    font-size: 0.82em;
    color: #9fb6cd;
    line-height: 1.65;
    width: min(360px, calc(100vw - 28px));
    max-width: calc(100vw - 28px);
    display: none;
    padding: 10px 14px;
    border: 1px solid rgba(130, 178, 230, 0.2);
    background: rgba(9, 16, 24, 0.84);
    border-radius: 8px;
    text-align: left;
    white-space: normal;
    pointer-events: auto;
}

.rules-toggle-btn {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 431;
    min-width: 94px;
    padding: 8px 14px;
    font-size: 11px;
}

#btn-rules-toggle {
    background: linear-gradient(180deg, rgba(28, 68, 118, 0.92), rgba(12, 30, 54, 0.95)) !important;
    border: 1px solid rgba(129, 210, 255, 0.92) !important;
    color: #d9f1ff !important;
    text-shadow: 0 0 10px rgba(124, 206, 255, 0.6);
    box-shadow: 0 0 14px rgba(73, 156, 218, 0.46), inset 0 0 12px rgba(109, 186, 248, 0.2);
}

#btn-rules-toggle:hover {
    background: linear-gradient(180deg, rgba(40, 88, 146, 0.96), rgba(18, 40, 72, 0.96)) !important;
    border-color: rgba(166, 228, 255, 0.98) !important;
    color: #f0f9ff !important;
    box-shadow: 0 0 22px rgba(98, 183, 246, 0.58), inset 0 0 12px rgba(149, 214, 255, 0.26) !important;
}

.rules-text strong:first-child {
    color: #8dd4ff;
    letter-spacing: 0.08em;
    text-shadow: 0 0 10px rgba(83, 177, 242, 0.45);
}

.chat-toggle-btn {
    position: fixed;
    right: 14px;
    bottom: 56px;
    z-index: 431;
    min-width: 94px;
    padding: 8px 14px;
    font-size: 11px;
}

@media (pointer: fine) {
    #language-switcher {
        left: 4px !important;
        right: auto !important;
        top: 4px !important;
        transform: none !important;
        width: min(180px, calc(100vw - 8px)) !important;
        padding: 8px 7px !important;
        gap: 4px !important;
    }

    #lang-buttons {
        flex-direction: row !important;
        gap: 4px !important;
        justify-content: space-between !important;
    }

    #lang-buttons .lang-btn {
        width: 34px !important;
        min-width: 34px !important;
        height: 22px !important;
        min-height: 22px !important;
        padding: 0 2px !important;
        font-size: 10px !important;
        letter-spacing: 0.01em !important;
    }

    #btn-rules-toggle,
    #btn-controls-toggle,
    #btn-chat-toggle,
    #btn-brada-toggle {
        width: 118px !important;
        min-width: 118px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 12px !important;
        box-sizing: border-box;
        font-size: 11px !important;
        line-height: 34px !important;
        text-align: center;
    }

    /* Match vertical gap with START/LEVEL EDITOR buttons (15px gap). */
    #btn-rules-toggle { bottom: 14px !important; }
    #btn-chat-toggle { bottom: 63px !important; }
    #btn-brada-toggle { bottom: 112px !important; }
    #btn-controls-toggle { bottom: 161px !important; }
}

/* ML (phone landscape): minimap down to ~1/4 size. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    #blocker {
        background:
            linear-gradient(rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.78)),
            url('/assets/ui-ref/robot-reference.png') center top / cover no-repeat,
            rgba(0, 0, 0, 0.84) !important;
    }

    #minimap-canvas {
        width: 68px !important;
        height: 68px !important;
        top: 8px !important;
        left: 8px !important;
    }

    #speedrun-timer {
        top: 8px !important;
        left: 86px !important;
        font-size: 11px !important;
    }
    #speedrun-timer #speedrun-time {
        font-size: 14px !important;
    }

    /* ML: keep first home screen title aligned like START submenu screen. */
    #start-buttons {
        position: static !important;
        left: auto !important;
        top: auto !important;
        transform: none !important;
        margin: 1.2em auto 0 !important;
        width: min(360px, 92vw) !important;
        z-index: auto !important;
    }

    #start-buttons .menu-btn {
        animation: none !important;
        transform: none !important;
    }

    /* ML: make START submenu button width match home START tile width. */
    #start-submenu-buttons {
        width: calc((min(360px, 92vw) - 10px) / 2) !important;
        margin-left: auto !important;
        margin-right: auto !important;
        align-items: center !important;
    }

    #start-submenu-buttons .menu-btn {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* FINAL iOS portrait HOME override (must stay last): RULES+CHAT at screen bottom. */
@media (pointer: coarse) and (orientation: portrait) and (max-width: 900px) {
    #btn-rules-toggle {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
    }
    #btn-chat-toggle {
        bottom: calc(45px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
    }
    #btn-fullscreen-retry {
        top: auto !important;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
    }
}

/* iOS portrait HOME: utility buttons anchored to bottom edge. */
@media (pointer: coarse) and (orientation: portrait) {
    #blocker[style*="display: flex"] ~ #btn-rules-toggle {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
    #blocker[style*="display: flex"] ~ #btn-chat-toggle {
        bottom: calc(45px + env(safe-area-inset-bottom, 0px)) !important;
    }
    #blocker[style*="display: flex"] ~ #btn-fullscreen-retry {
        top: auto !important;
        bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
    }
}

/* PL: keep VERSION anchored to the bottom on HOME and MP. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    #btn-version-info,
    #blocker[style*="display: flex"] ~ #btn-version-info,
    #mp-menu[style*="display: flex"] ~ #btn-version-info,
    #mp-lobby[style*="display: flex"] ~ #btn-version-info {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* Final ML override: keep Send message fully left on HOME and MP. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    #btn-send-dev-message,
    #blocker[style*="display: flex"] ~ #btn-send-dev-message {
        left: calc(2px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        transform: none !important;
    }
}

/* Tablet (TL/TP): separate name field + compact deathmatch toggle row. */
@media (pointer: coarse) and (min-width: 700px) {
    #mp-menu .mp-panel {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        position: relative;
        padding-bottom: 50px;
    }

    #mp-menu .mp-panel > .mp-form:first-of-type {
        order: 3;
        align-self: center;
        width: min(260px, 70vw);
        margin: 0 0 8px 0;
        padding: 6px 8px;
        border: 1px solid rgba(132, 176, 226, 0.35);
        border-radius: 6px;
        background: rgba(12, 24, 38, 0.42);
        text-align: center;
    }
    #mp-menu #mp-name-label {
        text-align: center;
        margin-bottom: 4px;
    }
    #mp-menu #mp-name {
        width: 100%;
        text-align: center;
        letter-spacing: 0.03em;
    }

    /* Match Server URL section to the same semi-transparent framed style. */
    #mp-menu .mp-panel > .mp-form:nth-of-type(2) {
        order: 5;
        align-self: center;
        width: min(420px, 88vw);
        margin: 0 0 10px 0;
        padding: 6px 8px;
        border: 1px solid rgba(132, 176, 226, 0.35);
        border-radius: 6px;
        background: rgba(12, 24, 38, 0.42);
        text-align: center;
    }
    #mp-menu #mp-server-label {
        text-align: center;
        margin-bottom: 4px;
    }
    #mp-menu #mp-server-url {
        width: 100%;
        text-align: center;
        letter-spacing: 0.02em;
    }

    /* Available rooms immediately below name field. */
    #mp-menu .mp-panel > .mp-browser {
        order: 4;
        margin-top: 0;
        margin-bottom: 10px;
    }
    #mp-menu .mp-panel > .mp-form:nth-of-type(3) { order: 6; margin-bottom: 0.8em; }
    #mp-menu .mp-panel > .mp-actions:nth-of-type(1) { order: 7; margin-bottom: 0.7em; }
    #mp-menu .mp-panel > .mp-actions:nth-of-type(2) { order: 9; margin: 0; }
    #mp-menu .mp-panel > #btn-mp-back {
        order: 9;
        position: absolute;
        left: 0;
        bottom: 8px;
        align-self: auto;
    }
    #mp-menu .mp-panel > .mp-actions:nth-of-type(2) {
        position: absolute;
        left: calc(min(110px, 40vw) + 10px);
        bottom: 8px;
        display: flex;
        justify-content: flex-start;
        width: auto;
    }
    #mp-menu .mp-panel > #mp-connect-status { order: 11; margin-top: 44px; }

    /* Deathmatch row: narrow checkbox area, text close with on/off rectangle state. */
    #mp-menu .mp-form label[style*="display:flex"] {
        gap: 1px !important;
        justify-content: center !important;
    }
    #mp-menu #mp-room-deathmatch {
        margin-right: 0 !important;
        width: 13px;
        height: 13px;
        min-width: 13px;
        min-height: 13px;
    }
    #mp-menu #mp-room-deathmatch + span {
        display: inline-block;
        border: 1px solid rgba(80, 200, 120, 0.95);
        background: rgba(24, 74, 38, 0.34);
        color: #b9f3c8;
        border-radius: 4px;
        padding: 2px 6px;
        line-height: 1.1;
    }
    #mp-menu #mp-room-deathmatch:checked + span {
        border-color: rgba(160, 56, 56, 0.98);
        background: rgba(72, 14, 14, 0.74);
        color: #ffb2b2;
    }

    /* Available Rooms and empty message in same semi-transparent framed look. */
    #mp-menu #mp-browser-title,
    #mp-menu .mp-browser-empty {
        display: inline-block;
        border: 1px solid rgba(132, 176, 226, 0.35);
        border-radius: 6px;
        background: rgba(12, 24, 38, 0.42);
        padding: 3px 8px;
    }
    #mp-menu #mp-browser-title {
        color: #b8d7f4;
    }
    #mp-menu .mp-browser-empty {
        color: #a3b9cf;
    }

    /* Tablet: remove global CONTROLS toggle from utility stack. */
    #btn-controls-toggle {
        display: none !important;
    }

    /* Tablet: BACK and OPEN EDITOR as left-aligned compact chat-like buttons. */
    #mp-menu #btn-mp-back,
    #mp-lobby #btn-lobby-back,
    #mp-gameover #btn-back-lobby,
    #mp-menu #btn-mp-open-editor {
        width: min(110px, 40vw) !important;
        min-width: min(110px, 40vw) !important;
        max-width: min(140px, 46vw) !important;
        min-height: 32px !important;
        padding: 6px 10px !important;
        text-align: center !important;
        align-self: flex-start !important;
        margin-left: 0 !important;
        background: linear-gradient(180deg, rgba(40, 86, 132, 0.95), rgba(22, 50, 84, 0.95)) !important;
        border: 1px solid rgba(142, 196, 255, 0.55) !important;
        color: #d2e9ff !important;
        text-shadow: 0 0 8px rgba(84, 162, 255, 0.35);
        box-shadow: 0 0 10px rgba(40, 96, 160, 0.22), inset 0 0 8px rgba(118, 188, 255, 0.12);
    }
    #mp-menu #btn-mp-open-editor {
        align-self: auto !important;
        margin-left: 0 !important;
    }
    #mp-menu #btn-mp-back:hover,
    #mp-lobby #btn-lobby-back:hover,
    #mp-gameover #btn-back-lobby:hover,
    #mp-menu #btn-mp-open-editor:hover {
        background: linear-gradient(180deg, rgba(50, 98, 146, 0.96), rgba(28, 60, 97, 0.96)) !important;
        border-color: rgba(164, 212, 255, 0.68) !important;
        color: #e2f2ff !important;
    }
}

/* Phone (ML/MP): cleaner MP menu + compact deathmatch row + BACK near RULES. */
@media (pointer: coarse) and (max-width: 900px) {
    /* Hide hosting help text on phones. */
    #mp-menu #mp-hint {
        display: none !important;
    }

    /* Move MP content upward on phone. */
    #mp-menu .mp-panel > h2 {
        margin-bottom: 0.18em;
    }
    #mp-menu .mp-form {
        margin-bottom: 0.55em;
    }
    #mp-menu .mp-actions {
        margin-bottom: 0.6em;
    }
    #mp-menu .mp-browser {
        margin-top: 0;
        margin-bottom: 0.7em;
    }

    /* Deathmatch row: narrow checkbox + tablet-like on/off rectangle text. */
    #mp-menu .mp-form label[style*="display:flex"] {
        gap: 1px !important;
        justify-content: center !important;
    }
    #mp-menu #mp-room-deathmatch {
        margin-right: 0 !important;
        width: 13px;
        height: 13px;
        min-width: 13px;
        min-height: 13px;
    }
    #mp-menu #mp-room-deathmatch + span {
        display: inline-block;
        border: 1px solid rgba(80, 200, 120, 0.95);
        background: rgba(24, 74, 38, 0.34);
        color: #b9f3c8;
        border-radius: 4px;
        padding: 2px 6px;
        line-height: 1.1;
    }
    #mp-menu #mp-room-deathmatch:checked + span {
        border-color: rgba(160, 56, 56, 0.98);
        background: rgba(72, 14, 14, 0.74);
        color: #ffb2b2;
    }

    /* Remove CONTROLS on phone; keep RULES and CHAT. */
    #btn-controls-toggle {
        display: none !important;
    }

    /* MP mode (phone): send bottom-left, version above it, back right of version. */
    #mp-menu[style*="display: flex"] ~ #btn-send-dev-message,
    #mp-lobby[style*="display: flex"] ~ #btn-send-dev-message {
        left: calc(10px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
    #mp-menu[style*="display: flex"] ~ #btn-version-info,
    #mp-lobby[style*="display: flex"] ~ #btn-version-info {
        left: calc(10px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important;
        width: 75px !important;
        min-width: 75px !important;
        height: 27px !important;
        min-height: 27px !important;
        padding: 0 6px !important;
        line-height: 27px !important;
        z-index: 433 !important;
    }
    #mp-menu[style*="display: flex"] #btn-mp-back,
    #mp-lobby[style*="display: flex"] #btn-lobby-back {
        position: fixed !important;
        left: calc(90px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 432 !important;
        width: 75px !important;
        min-width: 75px !important;
        height: 27px !important;
        min-height: 27px !important;
        padding: 0 6px !important;
        line-height: 27px !important;
        margin: 0 !important;
        background: linear-gradient(180deg, rgba(40, 86, 132, 0.95), rgba(22, 50, 84, 0.95)) !important;
        border: 1px solid rgba(142, 196, 255, 0.55) !important;
        color: #d2e9ff !important;
    }
}

/* Send message: always left next to VERSION (left: 98px, bottom: 10px). */
/* Final Send Message readability override (all platforms):
   keep full label visible by allowing wrap instead of ellipsis. */
#btn-send-dev-message {
    width: auto !important;
    min-width: 170px !important;
    max-width: min(76vw, 360px) !important;
    height: auto !important;
    min-height: 30px !important;
    padding: 4px 10px !important;
    line-height: 1.12 !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    text-align: center !important;
}

/* ML hard visibility fix: always show MULTIPLAYER on start screen. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    #blocker #start-buttons #btn-multiplayer.menu-btn {
        display: inline-flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Touch overlay (FPS action buttons). FPS-Arena style: semi-transparent black, red border/text. */
.touch-action-btn {
    position: fixed !important;
    z-index: 432 !important;
    min-width: 58px;
    min-height: 58px;
    width: 58px;
    height: 58px;
    padding: 0;
    border-radius: 50% !important;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    touch-action: none;
    letter-spacing: 0.05em;
    border: 2px solid rgba(220, 60, 60, 0.9) !important;
    color: #ff5a5a !important;
    background: rgba(4, 4, 8, 0.65) !important;
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.5) !important;
}

.touch-action-btn.touch-btn-icon {
    font-size: 26px;
}

body.touch-match-active #btn-touch-fire,
body.touch-match-active #btn-touch-reload,
body.touch-match-active #btn-touch-switch,
body.touch-match-active #btn-touch-mode,
body.touch-match-active #btn-touch-run,
body.touch-match-active #btn-touch-pause,
body.touch-match-active #btn-touch-action {
    display: inline-flex !important;
    position: fixed !important;
    visibility: visible !important;
    pointer-events: auto !important;
    z-index: 432 !important;
}

/* RUN+PAUSE gore ispod minimape. ACTION iznad RELOAD (right 78px). */
body.touch-match-active #btn-touch-action { right: 78px !important; left: auto !important; bottom: calc(190px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-run { left: 14px !important; right: auto !important; bottom: calc(230px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-pause { left: 78px !important; right: auto !important; bottom: calc(230px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active #btn-touch-fire { right: 14px !important; left: auto !important; bottom: calc(126px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active #btn-touch-reload { right: 78px !important; left: auto !important; bottom: calc(126px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active #btn-touch-switch { right: 186px !important; left: auto !important; bottom: calc(126px + env(safe-area-inset-bottom, 0px)) !important; }
body.touch-match-active #btn-touch-mode { right: 142px !important; left: auto !important; bottom: calc(126px + env(safe-area-inset-bottom, 0px)) !important; }

/* 3D editor: sakrij samo RUN/PAUSE, ostali (FIRE, RELOAD, SWITCH, ACTION) vidljivi za edit */
body.edit3d-overlay-layout #btn-touch-run,
body.edit3d-overlay-layout #btn-touch-pause {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#btn-touch-run.touch-toggle-on {
    background: rgba(4, 4, 8, 0.65) !important;
    border: 2px solid rgba(80, 255, 100, 0.9) !important;
    color: #66ff88 !important;
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.5) !important;
}

#btn-touch-run.touch-toggle-off {
    background: rgba(4, 4, 8, 0.65) !important;
    border: 2px solid rgba(220, 60, 60, 0.9) !important;
    color: #ff5a5a !important;
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.5) !important;
}

/* RUN/PAUSE buttons: square with text labels. */
#btn-touch-run,
#btn-touch-pause {
    border-radius: 6px !important;
    width: 58px !important;
    height: 58px !important;
    min-width: 58px !important;
    min-height: 58px !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 1 !important;
    text-align: center !important;
    letter-spacing: 0.04em !important;
    border: 2px solid rgba(220, 60, 60, 0.9) !important;
    color: #ff5a5a !important;
    background: rgba(4, 4, 8, 0.65) !important;
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.5) !important;
}

/* Gamepad detected: hide combat overlay (FIRE, RELOAD, etc.), keep PAUSE visible on ML. */
body.gamepad-overlay-hidden #btn-touch-fire,
body.gamepad-overlay-hidden #btn-touch-reload,
body.gamepad-overlay-hidden #btn-touch-switch,
body.gamepad-overlay-hidden #btn-touch-mode,
body.gamepad-overlay-hidden #btn-touch-action,
body.gamepad-overlay-hidden #btn-touch-run {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
body.gamepad-overlay-hidden:not(.edit3d-overlay-layout) #btn-touch-pause {
    display: inline-flex !important;
    visibility: visible !important;
    pointer-events: auto !important;
    left: 78px !important;
    right: auto !important;
    bottom: calc(230px + env(safe-area-inset-bottom, 0px)) !important;
}

@media (pointer: coarse) and (orientation: portrait) {
    #btn-touch-action { right: 78px; left: auto; bottom: calc(190px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-run { left: 14px; bottom: calc(230px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-pause { left: 78px; bottom: calc(230px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-fire { right: 14px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-reload { right: 78px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-switch { right: 186px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-mode { right: 142px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
}

@media (pointer: coarse) and (orientation: landscape) {
    #btn-touch-action { right: 78px; left: auto; bottom: calc(190px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-run { left: 14px; bottom: calc(230px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-pause { left: 78px; bottom: calc(230px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-fire { right: 14px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-reload { right: 78px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-switch { right: 186px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
    #btn-touch-mode { right: 142px; bottom: calc(126px + env(safe-area-inset-bottom, 0px)); }
}

#mp-chat-send-touch-fallback {
    position: fixed;
    left: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 640;
    border: 1px solid rgba(126, 196, 255, 0.55);
    background: rgba(17, 48, 78, 0.92);
    color: #d7e8f8;
    border-radius: 6px;
    min-height: 38px;
    min-width: 82px;
    padding: 7px 12px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
}

#mp-chat-send-touch-fallback.chat-keyboard-avoid {
    top: 56px;
    bottom: auto;
}

@media (pointer: fine) {
    #mp-chat-send-touch-fallback {
        display: none !important;
    }
}

body.touch-editor-mode-active::before {
    content: '';
    position: fixed;
    inset: 0;
    /* Solid high-contrast editor backdrop: game scene must not be visible. */
    background: #101822;
    z-index: 700;
    pointer-events: none;
}

body.touch-editor-mode-active .touch-action-btn {
    z-index: 820 !important;
    opacity: 1 !important;
    filter: brightness(1.1) contrast(1.06);
}

body.touch-editor-mode-active .touch-action-btn.touch-editor-selected {
    border: 2px solid #8fd3ff !important;
    box-shadow: inset 0 0 14px rgba(0, 0, 0, 0.4) !important;
}

#touch-editor-toolbar {
    position: fixed;
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 8px;
    right: 8px;
    z-index: 830;
}

.touch-editor-toolbar-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(18, 22, 30, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    padding: 8px 10px;
}

#touch-editor-selected-label {
    min-width: 92px;
    color: #d6e8ff;
    font-size: 11px;
    font-weight: 700;
}

#touch-editor-opacity-slider {
    flex: 1;
}

#btn-touch-editor-done {
    min-width: 76px;
    height: 30px;
    font-size: 10px;
    letter-spacing: 0.06em;
}

#btn-touch-editor-reset {
    min-width: 76px;
    height: 30px;
    font-size: 10px;
    letter-spacing: 0.06em;
}

/* Send message: always left, next to VERSION (left: 98px). */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    /* ML multiplayer: always allow vertical scrolling when content grows. */
    #mp-menu,
    #mp-lobby {
        align-items: flex-start !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }
    #mp-menu .mp-panel,
    #mp-lobby .mp-panel {
        max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    #btn-send-dev-message {
        left: 98px !important;
        right: auto !important;
        transform: none !important;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        width: 96px !important;
        min-width: 96px !important;
        max-width: 96px !important;
        min-height: 28px !important;
        height: auto !important;
        padding: 4px 6px !important;
        font-size: 7px !important;
        line-height: 1.05 !important;
        letter-spacing: 0 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
        text-align: center !important;
        z-index: 431 !important;
    }
}

#language-switcher {
    position: fixed;
    right: 14px;
    top: 14px;
    z-index: 450;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
    width: min(185px, calc(100vw - 18px));
    background: rgba(7, 12, 20, 0.65);
    border: 1px solid rgba(126, 186, 248, 0.35);
    border-radius: 10px;
    box-shadow: 0 0 22px rgba(41, 120, 193, 0.2);
    pointer-events: auto;
}

#lang-title {
    font-size: 10px;
    letter-spacing: 0.12em;
    color: #8fc9ff;
    text-transform: uppercase;
    display: none !important;
}

#lang-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    justify-content: flex-start;
}

.lang-btn {
    width: 100%;
    height: 24px;
    border-radius: 5px;
    border: 1px solid rgba(136, 194, 255, 0.45);
    background: rgba(25, 52, 82, 0.55);
    color: #d4ecff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: all 0.14s ease;
}

.lang-btn:hover {
    background: rgba(48, 97, 150, 0.65);
}

.lang-btn.active {
    background: linear-gradient(180deg, rgba(102, 170, 235, 0.95), rgba(54, 121, 191, 0.95));
    color: #091624;
    border-color: #7ec4ff;
    box-shadow: 0 0 12px rgba(89, 168, 240, 0.45);
}

#btn-send-dev-message {
    position: fixed;
    left: 98px;
    right: auto;
    top: auto;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    transform: none;
    z-index: 431;
    width: min(220px, calc(100vw - 220px));
    min-width: 132px;
    margin-top: 0 !important;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.12;
    height: auto;
    min-height: 30px;
    padding: 6px 8px;
    letter-spacing: 0.01em;
}

#lang-hint {
    font-size: 9px;
    color: #9db4ca;
    text-align: center;
    line-height: 1.25;
}

#language-switcher .controls {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(126, 186, 248, 0.2);
    font-size: 0.78em;
    color: #9bb4cc;
    line-height: 1.65;
    text-align: left;
}

#language-switcher .controls span {
    color: #8ec6ff;
    font-weight: 700;
}

#language-switcher .controls .control-item {
    display: block;
    white-space: normal;
    overflow-wrap: anywhere;
    margin-bottom: 3px;
}

#language-switcher .controls .control-item:last-child {
    margin-bottom: 0;
}

#dev-message-modal {
    position: fixed;
    inset: 0;
    z-index: 700;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#dev-message-card {
    width: min(460px, calc(100vw - 24px));
    background: rgba(12, 18, 28, 0.97);
    border: 1px solid rgba(128, 184, 245, 0.35);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#dev-message-card h3 {
    margin: 0 0 2px 0;
    color: #bfe0ff;
    font-size: 16px;
}

#player-name-modal {
    position: fixed;
    inset: 0;
    z-index: 704;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#player-name-card {
    width: min(420px, calc(100vw - 24px));
    background: rgba(12, 18, 28, 0.97);
    border: 1px solid rgba(128, 184, 245, 0.35);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#player-name-title {
    margin: 0;
    color: #bfe0ff;
    font-size: 17px;
}

#player-name-label {
    color: #a7bdd4;
    font-size: 13px;
}

#player-name-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid rgba(130, 178, 230, 0.45);
    border-radius: 8px;
    background: rgba(8, 12, 18, 0.88);
    color: #d8ecff;
    padding: 8px 10px;
    font-size: 14px;
}

#player-name-status {
    min-height: 18px;
    color: #9dd7a9;
    font-size: 12px;
}

.player-name-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

#options-modal {
    position: fixed;
    inset: 0;
    z-index: 705;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#options-card {
    width: min(460px, calc(100vw - 24px));
    background: rgba(12, 18, 28, 0.97);
    border: 1px solid rgba(128, 184, 245, 0.35);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#options-card h3 {
    margin: 0;
    color: #bfe0ff;
    font-size: 18px;
}

#version-info-modal {
    position: fixed;
    inset: 0;
    z-index: 706;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#weapon-credits-modal {
    position: fixed;
    inset: 0;
    z-index: 707;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#important-notice-modal {
    position: fixed;
    inset: 0;
    z-index: 707;
    background: rgba(0, 0, 0, 0.62);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

#important-notice-card {
    width: min(560px, calc(100vw - 24px));
    max-height: min(72vh, 620px);
    overflow: auto;
    background: rgba(20, 10, 12, 0.97);
    border: 1px solid rgba(255, 120, 120, 0.45);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#important-notice-title {
    margin: 0;
    color: #ff6c6c;
    letter-spacing: 0.08em;
    text-shadow: 0 0 10px rgba(255, 72, 72, 0.45);
}

#important-notice-text {
    color: #ffd7d7;
    font-size: 14px;
    line-height: 1.5;
}

.important-notice-actions {
    display: flex;
    justify-content: flex-end;
}

#version-info-card {
    width: min(520px, calc(100vw - 24px));
    max-height: min(72vh, 620px);
    overflow: auto;
    background: rgba(12, 18, 28, 0.97);
    border: 1px solid rgba(128, 184, 245, 0.35);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#weapon-credits-card {
    width: min(700px, calc(100vw - 24px));
    max-height: min(76vh, 700px);
    overflow: auto;
    background: rgba(12, 18, 28, 0.97);
    border: 1px solid rgba(128, 184, 245, 0.35);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#weapon-credits-title {
    margin: 0;
    color: #bfe0ff;
    font-size: 18px;
}

#weapon-credits-legal {
    color: #cfe3f8;
    font-size: 13px;
    line-height: 1.45;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(118, 168, 220, 0.28);
    background: rgba(20, 32, 49, 0.64);
    white-space: pre-wrap;
}

#weapon-credits-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weapon-credit-item {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(118, 168, 220, 0.28);
    background: rgba(20, 32, 49, 0.64);
}

.weapon-credit-name {
    color: #9ec7ee;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.weapon-credit-text {
    color: #d6e7f8;
    font-size: 13px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.weapon-credit-link {
    color: #8ecbff;
    text-decoration: underline;
    word-break: break-all;
}

.weapon-credit-link:hover {
    color: #bde3ff;
}

.weapon-credits-actions {
    display: flex;
    justify-content: flex-end;
}

#version-info-title {
    margin: 0;
    color: #bfe0ff;
    font-size: 18px;
}

#version-info-filter-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#btn-version-filter-reset {
    min-height: 24px;
    padding: 4px 8px;
    font-size: 9px;
    letter-spacing: 0.06em;
}

#version-info-count {
    color: #8fb9e3;
    font-size: 11px;
    letter-spacing: 0.06em;
}

.version-filter-row {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.version-filter-label {
    color: #9ec7ee;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.version-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.version-filter-chip {
    border: 1px solid rgba(118, 168, 220, 0.4);
    border-radius: 6px;
    background: rgba(21, 39, 60, 0.72);
    color: #d5e9ff;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    letter-spacing: 0.03em;
}

/* Keep YEAR readable; MONTH and DAY stay compact in one line. */
#version-filter-months.version-filter-chips,
#version-filter-days.version-filter-chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
}
#version-filter-months .version-filter-chip,
#version-filter-days .version-filter-chip {
    flex: 0 0 auto;
    min-width: 36px;
    padding: 2px 7px;
    font-size: 10px;
}

.version-filter-chip.active {
    border-color: rgba(152, 205, 255, 0.9);
    background: rgba(58, 112, 176, 0.9);
    color: #fff;
}

.version-date-picker {
    border: 1px solid rgba(132, 184, 245, 0.45);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(22, 28, 40, 0.96), rgba(18, 24, 34, 0.96));
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), inset 0 0 16px rgba(82, 140, 212, 0.08);
    padding: 10px;
    margin-top: 2px;
}

.version-date-head {
    margin-bottom: 6px;
}

.version-date-title-weekday {
    color: #9db3ca;
    font-size: 12px;
    font-weight: 700;
}

.version-date-title-date {
    color: #d9eaff;
    font-size: 34px;
    line-height: 1.1;
    font-weight: 800;
    margin-top: 2px;
}

.version-date-month-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.version-date-nav {
    border: 0;
    background: transparent;
    color: #d8e9ff;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.9;
    width: 28px;
    height: 24px;
}

.version-date-nav:hover {
    opacity: 1;
}

.version-date-month-label {
    color: #dbeeff;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.version-date-weekdays {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
    margin-bottom: 4px;
}

.version-date-weekday {
    color: #97aec8;
    font-size: 11px;
    text-align: center;
    font-weight: 700;
    text-transform: uppercase;
}

.version-date-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
}

.version-date-day {
    position: relative;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: #d8e9ff;
    font-size: 14px;
    font-weight: 700;
    min-height: 32px;
    cursor: pointer;
}

.version-date-day.muted {
    color: rgba(180, 198, 216, 0.45);
}

.version-date-day.has-change::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: 4px;
    width: 5px;
    height: 5px;
    margin-left: -2.5px;
    border-radius: 50%;
    background: #67b0ff;
    box-shadow: 0 0 8px rgba(103, 176, 255, 0.75);
}

.version-date-day.selected {
    background: #3c86d9;
    border-color: rgba(142, 197, 255, 0.95);
    color: #ffffff;
}

#version-info-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: #d6e7f8;
}

.version-entry {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(118, 168, 220, 0.28);
    background: rgba(20, 32, 49, 0.64);
}

.version-entry-date {
    font-size: 11px;
    letter-spacing: 0.08em;
    color: #8fb9e3;
    margin-bottom: 4px;
}

.version-entry-text {
    font-size: 13px;
    line-height: 1.35;
}

.version-info-actions {
    display: flex;
    justify-content: flex-end;
}

.option-row {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    color: #c5dbef;
}

.option-row label {
    font-size: 13px;
    letter-spacing: 0.05em;
}

.option-slider-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
}

.option-slider-wrap input[type="range"] {
    flex: 1;
    min-width: 220px;
    max-width: 320px;
    accent-color: #67b4ff;
}


#mouse-sensitivity-value {
    min-width: 52px;
    text-align: right;
    color: #9fd0ff;
    font-weight: 700;
    font-size: 13px;
}

.options-actions {
    display: flex;
    justify-content: flex-end;
}

#dev-message-name,
#dev-message-text {
    width: 100%;
    background: rgba(9, 14, 22, 0.95);
    border: 1px solid rgba(122, 170, 219, 0.35);
    border-radius: 6px;
    color: #d8ebff;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    font-size: 13px;
    padding: 8px;
}

#dev-message-text {
    min-height: 108px;
    resize: vertical;
}

#dev-message-status {
    min-height: 16px;
    color: #8ee6a1;
    font-size: 12px;
}

.dev-message-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

#minimap-toggle-control {
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #9cc7ee;
    font-size: 11px;
}

#minimap-toggle-control input,
#toggle-minimap {
    width: 14px;
    height: 14px;
    accent-color: #67b4ff;
}

/* ---- HUD ---- */

#hud {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

#crosshair {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(164, 216, 255, 0.75);
    font-size: 22px;
    text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
    font-weight: 100;
    line-height: 1;
}

#health-bar {
    position: absolute;
    bottom: 30px; left: 30px;
    display: flex;
    align-items: center;
    gap: 10px;
}

#health-icon {
    color: #ffd700;
    font-size: 26px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

#health-bg {
    width: 220px; height: 8px;
    background: rgba(24, 31, 45, 0.85);
    border: 1px solid rgba(140, 176, 220, 0.25);
    border-radius: 3px;
    overflow: hidden;
}

#health-fill {
    width: 100%; height: 100%;
    background: linear-gradient(90deg, #22ff44, #44ff66);
    border-radius: 3px;
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(34, 255, 68, 0.3);
}

#health-text {
    color: #44ff66;
    font-size: 18px;
    min-width: 35px;
    text-shadow: 0 0 8px rgba(34, 255, 68, 0.3);
}

#ammo-display {
    position: absolute;
    bottom: 30px; right: 30px;
    text-align: right;
    color: #e6f3ff;
    font-size: 22px;
    text-shadow: 0 0 10px rgba(255, 170, 0, 0.3);
}

#weapon-name {
    font-size: 11px;
    color: rgba(157, 195, 235, 0.72);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 4px;
}

#kills-display {
    position: absolute;
    top: 20px; right: 30px;
    color: rgba(255, 255, 255, 0.4);
    font-size: 13px;
    letter-spacing: 0.15em;
}

#kills-count {
    color: #ff4400;
    font-size: 15px;
}

#coins-display {
    position: absolute;
    top: 42px; right: 30px;
    color: rgba(255, 215, 0, 0.6);
    font-size: 13px;
    letter-spacing: 0.15em;
}

#coins-count {
    color: #ffd700;
    font-size: 15px;
}

#robots-display {
    position: absolute;
    top: 64px; right: 30px;
    color: rgba(136, 221, 255, 0.65);
    font-size: 13px;
    letter-spacing: 0.15em;
}

#robots-count {
    color: #88ddff;
    font-size: 15px;
}

#floor-display {
    position: absolute;
    top: 86px; right: 30px;
    color: rgba(158, 209, 255, 0.7);
    font-size: 13px;
    letter-spacing: 0.15em;
}

#minimap-canvas {
    position: absolute;
    top: 20px;
    left: 30px;
    width: 180px;
    height: 180px;
    border: 1px solid rgba(138, 197, 255, 0.45);
    border-radius: 4px;
    background: rgba(4, 11, 20, 0.65);
    box-shadow: 0 0 12px rgba(50, 116, 180, 0.25);
    opacity: 0.88;
}

#speedrun-timer {
    position: absolute;
    top: 20px;
    left: 218px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #ffd700;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

#speedrun-timer #speedrun-level {
    color: rgba(255, 215, 0, 0.9);
}

#speedrun-timer #speedrun-time {
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

#damage-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(180, 0, 0, 0.5) 100%);
    opacity: 0;
    transition: opacity 0.1s ease;
    pointer-events: none;
}

#hit-marker {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #ff4400;
    font-size: 18px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.05s;
    text-shadow: 0 0 6px rgba(255, 68, 0, 0.8);
}

#interact-prompt {
    position: absolute;
    bottom: 45%;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 15px;
    letter-spacing: 0.12em;
    text-shadow: 0 0 8px rgba(0,0,0,0.9), 0 0 20px rgba(0,0,0,0.5);
    background: rgba(0,0,0,0.4);
    padding: 8px 20px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
}

#interact-prompt span {
    color: #ff6600;
    font-weight: bold;
}

#key-indicator {
    position: absolute;
    top: 20px;
    left: 30px;
    color: #ffcc00;
    font-size: 14px;
    letter-spacing: 0.12em;
    text-shadow: 0 0 10px rgba(255,204,0,0.5);
}

#start-buttons {
    margin-top: 2em;
    display: flex;
    gap: 15px;
    flex-direction: column;
    align-items: center;
}

#start-buttons .menu-btn {
    width: min(360px, 88vw);
}

#start-submenu {
    margin-top: 18px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#start-submenu-title {
    color: #9fcbf2;
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.95;
}

#start-submenu-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#start-submenu-buttons .menu-btn {
    width: min(360px, 88vw);
}

/* LOAD EDITED LEVEL: hidden on laptop, TL, TP, ML, MP (PC only). */
@media (pointer: coarse) {
    #btn-load-editor-level { display: none !important; }
}
@media (pointer: fine) and (max-width: 1600px) {
    #btn-load-editor-level { display: none !important; }
}

#map-toggle-wrap {
    margin-top: 14px;
    display: flex;
    justify-content: center;
}

#minimap-toggle-control {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid rgba(144,194,255,0.35);
    border-radius: 6px;
    background: rgba(20, 40, 62, 0.35);
    color: #bfe0ff;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    min-height: 30px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
}

#toggle-minimap {
    width: 14px;
    height: 14px;
    accent-color: #67b4ff;
    cursor: pointer;
}

.menu-btn {
    background: linear-gradient(180deg, rgba(73,123,173,0.26), rgba(22,44,70,0.45));
    border: 1px solid rgba(144,194,255,0.55);
    color: #bfe0ff;
    font-family: 'Segoe UI', 'Arial', sans-serif;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 0.15em;
    padding: 12px 24px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    pointer-events: auto;
    position: relative;
    z-index: 200;
    text-transform: uppercase;
}

.menu-btn:hover {
    background: rgba(79,140,206,0.36);
    border-color: #88c6ff;
    box-shadow: 0 0 20px rgba(96,177,255,0.3);
    transform: scale(1.05);
}

/* When navigating with gamepad, avoid mouse hover "fake selection". */
.gamepad-nav-active .menu-btn:hover {
    background: linear-gradient(180deg, rgba(73,123,173,0.26), rgba(22,44,70,0.45));
    border-color: rgba(144,194,255,0.55);
    box-shadow: none;
    transform: none;
}

/* Override all hover variants while gamepad focus is driving selection. */
body.gamepad-nav-active .menu-btn:hover,
body.gamepad-nav-active .mp-btn:hover {
    background: linear-gradient(180deg, rgba(73,123,173,0.26), rgba(22,44,70,0.45)) !important;
    border-color: rgba(144,194,255,0.55) !important;
    box-shadow: none !important;
    transform: none !important;
}

/* Fully hide cursor while gamepad input mode is active. */
body.gamepad-input-active,
body.gamepad-input-active * {
    cursor: none !important;
}

/* In gamepad mode, disable the mouse-reveal mask completely. */
body.gamepad-input-active #blocker::before {
    -webkit-mask-image: none !important;
    mask-image: none !important;
}

/* Single source of truth for gamepad selection styling. */
body.gamepad-nav-active .gp-selected {
    border-color: rgba(125, 196, 255, 0.98) !important;
    box-shadow: 0 0 0 2px rgba(125, 196, 255, 0.9), 0 0 18px rgba(125, 196, 255, 0.28) !important;
    transform: none !important;
}
body.gamepad-nav-active .gp-selected:hover,
body.gamepad-nav-active .gp-selected:active,
body.gamepad-nav-active .gp-selected:focus,
body.gamepad-nav-active .gp-selected:focus-visible {
    background: linear-gradient(180deg, rgba(73,123,173,0.26), rgba(22,44,70,0.45)) !important;
    border-color: rgba(125, 196, 255, 0.98) !important;
    box-shadow: 0 0 0 2px rgba(125, 196, 255, 0.9), 0 0 18px rgba(125, 196, 255, 0.28) !important;
    transform: none !important;
    outline: none !important;
}

.mp-btn {
    background: linear-gradient(180deg, rgba(77,173,255,0.25), rgba(38,89,138,0.18));
    border-color: rgba(94,193,255,0.5);
    color: #6ecfff;
}

.mp-btn:hover {
    background: rgba(68,136,255,0.3);
    border-color: #4488ff;
    box-shadow: 0 0 20px rgba(68,136,255,0.3);
}

/* ---- Death Screen ---- */

#death-screen {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(80, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 200;
    cursor: pointer;
    color: #fff;
    font-family: 'Courier New', monospace;
}

#death-screen h1 {
    font-size: 4em;
    color: #ff0000;
    text-shadow: 0 0 40px rgba(255, 0, 0, 0.8);
    margin-bottom: 0.5em;
    letter-spacing: 0.15em;
}

#death-screen p {
    font-size: 1.2em;
    color: #ddd;
    margin: 0.3em;
}

#death-screen .restart-hint {
    margin-top: 1.5em;
    color: #999;
    animation: pulse 2s ease-in-out infinite;
}

/* ---- Multiplayer UI ---- */

#mp-menu, #mp-lobby {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background:
        linear-gradient(rgba(4, 10, 18, 0.72), rgba(2, 8, 14, 0.88)),
        url('/assets/ui-ref/robot-reference.png') center center / cover no-repeat,
        rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    color: #fff;
    font-family: 'Courier New', monospace;
}

.mp-panel {
    text-align: center;
    max-width: 500px;
    width: 90%;
    max-height: min(86vh, 700px);
    overflow-y: auto;
    padding-bottom: 10px;
}

.mp-panel h2 {
    font-size: 2.5em;
    color: #4488ff;
    letter-spacing: 0.15em;
    margin-bottom: 0.5em;
    text-shadow: 0 0 20px rgba(68,136,255,0.4);
}

.mp-hint {
    color: #666;
    font-size: 0.85em;
    margin-bottom: 2em;
    line-height: 1.8;
}

.mp-hint code {
    color: #4488ff;
    background: rgba(68,136,255,0.1);
    padding: 2px 8px;
    border-radius: 3px;
}

.mp-hint a {
    color: #4488ff;
}

.mp-form {
    margin-bottom: 1.5em;
}

.mp-form label {
    display: block;
    color: #888;
    font-size: 0.85em;
    margin-bottom: 6px;
}

.mp-form input, .mp-form select, .mp-join-row input {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    padding: 10px 15px;
    border-radius: 4px;
    text-align: center;
    width: 200px;
    letter-spacing: 0.1em;
}

.mp-hostmap-row {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

#lobby-host-map {
    width: min(320px, 80vw);
    text-transform: none;
    letter-spacing: 0.02em;
}

#mp-server-url {
    width: min(440px, 86vw);
    letter-spacing: 0.02em;
    text-transform: none;
}

.mp-form input:focus, .mp-join-row input:focus {
    outline: none;
    border-color: #4488ff;
    box-shadow: 0 0 10px rgba(68,136,255,0.2);
}

.mp-actions {
    margin-bottom: 1.5em;
}

.mp-browser {
    margin-top: 6px;
    margin-bottom: 14px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
    padding: 8px;
}

.mp-browser-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

#mp-browser-title {
    color: #8ab2da;
    font-size: 0.82em;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.mp-mini-btn {
    padding: 6px 10px;
    font-size: 11px;
    letter-spacing: 0.1em;
}

.mp-browser-list {
    max-height: 190px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mp-browser-row {
    display: grid;
    grid-template-columns: 78px 1fr 62px 62px;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 5px;
    background: rgba(255,255,255,0.03);
    cursor: pointer;
}

.mp-browser-row:hover {
    background: rgba(68,136,255,0.12);
    border-color: rgba(68,136,255,0.35);
}

.mp-browser-code {
    color: #72b5ff;
    font-weight: 700;
    letter-spacing: 0.08em;
}

.mp-browser-host {
    color: #d0e4ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mp-browser-count {
    color: #ffd57a;
    text-align: right;
}

.mp-browser-state {
    color: #8ec8a0;
    text-align: right;
    font-size: 0.85em;
}

.mp-browser-row.started .mp-browser-state {
    color: #ffae7a;
}

.mp-browser-empty {
    color: #8a8a8a;
    font-size: 0.85em;
    padding: 10px 8px;
    text-align: center;
}

.mp-or {
    color: #555;
    margin: 12px 0;
    font-size: 0.9em;
}

.mp-join-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.mp-join-row input {
    width: 140px;
    text-transform: uppercase;
}

.mp-back {
    margin-top: 1em;
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.2);
    color: #888;
}

.mp-back:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.4);
    color: #ccc;
    box-shadow: none;
}

#mp-connect-status {
    margin-top: 15px;
    color: #ff4400;
    font-size: 0.85em;
    min-height: 20px;
}

/* Lobby */

.lobby-code-display {
    font-size: 1.8em;
    color: #4488ff;
    letter-spacing: 0.2em;
    margin: 15px 0;
    text-shadow: 0 0 15px rgba(68,136,255,0.3);
}

.lobby-role {
    color: #888;
    font-size: 0.9em;
    margin-bottom: 15px;
}

.lobby-list {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 10px;
    min-height: 60px;
    margin: 10px 0;
}

.lobby-player {
    padding: 8px 12px;
    color: #ddd;
    font-size: 0.95em;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.lobby-player:last-child {
    border-bottom: none;
}

.lobby-count {
    color: #666;
    font-size: 0.85em;
}

.lobby-events {
    margin-top: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
}

.lobby-events-title {
    color: #a9c8ea;
    font-size: 0.82em;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.lobby-events-list {
    max-height: 120px;
    overflow-y: auto;
}

.lobby-event-line {
    color: #d9e8f7;
    font-size: 0.86em;
    line-height: 1.35;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.lobby-event-line:last-child {
    border-bottom: none;
}

.lobby-event-join {
    color: #8ec5ff;
}

.lobby-event-left {
    color: #74e88e;
}

.lobby-event-dead {
    color: #ff7f7f;
}

.lobby-event-empty {
    color: #90a8c0;
}

/* In-game scoreboard */

#mp-scoreboard {
    position: fixed;
    top: 122px; right: 20px;
    background: rgba(0,0,0,0.6);
    border: 1px solid rgba(68,136,255,0.3);
    border-radius: 6px;
    padding: 8px 12px;
    z-index: 15;
    pointer-events: none;
    min-width: 200px;
    font-family: 'Courier New', monospace;
}

.mp-sb-header {
    display: flex;
    justify-content: space-between;
    color: #666;
    font-size: 10px;
    letter-spacing: 0.1em;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 4px;
}

.mp-sb-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    color: #aaa;
    font-size: 12px;
}

.mp-sb-row.mp-me {
    color: #4488ff;
    font-weight: bold;
}

.mp-sb-name { flex: 1; }
.mp-sb-coins { width: 45px; text-align: center; color: #ffd700; }
.mp-sb-kills { width: 45px; text-align: center; color: #ff4400; }

/* Tablet: make player names bolder in MP scoreboard. */
@media (pointer: coarse) and (min-width: 901px) {
    .mp-sb-name {
        font-weight: 700;
    }
}

/* Game over */

#mp-gameover {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 20, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
    color: #fff;
    font-family: 'Courier New', monospace;
    text-align: center;
}

#mp-gameover h1 {
    font-size: 3em;
    color: #ffd700;
    text-shadow: 0 0 30px rgba(255,215,0,0.5);
    letter-spacing: 0.15em;
    margin-bottom: 0.3em;
}

#mp-gameover h2 {
    font-size: 1.5em;
    color: #4488ff;
    margin-bottom: 1em;
}

#mp-gameover table {
    border-collapse: collapse;
    margin: 0 auto;
}

#mp-gameover th, #mp-gameover td {
    padding: 8px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

#mp-gameover th {
    color: #888;
    font-size: 0.85em;
    letter-spacing: 0.1em;
}

#mp-gameover td {
    font-size: 1.1em;
}

@media (pointer: coarse) {
    #mp-gameover {
        padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    #mp-gameover h1 { font-size: 2em; }
    #mp-gameover h2 { font-size: 1.2em; }
    #mp-gameover .menu-btn {
        min-height: 44px;
        padding: 12px 24px;
        font-size: 14px;
    }
}

/* Notification */

#mp-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.7);
    border: 1px solid rgba(68,136,255,0.4);
    color: #4488ff;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    padding: 8px 20px;
    border-radius: 4px;
    z-index: 600;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

#mp-waiting-overlay {
    position: fixed;
    inset: 0;
    z-index: 590;
    pointer-events: none;
    display: none;
    align-items: center;
    justify-content: center;
    text-align: center;
    background: rgba(18, 8, 10, 0.14);
}

#mp-waiting-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 45%, rgba(210, 52, 52, 0.22), rgba(90, 0, 0, 0.06) 42%, rgba(0, 0, 0, 0.1) 100%);
    opacity: 0.85;
    animation: mp-waiting-pulse 2.2s ease-in-out infinite;
}

#mp-waiting-overlay.countdown-active::before {
    animation-duration: 0.9s;
    opacity: 1;
}

.mp-waiting-overlay.compact,
#mp-waiting-overlay.compact {
    inset: auto 0 auto 0;
    top: 12px;
    bottom: auto;
    background: transparent;
    align-items: flex-start;
    justify-content: center;
    z-index: 610;
}

#mp-waiting-overlay.compact::before {
    display: none;
}

.mp-waiting-content {
    position: relative;
    z-index: 1;
    font-family: 'Courier New', monospace;
    color: #ffd2d2;
    text-shadow: 0 0 12px rgba(255, 82, 82, 0.8), 0 0 22px rgba(120, 0, 0, 0.6);
    max-width: min(92vw, 920px);
    padding: 14px 18px;
}

#mp-waiting-overlay.compact .mp-waiting-content {
    max-width: min(92vw, 680px);
    border: 1px solid rgba(255, 120, 120, 0.55);
    border-radius: 8px;
    background: rgba(38, 6, 8, 0.82);
    box-shadow: 0 0 16px rgba(255, 76, 76, 0.28);
    padding: 6px 12px;
}

#mp-waiting-text {
    font-size: clamp(20px, 3.6vw, 42px);
    font-weight: 700;
    letter-spacing: 0.04em;
    margin-bottom: 10px;
}

#mp-waiting-overlay.compact #mp-waiting-text {
    font-size: clamp(11px, 1.2vw, 14px);
    margin-bottom: 2px;
}

#mp-waiting-subtext {
    font-size: clamp(15px, 2.2vw, 28px);
    color: #ffe8e8;
}

#mp-waiting-overlay.compact #mp-waiting-subtext {
    font-size: clamp(10px, 1.1vw, 12px);
    color: #ffd9d9;
}

.mp-waiting-hint {
    font-size: clamp(10px, 1.1vw, 13px);
    color: #ffe0e0;
    margin-top: 6px;
    font-style: italic;
}

#btn-waiting-start-solo,
#btn-waiting-exit {
    pointer-events: auto;
    margin-top: 8px;
}

@keyframes mp-waiting-pulse {
    0% { opacity: 0.75; }
    50% { opacity: 1; }
    100% { opacity: 0.75; }
}

#mp-chat-panel {
    position: fixed;
    left: 18px;
    bottom: 86px;
    width: min(200px, calc(100vw - 36px));
    max-height: 28vh;
    background: rgba(0, 0, 0, 0.62);
    border: 1px solid rgba(86, 151, 220, 0.4);
    border-radius: 6px;
    padding: 8px;
    z-index: 620;
    font-family: 'Courier New', monospace;
    pointer-events: auto;
}

@media (pointer: coarse) {
    .mp-panel {
        width: min(94vw, 540px);
        max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 24px);
        padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    }

    #title-main {
        animation: title-unease-soft 6.4s ease-in-out infinite;
        -webkit-text-stroke: 1px #7a0f1c;
        text-stroke: 1px #7a0f1c;
        text-shadow:
            0 0 10px rgba(122, 15, 28, 0.34),
            0 0 14px rgba(125, 201, 255, 0.38),
            0 0 32px rgba(42, 107, 171, 0.2);
    }

    .menu-btn {
        font-size: 12px;
        padding: 9px 16px;
        letter-spacing: 0.1em;
    }

    #start-buttons {
        margin-top: 1.2em;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        width: min(360px, 92vw);
        align-items: stretch;
    }

    #start-buttons .menu-btn,
    #start-submenu-buttons .menu-btn {
        width: 100%;
        min-width: 0;
    }

    #btn-start { grid-column: 1; grid-row: 1; }
    #btn-open-editor { grid-column: 2; grid-row: 1; }
    #btn-multiplayer { grid-column: 1; grid-row: 2; }
    #btn-options { grid-column: 2; grid-row: 2; }
    #btn-exit {
        grid-column: 1 / -1;
        grid-row: 3;
        width: min(220px, 100%);
        justify-self: center;
    }

    .rules-toggle-btn,
    .chat-toggle-btn {
        min-width: 84px;
        padding: 7px 12px;
        font-size: 10px;
    }

    #mp-chat-panel {
        left: 12px;
        top: 73%;
        bottom: auto;
        transform: translateY(-50%);
        width: min(360px, calc(100vw - 24px));
        max-height: 34vh;
    }

    #mp-chat-panel.chat-open {
        top: 39%;
        max-height: 64vh;
    }

    #mp-chat-panel.chat-open #mp-chat-messages {
        max-height: 42vh;
    }

    #mp-chat-panel.chat-keyboard-avoid {
        top: 12px;
        left: 12px;
        bottom: auto;
        transform: none;
    }
}

@media (pointer: coarse) and (min-width: 901px) {
    #title-main {
        position: relative;
        top: -2.1em;
        font-size: 9em;
        letter-spacing: 0.14em;
    }

    #start-buttons {
        display: flex;
        flex-direction: column;
        width: auto;
    }

    #start-buttons .menu-btn {
        width: min(320px, 84vw);
    }

    #btn-exit {
        width: min(320px, 84vw);
    }
}

@media (pointer: coarse) and (max-width: 900px) {
    /* Keep button grid structure, just shift whole block left. */
    #start-buttons {
        transform: translateX(-18px);
    }
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 900px) {
    #instructions {
        width: 100vw;
        box-sizing: border-box;
        padding-left: calc(10px + env(safe-area-inset-left, 0px));
        padding-right: 10px;
    }

    #start-buttons {
        transform: none !important;
        margin-left: 0 !important;
        margin-right: auto !important;
        align-self: flex-start;
    }

    #title-subtitle {
        display: none !important;
    }

    #language-switcher {
        top: calc(8px + env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(360px, 94vw);
        padding: 6px 9px;
        gap: 4px;
    }

    #lang-title {
        display: none !important;
    }

    #lang-buttons {
        flex-direction: row;
        gap: 6px;
    }

    #lang-buttons .lang-btn {
        flex: 1 1 0;
        width: auto;
        height: 24px;
        font-size: 11px;
        letter-spacing: 0.03em;
    }

    #btn-controls-toggle {
        height: 24px;
        font-size: 9px;
        letter-spacing: 0.03em;
    }

    #btn-send-dev-message {
        width: min(190px, calc(100vw - 220px));
        max-width: 56vw;
        min-width: 128px;
        padding: 6px 8px;
        font-size: 9px;
        letter-spacing: 0.01em;
        line-height: 1.1;
    }

    #map-toggle-wrap {
        flex-direction: column;
        gap: 6px;
        align-items: center;
        flex-wrap: nowrap;
    }

    #minimap-toggle-control {
        margin-top: 0;
        width: min(132px, 58vw);
        padding: 4px 6px;
        min-height: 26px;
        border: 1px solid rgba(144,194,255,0.35);
        border-radius: 6px;
        background: rgba(20, 40, 62, 0.35);
        color: #bfe0ff;
        font-size: 8.5px;
        letter-spacing: 0.04em;
        line-height: 1;
        white-space: nowrap;
        justify-content: center;
    }

    #minimap-toggle-control {
        width: min(132px, 58vw);
        padding: 4px 6px;
        min-height: 26px;
        font-size: 8.5px;
        letter-spacing: 0.04em;
        justify-content: center;
    }

    #minimap-toggle-control input,
    #toggle-minimap {
        width: 12px;
        height: 12px;
    }

    #mp-chat-panel {
        top: 12px;
        left: 12px;
        bottom: auto;
        transform: none;
    }

    /* Bottom action row alignment in portrait. */
    #btn-rules-toggle,
    #btn-version-info,
    #btn-chat-toggle {
        min-width: 84px !important;
        min-height: 30px !important;
        padding: 6px 9px !important;
        font-size: 10px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #btn-rules-toggle,
    #btn-version-info {
        width: 84px !important;
    }

    /* Keep CHAT above RULES in portrait. */
    #btn-chat-toggle {
        bottom: calc(50px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Place ZA BRADU centered above Send message button. */
    #btn-brada-toggle {
        left: 50% !important;
        right: auto !important;
        transform: translateX(-50%) !important;
        bottom: calc(50px + env(safe-area-inset-bottom, 0px)) !important;
        min-width: 84px !important;
        min-height: 30px !important;
        padding: 6px 9px !important;
        font-size: 10px !important;
    }

    #btn-send-dev-message {
        left: 98px !important;
        right: auto !important;
        transform: none !important;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
        min-height: 30px !important;
        height: 30px !important;
        width: min(164px, calc(100vw - 210px)) !important;
        max-width: 52vw !important;
        padding: 0 8px !important;
        font-size: 8.5px !important;
        line-height: 30px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }
}

/* TP: mirror MP language switcher placement and button styling. */
@media (pointer: coarse) and (orientation: portrait) and (min-width: 901px) {
    #language-switcher {
        top: calc(8px + env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(360px, 94vw);
        padding: 6px 9px;
        gap: 4px;
    }

    #lang-title {
        display: none !important;
    }

    #lang-buttons {
        flex-direction: row;
        gap: 6px;
    }

    #lang-buttons .lang-btn {
        flex: 1 1 0;
        width: auto;
        height: 24px;
        font-size: 11px;
        letter-spacing: 0.03em;
    }
}

@media (pointer: coarse) and (orientation: portrait) {
    #title-subtitle {
        display: none !important;
    }
}

@media (pointer: coarse) and (orientation: landscape) {
    #title-subtitle {
        display: none !important;
    }

    .menu-btn {
        min-height: 27px;
        padding: 6px 10px;
        font-size: 11px;
        letter-spacing: 0.12em;
    }

    #language-switcher {
        top: calc(8px + env(safe-area-inset-top, 0px));
        left: 8px;
        right: auto;
        transform: none;
        width: auto;
        padding: 5px 6px;
        gap: 3px;
        align-items: flex-start;
    }

    #lang-title,
    #lang-hint {
        display: none !important;
    }

    #lang-buttons {
        flex-direction: row;
        gap: 4px;
        justify-content: flex-start;
    }

    #lang-buttons .lang-btn {
        width: 34px;
        height: 16px;
        min-height: 16px;
        padding: 0 4px;
        font-size: 8px;
        letter-spacing: 0.02em;
    }

    #btn-send-dev-message {
        min-height: 24px;
        padding: 5px 8px;
        font-size: 8px;
        letter-spacing: 0.01em;
    }

    /* PL: keep VERSION clearly above nearby footer buttons. */
    #btn-version-info {
        left: 10px !important;
        bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 693 !important;
    }

    /* Bottom-right utility row on landscape. */
    #map-toggle-wrap {
        margin-top: 0;
        position: fixed;
        right: 14px;
        bottom: calc(14px + env(safe-area-inset-bottom, 0px));
        z-index: 431;
        display: block;
        pointer-events: none;
    }

    #minimap-toggle-control {
        pointer-events: auto;
        position: fixed;
        min-width: 75px;
        min-height: 27px;
        padding: 6px 10px;
        border-radius: 4px;
        font-size: 9px;
        font-weight: 700;
        letter-spacing: 0.05em;
        line-height: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        white-space: nowrap;
        margin: 0;
    }

    /* Keep these buttons same size and stacked bottom->top. */
    #btn-rules-toggle,
    #btn-chat-toggle,
    #btn-brada-toggle,
    #minimap-toggle-control {
        right: 14px !important;
        min-width: 75px !important;
        min-height: 27px !important;
        padding: 6px 10px !important;
        font-size: 9px !important;
        line-height: 1 !important;
    }

    #btn-rules-toggle {
        bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #btn-chat-toggle {
        bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #btn-brada-toggle {
        bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #minimap-toggle-control {
        bottom: calc(154px + env(safe-area-inset-bottom, 0px)) !important;
        color: #bfe0ff;
        border: 1px solid rgba(144,194,255,0.35);
        background: rgba(20, 40, 62, 0.35);
    }

    #minimap-toggle-control input,
    #toggle-minimap {
        width: 14px;
        height: 14px;
    }
}

@media (pointer: coarse) {
    #btn-controls-toggle {
        display: none !important;
    }

    #controls-text {
        display: none !important;
    }

    #title-credit {
        margin-top: 0.22em;
        margin-bottom: 1.5em;
        animation: author-credit-fade-soft 3.2s ease-in-out infinite;
    }
}

#mp-chat-title {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    color: #9cc7f2;
    font-size: 11px;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

#mp-chat-title-main {
    display: block;
}

#mp-chat-hint {
    color: #6f8eaf;
    letter-spacing: normal;
    font-size: 10px;
}

#mp-chat-messages {
    overflow-y: auto;
    max-height: 17vh;
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: #d7e8f8;
    font-size: 12px;
    line-height: 1.35;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#mp-chat-messages::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.no-scrollbar::-webkit-scrollbar {
    width: 0;
    height: 0;
}

#mp-chat-panel.chat-open {
    max-height: 52vh;
}

#mp-chat-panel.chat-open #mp-chat-messages {
    max-height: 34vh;
}

.mp-chat-line {
    white-space: pre-wrap;
    word-break: break-word;
}

.mp-chat-name {
    color: #74b2ff;
}

.mp-chat-typing {
    color: #9fd0ff;
    font-style: italic;
}

#mp-chat-compose {
    margin-top: 7px;
    padding-top: 6px;
    border-top: 1px solid rgba(122, 171, 221, 0.25);
    color: #bde0ff;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#mp-chat-input {
    flex: 1;
    min-width: 0;
    background: rgba(7, 16, 27, 0.92);
    border: 1px solid rgba(92, 151, 214, 0.45);
    color: #d7e8f8;
    border-radius: 4px;
    padding: 5px 7px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    outline: none;
}

#mp-chat-input:focus {
    border-color: #7ec4ff;
    box-shadow: 0 0 0 1px rgba(126, 196, 255, 0.35);
}

#mp-chat-send-btn {
    border: 1px solid rgba(126, 196, 255, 0.45);
    background: rgba(17, 48, 78, 0.82);
    color: #d7e8f8;
    border-radius: 4px;
    padding: 5px 8px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    letter-spacing: 0.05em;
    cursor: pointer;
}

#mp-chat-send-btn:active {
    transform: translateY(1px);
}

@media (pointer: coarse) and (max-width: 640px) {
    #mp-chat-compose {
        flex-wrap: wrap;
        align-items: stretch;
        gap: 6px;
    }

    #mp-chat-prompt {
        display: none;
    }

    #mp-chat-input {
        flex: 1 1 100%;
        width: 100%;
        min-height: 36px;
        font-size: 15px;
    }

    #mp-chat-send-btn {
        margin-left: auto;
        min-height: 36px;
        min-width: 72px;
        padding: 7px 12px;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.06em;
    }
}

#mp-chat-caret {
    color: #86c2ff;
    animation: pulse 0.8s ease-in-out infinite;
}

/* Spawn shield */

#spawn-shield {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    border: 3px solid rgba(68,136,255,0.4);
    pointer-events: none;
    z-index: 11;
    animation: shield-pulse 0.5s ease-in-out infinite;
}

#elevator-panel {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 650;
    display: none;
    align-items: center;
    justify-content: center;
}

.elevator-box {
    width: min(460px, 92vw);
    padding: 22px 20px;
    border: 1px solid rgba(126, 196, 255, 0.45);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(12, 20, 32, 0.96), rgba(5, 10, 18, 0.95));
    box-shadow: 0 0 30px rgba(66, 160, 255, 0.25);
    text-align: center;
}

#elevator-title {
    color: #85c8ff;
    font-size: 1.5em;
    letter-spacing: 0.12em;
    margin-bottom: 10px;
}

#elevator-status {
    color: #d5e7f9;
    margin-bottom: 12px;
    font-size: 0.95em;
}

#elevator-floors {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
    gap: 8px;
    margin: 10px 0 14px;
}

.elevator-floor-btn {
    padding: 10px 6px;
    border: 1px solid rgba(129, 198, 255, 0.45);
    border-radius: 6px;
    background: rgba(28, 56, 88, 0.75);
    color: #d9edff;
    font-weight: 700;
    cursor: pointer;
}

.elevator-floor-btn:hover {
    background: rgba(59, 111, 163, 0.78);
}

.elevator-floor-btn.active {
    background: linear-gradient(180deg, rgba(133, 196, 255, 0.95), rgba(76, 141, 208, 0.95));
    color: #081420;
}

#elevator-hint {
    color: #94adc6;
    font-size: 0.8em;
    margin-top: 4px;
}

#screen-vignette {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 8;
    background:
        radial-gradient(circle at center, rgba(0,0,0,0) 45%, rgba(0,0,0,0.35) 100%),
        radial-gradient(circle at 50% 10%, rgba(56,124,178,0.08), rgba(0,0,0,0) 60%);
}

#screen-grain {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9;
    opacity: 0.08;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(255,255,255,0.4) 0.6px, transparent 0.7px),
        radial-gradient(circle at 80% 60%, rgba(255,255,255,0.28) 0.6px, transparent 0.7px),
        radial-gradient(circle at 40% 80%, rgba(255,255,255,0.22) 0.5px, transparent 0.6px);
    background-size: 3px 3px, 4px 4px, 5px 5px;
    mix-blend-mode: soft-light;
    animation: grainShift 0.25s steps(2) infinite;
}

@keyframes grainShift {
    0% { transform: translate(0, 0); }
    50% { transform: translate(-1px, 1px); }
    100% { transform: translate(1px, -1px); }
}

@keyframes shield-pulse {
    0%, 100% { border-color: rgba(68,136,255,0.2); }
    50% { border-color: rgba(68,136,255,0.5); }
}

@keyframes title-unease-soft {
    0%, 100% {
        letter-spacing: 0.30em;
        text-shadow:
            0 0 22px rgba(125, 201, 255, 0.55),
            0 0 58px rgba(42, 107, 171, 0.3);
    }
    45% {
        letter-spacing: 0.36em;
        text-shadow:
            0 0 6px rgba(120, 16, 30, 0.38),
            0 0 20px rgba(125, 201, 255, 0.5),
            0 0 52px rgba(40, 96, 156, 0.28);
    }
    55% {
        letter-spacing: 0.32em;
        text-shadow:
            0 0 8px rgba(120, 16, 30, 0.46),
            0 0 24px rgba(125, 201, 255, 0.58),
            0 0 60px rgba(42, 107, 171, 0.34);
    }
}

@keyframes title-beam-breathe {
    0%, 100% {
        opacity: 0.07;
        transform: translate(-50%, -52%) scale(0.62);
    }
    45% {
        opacity: 0.2;
        transform: translate(-50%, -52%) scale(1.02);
    }
    55% {
        opacity: 0.28;
        transform: translate(-50%, -52%) scale(1.2);
    }
}

/* Desktop: fill screen from top (cover), cropping lower part if needed. */
@media (pointer: fine) and (hover: hover) {
    #title-main,
    #title-credit {
        position: relative;
        top: -0.15em;
    }

    #instructions #title-main {
        transform: none;
        font-size: 7.2em !important;
        font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', 'Segoe UI', sans-serif;
        letter-spacing: 0.18em;
        -webkit-text-stroke: 2px #7a0f1c;
        text-stroke: 2px #7a0f1c;
        text-shadow:
            0 0 22px rgba(125, 201, 255, 0.55),
            0 0 58px rgba(42, 107, 171, 0.3);
        animation: title-unease-soft 6.4s ease-in-out infinite;
        position: relative;
        isolation: isolate;
    }

    #title-main::after {
        content: none;
    }

    #instructions #title-main::before { content: none; }

    #title-credit {
        font-size: 1em !important;
        margin-top: -0.22em;
        margin-bottom: 0.95em;
    }

    #blocker .menu-btn,
    #blocker #start-buttons .menu-btn,
    #blocker #start-submenu-buttons .menu-btn {
        font-size: 12px !important;
        padding: 10px 20px !important;
    }

    #instructions p {
        font-size: 1.15em !important;
    }

    #instructions .subtitle {
        font-size: 0.82em !important;
    }

    #blocker {
        background:
            url('/assets/ui-ref/robot-reference.png') center top / cover no-repeat,
            radial-gradient(120% 95% at 50% 10%, rgba(44, 85, 126, 0.14), rgba(0, 0, 0, 0.42));
    }

    #blocker::before {
        content: '';
        position: absolute;
        inset: 0;
        pointer-events: none;
        z-index: 0;
        background:
            linear-gradient(rgba(3, 8, 14, 0.72), rgba(2, 7, 12, 0.84)),
            rgba(0, 0, 0, 0.62);
        -webkit-mask-image: radial-gradient(220px circle at var(--cursor-x, 50vw) var(--cursor-y, 50vh), rgba(0,0,0,0) 0%, rgba(0,0,0,0) 36%, rgba(0,0,0,1) 76%);
        mask-image: radial-gradient(220px circle at var(--cursor-x, 50vw) var(--cursor-y, 50vh), rgba(0,0,0,0) 0%, rgba(0,0,0,0) 36%, rgba(0,0,0,1) 76%);
    }

    #mp-menu, #mp-lobby {
        background-position: center center, center top, center center;
        background-size: auto, cover, auto;
    }
}

/* Title typeface. */
#title-main {
    font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', 'Segoe UI', sans-serif;
}

/* Subtle desktop cursor light + reflective feel on titles/buttons. */
@media (pointer: fine) and (hover: hover) {
    body.desktop-lightfx::before {
        content: '';
        position: fixed;
        inset: 0;
        pointer-events: none;
        z-index: 460;
        opacity: 0.42;
        background:
            radial-gradient(170px circle at var(--cursor-x, 50vw) var(--cursor-y, 50vh),
                rgba(255, 255, 255, 0.22) 0%,
                rgba(188, 224, 255, 0.16) 30%,
                rgba(138, 197, 245, 0.08) 54%,
                rgba(125, 185, 236, 0) 75%);
        mix-blend-mode: screen;
        transition: opacity 0.25s ease;
    }

    body.desktop-lightfx::after {
        content: '';
        position: fixed;
        inset: 0;
        pointer-events: none;
        z-index: 459;
        opacity: 0.34;
        background:
            radial-gradient(340px circle at var(--cursor-x, 50vw) var(--cursor-y, 50vh),
                rgba(172, 221, 255, 0.12) 0%,
                rgba(131, 191, 242, 0.06) 40%,
                rgba(131, 191, 242, 0) 72%);
        mix-blend-mode: screen;
        transition: opacity 0.25s ease;
    }

    body.desktop-lightfx .menu-btn,
    body.desktop-lightfx #title-main,
    body.desktop-lightfx #title-subtitle,
    body.desktop-lightfx #title-credit {
        transition: box-shadow 0.16s ease, text-shadow 0.16s ease, border-color 0.16s ease;
    }

    body.desktop-lightfx .menu-btn {
        box-shadow: 0 0 14px rgba(118, 185, 246, 0.22), inset 0 0 10px rgba(125, 194, 255, 0.08);
    }

    body.desktop-lightfx #title-main {
        text-shadow:
            0 0 24px rgba(125, 201, 255, 0.62),
            0 0 62px rgba(42, 107, 171, 0.34);
    }

    body.desktop-lightfx #title-credit {
        text-shadow: 0 0 12px rgba(156, 198, 232, 0.65), 0 0 30px rgba(66, 150, 220, 0.34);
    }

    #instructions,
    #mp-pause-menu {
        position: relative;
        z-index: 1;
    }
}

/* Touch devices (phone + tablet): slightly brighter background overlays. */
@media (pointer: coarse) {
    #blocker {
        background:
            linear-gradient(rgba(8, 16, 28, 0.50), rgba(4, 10, 18, 0.66)),
            url('/assets/ui-ref/robot-reference.png') center center / cover no-repeat,
            radial-gradient(120% 95% at 50% 10%, rgba(44, 85, 126, 0.18), rgba(0, 0, 0, 0.92)),
            rgba(0, 0, 0, 0.74);
    }

    #mp-menu, #mp-lobby {
        background:
            linear-gradient(rgba(8, 16, 28, 0.52), rgba(4, 10, 18, 0.70)),
            url('/assets/ui-ref/robot-reference.png') center center / cover no-repeat,
            rgba(0, 0, 0, 0.80);
    }

}

/* Utility button stack override:
   bottom -> ZA BRADU, SEND MESSAGE, CHAT, RULES. */
#chat-start-hint {
    display: none !important;
}

#btn-brada-toggle {
    left: auto !important;
    right: 14px !important;
    transform: none !important;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
}

#btn-send-dev-message {
    position: fixed !important;
    left: 98px !important;
    right: auto !important;
    transform: none !important;
    top: auto !important;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 431 !important;
    width: 118px !important;
    min-width: 118px !important;
    min-height: 34px !important;
    padding: 0 12px !important;
    font-size: 10px !important;
    line-height: 34px !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

#btn-chat-toggle {
    bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important;
}


#btn-rules-toggle {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
}

@media (pointer: coarse) and (orientation: portrait) {
    #btn-send-dev-message {
        width: 104px !important;
        min-width: 104px !important;
        min-height: 30px !important;
        height: auto !important;
        padding: 4px 6px !important;
        font-size: 7.2px !important;
        line-height: 1.06 !important;
        letter-spacing: 0 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
    }
}

/* Ensure "Send message" label is fully visible on PC/tablet landscapes. */
@media (pointer: fine) {
    #btn-send-dev-message {
        width: auto !important;
        min-width: 210px !important;
        max-width: min(46vw, 360px) !important;
        min-height: 34px !important;
        height: auto !important;
        padding: 6px 10px !important;
        line-height: 1.15 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
    }

    /* Laptop/desktop: keep utility buttons anchored to bottom edge on HOME + MP. */
    #btn-controls-toggle { bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important; }
    #btn-rules-toggle { bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important; }
    #btn-chat-toggle { bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important; }

    /* Laptop/desktop: MP panel without vertical scrollbar and name field top-left. */
    #mp-menu .mp-panel {
        display: flex;
        flex-direction: column;
        max-height: none !important;
        overflow-y: visible !important;
    }
    #mp-menu .mp-panel > h2 {
        margin-bottom: 0.2em;
    }
    #mp-menu .mp-panel > .mp-hint {
        margin-bottom: 0.7em;
    }
    #mp-menu .mp-panel > .mp-form:first-of-type {
        align-self: flex-start;
        text-align: left;
        margin: 0 0 0.7em 0;
        width: min(260px, 70vw);
    }
    #mp-menu .mp-panel > .mp-form:nth-of-type(1) { order: 3; }
    #mp-menu .mp-panel > .mp-browser { order: 4; margin-top: 0; margin-bottom: 12px; }
    #mp-menu .mp-panel > .mp-form:nth-of-type(2) { order: 5; margin-bottom: 0.9em; }
    #mp-menu .mp-panel > .mp-form:nth-of-type(3) { order: 6; margin-bottom: 0.9em; }
    #mp-menu .mp-panel > .mp-actions:nth-of-type(1) { order: 7; margin-bottom: 0.8em; }
    #mp-menu .mp-panel > .mp-actions:nth-of-type(2) { order: 8; margin-bottom: 0.8em; }
    #mp-menu .mp-panel > #btn-mp-back { order: 9; }
    #mp-menu .mp-panel > #mp-connect-status { order: 10; }
    #mp-menu #mp-name-label {
        text-align: left;
        margin-bottom: 4px;
    }
    #mp-menu #mp-name {
        width: 100%;
        text-align: left;
        letter-spacing: 0.04em;
    }
    #mp-menu .mp-browser-list {
        max-height: none;
        overflow-y: visible;
    }

    /* Deathmatch room visual state: green when OFF, dark red when ON. */
    #mp-menu .mp-form label[style*="display:flex"] {
        gap: 2px !important;
        justify-content: flex-start !important;
    }
    #mp-menu #mp-room-deathmatch {
        margin-right: 1px;
    }
    #mp-menu #mp-room-deathmatch + span {
        display: inline-block;
        border: 1px solid rgba(80, 200, 120, 0.9);
        background: rgba(24, 74, 38, 0.35);
        color: #b9f3c8;
        border-radius: 4px;
        padding: 2px 6px;
        line-height: 1.15;
    }
    #mp-menu #mp-room-deathmatch:checked + span {
        border-color: rgba(160, 56, 56, 0.95);
        background: rgba(72, 14, 14, 0.72);
        color: #ffb2b2;
    }
}

@media (pointer: coarse) and (orientation: landscape) {
    #btn-send-dev-message {
        width: auto !important;
        min-width: 170px !important;
        max-width: min(50vw, 300px) !important;
        min-height: 28px !important;
        height: auto !important;
        padding: 5px 8px !important;
        line-height: 1.1 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
    }

    /* Keep RULES separated from MINI MAP on ML/TL. */
    #btn-rules-toggle {
        bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Keep MINI MAP clearly above RULES on TL/PL(ML). */
    #minimap-toggle-control {
        bottom: calc(119px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Prevent RULES and ZA BRADU overlap on TL/ML. */
    #btn-brada-toggle {
        right: 14px !important;
        left: auto !important;
        transform: none !important;
        bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* Final ordering override for landscape: bottom -> RULES, CHAT, CONTROLS, ZA BRADU */
@media (pointer: coarse) and (orientation: landscape) {
    #btn-controls-toggle {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #btn-rules-toggle,
    #btn-chat-toggle,
    #btn-controls-toggle,
    #btn-brada-toggle {
        right: 14px !important;
        min-width: 75px !important;
        min-height: 27px !important;
        padding: 6px 10px !important;
        font-size: 9px !important;
        line-height: 1 !important;
    }

    #btn-rules-toggle { bottom: calc(14px + env(safe-area-inset-bottom, 0px)) !important; }
    #btn-chat-toggle { bottom: calc(49px + env(safe-area-inset-bottom, 0px)) !important; }
    #btn-controls-toggle { bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important; }
    #btn-brada-toggle { bottom: calc(119px + env(safe-area-inset-bottom, 0px)) !important; }

    /* Keep minimap controls above the 4-button stack. */
    #minimap-toggle-control { bottom: calc(154px + env(safe-area-inset-bottom, 0px)) !important; }

    /* TL: minimap 180px @ top:20 → bottom 200px. RUN+PAUSE odmah ispod (206px). */
    #btn-touch-run {
        left: 14px !important;
        right: auto !important;
        top: calc(206px + env(safe-area-inset-top, 0px)) !important;
        bottom: auto !important;
    }
    #btn-touch-pause {
        left: 78px !important;
        right: auto !important;
        top: calc(206px + env(safe-area-inset-top, 0px)) !important;
        bottom: auto !important;
    }

    /* Uniform size for landscape utility buttons. */
    #btn-send-dev-message,
    #btn-rules-toggle,
    #btn-chat-toggle,
    #btn-controls-toggle,
    #btn-brada-toggle {
        min-width: 75px !important;
        width: 75px !important;
        min-height: 27px !important;
        height: 27px !important;
        padding: 0 6px !important;
        font-size: 9px !important;
        line-height: 27px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* TL/ML: allow full "Send message" label readability. */
    #btn-send-dev-message {
        width: auto !important;
        min-width: 172px !important;
        max-width: min(52vw, 320px) !important;
        height: auto !important;
        min-height: 27px !important;
        padding: 4px 8px !important;
        line-height: 1.1 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
    }

}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
    /* ML: minimap 68px @ top:8 → bottom 76px. RUN+PAUSE odmah ispod (82px). */
    #btn-touch-run {
        left: calc(8px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        top: calc(82px + env(safe-area-inset-top, 0px)) !important;
        bottom: auto !important;
    }
    #btn-touch-pause {
        left: calc(72px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        top: calc(82px + env(safe-area-inset-top, 0px)) !important;
        bottom: auto !important;
    }

    /* ML: move MP scoreboard fully to top-left. */
    #mp-scoreboard {
        top: calc(8px + env(safe-area-inset-top, 0px)) !important;
        left: calc(8px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
    }
}

/* Tablet multiplayer: hide CONTROLS button while MP menu/lobby is open. */
@media (pointer: coarse) and (min-width: 901px) {
    #mp-menu[style*="display: flex"] ~ #btn-controls-toggle,
    #mp-lobby[style*="display: flex"] ~ #btn-controls-toggle {
        display: none !important;
    }
}

/* PL home screen: send message fully left; VERSION lowered to same row next to it. */
@media (pointer: coarse) and (orientation: landscape) {
    #blocker[style*="display: flex"] ~ #btn-send-dev-message {
        left: calc(10px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
    #blocker[style*="display: flex"] ~ #btn-version-info {
        left: calc(188px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
        z-index: 693 !important;
    }
}

/* Final ML override: force VERSION to bottom on HOME + MP. */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 900px) {
    #btn-version-info,
    #blocker[style*="display: flex"] ~ #btn-version-info,
    #mp-menu[style*="display: flex"] ~ #btn-version-info,
    #mp-lobby[style*="display: flex"] ~ #btn-version-info {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* Final ML override: place BACK fully on right in multiplayer. */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 900px) {
    #mp-menu[style*="display: flex"] #btn-mp-back,
    #mp-lobby[style*="display: flex"] #btn-lobby-back {
        left: auto !important;
        right: calc(10px + env(safe-area-inset-right, 0px)) !important;
    }
}

/* Phone MP hard fallback: hide CONTROLS in MP states (PL + PP). */
@media (pointer: coarse) and (max-width: 900px) {
    body:has(#mp-menu[style*="display: flex"]) #btn-controls-toggle,
    body:has(#mp-lobby[style*="display: flex"]) #btn-controls-toggle {
        display: none !important;
    }
}

/* PL hard remove: hide CONTROLS globally (HOME + MP). */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 900px) and (max-height: 520px) {
    #btn-controls-toggle {
        display: none !important;
    }
}

/* PL: keep Send message hard-left on HOME + MP. */
@media (pointer: coarse) and (orientation: landscape) and (max-width: 900px) and (max-height: 520px) {
    #btn-send-dev-message,
    #blocker[style*="display: flex"] ~ #btn-send-dev-message,
    #mp-menu[style*="display: flex"] ~ #btn-send-dev-message,
    #mp-lobby[style*="display: flex"] ~ #btn-send-dev-message {
        position: fixed !important;
        left: calc(0px + env(safe-area-inset-left, 0px)) !important;
        right: auto !important;
        top: calc(42px + env(safe-area-inset-top, 0px)) !important;
        bottom: auto !important;
        transform: none !important;
        margin-left: 0 !important;
    }
}

/* PL multiplayer: hide CONTROLS and place BACK in its slot. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) and (max-width: 900px) {
    body:has(#mp-menu[style*="display: flex"]) #btn-controls-toggle,
    body:has(#mp-lobby[style*="display: flex"]) #btn-controls-toggle {
        display: none !important;
    }
    #mp-menu[style*="display: flex"] #btn-mp-back,
    #mp-lobby[style*="display: flex"] #btn-lobby-back {
        left: auto !important;
        right: calc(14px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(84px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* Uniform size for desktop utility buttons as requested. */
@media (pointer: fine) {
    #btn-send-dev-message,
    #btn-rules-toggle,
    #btn-chat-toggle,
    #btn-controls-toggle,
    #btn-brada-toggle {
        min-width: 118px !important;
        width: 118px !important;
        min-height: 34px !important;
        height: 34px !important;
        padding: 0 12px !important;
        font-size: 11px !important;
        line-height: 34px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* PC: keep full label visible for Send message button. */
    #btn-send-dev-message {
        width: auto !important;
        min-width: 198px !important;
        max-width: min(34vw, 320px) !important;
        height: auto !important;
        min-height: 34px !important;
        padding: 4px 12px !important;
        line-height: 1.12 !important;
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        overflow-wrap: anywhere !important;
        word-break: break-word !important;
    }
}


/* === MODERN UI MAX THEME v2 === */
:root {
    --ui-bg-0: #000000;
    --ui-bg-1: #070707;
    --ui-card: rgba(0, 0, 0, 0.66);
    --ui-card-strong: rgba(0, 0, 0, 0.82);
    --ui-border: rgba(255, 255, 255, 0.22);
    --ui-border-strong: rgba(255, 255, 255, 0.42);
    --ui-text: #e7f2ff;
    --ui-text-soft: #9eb4cd;
    --ui-accent: #62b3ff;
    --ui-accent-2: #8cd9ff;
    --ui-warn: #ff9f4f;
}

body {
    color: var(--ui-text);
    background: #000;
}

#blocker,
#mp-menu,
#mp-lobby {
    backdrop-filter: blur(7px) saturate(1.18);
}

#instructions,
#mp-pause-menu,
.mp-panel,
#version-info-card,
#options-card,
#player-name-card,
#dev-message-card,
#important-notice-card,
.elevator-box {
    background: linear-gradient(180deg, rgba(8, 8, 8, 0.78), rgba(0, 0, 0, 0.88));
    border: 1px solid var(--ui-border);
    border-radius: 14px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.46), inset 0 1px 0 rgba(199, 229, 255, 0.08);
}

.menu-btn,
.mp-btn,
.mp-back,
#btn-send-dev-message,
#btn-rules-toggle,
#btn-chat-toggle,
#btn-controls-toggle,
#btn-brada-toggle,
#btn-version-info,
#btn-important-notice {
    border-radius: 12px !important;
    border: 1px solid var(--ui-border) !important;
    color: #e9f4ff !important;
    background: linear-gradient(180deg, rgba(32, 32, 32, 0.58), rgba(0, 0, 0, 0.72)) !important;
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(201, 230, 255, 0.16);
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
    transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.menu-btn:hover,
.mp-btn:hover,
#btn-send-dev-message:hover,
#btn-rules-toggle:hover,
#btn-chat-toggle:hover,
#btn-controls-toggle:hover,
#btn-brada-toggle:hover,
#btn-version-info:hover,
#btn-important-notice:hover {
    transform: translateY(-1px) scale(1.02) !important;
    border-color: var(--ui-border-strong) !important;
    background: linear-gradient(180deg, rgba(52, 52, 52, 0.68), rgba(0, 0, 0, 0.84)) !important;
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.4), 0 0 16px rgba(255, 255, 255, 0.14) !important;
}

#hud {
    filter: saturate(1.06) contrast(1.06);
}

#health-bg,
#ammo-display,
#kills-display,
#coins-display,
#robots-display,
#floor-display,
#speedrun-timer,
#interact-prompt,
#key-indicator,
#mp-scoreboard,
#mp-chat-panel,
#language-switcher {
    background: var(--ui-card);
    border: 1px solid var(--ui-border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(8px) saturate(1.15);
}

#health-bg { padding: 3px; }
#health-fill { border-radius: 8px; }

#minimap-canvas {
    border-radius: 14px;
    border: 1px solid var(--ui-border-strong);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.36);
}

#crosshair {
    color: #d8eeff;
    text-shadow: 0 0 9px rgba(122, 196, 255, 0.75), 0 0 2px rgba(0, 0, 0, 0.9);
}

#instructions h1,
.mp-panel h2,
#mp-gameover h1 {
    letter-spacing: 0.11em;
    color: #cbe8ff;
    text-shadow: 0 0 22px rgba(111, 186, 255, 0.5), 0 0 70px rgba(30, 90, 156, 0.34);
}

/* Keep square panel, but make it more transparent over robot. */
#instructions {
    background: linear-gradient(180deg, rgba(15, 24, 38, 0.36), rgba(10, 16, 28, 0.28));
    border: 1px solid rgba(150, 203, 255, 0.3);
}


/* === MODERN FPS TOUCH OVERLAY v3 === */
.touch-action-btn {
    width: 64px !important;
    height: 64px !important;
    min-width: 64px !important;
    min-height: 64px !important;
    border-radius: 50% !important;
    border: 1.5px solid rgba(170, 214, 255, 0.72) !important;
    color: #eaf6ff !important;
    background: radial-gradient(circle at 30% 20%, rgba(88, 160, 240, 0.28), rgba(8, 14, 24, 0.68)) !important;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.18) !important;
    backdrop-filter: blur(6px) saturate(1.12);
}

#btn-touch-fire {
    width: 84px !important;
    height: 84px !important;
    min-width: 84px !important;
    min-height: 84px !important;
    font-size: 14px !important;
    border-color: rgba(255, 140, 140, 0.88) !important;
    background: radial-gradient(circle at 30% 20%, rgba(255, 122, 122, 0.32), rgba(32, 8, 10, 0.72)) !important;
}

#btn-touch-run,
#btn-touch-pause {
    border-radius: 12px !important;
    width: 64px !important;
    height: 64px !important;
    min-width: 64px !important;
    min-height: 64px !important;
    padding: 0 !important;
    font-size: 10px !important;
    line-height: 1 !important;
}

/* Standard modern FPS grouping around right-thumb zone. */
body.touch-match-active #btn-touch-fire {
    right: calc(16px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(108px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
}

body.touch-match-active #btn-touch-action {
    right: calc(112px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(178px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
}

body.touch-match-active #btn-touch-reload {
    right: calc(112px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(104px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
}

body.touch-match-active #btn-touch-switch {
    right: calc(186px + env(safe-area-inset-right, 0px)) !important;
    bottom: calc(104px + env(safe-area-inset-bottom, 0px)) !important;
    left: auto !important;
}

body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-run {
    left: calc(16px + env(safe-area-inset-left, 0px)) !important;
    right: auto !important;
    bottom: calc(220px + env(safe-area-inset-bottom, 0px)) !important;
}

body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-pause {
    left: calc(90px + env(safe-area-inset-left, 0px)) !important;
    right: auto !important;
    bottom: calc(220px + env(safe-area-inset-bottom, 0px)) !important;
}



/* === START SCREEN DE-SQUARE v1 === */
/* Remove big square panels on start screen, keep other UI intact. */
#blocker[style*="display: flex"] #instructions,
#blocker[style*="display: flex"] #controls-text,
#blocker[style*="display: flex"] #rules-text {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

#blocker[style*="display: flex"] #instructions {
    padding: 10px 10px 4px !important;
    max-width: min(94vw, 760px) !important;
}

#blocker[style*="display: flex"] #title-main,
#blocker[style*="display: flex"] #title-subtitle,
#blocker[style*="display: flex"] #title-credit,
#blocker[style*="display: flex"] #start-prompt {
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55) !important;
}

/* === TOUCH HUD COMPACT (6.8") === */
@media (pointer: coarse) and (max-width: 920px) {
    #minimap-canvas {
        width: 132px;
        height: 132px;
        top: 10px;
        left: 10px;
    }

    #ammo-display {
        right: 14px;
        bottom: 12px;
        font-size: 18px;
    }

    #weapon-name {
        font-size: 10px;
        margin-bottom: 2px;
    }

    #health-bar {
        left: 12px;
        bottom: 12px;
        gap: 8px;
    }

    #health-icon { font-size: 20px; }
    #health-bg { width: 170px; height: 7px; }
    #health-text { font-size: 14px; min-width: 28px; }

    #kills-display,
    #coins-display,
    #robots-display,
    #floor-display {
        right: 12px;
        font-size: 11px;
        letter-spacing: 0.1em;
        padding: 4px 8px;
    }

    #kills-display { top: 10px; }
    #coins-display { top: 34px; }
    #robots-display { top: 58px; }
    #floor-display { top: 82px; }

    #kills-count,
    #coins-count,
    #robots-count { font-size: 13px; }

    #mp-scoreboard {
        top: 110px;
        right: 10px;
        min-width: 168px;
        padding: 6px 8px;
    }

    .mp-sb-header { font-size: 9px; }
    .mp-sb-row { font-size: 11px; }
    .mp-sb-coins,
    .mp-sb-kills { width: 38px; }

    .touch-action-btn {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
    }

    #btn-touch-fire {
        width: 72px !important;
        height: 72px !important;
        min-width: 72px !important;
        min-height: 72px !important;
        font-size: 12px !important;
    }

    #btn-touch-run,
    #btn-touch-pause {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        font-size: 10px !important;
    }

    body.touch-match-active #btn-touch-fire {
        right: calc(12px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active #btn-touch-action {
        right: calc(96px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(154px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active #btn-touch-reload {
        right: calc(96px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active #btn-touch-switch {
        right: calc(162px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-run {
        left: calc(12px + env(safe-area-inset-left, 0px)) !important;
        bottom: calc(192px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active:not(.edit3d-overlay-layout) #btn-touch-pause {
        left: calc(78px + env(safe-area-inset-left, 0px)) !important;
        bottom: calc(192px + env(safe-area-inset-bottom, 0px)) !important;
    }

    body.touch-match-active #btn-touch-mode {
        right: calc(96px + env(safe-area-inset-right, 0px)) !important;
        bottom: calc(26px + env(safe-area-inset-bottom, 0px)) !important;
    }
}
