/* Galactic Empire - Space Theme */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: #0a0a1a;
    color: #c8c8e0;
    font-family: 'Courier New', monospace;
    overflow: hidden;
    height: 100vh;
}

h1, h2, h3 {
    color: #88aaff;
    text-shadow: 0 0 10px rgba(100, 150, 255, 0.5);
}

/* Landing Page */
#landing {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    gap: 30px;
    padding: 20px 10px;
    overflow-y: auto;
}

#landing h1 {
    font-size: 3em;
    letter-spacing: 8px;
    text-transform: uppercase;
    color: #aaccff;
    text-shadow: 0 0 20px rgba(100, 180, 255, 0.7), 0 0 40px rgba(100, 150, 255, 0.3);
}

h1 .subtitle {
    display: block;
    font-size: 0.5em;
    letter-spacing: 4px;
    color: #667799;
    margin-top: 5px;
}

.panel {
    background: rgba(20, 20, 50, 0.85);
    border: 1px solid #334;
    border-radius: 8px;
    padding: 20px;
    min-width: 350px;
}

.panel h2 {
    font-size: 1.1em;
    margin-bottom: 15px;
    border-bottom: 1px solid #334;
    padding-bottom: 8px;
}

label {
    display: block;
    font-size: 0.85em;
    color: #889;
    margin-bottom: 4px;
    margin-top: 10px;
}

input, select {
    width: 100%;
    padding: 8px 10px;
    background: #0d0d25;
    border: 1px solid #445;
    border-radius: 4px;
    color: #cce;
    font-family: inherit;
    font-size: 0.95em;
}

input:focus, select:focus {
    outline: none;
    border-color: #66aaff;
    box-shadow: 0 0 6px rgba(100, 170, 255, 0.3);
}

button {
    padding: 10px 20px;
    background: linear-gradient(135deg, #2244aa, #3366cc);
    border: 1px solid #4477dd;
    border-radius: 4px;
    color: #ddeeff;
    font-family: inherit;
    font-size: 0.95em;
    cursor: pointer;
    margin-top: 12px;
    transition: all 0.2s;
}

button:hover {
    background: linear-gradient(135deg, #3355bb, #4477dd);
    box-shadow: 0 0 10px rgba(100, 150, 255, 0.4);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.danger {
    background: linear-gradient(135deg, #882222, #aa3333);
    border-color: #cc4444;
}

button.success {
    background: linear-gradient(135deg, #228822, #33aa33);
    border-color: #44cc44;
}

.game-list {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 10px;
}

.game-item {
    padding: 8px 12px;
    border: 1px solid #334;
    border-radius: 4px;
    margin-bottom: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.game-item:hover {
    background: rgba(50, 80, 150, 0.3);
}

.game-item .status {
    font-size: 0.8em;
    padding: 2px 8px;
    border-radius: 10px;
}

.status-lobby { background: #335; color: #8af; }
.status-active { background: #353; color: #8f8; }
.status-finished { background: #533; color: #f88; }

/* Game View */
#game-view {
    display: none;
    height: 100vh;
    width: 100vw;
    grid-template-columns: 200px minmax(0, 1fr) 200px 200px;
    grid-template-rows: 40px minmax(0, 1fr) 180px;
    gap: 0;
    overflow: hidden;
}

#game-view.active {
    display: grid;
}

/* Top bar */
#top-bar {
    grid-column: 1 / -1;
    position: relative;
    background: rgba(15, 15, 40, 0.95);
    border-bottom: 1px solid #334;
    display: flex;
    align-items: center;
    padding: 0 15px;
    gap: 20px;
    font-size: 0.9em;
}

#top-bar .game-title {
    color: #88aaff;
    font-weight: bold;
    font-size: 1.1em;
}

#top-bar .turn-info {
    color: #aab;
}

#top-bar .player-info {
    margin-left: auto;
    display: flex;
    gap: 10px;
    align-items: center;
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

/* Worlds Panels (right) */
#worlds-panel-lower {
    grid-column: 3;
    grid-row: 2;
    background: rgba(15, 15, 40, 0.95);
    border-left: 1px solid #334;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    min-width: 0;
    font-size: 0.82em;
}

#worlds-panel-upper {
    grid-column: 4;
    grid-row: 2;
    background: rgba(15, 15, 40, 0.95);
    border-left: 1px solid #334;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    min-width: 0;
    font-size: 0.82em;
}

/* Star Map */
#map-container {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    overflow: hidden;
    background: #050510;
}

#star-map {
    width: 100%;
    height: 100%;
    display: block;
}

/* Info Panel (left) */
#info-panel {
    grid-column: 1;
    grid-row: 2;
    background: rgba(15, 15, 40, 0.95);
    border-right: 1px solid #334;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    min-width: 0;
    font-size: 0.82em;
}

#info-panel h3 {
    font-size: 0.95em;
    margin-bottom: 8px;
    color: #88aaff;
}

.info-section {
    margin-bottom: 15px;
}

.world-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.world-table th {
    text-align: left;
    color: #667;
    font-size: 0.85em;
    padding: 2px 4px;
    border-bottom: 1px solid #223;
}

.world-table td {
    padding: 2px 4px;
    border-bottom: 1px solid #1a1a30;
    font-size: 0.9em;
}

.world-table tr:hover {
    background: rgba(50, 80, 150, 0.2);
}

.world-table tr.selected {
    background: rgba(80, 120, 200, 0.3);
}

.fleet-item {
    padding: 4px 8px;
    border: 1px solid #223;
    border-radius: 3px;
    margin-bottom: 4px;
    font-size: 0.9em;
}

.combat-item {
    padding: 6px 8px;
    border-left: 3px solid #ff6644;
    margin-bottom: 6px;
    background: rgba(50, 20, 10, 0.4);
    font-size: 0.85em;
}

.combat-item.victory {
    border-left-color: #44ff66;
    background: rgba(10, 50, 20, 0.4);
}

/* Order Panel */
#order-panel {
    grid-column: 1 / -1;
    grid-row: 3;
    position: relative;
    z-index: 50;
    background: rgba(15, 15, 40, 0.95);
    border-top: 1px solid #334;
    padding: 10px 15px;
    display: flex;
    gap: 15px;
    align-items: flex-start;
    overflow: visible;
    overflow-y: auto;
}

.order-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    overflow: visible;
}

.order-form label {
    margin: 0;
}

.order-form .field {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.order-form input, .order-form select {
    width: 140px;
    padding: 6px 8px;
    font-size: 0.9em;
}

.order-form button {
    margin-top: 0;
    padding: 6px 14px;
}

#pending-orders {
    flex: 1;
    max-height: 150px;
    overflow-y: auto;
}

.pending-order {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(30, 50, 100, 0.5);
    border: 1px solid #445;
    border-radius: 4px;
    margin: 2px;
    font-size: 0.85em;
}

.pending-order .remove {
    cursor: pointer;
    color: #f66;
    font-weight: bold;
}

.pending-order .remove:hover {
    color: #ff4444;
}

#turn-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 140px;
}

/* Players sidebar section */
.player-entry {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 0.9em;
}

.player-entry .worlds-count {
    margin-left: auto;
    color: #889;
    font-size: 0.85em;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #0a0a1a;
}
::-webkit-scrollbar-thumb {
    background: #334;
    border-radius: 3px;
}

/* Tooltip */
#tooltip {
    display: none;
    position: absolute;
    background: rgba(10, 10, 30, 0.95);
    border: 1px solid #556;
    border-radius: 4px;
    padding: 8px 12px;
    font-size: 0.85em;
    pointer-events: none;
    z-index: 100;
    max-width: 200px;
}

/* Join dialog */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: #141432;
    border: 1px solid #445;
    border-radius: 8px;
    padding: 25px;
    min-width: 300px;
}

.modal h2 {
    margin-bottom: 15px;
}

/* Color picker grid */
.color-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.color-swatch:hover, .color-swatch.selected {
    border-color: #fff;
}

/* Auth screens */
#login-screen, #gamer-tag-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.google-btn {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: #fff;
    color: #333;
    border-radius: 4px;
    text-decoration: none;
    font-size: 1em;
    font-weight: 500;
    transition: box-shadow 0.2s;
    border: 1px solid #ddd;
}

.google-btn:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    background: #f8f8f8;
}

#user-bar a {
    text-decoration: none;
}
#user-bar a:hover {
    color: #aab;
}

/* Combat dropdown */
#combat-bar {
    position: absolute;
    top: 40px;
    left: 0;
    right: 0;
    background: rgba(17, 8, 8, 0.95);
    border-bottom: 1px solid #3a1a1a;
    font-size: 0.85em;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
#combat-bar-content .combat-entry {
    padding: 3px 0;
    border-bottom: 1px solid #1a1010;
    color: #aab;
}
#combat-bar-content .combat-entry .turn-label {
    color: #667;
    font-size: 0.85em;
    margin-right: 8px;
}
#combat-bar-content .combat-entry.victory {
    color: #8f8;
}
#combat-bar-content .combat-entry.defeat {
    color: #f88;
}
#combat-bar-content .combat-entry.other {
    color: #aab;
}

/* Custom dropdown (opens upward) */
.custom-select {
    position: relative;
    display: inline-block;
    min-width: 140px;
}
.custom-select .select-display {
    padding: 6px 10px;
    background: #1a1a3a;
    border: 1px solid #334;
    border-radius: 4px;
    color: #c8c8e0;
    cursor: pointer;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.custom-select .select-display:hover {
    border-color: #556;
}
.custom-select .select-options {
    display: none;
    position: fixed;
    max-height: 300px;
    width: 200px;
    overflow-y: auto;
    background: #111128;
    border: 1px solid #446;
    border-radius: 4px 4px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.7);
    z-index: 9999;
}
.custom-select.open .select-options {
    display: block;
}
.custom-select .select-option {
    padding: 6px 10px;
    cursor: pointer;
    font-size: 0.85em;
    color: #aab;
}
.custom-select .select-option:hover {
    background: rgba(50, 80, 150, 0.3);
    color: #fff;
}
.custom-select .select-option.selected {
    background: rgba(80, 120, 200, 0.2);
    color: #8af;
}

/* Battle Overlay */
#battle-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 5, 0.85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}

#battle-content {
    width: 90%;
    max-width: 500px;
    text-align: center;
    font-family: 'Courier New', monospace;
}

#battle-title {
    font-size: 1.4em;
    color: #ff8844;
    margin-bottom: 25px;
    min-height: 2em;
    text-shadow: 0 0 10px rgba(255, 136, 68, 0.5);
}

#battle-combatants {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 25px;
}

.battle-side {
    flex: 1;
    max-width: 180px;
}

.battle-name {
    font-size: 0.9em;
    margin-bottom: 8px;
    font-weight: bold;
}

.battle-bar-container {
    height: 20px;
    background: #1a1a30;
    border: 1px solid #334;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 5px;
}

.battle-bar {
    height: 100%;
    transition: width 0.15s ease-out;
    border-radius: 2px;
}

#battle-def-bar {
    background: linear-gradient(90deg, #44aa44, #66cc66);
}

#battle-atk-bar {
    background: linear-gradient(90deg, #cc4444, #ff6644);
}

.battle-count {
    font-size: 1.8em;
    font-weight: bold;
    font-family: 'Courier New', monospace;
}

#battle-vs {
    font-size: 1.2em;
    color: #556;
    font-weight: bold;
}

#battle-result {
    font-size: 1.2em;
    margin-top: 10px;
    min-height: 1.5em;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

#battle-skip {
    margin-top: 20px;
    font-size: 0.75em;
    color: #445;
    cursor: pointer;
}
#battle-skip:hover {
    color: #667;
}

/* Mobile responsive */
@media (max-width: 768px) {
    body {
        overflow: auto !important;
        height: auto !important;
    }

    #landing {
        padding: 15px 10px;
        gap: 15px;
    }

    #landing h1 {
        font-size: 1.8em;
        letter-spacing: 4px;
    }

    /* Stack the two columns vertically on mobile */
    #landing > div[style*="display:flex"] {
        flex-direction: column !important;
    }

    .panel {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* Hide create game on mobile */
    #landing .panel:has(#btn-create) {
        display: none;
    }

    /* Game view: portrait — map only */
    #game-view, #game-view.active {
        grid-template-columns: 1fr !important;
        grid-template-rows: 40px 1fr 150px !important;
        width: 100vw !important;
        overflow: hidden !important;
    }

    #info-panel { display: none !important; }
    #worlds-panel-lower, #worlds-panel-upper { display: none !important; }

    #map-container {
        grid-column: 1 !important;
        grid-row: 2 !important;
        min-height: 0;
        touch-action: none;
    }

    #order-panel {
        grid-column: 1 !important;
        grid-row: 3 !important;
        flex-wrap: wrap;
        overflow-y: auto;
        max-height: 150px;
    }

    .order-form { flex-wrap: wrap; }
    .custom-select { min-width: 120px; }

    /* Smaller top bar on mobile */
    #top-bar {
        font-size: 0.75em;
        padding: 0 8px;
        gap: 8px;
    }
}

/* Mobile landscape — show all columns, map at 50%, horizontal scroll */
@media (max-width: 932px) and (orientation: landscape) {
    body {
        overflow: auto !important;
        height: auto !important;
    }

    #game-view, #game-view.active {
        grid-template-columns: 160px 50vw 160px 160px !important;
        grid-template-rows: 36px 1fr 120px !important;
        width: max(100vw, 640px) !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
    }

    #info-panel {
        display: block !important;
        grid-column: 1 !important;
        grid-row: 2 !important;
        border-right: 1px solid #334 !important;
        font-size: 0.75em;
        width: auto !important;
    }

    #map-container {
        grid-column: 2 !important;
        grid-row: 2 !important;
        touch-action: none;
    }

    #worlds-panel-lower {
        display: block !important;
        grid-column: 3 !important;
        grid-row: 2 !important;
        font-size: 0.7em;
    }

    #worlds-panel-upper {
        display: block !important;
        grid-column: 4 !important;
        grid-row: 2 !important;
        font-size: 0.7em;
    }

    #order-panel {
        grid-column: 1 / -1 !important;
        grid-row: 3 !important;
        flex-wrap: wrap;
        font-size: 0.85em;
    }

    #top-bar {
        font-size: 0.7em;
        padding: 0 6px;
        gap: 6px;
    }
}

/* Login/gamer-tag screens on mobile */
@media (max-width: 768px) {
    #login-screen h1,
    #gamer-tag-screen h1 {
        font-size: 1.8em;
        letter-spacing: 4px;
    }
}
