:root {
    /* Gritty Dark Sci-Fi Palette */
    --bg-paper: #0a0a0a;
    /* Almost black */
    --bg-dark-panel: #141414;
    /* Dark gray */
    --bg-darker-panel: #0a0a0a;

    --text-main: #e0e0e0;
    /* Light gray for readability */
    --text-light: #ffffff;
    --text-muted: #8B8B8B;

    --accent-orange: #ff4500;
    /* Neon Orange / Red */
    --accent-orange-hover: #ff6347;

    --accent-red: #d32f2f;
    --accent-red-hover: #f44336;

    --accent-gold: #ffb300;
    /* Neon Amber */
    --accent-blue: #3296ff;

    --font-title: 'Black Ops One', sans-serif;
    --font-header: 'Black Ops One', sans-serif;
    --font-body: 'Roboto', sans-serif;
}

/* Light Theme Overrides */
.theme-light {
    --bg-paper: #f0f0f0;
    --bg-dark-panel: #e0e0e0;
    --bg-darker-panel: #d5d5d5;

    --text-main: #2b2b2b;
    --text-light: #111111;
    --text-muted: #555555;

    --accent-orange: #d84315;
    /* Sligthly darker orange for contrast */
    --accent-orange-hover: #bf360c;

    --accent-red: #c62828;
    --accent-red-hover: #b71c1c;

    --accent-gold: #f57f17;
    /* Darker amber */
}

body {
    background-color: var(--bg-paper);
    background-image: url('bg_texture.png');
    background-size: cover;
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-position: center;
    color: var(--text-main);
    font-family: var(--font-body);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

h1,
h2,
h3,
h4,
.font-title,
.font-header {
    font-family: var(--font-header);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.accent-text {
    color: var(--accent-orange);
}

/* Header */
.app-header {
    background-color: var(--bg-dark-panel);
    border-bottom: 4px solid var(--accent-orange);
    padding: 1rem 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    color: var(--text-light);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.main-title {
    margin: 0;
    font-size: 2.5rem;
}

.main-title .accent {
    color: var(--accent-orange);
}

.subtitle {
    margin: 0.2rem 0 0 0;
    color: var(--accent-gold);
    font-style: italic;
    font-size: 0.9rem;
}

.header-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.scrip-display {
    font-family: var(--font-header);
    font-size: 1.5rem;
    background: var(--bg-darker-panel);
    padding: 0.5rem 1rem;
    border: 2px solid var(--accent-gold);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.earned-scrip-input {
    background: white;
    color: #111;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    font-size: 1rem;
    width: 60px;
    font-family: var(--font-body);
}

@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .scrip-display {
        font-size: 1.2rem;
        flex-wrap: wrap;
    }

    .crew-manager select {
        width: 120px !important;
    }
}

/* Layout Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Panels */
.theme-panel {
    background-color: rgba(20, 20, 20, 0.9);
    /* Dark semi-transparent */
    border: 1px solid #333;
    border-top: 3px solid var(--accent-orange);
    padding: 1.5rem;
    margin-bottom: 2rem;
    border-radius: 4px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.7);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

select {
    width: 100%;
    padding: 0.75rem;
    background-color: #333333;
    border: 2px solid var(--bg-dark-panel);
    color: #ffffff;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: bold;
    border-radius: 4px;
    transition: border-color 0.2s;
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--accent-orange);
    box-shadow: 0 0 5px rgba(255, 69, 0, 0.5);
}

.hidden {
    display: none !important;
}

/* Roster Grid */
.roster-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

/* Empty Slot Button */
.unit-slot-empty {
    border: 2px dashed #444;
    border-radius: 8px;
    height: 350px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: rgba(0, 0, 0, 0.5);
}

.unit-slot-empty:hover {
    border-color: var(--accent-orange);
    background: rgba(255, 69, 0, 0.1);
}

.add-icon {
    font-size: 4rem;
    color: #444;
    font-family: var(--font-title);
    line-height: 1;
    margin-bottom: 1rem;
    transition: color 0.2s;
}

.unit-slot-empty:hover .add-icon {
    color: var(--accent-orange);
}

/* Buttons */
.btn {
    font-family: var(--font-header);
    font-size: 1.1rem;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
    text-transform: uppercase;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(100%);
}

.btn-primary {
    background-color: var(--accent-orange);
    color: white;
    border-color: #722d1b;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--accent-orange-hover);
}

.btn-secondary {
    background-color: var(--bg-dark-panel);
    color: var(--text-light);
    border-color: #1a1a1a;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #444;
}

.btn-danger {
    background-color: var(--accent-red);
    color: white;
    border-color: #8b0000;
}

.btn-danger:hover:not(:disabled) {
    background-color: var(--accent-red-hover);
}

.btn-exhausted {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px dashed var(--text-muted);
    cursor: pointer;
    opacity: 0.7;
}

.btn-exhausted:hover {
    color: var(--text-main);
    border-color: var(--text-main);
}

/* Modal and Editor Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

/* Floating Mission Panel (Non-blocking) */
.mission-panel {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.8);
}

.mission-panel.minimized .panel-content {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.mission-panel.minimized #mission-panel-collapse {
    display: none;
}

.btn-minimize {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 0.5;
    padding-bottom: 8px;
}

.btn-minimize:hover {
    color: var(--accent-orange);
}

.modal-content {
    background-color: var(--bg-paper);
    border: 4px solid var(--bg-dark-panel);
    border-top: 8px solid var(--accent-orange);
    width: 90%;
    max-width: 1000px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 10px 10px 0px rgba(0, 0, 0, 0.5);
    border-radius: 8px;
}

.editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background-color: var(--bg-darker-panel);
    color: var(--text-light);
    border-bottom: 2px solid var(--accent-gold);
}

.editor-header h2 {
    margin: 0;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 2rem;
    cursor: pointer;
}

.btn-close:hover {
    color: var(--accent-red);
}

.editor-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-sidebar {
    width: 320px;
    padding: 2rem;
    border-right: 3px solid var(--bg-dark-panel);
    background-color: rgba(0, 0, 0, 0.05);
    overflow-y: auto;
}

.editor-main {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.editor-footer {
    padding: 1rem 2rem;
    border-top: 3px solid var(--bg-dark-panel);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    background-color: rgba(0, 0, 0, 0.05);
}

/* Equipment Accordion Styling */
.equipment-category {
    margin-bottom: 1rem;
    border: 2px solid var(--bg-dark-panel);
    border-radius: 4px;
    overflow: hidden;
}

.eq-accordion-btn {
    width: 100%;
    text-align: left;
    background-color: var(--bg-darker-panel);
    color: var(--text-light);
    padding: 0.75rem 1rem;
    font-family: var(--font-header);
    font-size: 1.1rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.eq-accordion-btn:hover {
    background-color: var(--bg-dark-panel);
}

.eq-accordion-btn.active {
    background-color: var(--accent-orange);
    color: white;
}

.eq-accordion-icon {
    font-weight: bold;
    transition: transform 0.2s;
}

.eq-accordion-btn.active .eq-accordion-icon {
    transform: rotate(180deg);
}

.equipment-list {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background-color: var(--bg-darker-panel);
}

.equipment-list.expanded {
    max-height: 800px;
    border-top: 2px solid var(--bg-dark-panel);
}

.eq-item-card {
    background: var(--bg-dark-panel);
    border-bottom: 1px solid #333;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.1s ease;
    color: var(--text-main);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

@media (hover: hover) and (pointer: fine) {
    .eq-item-card:hover {
        background-color: rgba(255, 69, 0, 0.1);
        border-left: 4px solid var(--accent-orange);
    }
}

.eq-item-card.selected {
    background-color: rgba(255, 69, 0, 0.15);
    border-left: 4px solid var(--accent-orange);
    color: var(--text-light);
}

.eq-details {
    display: flex;
    flex-direction: column;
}

.eq-name {
    font-weight: bold;
    font-family: var(--font-header);
    letter-spacing: 0.5px;
}

.eq-stats {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.eq-item-card.selected .eq-stats {
    color: #ccc;
}

.eq-meta {
    text-align: right;
    font-family: var(--font-header);
}

.eq-cost {
    color: var(--accent-red);
}

.eq-size {
    color: var(--accent-orange);
}

/* Errors & Summaries in Sidebar */
.cost-summary,
.capacity-summary {
    background: var(--bg-dark-panel);
    color: var(--text-light);
    padding: 1rem;
    margin-top: 1rem;
    border-radius: 4px;
    font-family: var(--font-header);
    font-size: 1.1rem;
}

.capacity-alert {
    color: var(--accent-red);
}

.suit-flaw {
    background: rgba(139, 0, 0, 0.15);
    /* Dark translucent red */
    color: #ff9999;
    /* Light red text that's readable on dark background */
    padding: 0.5rem;
    border: 1px solid rgba(211, 47, 47, 0.3);
    border-left: 4px solid var(--accent-red);
    font-size: 0.9rem;
    margin-top: 0.5rem;
    border-radius: 4px;
}

.error-msg {
    color: var(--accent-red);
    font-weight: bold;
    align-self: center;
    margin-right: auto;
}

/* Stat Grid Preview */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    background: var(--bg-dark-panel);
    color: var(--text-light);
    padding: 1rem;
    border-radius: 4px;
    text-align: center;
    font-family: var(--font-header);
}

.stat-grid>div:nth-child(5),
.stat-grid>div:nth-child(6) {
    grid-column: span 2;
}

.stat-box {
    border: 1px solid var(--text-muted);
    padding: 0.25rem;
    background: var(--bg-darker-panel);
    min-width: 0;
    word-wrap: break-word;
}

.stat-box .stat-val {
    font-size: 1.5rem;
    color: var(--accent-gold);
    display: block;
}

/* Unit Cards in Roster */
.unit-card {
    background: var(--bg-dark-panel);
    border: 1px solid #333;
    border-radius: 4px;
    box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
}

.unit-card-header {
    background: var(--bg-dark-panel);
    color: var(--text-light);
    padding: 0.5rem 1rem;
    border-bottom: 2px solid var(--accent-orange);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.unit-card-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.unit-cost {
    font-family: var(--font-header);
    color: var(--accent-gold);
}

.unit-card-body {
    padding: 1rem;
    flex: 1;
}

.unit-card-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
    text-align: center;
    font-family: var(--font-header);
    background: rgba(0, 0, 0, 0.05);
    padding: 0.5rem;
    border: 1px solid var(--bg-dark-panel);
}

.unit-card-stats>div:nth-child(5),
.unit-card-stats>div:nth-child(6) {
    grid-column: span 2;
}

.unit-card-stats>div {
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.25rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    min-width: 0;
    word-wrap: break-word;
}

.unit-card-stats span {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-muted);
    text-transform: uppercase;
}

.unit-card-equipment {
    margin-bottom: 1rem;
}

.unit-card-equipment ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
}

.unit-card-equipment li {
    font-size: 0.9rem;
    border-bottom: 1px dashed #ccc;
    padding: 0.2rem 0;
}

/* Detailed Stat Breakdown Formatting */
.stat-main {
    color: var(--text-light);
}

.gear-capacity-header {
    color: var(--text-light);
}

.detailed-stats .stat-main {
    font-size: 1.1rem;
    display: block;
    margin-bottom: 0.1rem;
    font-weight: bold;
}

.stat-breakdown {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.2rem;
    font-family: var(--font-body);
    font-size: 0.70rem;
    line-height: 1.1;
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px dotted rgba(255, 255, 255, 0.1);
}

.stat-base {
    color: var(--text-muted);
    font-style: italic;
    width: 100%;
    margin-bottom: 0.2rem;
}

.stat-mod {
    font-weight: bold;
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1rem 0.2rem;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    min-width: 0;
    word-wrap: break-word;
}


.unit-card-actions {
    padding: 1rem;
    background: rgba(0, 0, 0, 0.05);
    border-top: 2px solid var(--bg-dark-panel);
    display: flex;
    justify-content: flex-end;
}

@media (max-width: 768px) {
    .editor-body {
        flex-direction: column;
        overflow-y: auto;
    }

    .editor-sidebar {
        width: 100%;
        padding: 1rem;
        border-right: none;
        border-bottom: 3px solid var(--bg-dark-panel);
        overflow-y: visible;
    }

    .editor-main {
        padding: 1rem;
        overflow-y: visible;
    }

    .modal-content {
        width: 95%;
    }

    .editor-header,
    .editor-footer {
        padding: 1rem;
    }

    /* Mission panel mobile adjustments */
    .mission-panel {
        right: 5vw;
        left: 5vw;
        bottom: 10px;
        width: 90vw;
    }

    .mission-panel .panel-content {
        width: 100% !important;
        max-width: none !important;
    }
}

/* --- Print Friendly Export Rules --- */
@media print {
    body {
        background: white;
        background-image: none !important;
        color: black;
        margin: 0;
        padding: 0;
    }

    /* Rules for Printing Roster */
    body:not(.print-mission-mode) .app-header,
    body:not(.print-mission-mode) .crew-controls,
    body:not(.print-mission-mode) #add-unit-card,
    body:not(.print-mission-mode) .overlay,
    body:not(.print-mission-mode) .mission-panel,
    body:not(.print-mission-mode) .app-footer-info {
        display: none !important;
    }

    /* Rules for Printing Mission */
    body.print-mission-mode .app-header,
    body.print-mission-mode .container,
    body.print-mission-mode .overlay,
    body.print-mission-mode .editor-header,
    body.print-mission-mode .editor-footer,
    body.print-mission-mode .app-footer-info {
        display: none !important;
    }

    body.print-mission-mode .mission-panel {
        position: static !important;
        box-shadow: none !important;
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
    }

    body.print-mission-mode .mission-panel .panel-content {
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        max-width: 100% !important;
        background: white !important;
        color: black !important;
    }

    body.print-mission-mode .mission-panel .editor-body {
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        color: black !important;
    }

    body.print-mission-mode .accent-text {
        color: black !important;
        border-bottom-color: black !important;
    }

    body.print-mission-mode [style*="var(--bg-dark-panel)"] {
        background: white !important;
        color: black !important;
        border: 1px solid black !important;
    }

    body.print-mission-mode .text-muted {
        color: #333 !important;
    }

    body.print-mission-mode [style*="rgba(50, 150, 255, 0.1)"] {
        background: white !important;
        border-left-color: black !important;
        border: 1px solid black !important;
        color: black !important;
    }

    body.print-mission-mode [style*="rgba(255, 80, 80, 0.1)"] {
        background: white !important;
        border-left-color: black !important;
        border: 1px solid black !important;
        color: black !important;
    }

    /* Common Print Rules */
    .container {
        margin: auto;
        padding: 0;
        max-width: 100%;
    }

    .unit-card {
        page-break-inside: avoid;
        border: 2px solid black;
        margin-bottom: 1rem;
        box-shadow: none;
        background: white;
        color: black;
    }

    .unit-card-header {
        background: #f0f0f0;
        color: black;
        border-bottom: 2px solid black;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .unit-cost {
        color: black;
        font-weight: bold;
    }

    .unit-card-stats {
        background: #f9f9f9;
        border: 1px solid #ccc;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .unit-card-stats span,
    .unit-card-equipment span,
    .gear-capacity-header,
    .stat-main {
        color: #333 !important;
    }

    .unit-card-actions {
        display: none !important;
        /* Hide delete buttons */
    }

    .faction-perks {
        background: white;
        border: 2px dashed black;
        padding: 1rem;
        margin-bottom: 1rem;
        color: black;
    }

    .faction-perks h3 {
        color: black;
    }

    /* Print specific overwrites */
    .suit-flaw {
        background: none;
        border-left: 2px solid black;
        color: black;
    }
}

/* App Footer Info */
.app-footer-info {
    text-align: center;
    padding: 2rem 1rem 1rem 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--bg-panel-border, rgba(255, 255, 255, 0.1));
    color: var(--text-muted);
    font-size: 0.9rem;
    font-family: var(--font-body);
}

.app-footer-info a {
    color: var(--accent-orange);
    text-decoration: none;
    transition: color 0.2s ease;
}

.app-footer-info a:hover {
    color: var(--text-light);
    text-decoration: underline;
}