/* CSS for the web app */
:root {
    --primary-text-color: #FFA500; --highlight-text-color: #FF4500; --background-color: #000000;
    --header-color: #FF0000; --armor-color: #0077cc; --structure-color: #f0ad4e;
    --danger-color: #d9534f; --crit-color: #ff00ff; --success-color: #5cb85c;
    --player-a-color: #00aeff; --player-b-color: #9400D3;
    --attacker-highlight: #00cc00; /* Green for attacker */
    --target-highlight: #ff0000;   /* Red for target */
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background-color: var(--background-color);
    color: var(--primary-text-color); margin: 0; padding: 0; line-height: 1.6; min-height: 100vh;
    display: flex; flex-direction: column; background-image:
        radial-gradient(2px 2px at 20px 30px, #eee, rgba(0,0,0,0)), radial-gradient(2px 2px at 80px 70px, #fff, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 150px 100px, #ddd, rgba(0,0,0,0)), radial-gradient(2px 2px at 50px 150px, #eee, rgba(0,0,0,0)),
        radial-gradient(2px 2px at 120px 200px, #fff, rgba(0,0,0,0)), radial-gradient(2px 2px at 200px 250px, #ddd, rgba(0,0,0,0));
    background-repeat: repeat; background-size: 200px 200px; animation: twinkling-stars 60s linear infinite;
}

@keyframes twinkling-stars { from { background-position: 0 0; } to { background-position: 1000px 1000px; } }
header { background: rgba(0, 0, 0, 0.7); padding: 1rem 0; text-align: center; border-bottom: 2px solid var(--highlight-text-color); }
h1 { color: var(--header-color); margin: 0; }
main { display: flex; flex-direction: column; padding: 0; gap: 0; flex-grow: 1; } /* Adjusted for tabs */
section { background: rgba(0, 0, 0, 0.8); border: 1px solid var(--primary-text-color); padding: 20px; border-radius: 8px; box-shadow: 0 0 15px rgba(255, 69, 0, 0.4); display: flex; flex-direction: column; }
#unit-database { flex: 0 0 280px; gap: 15px; }
/* Removed specific flex rules for #combat-calculator as it's now handled by .combat-main-layout */
#force-roster { flex: 2; min-width: 400px; gap: 15px; }
h2, h3 { color: var(--highlight-text-color); border-bottom: 1px dashed var(--primary-text-color); padding-bottom: 5px; margin-top: 0; }
label { display: block; margin-bottom: 5px; font-weight: bold; color: var(--primary-text-color); }
select, input, button, textarea { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid var(--primary-text-color); background-color: #333; color: var(--primary-text-color); border-radius: 4px; box-sizing: border-box; }
button { background-color: var(--highlight-text-color); color: var(--background-color); cursor: pointer; border: none; font-weight: bold; }
button:hover { background-color: var(--header-color); }

.link-as-button {
    display: block; text-align: center; text-decoration: none; background-color: var(--success-color);
    color: var(--background-color); cursor: pointer; border: none; font-weight: bold;
    width: 100%; padding: 10px; margin-bottom: 10px; border-radius: 4px; box-sizing: border-box;
}
.link-as-button:hover { background-color: #4cae4c; }

button.danger { background-color: var(--danger-color); }
button.danger:hover { background-color: #c9302c; }
button.success { background-color: var(--success-color); }
button.success:hover { background-color: #4cae4c; }

/* ANNOTATION: Styles for the new scrolling combat log. */
#combatResultsDisplay {
    max-height: 400px; /* Limit height */
    overflow-y: auto; /* Add scrollbar when needed */
    padding: 5px;
    border: 1px solid #444;
    border-radius: 4px;
}
.log-entry {
    padding: 10px;
    border-bottom: 1px dashed var(--primary-text-color);
    margin-bottom: 5px;
}
.log-entry:first-child {
    background-color: rgba(255, 255, 255, 0.05); /* Highlight the most recent entry */
}
.log-entry p { margin: 0; }

.combat-result .crit-hit { color: var(--crit-color); border: 1px dashed var(--crit-color); padding: 8px; margin-top: 10px; border-radius: 4px; background-color: rgba(255, 0, 255, 0.1); }
.input-button-group { display: flex; align-items: center; gap: 10px; }
.input-button-group input { flex-grow: 1; margin-bottom: 0; }
.input-button-group button { flex-shrink: 0; padding: 10px 15px; margin-bottom: 0; width: auto; }
.health-bar-container { width: 100%; height: 10px; background-color: #222; border: 1px solid var(--primary-text-color); border-radius: 5px; margin-bottom: 10px; box-sizing: border-box; overflow: hidden; }
.health-bar { height: 100%; width: 100%; border-radius: 4px; transition: width 0.3s ease-in-out; }
.health-bar.armor { background-color: var(--armor-color); }
.health-bar.structure { background-color: var(--structure-color); }
/* Updated roster display to be flexible within tabs */
#player-a-roster-display,
#player-b-roster-display {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
    overflow-y: auto;
    padding: 5px;
    flex-grow: 1;
}
.roster-card { border: 2px solid var(--primary-text-color); border-radius: 8px; padding: 15px; background: #1a1a1a; display: flex; flex-direction: column; gap: 5px; }
.roster-card.destroyed { border-color: var(--danger-color); background-color: #4d1a1a; }
.roster-card.player-a { border-color: var(--player-a-color); }
.roster-card.player-b { border-color: var(--player-b-color); }
/* ANNOTATION: New styles for active attacker and target */
.roster-card.active-attacker { border-color: var(--attacker-highlight); box-shadow: 0 0 15px var(--attacker-highlight); }
.roster-card.active-target { border-color: var(--target-highlight); box-shadow: 0 0 15px var(--target-highlight); }

.roster-card h4 { margin: 0 0 5px 0; color: var(--highlight-text-color); border-bottom: 1px solid var(--primary-text-color); padding-bottom: 5px; }
.roster-card p { margin: 0; font-size: 0.9em; }
.roster-card .actions { display: flex; gap: 5px; margin-top: 5px; }
.roster-card .actions button { font-size: 0.8em; padding: 5px; width: 100%; margin: 0; }
.roster-card label { font-size: 0.9em; margin-top: 5px; }
.roster-card input { padding: 5px; margin: 0; font-size: 0.9em; }
#turn-controls { background: #1a1a1a; padding: 10px; border-radius: 8px; }
.turn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.initiative-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; align-items: center; margin-top: 10px; }
.initiative-grid input { margin: 0; }
.initiative-grid button { margin: 0; height: 100%; }
#turn-controls h3 { margin: 0; border: none; }
#turn-controls button { width: auto; padding: 10px 20px; margin: 0; }
.checkbox-container { display: flex; align-items: center; margin-bottom: 10px; }
.checkbox-container label { margin-bottom: 0; font-weight: normal; }
input[type="checkbox"] { width: auto; margin-right: 5px; vertical-align: middle; }
.radio-group { display: flex; gap: 15px; margin-bottom: 10px; align-items: center; }
.radio-group label { margin-bottom: 0; }
.radio-group input[type="radio"] { width: auto; margin-right: 5px; }
.hidden { display: none; }
.save-load-group { display: flex; gap: 10px; align-items: center; }
.save-load-group > * { margin-bottom: 10px !important; }
.save-load-group input, .save-load-group select { flex-grow: 1; }
.save-load-group button { flex-shrink: 0; width: auto; padding: 10px 15px; }
footer { text-align: center; padding: 10px; margin-top: 20px; border-top: 1px solid var(--primary-text-color); color: var(--primary-text-color); font-size: 0.8em; }
@media (max-width: 1200px) { main { flex-direction: column; } #unit-database, #force-roster, #combat-calculator { flex: 1 1 100%; min-width: unset; } }

/* ANNOTATION: New styles for the tab system */
.tabs {
    display: flex;
    justify-content: center;
    background: rgba(0, 0, 0, 0.7);
    border-bottom: 2px solid var(--highlight-text-color);
    padding: 0 20px;
    flex-wrap: wrap; /* Allow tabs to wrap on smaller screens */
}

.tab-button {
    background-color: transparent;
    color: var(--primary-text-color);
    border: none;
    padding: 15px 25px;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    transition: background-color 0.3s, color 0.3s, border-bottom 0.3s;
    border-bottom: 3px solid transparent;
    margin: 0 5px;
    width: auto; /* Override generic button 100% width */
    flex-shrink: 0; /* Prevent shrinking too much */
}

.tab-button:hover {
    color: var(--highlight-text-color);
    background-color: rgba(255, 69, 0, 0.1);
}

.tab-button.active {
    color: var(--highlight-text-color);
    border-bottom: 3px solid var(--highlight-text-color);
    background-color: rgba(255, 69, 0, 0.2);
}

.tab-content {
    padding: 20px;
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--primary-text-color);
    border-top: none;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 0 15px rgba(255, 69, 0, 0.4);
    flex-grow: 1;
    gap: 20px; /* Consistent spacing */
}

.tab-content:not(.hidden) { /* Apply flex only when not hidden */
    display: flex;
    flex-direction: column;
}

/* Specific override for the management tab to create two columns */
#tab-management.tab-content:not(.hidden) {
    flex-direction: row; /* Arrange children horizontally */
    align-items: stretch; /* Ensure both columns stretch to fill height */
    gap: 20px; /* Space between left and right panels */
}

.management-left-panel {
    flex: 0 0 40%; /* Fixed 40% width, no shrinking/growing */
    display: flex; /* Make its content stack vertically */
    flex-direction: column;
    gap: 20px; /* Space between sections within the left panel */
}

.management-right-panel {
    flex: 1; /* Take remaining space */
    display: flex; /* To make iframe fill it */
    flex-direction: column; /* To make iframe fill it */
}

/* Re-apply section styling for sections within the left panel */
#tab-management .management-left-panel section {
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--primary-text-color);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 69, 0, 0.4);
    flex-shrink: 0; /* Prevent sections from shrinking too much */
}

#builder-iframe {
    width: 100%;
    height: 100%; /* Fill the parent container */
    border: none;
    background-color: transparent;
}

/* Manual tab iframe styling */
#manual-iframe {
    width: 100%;
    height: 80vh; /* Adjust height as needed */
    border: none;
    background-color: transparent; /* Allow manual.html's background to show */
}

/* New styles for the combat tab's two-column layout */
.combat-main-layout {
    display: flex;
    flex-direction: row; /* Arrange children horizontally */
    gap: 20px; /* Space between left and right panels */
    flex-grow: 1; /* Allow it to take available vertical space */
}

/* Ensure sections inside combat-main-layout get their default styling */
.combat-main-layout section {
    background: rgba(0, 0, 0, 0.8);
    border: 1px solid var(--primary-text-color);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(255, 69, 0, 0.4);
    display: flex;
    flex-direction: column;
    flex: 1; /* Each section takes equal space */
}

/* Adjust combat results display within its new panel */
#combatResultsDisplay {
    flex-grow: 1; /* Allow it to fill available vertical space */
    max-height: none; /* Remove fixed max-height, let flexbox manage */
}

@media (max-width: 768px) {
    .tabs {
        flex-direction: column;
        align-items: stretch;
    }
    .tab-button {
        margin: 0;
        border-bottom: 1px solid rgba(255, 69, 0, 0.2);
    }
    .tab-button.active {
        border-bottom: 1px solid var(--highlight-text-color);
    }
    /* Stack management panels vertically on smaller screens */
    #tab-management.tab-content:not(.hidden) {
        flex-direction: column;
    }
    .management-left-panel, .management-right-panel {
        flex: 1 1 auto; /* Allow them to take full width */
        width: 100%;
    }
    /* Stack combat panels vertically on smaller screens */
    .combat-main-layout {
        flex-direction: column; /* Stack panels vertically on smaller screens */
    }
}