#hudCanvas {
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    touch-action: none;
    transition: opacity 0.8s ease-in-out;
}

/* UI In-Game (Top Bar) */
#ui {
    pointer-events: none;
    position: fixed;
    z-index: 80;
    top: 0; left: 0; width: 100vw;
    height: auto; 
    max-height: 15vh;
    display: none;
    background: rgba(10, 20, 40, 0.4);
    backdrop-filter: blur(5px);
    border-bottom: 1px solid rgba(68,136,255,0.4);
    padding: env(safe-area-inset-top, 5px) env(safe-area-inset-right, 15px) 5px env(safe-area-inset-left, 15px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    font-family: monospace;
    color: #cceeff;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    transition: opacity 0.8s ease-in-out;
}

#status-bars-container {
    display: grid;
    gap: 5px 15px;
    align-items: center;
    justify-content: center;
    flex: 1;
    margin: 0 10px;
}

/* Status Bars */
.status-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.status-label {
    min-width: 45px;
    font-size: 10px;
    color: #88bbff;
    text-align: left;
    font-weight: bold;
    letter-spacing: 1px;
}
.status-bar-bg {
    width: 100px;
    height: 12px;
    background: rgba(0,0,0,0.7);
    border: 1px solid #4488ff;
    position: relative;
    overflow: hidden;
    border-radius: 2px;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}
.status-bar-fill { height: 100%; transition: width 0.3s ease-out; }
.status-bar-text { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    display: flex; align-items: center; justify-content: center;
    font-size: 9px; color: #fff; text-shadow: 1px 1px 1px #000; 
    font-weight: bold; pointer-events: none; 
}
#health-bar { background: #0c0; }
#fuel-bar { background: #fa0; }
#energy-bar { background: #0ff; }
#cargo-bar { background: #fff; }

.research-btn:hover {
    filter: brightness(1.3);
    text-shadow: 0 0 10px #4df;
}

#in-game-settings-btn, #minimap-toggle-btn, #missions-toggle-btn, #ship-control-btn, #research-center-btn {
    pointer-events: auto;
    background: rgba(10,20,40,0.6);
    border: 1px solid #4488ff;
    color: #fff;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 2px 5px;
    cursor: pointer;
    font-size: 1.2em;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
}
#in-game-settings-btn:hover, #minimap-toggle-btn:hover, #missions-toggle-btn:hover, #ship-control-btn:hover, #research-center-btn:hover {
    background: rgba(68,136,255,0.4);
    transform: scale(1.05);
}

/* Diálogo de Seleção de Nave */
#overlay-ship-selection .dialog-container {
    max-width: 800px;
    width: 90%;
}

.ship-selection-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 10px;
}

.ship-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(68, 136, 255, 0.2);
    border-radius: 8px;
    padding: 10px;
    cursor: pointer;
    transition: 0.2s;
}

.ship-item:hover {
    background: rgba(68, 136, 255, 0.2);
    border-color: rgba(68, 136, 255, 0.5);
}

.ship-item.active {
    background: rgba(68, 136, 255, 0.3);
    border-color: #4488ff;
    box-shadow: 0 0 10px rgba(68, 136, 255, 0.4);
}

.ship-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    pointer-events: none;
}

.ship-info {
    flex: 1;
    pointer-events: none;
}

.ship-name {
    font-weight: bold;
    color: #fff;
    font-size: 1.1em;
}

.ship-status {
    font-size: 0.8em;
    color: #88bbff;
    opacity: 0.8;
}

/* Painel de Missões */
.mission-panel {
    position: fixed;
    left: 15px;
    top: 100px; /* Será ajustado dinamicamente no HUDRenderer */
    background: rgba(10, 20, 40, 0.7);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(68, 136, 255, 0.5);
    border-radius: 8px;
    padding: 15px;
    width: 250px;
    display: none;
    z-index: 70;
    pointer-events: none;
    transition: opacity 0.8s ease-in-out;
}

.mission-header {
    font-weight: bold;
    color: #4488ff;
    border-bottom: 1px solid rgba(68, 136, 255, 0.3);
    margin-bottom: 10px;
    padding-bottom: 5px;
    letter-spacing: 1px;
}

.mission-item {
    margin-bottom: 8px;
    font-size: 0.9em;
    display: flex;
    gap: 10px;
}

.mission-check {
    min-width: 20px;
}

.mission-desc {
    color: #ccc;
}

.mission-item.completed .mission-desc {
    color: #44ff44;
    text-decoration: line-through;
    opacity: 0.7;
}

.mission-item.required .mission-desc {
    color: #fff;
}

#ranking-ui {
    top: 60px; right: 10px;
    background: rgba(10,20,40,0.5);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(68,136,255,0.3);
    padding: 10px; display: none; border-radius: 8px;
}

#upgrade-menu {
    background: transparent;
    padding: 0;
    display: none;
    text-align: center;
    width: 100%;
}

.tech-btn {
    width: 100%;
    background: rgba(34, 68, 170, 0.6);
    border: 1px solid #5588cc;
    color: #fff;
    padding: 8px 5px;
    margin: 0 0 5px 0;
    cursor: pointer;
    border-radius: 4px;
    font-weight: bold;
    pointer-events: auto;
    transition: 0.2s;
    box-shadow: inset 0 0 5px rgba(255,255,255,0.1);
    font-size: 0.75em;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    box-sizing: border-box;
}
.tech-btn:hover:not(:disabled) {
    background: rgba(68, 136, 255, 0.8);
    box-shadow: 0 0 10px #4488ff;
}
.tech-btn:disabled {
    background: rgba(51, 51, 51, 0.6);
    border-color: #444;
    color: #888;
    cursor: not-allowed;
    opacity: 0.7;
}

.tab-container {
    display: flex;
    border-bottom: 1px solid #4488ff;
    margin-bottom: 10px;
    flex-wrap: nowrap; /* Forçar uma única linha */
    justify-content: center;
    width: 100%;
    overflow-x: hidden; /* Evitar quebra e esconder overflow se necessário */
}
.tab-btn {
    background: none;
    border: none;
    color: #88bbff;
    padding: 10px 5px; /* Reduzido padding lateral */
    cursor: pointer;
    text-transform: uppercase;
    font-size: clamp(0.65em, 2vw, 0.8em); /* Fonte dinâmica para caber em telas pequenas */
    flex: 1; /* Distribuir espaço igualmente */
    white-space: nowrap; /* Impedir que o texto quebre */
    min-width: 0; /* Permitir encolhimento abaixo do conteúdo se necessário */
    transition: background 0.2s, color 0.2s;
}
.tab-btn.active {
    color: #fff;
    border-bottom: 2px solid #4488ff;
}
.tab-content {
    display: none;
    padding: 10px 0;
}
.tab-content.active {
    display: block;
}
.tech-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    padding: 10px 0;
}

.tech-grid > div {
    flex: 0 0 110px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: 8px 4px;
    border-radius: 6px;
    border: 1px solid rgba(68, 136, 255, 0.1);
    box-sizing: border-box;
}

/* Tela de Carregamento */
#loading-screen {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: #050505;
    z-index: 1000;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    font-family: 'Courier New', monospace;
}
#loading-screen h2 {
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #4488ff;
}
.loading-bar-container {
    width: 300px;
    height: 20px;
    background: #111;
    border: 1px solid #333;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}
#loading-bar-fill {
    width: 0%; height: 100%;
    background: linear-gradient(90deg, #0044ff, #00aaff);
    transition: width 0.2s ease;
}
#loading-text {
    margin-top: 10px; font-size: 0.9em; color: #aaa;
}

/* Controles Mobile */
#mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}
.joystick-container {
    position: absolute;
    bottom: 30px;
    width: 110px;
    height: 110px;
    pointer-events: auto;
    touch-action: none;
}
#joystick-left { left: 30px; }
#joystick-right { right: 30px; }

.joystick-base {
    position: absolute;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(2px);
    border: 2px solid rgba(136, 187, 255, 0.3);
    border-radius: 50%;
    box-shadow: inset 0 0 15px rgba(68,136,255,0.2);
}
.joystick-knob {
    position: absolute;
    top: 50%; left: 50%; width: 45px; height: 45px;
    background: rgba(68, 136, 255, 0.6);
    border: 2px solid #88bbff; border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    box-shadow: 0 0 10px rgba(68,136,255,0.8);
}

/* Responsividade Mobile (Geral) */
@media (max-width: 1024px) {
    .screen { padding-top: 70px; }
    h1 { margin-bottom: 10px; }
    .btn { padding: 12px 15px; }

    #ui {
        font-size: 0.75em;
        padding: env(safe-area-inset-top, 2px) 5px 2px 5px;
    }
    
    #status-bars-container {
        grid-template-columns: auto 1fr 1fr;
        grid-template-rows: auto auto;
        gap: 2px 8px;
        margin: 0 5px;
    }
    
    #money-label { font-size: 0.9em; }
    .status-bar-bg { width: 70px; height: 10px; }
    .status-label { min-width: 35px; font-size: 8px; }

    #status-bars-container > div:nth-child(1) {
        grid-column: 1;
        grid-row: 1 / 3;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    #ranking-ui { top: 60px; right: 5px; font-size: 0.7em; padding: 5px; }
    
    #in-game-settings-btn, #minimap-toggle-btn {
        padding: 5px;
        font-size: 1em;
        min-width: 36px;
        min-height: 36px;
    }
}

@media (min-width: 1025px) {
    #status-bars-container {
        grid-template-columns: repeat(5, auto);
        justify-content: center;
    }
}

/* Responsividade Landscape Mobile (Celulares Deitados) */
@media (max-height: 500px) and (orientation: landscape) {
    .screen {
        padding-top: 20px;
    }
    h1 {
        font-size: 1.5em;
        margin-bottom: 5px;
    }
    .btn-back {
        top: 5px;
        left: 5px;
    }
    .btn {
        padding: 8px 15px;
        margin: 5px;
        font-size: 0.9em;
    }
    #upgrade-menu {
        max-height: none;
        width: 100%;
    }
    .joystick-container {
        width: 90px;
        height: 90px;
        bottom: 10px;
    }
    #ui {
        padding: 2px 10px;
    }
    #status-bars-container {
        grid-template-columns: repeat(5, auto);
        grid-template-rows: auto;
        gap: 2px 12px;
    }
    #status-bars-container > div:nth-child(1) {
        grid-column: auto;
        grid-row: auto;
        flex-direction: row;
        gap: 5px;
    }
    .status-bar-bg {
        width: 60px;
    }
}
