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

body {
    background: #0a0a14;
    color: #d0d0d0;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
}

button, select, input {
    transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

button:focus-visible, select:focus-visible, input:focus-visible {
    outline: 1px solid #4a6af0;
    outline-offset: 1px;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

#galaxy-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* UI Overlay */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#ui-overlay > * {
    pointer-events: auto;
}

/* Top Bar */
#top-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4em 1.2em;
    padding: 0.5em 1em;
    background: rgba(10, 10, 20, 0.85);
    border-bottom: 1px solid #2a2a3a;
    font-size: 0.9em;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

#game-title {
    font-weight: bold;
    font-size: 1.1em;
    color: #7af;
    text-shadow: 0 0 8px rgba(119, 170, 255, 0.3);
}

#turn-info {
    color: #aaa;
    min-width: 0;
    flex-shrink: 1;
}

#resource-info {
    color: #8c8;
    margin-left: auto;
    min-width: 0;
    flex-shrink: 1;
}

#turn-buttons {
    display: flex;
    gap: 4px;
}

#top-bar button {
    background: #1a2a3a;
    color: #aaa;
    border: 1px solid #2a3a4a;
    padding: 0.3em 0.8em;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8em;
}

#top-bar button:hover {
    background: #2a3a5a;
    color: #ddd;
}

#end-turn-btn {
    background: #3a7 !important;
    color: #fff !important;
    border: none !important;
}

#end-turn-btn:hover {
    background: #4b8 !important;
}

/* Settlement rows */
.settlement-row {
    font-size: 0.9em;
}

/* Queue items */
.queue-item {
    font-size: 0.9em;
}

.queue-item:hover {
    background: rgba(100, 140, 255, 0.08);
}

/* Panels */
.panel {
    background: rgba(10, 10, 20, 0.92);
    border: 1px solid #2a2a3a;
    border-radius: 6px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#left-panel {
    position: absolute;
    top: 50px;
    left: 10px;
    width: min(280px, calc(100vw - 20px));
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    padding: 0.8em;
}

#panel-title {
    font-size: 1.1em;
    font-weight: bold;
    color: #7af;
    margin-bottom: 0.5em;
    padding-bottom: 0.4em;
    border-bottom: 1px solid #2a2a3a;
}

#panel-content {
    font-size: 0.85em;
    line-height: 1.6;
}

#panel-content .stat-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25em 0.2em;
    border-radius: 2px;
}
#panel-content .stat-row:hover {
    background: rgba(119, 170, 255, 0.04);
}
.battle-plan-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2em 0;
}
.battle-plan-select {
    background: #1a1a2a;
    color: #ccc;
    border: 1px solid #2a2a4a;
    border-radius: 3px;
    padding: 2px 4px;
    font-size: 0.8em;
    max-width: 140px;
}

#panel-content .stat-label {
    color: #999;
}

#panel-content .stat-value {
    color: #ccc;
}

#panel-content .section-header {
    color: #7af;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.8em;
    margin-bottom: 0.3em;
    padding-bottom: 0.25em;
    border-bottom: 1px solid #1a1a3a;
    font-weight: bold;
}

#bottom-panel {
    position: absolute;
    bottom: 10px;
    left: min(300px, calc(100vw - 20px));
    right: 10px;
    max-height: 150px;
    overflow-y: auto;
    padding: 0.6em;
    font-size: 0.8em;
}

#message-log .msg {
    padding: 0.2em 0;
    border-bottom: 1px solid #1a1a2a;
}

#message-filters {
    display: flex;
    gap: 4px;
    padding: 4px 0 6px;
    border-bottom: 1px solid #1a1a3a;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.msg-filter-btn {
    background: #1a1a2a;
    border: 1px solid #2a2a4a;
    color: #aaa;
    padding: 2px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.75em;
}
.msg-filter-btn:hover {
    background: #2a2a3a;
    color: #ccc;
}
.msg-filter-btn.msg-filter-inactive {
    opacity: 0.4;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(15, 15, 30, 0.95);
    border: 1px solid #3a3a5a;
    border-radius: 4px;
    padding: 0.4em 0.7em;
    font-size: 0.8em;
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.tooltip .star-name {
    color: #7af;
    font-weight: bold;
}

.tooltip .star-info {
    color: #999;
    font-size: 0.9em;
}

.tooltip .bar-tooltip-content {
    white-space: normal;
    min-width: 140px;
    max-width: 220px;
    line-height: 1.4;
}

/* Screens (full-screen overlays) */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 5, 15, 0.97);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.screen-content {
    background: #12122a;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 2.5em;
    min-width: 400px;
    max-width: 620px;
    width: 90vw;
}

.screen-content h1 {
    color: #7af;
    font-size: 2em;
    margin-bottom: 0.1em;
}

.screen-content .subtitle {
    color: #666;
    margin-bottom: 1.5em;
    font-size: 0.9em;
}

.form-group {
    margin-bottom: 1.2em;
}

.form-group label {
    display: block;
    color: #888;
    font-size: 0.85em;
    margin-bottom: 0.4em;
}

.form-group select,
.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 0.5em 0.7em;
    background: #0a0a1a;
    border: 1px solid #2a2a4a;
    border-radius: 4px;
    color: #d0d0d0;
    font-size: 0.9em;
}

.form-group input[type="range"] {
    width: 100%;
    accent-color: #4a6af0;
    cursor: pointer;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: #4a6af0;
}

.player-entry {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.5em;
    padding: 0.5em;
    background: rgba(20, 20, 40, 0.5);
    border: 1px solid #1a1a3a;
    border-radius: 4px;
}

.player-entry input {
    flex: 1;
}

.player-color {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #444;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s, transform 0.15s;
}

.player-color:hover {
    border-color: #888;
    transform: scale(1.1);
}

.player-race {
    width: 130px;
    font-size: 0.8em;
    padding: 2px 4px;
    background: #1a1a2a;
    color: #aaa;
    border: 1px solid #3a3a5a;
    border-radius: 3px;
}

.player-ai-label {
    font-size: 0.8em;
    color: #888;
    white-space: nowrap;
    cursor: pointer;
}

.player-ai-check {
    margin-right: 2px;
}

.player-ai-difficulty {
    width: 80px;
    font-size: 0.8em;
    padding: 2px 4px;
    background: #1a1a2a;
    color: #aaa;
    border: 1px solid #3a3a5a;
    border-radius: 3px;
}

.player-entry input.player-name {
    width: 100px;
    flex: 0 0 100px;
}

#add-player-btn {
    background: none;
    border: 1px dashed #3a3a5a;
    color: #666;
    padding: 0.3em 0.8em;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    margin-top: 0.3em;
}

#add-player-btn:hover {
    border-color: #5a5a7a;
    color: #aaa;
}

.primary-btn {
    display: block;
    width: 100%;
    padding: 0.7em;
    background: #3060d0;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1.05em;
    cursor: pointer;
    margin-top: 1em;
}

.primary-btn:hover {
    background: #4070e0;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #0a0a14;
}

::-webkit-scrollbar-thumb {
    background: #2a2a4a;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3a3a5a;
}

/* Production Dialog */
.prod-dialog-content {
    width: 700px;
    max-width: 90vw;
    max-height: 85vh;
    background: #10102a;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.prod-header {
    display: flex;
    align-items: center;
    gap: 1em;
    padding: 0.8em 1em;
    background: #14143a;
    border-bottom: 1px solid #2a2a4a;
    position: relative;
}

.prod-header h2 {
    color: #7af;
    font-size: 1.1em;
    margin: 0;
    white-space: nowrap;
}

.prod-stats {
    display: flex;
    gap: 1em;
    font-size: 0.8em;
    color: #999;
    flex-wrap: wrap;
}

.prod-close-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.prod-close-btn:hover {
    background: #a33;
    color: #fff;
    border-color: #c44;
}

.prod-resources {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5em 1.5em;
    padding: 0.6em 1em;
    background: #0c0c22;
    border-bottom: 1px solid #1a1a3a;
    font-size: 0.8em;
}

.prod-resource {
    display: flex;
    gap: 0.4em;
}

.prod-res-label {
    color: #888;
}

.prod-res-val {
    color: #ccc;
    font-weight: bold;
}

.prod-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.prod-left {
    flex: 1;
    border-right: 1px solid #1a1a3a;
    overflow-y: auto;
    padding: 0.5em;
}

.prod-right {
    flex: 1;
    overflow-y: auto;
    padding: 0.5em;
}

.prod-left-header,
.prod-right-header {
    color: #7af;
    font-size: 0.85em;
    font-weight: bold;
    padding: 0.3em 0.5em;
    border-bottom: 1px solid #1a1a3a;
    margin-bottom: 0.3em;
}

.prod-eta {
    color: #999;
    font-weight: normal;
    font-size: 0.9em;
}

.prod-category {
    color: #88aacc;
    font-size: 0.75em;
    font-weight: bold;
    text-transform: uppercase;
    padding: 0.6em 0.5em 0.2em;
    letter-spacing: 0.05em;
}

.prod-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35em 0.5em;
    margin: 1px 0;
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

.prod-option:hover {
    background: rgba(80, 120, 200, 0.15);
}

.prod-opt-label {
    color: #ccc;
    font-size: 0.85em;
}

.prod-opt-cost {
    color: #888;
    font-size: 0.75em;
}

/* Auto-build toggles */
.prod-auto {
    border-top: 1px solid #1a1a3a;
    margin-top: 0.5em;
    padding-top: 0.3em;
}

.prod-auto-toggle {
    display: flex;
    align-items: center;
    gap: 0.5em;
    padding: 0.3em 0.5em;
    margin: 1px 0;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.82em;
    color: #888;
    transition: background 0.15s;
}

.prod-auto-toggle:hover {
    background: rgba(80, 200, 120, 0.1);
}

.prod-auto-active {
    color: #8f8;
}

.prod-auto-indicator {
    font-size: 1.1em;
}

/* Queue items */
.prod-queue-empty {
    color: #666;
    font-size: 0.82em;
    padding: 1em;
    text-align: center;
    font-style: italic;
}

.prod-queue-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4em 0.5em;
    margin: 2px 0;
    border-radius: 3px;
    background: rgba(20, 20, 40, 0.5);
    border-left: 3px solid transparent;
}

.prod-queue-active {
    border-left-color: #4a8af0;
    background: rgba(40, 60, 120, 0.2);
}

.prod-queue-auto {
    border-left-color: #4a8a4a;
    background: rgba(30, 60, 30, 0.15);
}

.prod-qi-info {
    flex: 1;
    min-width: 0;
}

.prod-qi-label {
    color: #ccc;
    font-size: 0.85em;
}

.prod-qi-bar {
    width: 100%;
    height: 4px;
    background: #1a1a3a;
    border-radius: 2px;
    margin-top: 3px;
    overflow: hidden;
}

.prod-qi-fill {
    height: 100%;
    background: #4a8af0;
    border-radius: 2px;
    transition: width 0.3s;
}

.prod-qi-controls {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.prod-qi-btn {
    cursor: pointer;
    color: #666;
    font-size: 0.8em;
    padding: 0 2px;
    transition: color 0.15s;
}

.prod-qi-btn:hover {
    color: #aaf;
}

.prod-qi-btn.qi-remove:hover {
    color: #f66;
}

/* System Popup */
#system-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.syspop-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
}

.syspop-dialog {
    position: relative;
    width: 750px;
    max-width: 95vw;
    max-height: 90vh;
    background: #0c0c22;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.syspop-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6em 1em;
    background: #12123a;
    border-bottom: 1px solid #2a2a4a;
}

.syspop-header h2 {
    color: #7af;
    font-size: 1.1em;
    margin: 0;
}

.syspop-close-btn {
    background: none;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.syspop-close-btn:hover {
    background: #a33;
    color: #fff;
    border-color: #c44;
}

.syspop-content {
    display: flex;
    flex: 1;
    min-height: 0;
}

.syspop-left {
    flex: 0 0 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #06060e;
    border-right: 1px solid #1a1a3a;
}

#syspop-canvas {
    display: block;
}

.syspop-right {
    flex: 1;
    padding: 0.8em;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#syspop-preview {
    text-align: center;
    margin-bottom: 4px;
}

.syspop-body-name {
    color: #7af;
    font-size: 1.1em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 2px;
}

.syspop-body-type {
    color: #889;
    font-size: 0.85em;
    text-align: center;
    margin-bottom: 8px;
}

.syspop-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 4px;
    font-size: 0.85em;
}

.syspop-detail-row span:first-child {
    color: #777;
}

.syspop-detail-row span:last-child {
    color: #bbb;
}

.syspop-section {
    color: #7af;
    font-size: 0.82em;
    font-weight: bold;
    margin-top: 8px;
    margin-bottom: 2px;
    padding-bottom: 2px;
    border-bottom: 1px solid #1a1a3a;
}

.syspop-footer {
    padding: 0.5em 0.8em;
    border-top: 1px solid #1a1a3a;
    background: #0a0a1e;
}

#syspop-bodylist {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-bottom: 6px;
    max-height: 60px;
    overflow-y: auto;
}

.syspop-body-btn {
    padding: 3px 8px;
    background: #14143a;
    border: 1px solid #2a2a4a;
    border-bottom: 2px solid #555;
    border-radius: 3px;
    color: #999;
    font-size: 0.75em;
    cursor: pointer;
    white-space: nowrap;
}

.syspop-body-btn:hover {
    background: #1a1a44;
    color: #ccc;
}

.syspop-body-btn.syspop-body-active {
    background: #1a2a4a;
    color: #fff;
    border-color: #4a6a8a;
}

.syspop-body-btn.syspop-body-moon {
    padding-left: 14px;
    font-size: 0.7em;
    color: #777;
}

.syspop-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.syspop-nav button {
    padding: 3px 10px;
    background: #1a1a3a;
    border: 1px solid #2a2a5a;
    color: #7af;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8em;
}

.syspop-nav button:hover {
    background: #2a2a4a;
    color: #adf;
}

#syspop-viewdetail {
    background: #2a3a5a !important;
    border-color: #4a6a8a !important;
    font-weight: bold;
}

#syspop-viewdetail:hover {
    background: #3a4a6a !important;
}

.syspop-nav span {
    color: #888;
    font-size: 0.8em;
    min-width: 50px;
    text-align: center;
}

/* Star button in system popup */
.syspop-body-btn.syspop-body-star {
    color: #ffee88;
    border-bottom-color: #ffbb44;
}

/* Screen buttons (Research, Design, Colonies, Fleets) */
#file-buttons {
    display: flex;
    gap: 4px;
}

#screen-buttons {
    display: flex;
    gap: 4px;
}

/* Command List Dialog */
#command-list-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cmdlist-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.cmdlist-panel {
    position: relative;
    width: 700px;
    max-width: 95vw;
    max-height: 80vh;
    background: #0c0c22;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.cmdlist-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5em 0.8em;
    background: #12123a;
    border-bottom: 1px solid #2a2a4a;
}

.cmdlist-tabs {
    display: flex;
    gap: 4px;
}

.cmdlist-tab {
    padding: 4px 12px;
    background: #1a1a3a;
    border: 1px solid #2a2a5a;
    color: #888;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85em;
}

.cmdlist-tab:hover {
    background: #2a2a4a;
    color: #ccc;
}

.cmdlist-tab-active {
    background: #2a3a5a !important;
    color: #7af !important;
    border-color: #4a6a8a !important;
}

.cmdlist-close {
    background: none;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cmdlist-close:hover {
    background: #a33;
    color: #fff;
}

.cmdlist-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5em;
}

.cmdlist-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82em;
}

.cmdlist-table th {
    color: #7af;
    font-weight: bold;
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid #2a2a4a;
    position: sticky;
    top: 0;
    background: #0c0c22;
}

.cmdlist-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #111;
}

.cmdlist-row {
    cursor: pointer;
}

.cmdlist-row:hover {
    background: rgba(80, 120, 200, 0.12);
}

/* Planet preview in left panel */
.planet-preview-container {
    text-align: center;
    margin: 4px 0 6px;
}

/* ═══════════ Ship Designer ═══════════ */

.sd-dialog {
    position: relative;
    width: 820px;
    max-width: 95vw;
    max-height: 90vh;
    background: #0c0c22;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.sd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5em 1em;
    background: #12123a;
    border-bottom: 1px solid #2a2a4a;
}

.sd-header h2 {
    color: #7af;
    font-size: 1.1em;
    margin: 0;
}

.sd-close-btn {
    background: none;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sd-close-btn:hover {
    background: #a33;
    color: #fff;
    border-color: #c44;
}

.sd-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sd-left {
    flex: 1;
    overflow-y: auto;
    padding: 0.8em;
    border-right: 1px solid #1a1a3a;
}

.sd-right {
    width: 220px;
    flex-shrink: 0;
    overflow-y: auto;
    padding: 0.8em;
    display: flex;
    flex-direction: column;
}

.sd-hull-row {
    display: flex;
    align-items: center;
    gap: 0.6em;
    margin-bottom: 0.5em;
}

.sd-hull-row label {
    color: #888;
    font-size: 0.85em;
    flex-shrink: 0;
}

.sd-hull-row select {
    flex: 1;
    padding: 0.35em 0.5em;
    background: #0a0a1a;
    border: 1px solid #2a2a4a;
    color: #d0d0d0;
    border-radius: 4px;
    font-size: 0.9em;
}

.sd-hull-info {
    display: flex;
    gap: 1em;
    margin-bottom: 0.6em;
    font-size: 0.78em;
    color: #777;
}

.sd-hull-stat {
    white-space: nowrap;
}

/* Hull container: relative positioning for canvas silhouette behind grid */
.sd-hull-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.8em;
    background: #08081a;
    border: 1px solid #1a1a3a;
    border-radius: 6px;
    overflow: hidden;
}

/* Background silhouette canvas */
.sd-hull-canvas {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 0;
}

/* Slot grid: CSS Grid with explicit row/column placement */
.sd-slot-grid {
    display: grid;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.sd-slot-cell {
    width: 72px;
    height: 72px;
    padding: 2px;
    background: rgba(14, 14, 36, 0.85);
    border: 1px solid #222244;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    position: relative;
    transition: border-color 0.15s, background 0.15s;
}

.sd-slot-cell:hover {
    background: rgba(20, 20, 56, 0.9);
    border-color: #3a3a6a;
}

.sd-slot-cell.sd-slot-selected {
    border-color: #5588ff;
    background: rgba(20, 20, 64, 0.95);
    box-shadow: 0 0 8px rgba(85, 136, 255, 0.35);
}

.sd-slot-icon {
    width: 40px;
    height: 40px;
    border: 2px solid #444;
    border-radius: 3px;
    background: #0a0a18;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.sd-slot-icon img {
    image-rendering: pixelated;
}

.sd-slot-type {
    font-size: 0.58em;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-align: center;
    white-space: nowrap;
    line-height: 1.1;
}

.sd-slot-comp {
    font-size: 0.52em;
    color: #555;
    text-align: center;
    max-width: 68px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.1;
}

.sd-slot-req {
    position: absolute;
    top: 1px;
    right: 3px;
    color: #ff6644;
    font-size: 0.7em;
    font-weight: bold;
}

/* Component picker */
.sd-picker-section {
    background: #08081a;
    border: 1px solid #1a1a3a;
    border-radius: 6px;
    overflow: hidden;
}

.sd-picker-title {
    padding: 0.4em 0.6em;
    background: #0e0e28;
    border-bottom: 1px solid #1a1a3a;
    font-size: 0.82em;
    color: #888;
}

.sd-picker-list {
    max-height: 180px;
    overflow-y: auto;
    padding: 2px;
}

.sd-picker-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.12s;
}

.sd-picker-row:hover {
    background: rgba(80, 120, 200, 0.12);
}

.sd-picker-row.sd-picker-active {
    background: rgba(80, 120, 200, 0.2);
    border-left: 2px solid #5588ff;
}

.sd-picker-icon {
    width: 30px;
    height: 30px;
    border: 1px solid #444;
    border-radius: 2px;
    background: #0a0a18;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.sd-picker-icon img {
    image-rendering: pixelated;
}

.sd-picker-info {
    flex: 1;
    min-width: 0;
}

.sd-picker-name {
    font-size: 0.82em;
    color: #ccc;
}

.sd-picker-stats {
    font-size: 0.68em;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sd-picker-cost {
    font-size: 0.72em;
    color: #888;
    flex-shrink: 0;
}

/* Stats panel */
.sd-stats {
    flex: 1;
    font-size: 0.82em;
    margin-bottom: 0.8em;
}

.sd-section {
    color: #7af;
    font-size: 0.9em;
    font-weight: bold;
    padding-bottom: 2px;
    border-bottom: 1px solid #1a1a3a;
    margin-bottom: 3px;
}

.sd-stat {
    display: flex;
    justify-content: space-between;
    padding: 1px 0;
}

.sd-stat span:first-child {
    color: #777;
}

.sd-stat span:last-child {
    color: #ccc;
}

.sd-cost-total {
    color: #8c8 !important;
    font-weight: bold;
}

/* Save row */
.sd-save-row {
    display: flex;
    gap: 4px;
    margin-bottom: 0.8em;
}

.sd-save-row input {
    flex: 1;
    padding: 0.35em 0.5em;
    background: #0a0a1a;
    border: 1px solid #2a2a4a;
    color: #d0d0d0;
    border-radius: 4px;
    font-size: 0.82em;
}

.sd-save-row button {
    padding: 0.35em 0.8em;
    background: #3060d0;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82em;
}

.sd-save-row button:hover {
    background: #4070e0;
}

/* Existing designs */
.sd-designs {
    font-size: 0.82em;
}

.sd-design-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 4px;
    border-bottom: 1px solid #111;
}

.sd-design-name {
    flex: 1;
    color: #ccc;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sd-design-hull {
    color: #666;
    font-size: 0.9em;
    flex-shrink: 0;
}

.sd-design-del {
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
    font-size: 1.1em;
    padding: 0 2px;
    line-height: 1;
}

.sd-design-del:hover {
    color: #f66;
}

/* Close button transitions */
.prod-close-btn, .syspop-close-btn, .sd-close-btn, .cmdlist-close {
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

/* Planet preview click hint */
.planet-preview-container {
    cursor: pointer;
}

/* ═══════════ Planet Viewer Modal ═══════════ */
.planet-viewer-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
}
.planet-viewer-backdrop {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
}
.planet-viewer-dialog {
    position: relative;
    background: #0c0c22;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
}
.planet-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5em 1em;
    background: #12123a;
    border-bottom: 1px solid #2a2a4a;
}
.planet-viewer-title {
    color: #7af;
    font-weight: bold;
    font-size: 1.1em;
}
.planet-viewer-close {
    background: none;
    border: 1px solid #444;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.planet-viewer-close:hover {
    background: #a33;
    color: #fff;
    border-color: #c44;
}
.planet-viewer-canvas-wrap {
    width: min(80vw, 600px);
    height: min(80vw, 600px);
    background: #000;
}

/* ═══════════ Mystery Trader Dialog ═══════════ */

.mt-title {
    color: #f0c040;
    font-size: 1.4em;
    margin-bottom: 0.2em;
}

.mt-subtitle {
    color: #999;
    font-size: 0.9em;
    margin-bottom: 1.2em;
}

.mt-offers {
    display: flex;
    flex-direction: column;
    gap: 0.7em;
    margin-bottom: 1.2em;
}

.mt-offer {
    background: #1a1a35;
    border: 1px solid #2a2a4a;
    border-radius: 6px;
    padding: 0.8em 1em;
    transition: border-color 0.15s;
}

.mt-offer:hover {
    border-color: #4a4a6a;
}

.mt-offer-bought {
    opacity: 0.5;
    border-color: #2a4a2a;
}

.mt-offer-header {
    color: #7af;
    font-weight: bold;
    font-size: 1.05em;
    margin-bottom: 0.3em;
}

.mt-offer-desc {
    color: #aaa;
    font-size: 0.85em;
    margin-bottom: 0.5em;
}

.mt-offer-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mt-offer-cost {
    color: #cc8;
    font-size: 0.85em;
}

.mt-buy-btn {
    background: #3060d0;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0.3em 1.2em;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s;
}

.mt-buy-btn:hover {
    background: #4070e0;
}

.mt-buy-disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

.mt-buy-disabled:hover {
    background: #333;
}

.mt-bought-label {
    color: #6a6;
    font-size: 0.85em;
    font-style: italic;
}

.mt-decline-btn {
    margin-top: 0.5em;
    background: #2a2a3a;
}

.mt-decline-btn:hover {
    background: #3a3a4a;
}

/* ═══════════ PBEM Dashboard ═══════════ */

#pbem-screen {
    position: fixed;
    top: 0; right: 0;
    width: 340px;
    max-height: calc(100vh - 40px);
    margin: 40px 10px 0 0;
    z-index: 120;
    pointer-events: auto;
}

.pbem-dashboard {
    background: rgba(12, 12, 30, 0.95);
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 1em;
    backdrop-filter: blur(8px);
}

.pbem-header {
    display: flex;
    align-items: center;
    gap: 0.5em;
    margin-bottom: 0.8em;
    flex-wrap: wrap;
}

.pbem-header h2 {
    color: #7af;
    font-size: 1em;
    margin: 0;
    flex: 1;
}

.pbem-turn-info {
    color: #888;
    font-size: 0.8em;
}

.pbem-close {
    background: none;
    border: none;
    color: #666;
    font-size: 1.4em;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.pbem-close:hover { color: #aaa; }

.pbem-section {
    margin-bottom: 0.8em;
}

.pbem-section-title {
    color: #888;
    font-size: 0.8em;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.3em;
}

.pbem-player-list {
    background: #08081a;
    border: 1px solid #1a1a3a;
    border-radius: 6px;
    overflow: hidden;
}

.pbem-player-row:last-child {
    border-bottom: none !important;
}

.pbem-actions {
    display: flex;
    gap: 0.4em;
    margin-bottom: 0.4em;
}

.pbem-actions-secondary {
    display: flex;
    gap: 0.4em;
    margin-bottom: 0.6em;
}

.pbem-btn {
    padding: 0.4em 0.8em;
    border: 1px solid #3a3a5a;
    border-radius: 5px;
    background: #1a1a2a;
    color: #aaa;
    cursor: pointer;
    font-size: 0.8em;
    flex: 1;
    text-align: center;
}
.pbem-btn:hover:not(:disabled) { background: #2a2a4a; color: #d0d0d0; }
.pbem-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.pbem-btn-primary {
    background: #2a4a3a;
    border-color: #3a6a4a;
    color: #8f8;
}
.pbem-btn-primary:hover:not(:disabled) { background: #3a5a4a; }

.pbem-btn-warn {
    background: #4a3a1a;
    border-color: #6a5a2a;
    color: #da4;
}
.pbem-btn-warn:hover:not(:disabled) { background: #5a4a2a; }

.pbem-btn-secondary {
    background: #12122a;
    border-color: #2a2a4a;
    color: #888;
    font-size: 0.75em;
}
.pbem-btn-secondary:hover { background: #1a1a3a; color: #aaa; }

.pbem-status-msg {
    font-size: 0.8em;
    color: #888;
    text-align: center;
    min-height: 1.2em;
}

/* PBEM Password Dialog */
.pbem-password-dialog-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pbem-password-dialog {
    background: #12122a;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 1.5em;
    min-width: 320px;
    max-width: 400px;
}

.pbem-password-dialog h3 {
    color: #7af;
    margin: 0 0 0.3em;
}

.pbem-password-dialog input[type="password"] {
    width: 100%;
    padding: 0.5em;
    background: #0a0a1a;
    border: 1px solid #2a2a4a;
    color: #d0d0d0;
    border-radius: 4px;
    box-sizing: border-box;
}

/* ═══════════ Tutorial Panel ═══════════ */

#tutorial-panel {
    position: fixed;
    top: 50px;
    right: 10px;
    width: 320px;
    max-height: calc(100vh - 70px);
    z-index: 900;
    background: rgba(10, 12, 28, 0.95);
    border: 1px solid #2a4a6a;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 4px 24px rgba(0, 40, 120, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto;
}

.tutorial-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6em 0.8em;
    background: #0e1430;
    border-bottom: 1px solid #2a4a6a;
}

.tutorial-header h3 {
    color: #5ac8fa;
    font-size: 0.95em;
    margin: 0;
}

.tutorial-close-btn {
    background: none;
    border: 1px solid #3a4a6a;
    color: #8aa;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tutorial-close-btn:hover {
    background: #a33;
    color: #fff;
    border-color: #c44;
}

.tutorial-progress {
    height: 3px;
    background: #1a1a3a;
    overflow: hidden;
}

.tutorial-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2a6af0, #5ac8fa);
    transition: width 0.4s ease;
}

.tutorial-body {
    padding: 0.8em;
    font-size: 0.88em;
    line-height: 1.55;
    color: #c0c8d8;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.tutorial-body b {
    color: #7af;
}

.tutorial-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5em 0.8em;
    border-top: 1px solid #1a2a4a;
    background: #0a0e22;
}

.tutorial-step-counter {
    color: #556;
    font-size: 0.75em;
}

.tutorial-buttons {
    display: flex;
    gap: 4px;
}

.tutorial-btn {
    padding: 0.3em 0.7em;
    border: 1px solid #2a3a5a;
    border-radius: 4px;
    background: #1a2a3a;
    color: #8aa;
    cursor: pointer;
    font-size: 0.8em;
    transition: background 0.15s, color 0.15s;
}

.tutorial-btn:hover {
    background: #2a3a5a;
    color: #cde;
}

.tutorial-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tutorial-btn-next {
    background: #1a3a5a;
    color: #5ac8fa;
    border-color: #2a5a8a;
}

.tutorial-btn-next:hover {
    background: #2a4a6a;
}

/* Highlight pulse on target elements */
.tutorial-highlight {
    outline: 2px solid #5ac8fa !important;
    outline-offset: 2px;
    animation: tutorial-pulse 1.5s ease-in-out infinite;
}

@keyframes tutorial-pulse {
    0%, 100% { outline-color: #5ac8fa; }
    50% { outline-color: rgba(90, 200, 250, 0.3); }
}

/* Spotlight overlay for blocking steps */
.tutorial-spotlight {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
}

.tutorial-spotlight-hole {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    pointer-events: none;
}

/* ═══════════ Responsive ═══════════ */

@media (max-width: 900px) {
    #resource-info { margin-left: 0; }
    #top-bar { gap: 0.3em 0.8em; }
}

@media (max-width: 600px) {
    #top-bar { font-size: 0.8em; padding: 0.3em 0.5em; }
    #game-title { display: none; }
    #left-panel { width: calc(100vw - 20px); }
    #bottom-panel { left: 10px; }
    #tutorial-panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 40vh;
        border-radius: 8px 8px 0 0;
    }
}
