:root {
    --bg-color: #121212;
    --panel-bg: #1e1e1e;
    --text-color: #e0e0e0;
    --accent-color: #4CAF50;
    --pending-color: #FFC107;
    --danger-color: #F44336;
    --border-color: #333;
    --map-bg: #000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    height: 100dvh; /* Dynamic Viewport Height for mobile */
    overflow: hidden;
}

/* Bulma Override / Layout Setup */
#game-layout {
    height: 100%;
    width: 100%;
    margin: 0 !important; /* Override Bulma margin if any */
    /* display: flex provided by Bulma .columns */
}

/* Column Styling */
.game-column {
    background-color: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 0; /* Ensure Bulma padding is gone */
}

#col-main {
    padding: 0;
    overflow-y: auto;
}

#col-tracker, #col-log, #col-map, #col-info {
    background-color: #181818;
}

#col-map {
    background-color: var(--map-bg);
    container-type: inline-size;
}

#col-info {
    padding: 0.5rem; /* Add back some padding for content */
    overflow-y: auto;
}

.info-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #333;
}

.info-header {
    color: var(--accent-color);
    font-weight: bold;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.info-body {
    color: #ccc;
    font-size: 0.85rem;
    line-height: 1.4;
    white-space: pre-wrap;
}

.info-body.obfuscated {
    color: #555;
    font-family: monospace;
}

.column-header {
    padding: 0.8rem;
    background-color: #252525;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
    flex-shrink: 0;
}

.column-header h2 {
    margin: 0;
    font-size: 1rem;
    color: #aaa;
    border: none;
}

h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--accent-color);
    font-size: 1.8rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

h2 {
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.4rem;
    color: #bbb;
}

.module {
    margin-bottom: 0;
    background: #252525;
    padding: 0.5rem;
    border-radius: 0;
    box-shadow: none;
}

.squad-stats {
    margin-bottom: 1rem;
}

#squad-level-display {
    color: var(--accent-color);
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

#squad-counts {
    font-size: 0.9rem;
    color: #aaa;
}

.action-btn {
    width: 100%;
    padding: 0.8rem;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.action-btn:hover {
    background-color: #43a047;
}

.action-btn:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Squad Buttons Row */
.squad-buttons-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    margin-top: 10px;
}

.compact-btn {
    font-size: 0.675rem;
    padding: 6px 12px;
    height: 36px;
    margin-top: 0; /* Override default */
    flex: 1; /* Equal width */
    display: flex;
    align-items: center;
    justify-content: center;
}

.zone-train-btn {
    background-color: #673AB7;
}
.zone-train-btn:hover {
    background-color: #7E57C2;
}

/* Runner Card Styles */
.runner-card {
    background: #000; /* Solid black per request */
    border: 1px solid #333;
    border-radius: 8px !important; /* Slightly rounded corners */
    padding: 0.4rem;
    margin-bottom: 0.8rem;
    position: relative;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Runner Status Tags */
.tag.state-ready { background-color: #4CAF50; color: #fff; }
.tag.state-running { background-color: #2196F3; color: #fff; }
.tag.state-upgrading { background-color: #FFC107; color: #000; }
.tag.state-queued { background-color: #9C27B0; color: #fff; }

.runner-card.state-upgrading {
    border-color: #FFC107;
}

.runner-card.state-queued {
    border-color: #9C27B0;
}

.runner-card.state-running {
    border-color: #2196F3;
    opacity: 0.8;
}

.runner-card.state-ready {
    border-color: #4CAF50;
}

.runner-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.runner-name {
    font-weight: bold;
    color: #fff;
    font-size: 1rem;
}

.runner-name img.emoji {
    width: 1.2em;
    height: 1.2em;
    vertical-align: -0.2em;
}

.runner-state {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
}

/* Scoped Badge Styles */
.runner-state.state-ready { background: #4CAF50; color: #fff; }
.runner-state.state-running { background: #2196F3; color: #fff; }
.runner-state.state-upgrading { background: #FFC107; color: #000; }
.runner-state.state-queued { background: #9C27B0; color: #fff; }

.runner-stats-4-col {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 0.5rem;
    text-align: center;
}

.runner-stats-4-col > div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.runner-stats-4-col span {
    font-weight: bold;
}

/* Text Colors */
.text-green { color: #4CAF50 !important; transition: color 0.2s; }
.text-red { color: #F44336 !important; transition: color 0.2s; }
.text-white { color: #fff !important; transition: color 0.2s; }

/* Relic Grid */
.relic-grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: auto auto;
    gap: 4px;
    margin-bottom: 0.5rem;
}

.relic-cell {
    background: #111;
    padding: 2px;
    text-align: center;
    border-radius: 2px;
    font-size: 0.75rem;
    font-family: monospace;
    color: #fff;
}

.upgrade-progress-container {
    background: #333;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin-top: 8px;
    margin-bottom: 4px;
}

.upgrade-bar {
    height: 100%;
    background: #2196F3; /* Blue */
    width: 0%;
    transition: width 0.2s;
}

.upgrade-text {
    font-size: 0.75rem;
    color: #2196F3; /* Match bar color */
    text-align: center;
    font-weight: bold;
}

.send-btn {
    width: 100%;
    background: #4CAF50;
    color: #fff;
    border: none;
    padding: 6px;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    margin-top: 8px;
}
.send-btn:hover { background: #43A047; }

/* Existing small-btn, warning, etc. */
.small-btn {
    padding: 0.4rem 0.8rem;
    background-color: #388E3C;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.2s;
}
.warning {
    background-color: var(--danger-color);
    color: white;
    margin-top: 1rem;
    width: 100%;
}

/* Tracker & Log & Map Styles (mostly unchanged) */
#tracker-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.5rem;
    min-height: 0;
}
.tracker-embed {
    background-color: #2f3136;
    border-left: 4px solid #3498db;
    border-radius: 4px;
    padding: 0.5rem;
    margin-bottom: 1rem;
}
.tracker-embed-header { font-weight: bold; color: #fff; margin-bottom: 0.5rem; }
.tracker-embed-description { color: #dcddde; margin-bottom: 1rem; }
.tracker-field { margin-bottom: 0.8rem; }
.tracker-field-name { font-weight: bold; color: #fff; font-size: 0.9rem; }
.tracker-field-value { font-size: 0.85rem; color: #dcddde; white-space: pre-wrap; }
.tracker-field-value img.emoji, .tracker-field-name img.emoji {
    width: 1em;
    height: 1em;
    vertical-align: -0.1em;
}

#game-log-content {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    font-family: monospace;
    padding: 0.5rem;
    color: #ccc;
    min-height: 0;
}
.log-entry {
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #2a2a2a;
    line-height: 1.3;
}
.log-entry img.emoji {
    width: 1em;
    height: 1em;
    vertical-align: -0.1em;
}

#map-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-top: 1rem;
    display: flex;
    justify-content: center;
    min-height: 0;
}
#map-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 2rem;
    width: 100%; /* Stretch to full width */
    padding-left: 10px;
    padding-right: 10px;
}
.map-segment {
    margin-bottom: 0;
    text-align: center;
    user-select: none;
    display: flex;
    flex-direction: column;
    width: 100%; /* Fill container */
}
.map-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

/* Updated Map Cell Styles for Layered & Flush Look */
.map-cell {
    /* Responsive Desktop Styles */
    flex: 1;
    min-width: 0;
    aspect-ratio: 1 / 1;
    position: relative; /* Context for absolute positioning of layers */

    /* Removed padding/gap settings implicit in flex items */
    margin: 0;
    padding: 0;

    /* Twemoji sizing */
    /* Use container query width if possible, or font-size trick */
    font-size: 5.0cqw;
    line-height: 1;
}

/* Layering Images */
.map-cell span.layer-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex; /* Centering if needed, but img usually block */
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 1;
}

.map-cell span img.emoji {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Dynamic Map Entities */
.map-entity {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
}

.map-entity img.emoji {
    width: 90%;
    height: 90%;
    object-fit: contain;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5));
    transition: transform 0.2s ease-in-out;
}

.cyclone-inner {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#map-progress-container {
    background-color: transparent;
    border-top: none;
    height: auto;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 0;
}

#map-zones-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
}

#map-summary-fixed {
    flex: 0 0 auto;
}
.map-progress-zone { margin-bottom: 0.5rem; border-bottom: 1px solid #333; padding-bottom: 0.2rem; }
.map-progress-header { color: var(--accent-color); font-weight: bold; margin-bottom: 2px; }
.map-progress-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #1e1e1e; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* Mobile Navigation */
#mobile-tab-nav {
    display: none;
}

@media (max-width: 768px) {
    #game-layout {
        display: block; /* Override Bulma flex */
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
        position: relative;
    }

    /* Tabs Navigation */
    #mobile-tab-nav {
        display: flex;
        justify-content: space-around;
        background-color: #252525;
        border-bottom: 1px solid var(--border-color);
        padding: 0.5rem;
        height: 50px;
        align-items: center;
        width: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 100;
    }

    .tab-btn {
        background: none;
        border: none;
        color: #888;
        font-size: 1rem;
        font-weight: bold;
        cursor: pointer;
        padding: 0.5rem 1rem;
        border-bottom: 2px solid transparent;
        transition: all 0.2s;
    }

    .tab-btn.active {
        color: var(--accent-color);
        border-bottom-color: var(--accent-color);
    }

    /* Columns handling */
    .game-column {
        display: none; /* Hide all by default */
        position: absolute;
        top: 50px; /* Below nav */
        bottom: 0;
        left: 0;
        width: 100%;
        height: calc(100% - 50px);
        border-right: none;
    }

    /* Specific Tab Views */

    /* Tab 0: Squad */
    #game-layout.mobile-tab-0 #col-main {
        display: flex;
        z-index: 10;
    }

    #game-layout.mobile-tab-0 #col-main::after {
        content: "";
        display: block;
        min-height: env(safe-area-inset-bottom);
        flex-shrink: 0;
    }

    /* Tab 3: Info */
    #game-layout.mobile-tab-3 #col-info {
        display: flex;
        z-index: 10;
    }

    #game-layout.mobile-tab-3 #col-info::after {
        content: "";
        display: block;
        min-height: env(safe-area-inset-bottom);
        flex-shrink: 0;
    }

    /* Tab 1: Tracker + Log Footer */
    #game-layout.mobile-tab-1 #col-tracker {
        display: flex;
        z-index: 10;
    }

    #game-layout.mobile-tab-1 #tracker-list::after {
        content: "";
        display: block;
        height: 180px;
        flex-shrink: 0;
    }

    #game-layout.mobile-tab-1 #col-log {
        display: flex; /* Show log as well */
        z-index: 20;
        top: auto; /* Unset top */
        bottom: 0;
        height: 180px; /* Fixed footer height increased for safe area */
        padding-bottom: env(safe-area-inset-bottom);
        border-top: 1px solid var(--accent-color);
        background-color: #111;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.5);
    }

    #game-layout.mobile-tab-1 #col-log .column-header {
        padding: 0.2rem;
        min-height: auto;
    }
    #game-layout.mobile-tab-1 #col-log h2 {
        font-size: 0.8rem;
        margin: 0;
        border: none;
    }

    /* Tab 2: Map */
    #game-layout.mobile-tab-2 #col-map {
        display: flex;
        z-index: 10;
    }

    #game-layout.mobile-tab-2 #map-content::after {
        content: "";
        display: block;
        min-height: env(safe-area-inset-bottom);
        flex-shrink: 0;
    }

    /* Restore Fixed Map Layout for Mobile */
    #map-content {
        width: auto;
        padding-left: 0;
        padding-right: 0;
    }
    .map-segment {
        width: auto;
    }
    .map-row {
        justify-content: center;
        width: auto;
    }
    .map-cell {
        flex: 0 0 auto;
        width: 24px;
        height: 24px;
        font-size: 1.2rem; /* Keep text fallback size */
    }
}

/* Upgrading Relic Border */
.relic-cell.upgrading-relic {
    border: 1px solid #4CAF50;
    box-shadow: 0 0 4px rgba(76, 175, 80, 0.5);
}

/* Map UI Stack (New System) */
#map-ui-stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end; /* Align items to the bottom */
    gap: 2px;
    padding: 4px;
    background: var(--bg-color); /* Match column background or distinct? */
    border-top: 1px solid var(--border-color);
    flex-shrink: 0; /* Don't shrink */
}

.map-ui-card {
    background: var(--module-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    width: 100%;
    transition: all 0.2s ease;
}

.map-ui-header {
    padding: 6px 8px;
    background: #2a2a2a;
    color: var(--accent-color);
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
    border-bottom: 1px solid transparent; /* Hidden by default */
}

.map-ui-header:hover {
    background: #333;
}

/* Expanded State styles */
.map-ui-card:not(.collapsed) .map-ui-header {
    border-bottom-color: #333;
}

.map-ui-body {
    padding: 4px;
    font-size: 0.85rem;
    color: #ccc;
    display: block;
}

/* Collapsed State */
.map-ui-card.collapsed .map-ui-body {
    display: none;
}

.map-ui-card.collapsed {
    /* Optional: visual cue for collapsed state */
}

/* Specific content styling within bodies */
.map-progress-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    font-family: monospace;
    font-size: 0.72rem;
}

.map-overall-stats {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.map-overall-row {
    margin-bottom: 4px;
}

/* Mobile Tweaks */
@media (max-width: 768px) {
    #map-ui-stack {
        padding: 5px;
    }
}

/* Offline Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

.overlay-content h2 {
    color: var(--accent-color);
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.offline-stats {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 2rem;
    font-size: 1.1rem;
    color: #fff;
    text-align: left;
    padding: 0 1rem;
}

.offline-stats span {
    float: right;
    font-weight: bold;
    color: var(--accent-color);
}

.offline-progress-container {
    width: 100%;
    height: 20px;
    background-color: #333;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.offline-progress-bar {
    height: 100%;
    width: 0%;
    background-color: var(--accent-color);
    transition: width 0.1s linear;
}

#offline-status-text {
    margin-bottom: 1.5rem;
    color: #888;
    font-style: italic;
    font-size: 0.9rem;
}