/* ==========================================================================
   AoE2 Unit Analyzer — Civ Detail Page Styles
   ========================================================================== */

/* ---------- Page-specific Variables ---------- */
:root {
    --parchment:       #d4c4a0;
}

/* ---------- Page Header (overrides base) ---------- */
.page-header {
    text-align: left;
    border-bottom-width: 3px;
    border-image: linear-gradient(
        90deg,
        transparent 5%,
        var(--gold-dark) 30%,
        var(--gold) 50%,
        var(--gold-dark) 70%,
        transparent 95%
    ) 1;
}

.header-top {
    max-width: 1100px;
    margin: 0 auto;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.8rem;
    transition: color 0.2s;
}

.back-link:hover {
    color: var(--gold);
}

.header-main {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
}

.civ-emblem {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--gold-dark);
    object-fit: cover;
    background: var(--bg);
}

.header-main h1 {
    font-size: 1.5rem;
}

/* ---------- Age Toggle (overrides base) ---------- */
.age-toggle {
    gap: 6px;
    margin-left: auto;
    justify-content: flex-end;
}

.age-btn {
    font-family: "Cinzel", serif;
    font-size: 0.8rem;
    padding: 6px 16px;
    border-color: var(--border-light);
    background: var(--bg-warm);
}

/* ---------- Loading ---------- */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
    font-size: 1rem;
}

/* ---------- Content Area ---------- */
.content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 28px 60px;
}

/* ---------- Buildings Grid ---------- */
.buildings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    align-items: start;
}

.building-group {
    background: rgba(58, 42, 24, 0.3);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 12px;
}

.building-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}

.building-icon {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    object-fit: cover;
}

.building-header h2 {
    font-size: 0.9rem;
}

/* ---------- Unit Cards ---------- */
.units-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.unit-card {
    width: 120px;
    padding: 10px 8px;
    background: var(--bg-warm);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.unit-card:hover {
    border-color: var(--gold-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.unit-icon {
    width: 88px;
    height: 88px;
    border-radius: 8px;
    border: 2px solid var(--gold-dark);
    object-fit: cover;
    background: var(--bg);
    margin: 0 auto 6px;
    display: block;
}

.unit-name {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}

.civ-star {
    position: absolute;
    top: 3px;
    right: 3px;
    color: var(--gold);
    font-size: 0.8rem;
}

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    overflow-y: auto;
    padding: 40px 20px;
}

.modal-overlay.open {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.modal {
    background: var(--bg-warm);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    max-width: 640px;
    width: 100%;
    position: relative;
    overflow: hidden;
}

.modal-gold-bar {
    height: 3px;
    background: linear-gradient(
        90deg,
        transparent,
        var(--gold-dark),
        var(--gold),
        var(--gold-dark),
        transparent
    );
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    z-index: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 28px;
}

/* ---------- Modal Header ---------- */
.modal-unit-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 22px;
}

.modal-unit-icon {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    border: 2px solid var(--gold-dark);
    object-fit: cover;
    background: var(--bg);
}

.modal-unit-info h3 {
    font-size: 1.4rem;
}

.modal-unit-info .class-badge {
    font-size: 0.8rem;
    color: var(--text-muted);
    background: rgba(201, 168, 76, 0.1);
    border: 1px solid rgba(201, 168, 76, 0.2);
    border-radius: 10px;
    padding: 2px 10px;
    display: inline-block;
    margin-top: 4px;
}

/* ---------- Stat Breakdown ---------- */
.stat-section {
    margin-bottom: 18px;
}

.stat-section h4 {
    font-family: "Cinzel", serif;
    font-size: 0.95rem;
    color: var(--gold);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.stat-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 6px 0;
    font-size: 0.9rem;
    flex-wrap: wrap;
    border-bottom: 1px solid rgba(90, 66, 40, 0.15);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    width: 110px;
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.stat-final-val {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    min-width: 36px;
}

.stat-final-val.improved {
    color: var(--green);
}

.stat-chain {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-chain .base-val {
    color: var(--text-muted);
}

.stat-chain .step {
    color: var(--text-muted);
    opacity: 0.85;
}

.stat-chain .step.positive {
    color: var(--green);
}

.stat-chain .step.negative {
    color: var(--red);
}

.stat-chain .step .tech-name {
    color: var(--text-muted);
    opacity: 0.7;
    font-size: 0.75rem;
}

/* ---------- Cost ---------- */
.cost-row {
    display: flex;
    gap: 12px;
    font-size: 0.8rem;
    margin-bottom: 4px;
}

.cost-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.cost-food {
    color: #d44;
}

.cost-wood {
    color: #a86;
}

.cost-gold {
    color: var(--gold);
}

/* ---------- Attack/Armor Tables ---------- */
.class-table {
    width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
}

.class-table th {
    text-align: left;
    padding: 4px 8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
    font-weight: 500;
}

.class-table td {
    padding: 3px 8px;
}

.class-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.1);
}

.class-table .val {
    text-align: right;
    font-weight: 600;
}

/* ---------- Special Effects ---------- */
.special-item {
    font-size: 0.85rem;
    padding: 5px 0;
    border-bottom: 1px solid rgba(90, 66, 40, 0.3);
}

.special-name {
    color: var(--gold);
    font-weight: 600;
}

.special-desc {
    color: var(--text-muted);
}

/* ---------- Two Column Layout ---------- */
.classes-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ---------- Light Mode Overrides ---------- */
[data-theme="light"] .building-group {
    background: rgba(0, 0, 0, 0.03);
}
[data-theme="light"] .modal {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
[data-theme="light"] .modal-overlay {
    background: rgba(0, 0, 0, 0.4);
}
[data-theme="light"] .class-table tr:nth-child(even) td {
    background: rgba(0, 0, 0, 0.03);
}
[data-theme="light"] .stat-final-val.improved {
    color: #2a7a22;
}
[data-theme="light"] .stat-chain .step.positive {
    color: #2a7a22;
}
[data-theme="light"] .stat-chain .step.negative {
    color: #b83030;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .header-main {
        flex-wrap: wrap;
    }

    .age-toggle {
        margin-left: 0;
        width: 100%;
        margin-top: 8px;
    }

    .age-btn {
        flex: 1;
        text-align: center;
    }

    .buildings-grid {
        grid-template-columns: 1fr;
    }

    .unit-card {
        width: 100px;
    }

    .unit-icon {
        width: 72px;
        height: 72px;
    }

    .classes-grid {
        grid-template-columns: 1fr;
    }

    .modal {
        margin: 10px;
    }

    .modal-body {
        padding: 16px;
    }
}
