/* =========================================================
   theme-stats — statistics hub (/stats) and every subpage
   Builds on theme.css tokens (--gold, --ink, --panel, ...).
   ========================================================= */

.stats-page {
    position: relative;
    padding: 8px 0 96px;
    --stats-row: rgba(201, 164, 99, .08);
    --stats-gold-1: #f3d48a;
    --stats-silver: #cfd3d8;
    --stats-bronze: #c98a55;
    --stats-good: #79d38f;
    --stats-bad: #e0715f;
}
.stats-page .wrap { position: relative; }

/* ---------- Navigation: UI_Tab groups + UI_BtnSmall sub links ---------- */
.stats-nav { margin: 0 0 28px; }
.stats-nav__tabs {
    display: flex; gap: 4px;
    padding: 0 2px;
    border-bottom: 1px solid var(--panel-border);
    overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.stats-nav__tabs::-webkit-scrollbar { display: none; }
.stats-nav__tab {
    flex: none; gap: 10px;
    min-height: 46px; padding: 6px 24px 4px;
    text-decoration: none; white-space: nowrap;
}
.stats-nav__tab svg { width: 18px; height: 18px; flex: none; opacity: .75; transition: opacity .2s; }
.stats-nav__tab:hover svg, .stats-nav__tab.active svg { opacity: 1; }
.stats-nav__sub {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding: 14px 16px;
    background: linear-gradient(180deg, rgba(36, 28, 21, .85), rgba(20, 16, 12, .6));
    border: 1px solid var(--panel-border); border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
}
.stats-nav__link { text-decoration: none; }
.stats-nav__link.is-active,
.stats-nav__link.is-active:hover {
    --ui-tex: url("../img/ui/UI_BtnSmall_Pressed.png");
    color: var(--gold);
    filter: none;
    cursor: default;
}

/* ---------- Panels ---------- */
.stats-panel { padding: 0; overflow: hidden; }
.stats-panel + .stats-panel { margin-top: 24px; }
.stats-panel__head {
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    padding: 18px 24px;
    border-bottom: 1px solid var(--panel-border);
    background: linear-gradient(90deg, rgba(230, 194, 122, .08), transparent 60%);
}
.stats-panel__title {
    display: flex; align-items: center; gap: 12px;
    margin: 0;
    font-family: var(--font-accent-bold), serif; font-size: 16px; font-weight: normal;
    letter-spacing: .1em; text-transform: uppercase; color: var(--gold);
}
.stats-panel__title img { width: 32px; height: 32px; flex: none; }
.stats-panel__title::before {
    content: ""; width: 8px; height: 8px; flex: none; transform: rotate(45deg);
    border: 1px solid var(--gold); box-shadow: 0 0 10px rgba(230, 194, 122, .45);
}
.stats-panel__title.has-icon::before { content: none; }
.stats-panel__meta {
    font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--text-muted);
}
.stats-panel__body { padding: 24px; }

/* ---------- Tables ---------- */
.stats-table-wrap {
    position: relative;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(201, 164, 99, .4) transparent;
}
.stats-table-wrap::-webkit-scrollbar { height: 6px; }
.stats-table-wrap::-webkit-scrollbar-thumb { background: rgba(201, 164, 99, .4); border-radius: 3px; }
.stats-table {
    width: 100%; min-width: 640px;
    border-collapse: separate; border-spacing: 0;
    color: var(--text); font-size: 14px;
}
.stats-table th {
    padding: 14px 16px;
    text-align: left; white-space: nowrap;
    font-family: var(--font-accent-bold), serif; font-size: 11px; font-weight: normal;
    letter-spacing: .14em; text-transform: uppercase; color: var(--gold-soft);
    background: rgba(0, 0, 0, .28);
    border-bottom: 1px solid var(--panel-border);
}
.stats-table td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--stats-row);
}
.stats-table tbody tr:last-child td { border-bottom: 0; }
.stats-table tbody tr { transition: background .2s; }
.stats-table tbody tr:nth-child(even) { background: rgba(255, 255, 255, .015); }
.stats-table tbody tr:hover { background: rgba(230, 194, 122, .07); }
.stats-table tbody tr.is-top { background: linear-gradient(90deg, rgba(230, 194, 122, .1), transparent 60%); }
.stats-table tbody tr.is-top:hover { background: linear-gradient(90deg, rgba(230, 194, 122, .16), rgba(230, 194, 122, .04)); }
.stats-table .col-rank { width: 64px; text-align: center; }
.stats-table .col-center { text-align: center; }
.stats-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stats-table .is-key { color: #f3e2b8; font-family: var(--font-accent-bold), serif; font-size: 15px; letter-spacing: .02em; }
.stats-table .is-bad { color: var(--stats-bad); }
.stats-table .is-muted { color: var(--text-muted); }
.stats-table a { color: #f1e2bf; transition: color .2s; }
.stats-adena { display: inline-flex; align-items: center; gap: 8px; }
.stats-adena img { width: 16px; height: 16px; filter: sepia(1) saturate(2.4) brightness(.95); }
.stats-table a:hover { color: var(--gold); }
.is-dim { color: #6f6455; }

/* rank badge */
.stats-rank {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    font-family: var(--font-accent-bold), serif; font-size: 13px; line-height: 1;
    color: var(--text-muted);
    border: 1px solid rgba(201, 164, 99, .22); border-radius: 50%;
    background: rgba(0, 0, 0, .3);
    font-variant-numeric: tabular-nums;
}
.stats-rank--1, .stats-rank--2, .stats-rank--3 {
    width: 34px; height: 34px; font-size: 15px; border: 0; color: #1b130a; text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}
.stats-rank--1 {
    background: radial-gradient(circle at 35% 30%, #fff1c4, var(--stats-gold-1) 40%, #a7752c 100%);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .5), 0 0 0 3px rgba(243, 212, 138, .7), 0 0 16px rgba(243, 212, 138, .45);
}
.stats-rank--2 {
    background: radial-gradient(circle at 35% 30%, #ffffff, var(--stats-silver) 40%, #7b8087 100%);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .5), 0 0 0 3px rgba(207, 211, 216, .6);
}
.stats-rank--3 {
    background: radial-gradient(circle at 35% 30%, #ffd9b5, var(--stats-bronze) 45%, #7a4a26 100%);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .5), 0 0 0 3px rgba(201, 138, 85, .6);
}

/* name + crests */
.stats-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.stats-crests {
    display: inline-flex; align-items: center; flex: none;
    padding: 3px; background: rgba(0, 0, 0, .45);
    border: 1px solid rgba(201, 164, 99, .25); border-radius: 2px;
}
.stats-crests img { display: block; image-rendering: pixelated; }
.stats-name__text { display: flex; flex-direction: column; min-width: 0; }
.stats-name__main { color: #f6ead0; font-weight: 600; white-space: nowrap; }
.stats-name__sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* chips / status pills */
.stats-chip {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-width: 28px; height: 24px; padding: 0 8px;
    font-size: 12px; letter-spacing: .06em; color: var(--text-muted);
    border: 1px solid rgba(201, 164, 99, .2); border-radius: 12px;
    background: rgba(0, 0, 0, .25); white-space: nowrap;
}
.stats-status {
    display: inline-flex; align-items: center; gap: 8px;
    height: 26px; padding: 0 12px;
    font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 600;
    border-radius: 13px; white-space: nowrap;
}
.stats-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 8px currentColor; }
.stats-status--good { color: var(--stats-good); background: rgba(121, 211, 143, .1); border: 1px solid rgba(121, 211, 143, .3); }
.stats-status--bad { color: var(--stats-bad); background: rgba(224, 113, 95, .1); border: 1px solid rgba(224, 113, 95, .3); }
.stats-status--idle { color: var(--text-muted); background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .1); }
.stats-status--idle::before { box-shadow: none; }

.stats-holdings { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.stats-holdings span { color: var(--text-muted); }
.stats-holdings b { color: #f1e2bf; font-weight: 600; }

/* ---------- Empty state ---------- */
.stats-empty {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    padding: 56px 24px 60px;
}
.stats-empty__icon { width: 54px; height: 54px; color: var(--gold-soft); opacity: .7; margin-bottom: 18px; }
.stats-empty__title {
    font-family: var(--font-accent-bold), serif; font-size: 18px; letter-spacing: .08em; text-transform: uppercase;
    color: #f1e2bf; margin: 0 0 8px;
}
.stats-empty__text { max-width: 420px; font-size: 14px; color: var(--text-muted); margin: 0; }

/* ---------- Generated footer ---------- */
.stats-generated {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 12px;
    margin: 24px 0 0; padding: 0;
    font-size: 12px; letter-spacing: .06em; color: #7d7365;
    background: none; border: 0; text-align: center;
}
.stats-generated svg { width: 14px; height: 14px; color: var(--gold-soft); }
.stats-generated__sep { font-size: 8px; color: var(--gold-soft); opacity: .6; }

/* ---------- Hub: KPIs + bars ---------- */
.stats-kpis {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 20px;
    margin-bottom: 24px;
}
.stats-kpi {
    display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
    padding: 28px 20px 24px;
}
.stats-kpi::after {
    content: ""; position: absolute; left: 50%; top: 0; width: 60%; height: 1px; transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.stats-kpi:hover { transform: translateY(-3px); border-color: rgba(230, 194, 122, .55); }
.stats-kpi__icon { width: 30px; height: 30px; color: var(--gold); opacity: .85; margin-bottom: 6px; }
.stats-kpi__value {
    font-family: var(--font-accent-bold), serif; font-size: clamp(28px, 3vw, 38px); line-height: 1.1;
    color: #f6e6c0; text-shadow: 0 0 22px rgba(230, 194, 122, .25); font-variant-numeric: tabular-nums;
}
.stats-kpi__label { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--text-muted); }

.stats-split { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 24px; align-items: stretch; }
.stats-split .stats-panel + .stats-panel { margin-top: 0; }

.stats-bars { display: flex; flex-direction: column; gap: 18px; padding: 24px; margin: 0; }
.stats-bar__row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.stats-bar__label { font-family: var(--font-accent-bold), serif; font-size: 14px; letter-spacing: .06em; color: #f1e2bf; }
.stats-bar__value { font-size: 14px; color: var(--text); font-variant-numeric: tabular-nums; }
.stats-bar__value em { font-style: normal; color: var(--gold); margin-left: 8px; font-weight: 600; }
.stats-bar__track {
    position: relative; height: 10px; overflow: hidden;
    background: rgba(0, 0, 0, .5);
    border: 1px solid rgba(201, 164, 99, .25); border-radius: 5px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, .6);
}
.stats-bar__fill {
    height: 100%; min-width: 2px; border-radius: 4px;
    background: linear-gradient(90deg, #8a6430, var(--gold) 70%, #fff0c8);
    box-shadow: 0 0 10px rgba(230, 194, 122, .45);
}
.stats-bar--male .stats-bar__fill { background: linear-gradient(90deg, #2f4f7a, #7fa8de 70%, #d6e6ff); box-shadow: 0 0 10px rgba(127, 168, 222, .45); }
.stats-bar--female .stats-bar__fill { background: linear-gradient(90deg, #7a2f5c, #de7fb4 70%, #ffd6ec); box-shadow: 0 0 10px rgba(222, 127, 180, .45); }

/* hub: explore cards */
.stats-explore { margin-top: 64px; }
.stats-explore__head { margin-bottom: 32px; }
.stats-explore__grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
.stats-explore__card {
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 28px; color: inherit; text-decoration: none;
}
.stats-explore__card:hover { transform: translateY(-4px); border-color: rgba(230, 194, 122, .55); }
.stats-explore__card h3 { margin: 0; }
.stats-explore__card p { margin: 0; flex: 1; font-size: 14px; }
.stats-explore__card .ui-btn { margin-top: 10px; }
.stats-explore__card:hover .ui-btn { --ui-tex: url("../img/ui/UI_BtnSmall_Hover.png"); color: #fff4d6; }
.stats-explore__icon {
    width: 44px; height: 44px; padding: 10px; margin-bottom: 4px;
    color: var(--gold); border: 1px solid var(--panel-border); border-radius: 50%;
    background: radial-gradient(circle, rgba(230, 194, 122, .14), transparent 70%);
}

/* ---------- Card grids (castles, epic bosses) ---------- */
.stats-cards {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px;
}
.stats-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.stats-card:hover { transform: translateY(-4px); border-color: rgba(230, 194, 122, .55); }
.stats-card__media { position: relative; aspect-ratio: 3 / 2; overflow: hidden; background: #000; }
.stats-card__media img { display: block; width: 100%; height: 100%; object-fit: cover; transition: transform .6s var(--ease), filter .3s; }
.stats-card:hover .stats-card__media img { transform: scale(1.05); }
.stats-card__media::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(180deg, transparent 45%, rgba(14, 11, 9, .95));
    box-shadow: inset 0 0 0 1px rgba(201, 164, 99, .2);
}
.stats-card__media.is-dead img { filter: grayscale(1) brightness(.55); }
.stats-card__badge { position: absolute; top: 12px; right: 12px; z-index: 1; backdrop-filter: blur(4px); }
.stats-card__title {
    position: absolute; left: 18px; right: 18px; bottom: 12px; z-index: 1; margin: 0;
    font-family: var(--font-accent-bold), serif; font-size: 20px; font-weight: normal; letter-spacing: .06em;
    color: #f6e6c0; text-shadow: 0 2px 8px rgba(0, 0, 0, .9);
}
.stats-card__title small { display: block; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.stats-card__body { padding: 18px 20px 20px; flex: 1; }
.stats-facts { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; margin: 0; font-size: 14px; }
.stats-facts dt { color: var(--text-muted); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; align-self: center; }
.stats-facts dd { margin: 0; color: var(--text); text-align: right; display: flex; justify-content: flex-end; align-items: center; gap: 8px; min-width: 0; }
.stats-facts dd.is-key { color: #f3e2b8; font-family: var(--font-accent-bold), serif; }
.stats-sides { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--stats-row); display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
.stats-sides p { margin: 0; color: var(--text-muted); line-height: 1.5; }
.stats-sides b { display: inline-block; min-width: 86px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: normal; }
.stats-sides .is-attack b { color: var(--stats-bad); }
.stats-sides .is-defend b { color: var(--stats-good); }
.stats-sides span { color: var(--text); }
.stats-note { display: block; font-size: 12px; color: var(--text-muted); }

/* ---------- Toolbar (olympiad class picker) ---------- */
.stats-toolbar {
    display: flex; align-items: center; justify-content: flex-start; gap: 16px; flex-wrap: wrap;
    margin-bottom: 24px; padding: 16px 20px;
}
.stats-toolbar label {
    font-family: var(--font-accent-bold), serif; font-size: 12px; letter-spacing: .14em;
    text-transform: uppercase; color: var(--gold);
}
.stats-select {
    appearance: none; -webkit-appearance: none;
    min-width: 280px; max-width: 100%; height: 44px; margin: 0;
    padding: 0 44px 0 16px;
    font: inherit; font-size: 14px; color: #f1e2bf;
    background: rgba(0, 0, 0, .45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e6c27a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6l6 -6'/%3E%3C/svg%3E") no-repeat right 14px center / 18px;
    border: 1px solid var(--panel-border); border-radius: var(--radius);
    box-shadow: inset 0 1px 4px rgba(0, 0, 0, .5);
    cursor: pointer; transition: border-color .2s;
}
.stats-select:hover, .stats-select:focus { border-color: var(--gold); outline: none; }
.stats-select option { background: var(--ink-2); color: var(--text); }

/* ---------- Item cells / pager ---------- */
.stats-item { display: flex; align-items: center; gap: 12px; }
.stats-item img {
    width: 32px; height: 32px; flex: none;
    border: 1px solid rgba(201, 164, 99, .35); border-radius: 3px; background: #000;
}
.stats-item__name { color: #f1e2bf; }
.stats-enchant { color: var(--gold); font-family: var(--font-accent-bold), serif; }
.stats-pager {
    display: flex; align-items: center; justify-content: center; gap: 14px;
    padding: 18px 24px; border-top: 1px solid var(--panel-border);
}
.stats-pager .ui-btn--small.is-disabled { --ui-tex: url("../img/ui/UI_BtnSmall_Disabled.png") !important; }
.stats-toolbar .stats-status { margin-left: auto; }
.stats-pager__info { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted); }

/* jewel panels (epic control) */
.stats-jewel__icon { display: inline-flex; padding: 2px; border: 1px solid rgba(201, 164, 99, .45); border-radius: 3px; background: #000; }
.stats-jewel__icon img { display: block; width: 32px; height: 32px; }
.stats-panel__title .stats-grade { width: auto; height: 16px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
    .stats-page { padding-bottom: 64px; }
    .stats-explore__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats-split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .stats-nav { margin-bottom: 20px; margin-left: -15px; margin-right: -15px; }
    .stats-nav__tabs {
        padding: 0 15px;
        -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
        mask-image: linear-gradient(90deg, #000 calc(100% - 36px), transparent);
    }
    .stats-nav__tab { min-height: 42px; padding: 4px 16px 2px; font-size: 12px; }
    .stats-nav__sub {
        flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
        padding: 12px 15px; border-left: 0; border-right: 0; border-radius: 0;
    }
    .stats-nav__sub::-webkit-scrollbar { display: none; }
    .stats-nav__link { flex: none; }
    .stats-panel__head { padding: 14px 16px; }
    .stats-panel__title { font-size: 14px; }
    .stats-table { font-size: 13px; }
    .stats-table th { padding: 12px 12px; }
    .stats-table td { padding: 10px 12px; }
    .stats-table .col-rank { width: 52px; }
    .stats-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .stats-kpi { padding: 20px 12px 18px; }
    .stats-split { grid-template-columns: 1fr; }
    .stats-bars { padding: 18px 16px; }
    .stats-cards { grid-template-columns: 1fr; gap: 16px; }
    .stats-explore { margin-top: 48px; }
    .stats-explore__grid { grid-template-columns: 1fr; gap: 16px; }
    .stats-explore__card { padding: 22px; }
    .stats-toolbar { padding: 14px 16px; }
    .stats-select { min-width: 0; width: 100%; }
}
