/* Build-mix palette: one source for the stacked bar, its legend, and the per-command bars, so a
   command's colour always matches the segment it is counted in. */
:root {
    --mix-economy: #d6a84c;
    --mix-fortification: #98a0a8;
    --mix-military: #7d9a4e;
}

.stats-page {
    width: min(980px, 100%);
    display: grid;
    gap: 18px;
}

.stats-header,
.stats-panel,
.stats-outcomes,
.stat-tile {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgb(26 32 41 / 0.88);
    box-shadow: 0 22px 60px var(--shadow);
}

.stats-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: clamp(16px, 4vw, 24px);
}

.stats-header h1 {
    margin: 4px 0 0;
    font-size: clamp(2rem, 5vw, 3.2rem);
    line-height: 1;
    letter-spacing: 0;
}

.stats-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.stats-scope {
    width: min(420px, 100%);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stat-tile {
    display: grid;
    gap: 4px;
    padding: 14px;
}

.stat-tile-value {
    overflow-wrap: anywhere;
    font-size: clamp(1.35rem, 3vw, 2rem);
    line-height: 1.1;
}

.stat-tile-label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.stats-panel {
    display: grid;
    gap: 12px;
    padding: clamp(14px, 3vw, 18px);
}

.stats-outcomes {
    grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
    align-items: center;
}

.stat-circle-bar {
    position: relative;
    width: 220px;
    max-width: 100%;
    aspect-ratio: 1;
    margin-top: 12px;
}

.stat-circle-bar svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.stat-circle-bar-track,
.stat-circle-bar-segment {
    fill: none;
    stroke-width: 14;
}

.stat-circle-bar-track {
    stroke: rgba(255, 255, 255, 0.08);
}

.stat-circle-bar-segment {
    stroke: var(--segment-color);
    stroke-linecap: butt;
    stroke-dasharray: var(--dash) var(--gap);
    stroke-dashoffset: var(--offset);
}

.stat-circle-bar-center {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
}

.stat-circle-bar-center strong {
    font-size: 2rem;
    line-height: 1;
}

.stat-circle-bar-center span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
}

.stat-legend {
    display: grid;
    gap: 10px;
}

.stat-legend-item {
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.stat-legend-swatch {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--legend-color);
}

/* The label column is capped rather than fractional: as a fr it grew with the viewport, so on wide
   screens it left a long dead gap before the bar. Each panel sets the cap its longest label needs. */
.stat-bar-row {
    display: grid;
    grid-template-columns: var(--bar-label-width, 15rem) minmax(120px, 1fr) minmax(54px, auto);
    align-items: center;
    gap: 10px;
}

.stats-bars-commands {
    --bar-label-width: 11rem;
}

.stats-bars-boards {
    --bar-label-width: 8rem;
}

.stat-bar-label {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
}

.stat-bar-label span:not(.control-glyph) {
    min-width: 0;
    overflow-wrap: anywhere;
}

.stat-bar-track {
    min-width: 0;
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.stat-bar-fill {
    width: var(--bar);
    height: 100%;
    border-radius: inherit;
    background: var(--bar-color);
}

.stat-bar-value {
    color: var(--muted);
    font-weight: 900;
    text-align: right;
}

@media (max-width: 520px) {
    .stats-header,
    .stats-outcomes {
        grid-template-columns: 1fr;
    }

    .stats-header {
        display: grid;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stat-circle-bar {
        width: 170px;
    }

    .stat-bar-row {
        grid-template-columns: minmax(0, 1fr) minmax(44px, auto);
        gap: 6px 10px;
    }

    .stat-bar-label {
        grid-column: 1 / 2;
    }

    .stat-bar-track {
        grid-column: 1 / 2;
    }

    .stat-bar-value {
        grid-column: 2 / 3;
        grid-row: 1 / 3;
        align-self: center;
        text-align: right;
    }
}

.build-mix {
    display: grid;
    gap: 12px;
    margin-bottom: 6px;
}

.build-mix-track {
    display: flex;
    height: 14px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
}

.build-mix-segment {
    width: var(--segment);
    background: var(--segment-color);
}

.build-mix-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
}

.build-mix-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
