/* ==========================================================================
   Battle Simulation — Page-specific styles
   ========================================================================== */

/* ---------- Simulate-specific variable aliases ---------- */
:root {
    --card-bg: var(--bg-warm);
    --card-border: var(--border-light);
    --parchment: #d4c4a0;
}

/* ---------- Main layout ---------- */
.main-layout {
    display: flex;
    gap: 12px;
}
.stats-panel {
    width: 200px;
    flex-shrink: 0;
}
.center-panel {
    flex: 1;
    min-width: 0;
}
.right-panel {
    width: 320px;
    flex-shrink: 0;
}

/* ---------- Config Panel - team selection ---------- */
.config-panel {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}
.team-config {
    flex: 1;
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 10px;
    padding: 14px;
    min-height: 120px;
}
.team-config.team1 {
    border-color: var(--team1);
}
.team-config.team2 {
    border-color: var(--team2);
}
.team-config h3 {
    font-family: "Cinzel", serif;
    font-size: 1rem;
    margin-bottom: 10px;
}
.team-config.team1 h3 {
    color: var(--team1);
}
.team-config.team2 h3 {
    color: var(--team2);
}

/* ---------- Selection badge ---------- */
.selection-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 6px 10px;
    margin-bottom: 8px;
}
.selection-badge img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}
.selection-badge .badge-text {
    font-weight: 600;
    font-size: 0.85rem;
}
.selection-badge .change-btn {
    margin-left: auto;
    color: var(--gold);
    font-size: 0.75rem;
    cursor: pointer;
    text-decoration: underline;
}
.selection-badge .change-btn:hover {
    color: var(--gold-light);
}

/* ---------- Civ grid ---------- */
.civ-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 6px;
}
.civ-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}
.civ-card:hover {
    border-color: var(--gold-dark);
    background: rgba(201, 168, 76, 0.1);
}
.civ-card img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}
.civ-card span {
    font-size: 0.6rem;
    text-align: center;
    color: var(--text-muted);
}

/* ---------- Age toggle (simulate-specific overrides) ---------- */
.age-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}
.age-btn {
    flex: 1;
    font-family: "Cinzel", serif;
    font-size: 0.75rem;
    padding: 6px 10px;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}
.age-btn:hover {
    border-color: var(--gold-dark);
    color: var(--text);
}
.age-btn.active {
    background: var(--gold-dark);
    color: var(--bg-deep);
    border-color: var(--gold);
    font-weight: 600;
}

/* ---------- Unit grid ---------- */
.unit-grid-section {
    margin-bottom: 6px;
}
.unit-grid-section h4 {
    font-family: "Cinzel", serif;
    font-size: 0.7rem;
    color: var(--gold);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.unit-grid-section h4 img {
    width: 18px;
    height: 18px;
    border-radius: 3px;
}
.unit-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.unit-pick {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    width: 64px;
}
.unit-pick:hover {
    border-color: var(--gold-dark);
    background: rgba(201, 168, 76, 0.1);
}
.unit-pick img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--card-border);
    object-fit: cover;
    background: var(--bg);
}
.unit-pick span {
    font-size: 0.55rem;
    text-align: center;
    color: var(--text-muted);
    line-height: 1.1;
}

/* ---------- Army config ---------- */
.army-config {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    text-align: center;
}
.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 8px;
}
.mode-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}
.mode-option input {
    accent-color: var(--gold);
}
.resource-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.85rem;
}
.resource-input label {
    color: var(--text-muted);
}
.resource-input input {
    width: 100px;
    padding: 6px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    border-radius: 4px;
    font-size: 0.85rem;
    text-align: center;
}
.count-inputs {
    display: flex;
    gap: 16px;
    justify-content: center;
}
.count-inputs label {
    color: var(--text-muted);
    font-size: 0.85rem;
}
.count-inputs input {
    width: 60px;
    padding: 6px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    border-radius: 4px;
    font-size: 0.85rem;
    text-align: center;
}

/* ---------- Controls ---------- */
.controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.controls button {
    padding: 8px 24px;
    font-size: 0.85rem;
    font-family: "Cinzel", serif;
    cursor: pointer;
    border: none;
    border-radius: 6px;
    transition: all 0.2s;
}
#startBtn {
    background: var(--green);
    color: white;
}
#pauseBtn {
    background: var(--gold-dark);
    color: var(--bg-deep);
}
#resetBtn {
    background: var(--red);
    color: white;
}
.controls button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.controls button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}
.speed-control {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
#speedSlider {
    width: 80px;
    accent-color: var(--gold);
}

/* ---------- Canvas ---------- */
#battleCanvas {
    display: block;
    border: 2px solid var(--gold-dark);
    border-radius: 8px;
    background: #2a3a1a;
    width: 100%;
}

/* ---------- Live battle progress (left sidebar) ---------- */
.battle-progress {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.progress-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 8px 10px;
}
.progress-card.team1 {
    border-left: 3px solid var(--team1);
}
.progress-card.team2 {
    border-left: 3px solid var(--team2);
}
.progress-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.progress-header img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}
.progress-header .prog-name {
    font-family: "Cinzel", serif;
    font-size: 0.8rem;
    font-weight: 600;
}
.progress-header.team1 .prog-name {
    color: var(--team1);
}
.progress-header.team2 .prog-name {
    color: var(--team2);
}
.progress-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 2px;
}
.progress-row .prog-label {
    color: var(--text-muted);
}
.progress-row .prog-value {
    font-weight: 600;
}
.battle-timer {
    text-align: center;
    font-family: "Cinzel", serif;
    font-size: 1.1rem;
    color: var(--gold);
    padding: 6px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
}

/* ---------- Debug panel ---------- */
.debug-panel {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 12px;
    font-size: 0.8rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    font-variant-numeric: tabular-nums;
}
.debug-panel h3 {
    font-family: "Cinzel", serif;
    color: var(--gold);
    margin-bottom: 10px;
    font-size: 0.9rem;
}
.debug-section {
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(90, 66, 40, 0.3);
}
.debug-section:last-child {
    border-bottom: none;
}
.debug-section h4 {
    font-size: 0.8rem;
    margin-bottom: 6px;
}
.debug-section.team1 h4 {
    color: var(--team1);
}
.debug-section.team2 h4 {
    color: var(--team2);
}
.formula-section {
    margin-bottom: 8px;
}
.formula-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-bottom: 2px;
}
.formula-value {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.formula-value .attack-val {
    color: #f39c12;
    font-size: 1.1rem;
    font-weight: bold;
}
.formula-value .armor-val {
    color: var(--team2);
    font-size: 1.1rem;
    font-weight: bold;
}
.formula-note {
    color: var(--text-muted);
    font-size: 0.65rem;
}
.bonus-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--green);
    font-weight: 600;
}
.class-tag {
    background: rgba(90, 154, 58, 0.2);
    color: var(--green);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.6rem;
    font-weight: normal;
}
.formula-result {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(90, 66, 40, 0.3);
}
.formula-total {
    color: var(--gold);
    font-size: 1.4rem;
    font-weight: bold;
}

/* ---------- Light Mode Overrides ---------- */
[data-theme="light"] .selection-badge {
    background: rgba(0, 0, 0, 0.06);
}
[data-theme="light"] .civ-card {
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .civ-card:hover {
    background: rgba(139, 105, 20, 0.1);
}
[data-theme="light"] .unit-pick {
    background: rgba(0, 0, 0, 0.04);
}
[data-theme="light"] .unit-pick:hover {
    background: rgba(139, 105, 20, 0.1);
}
[data-theme="light"] #battleCanvas {
    background: #8aab6a;
}
[data-theme="light"] .formula-value .attack-val {
    color: #b07a08;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .main-layout {
        flex-direction: column;
    }
    .right-panel {
        width: 100%;
    }
    .debug-panel {
        max-height: none;
    }
}
@media (max-width: 700px) {
    .config-panel {
        flex-direction: column;
    }
    .controls {
        flex-direction: column;
        gap: 8px;
    }
    .controls button {
        width: 100%;
    }
    .civ-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    }
}
