/* ==========================================================================
   OW Stat Tracker — design foundation
   Tokens, base elements, layout and shared components. Section-specific
   styles live in their own files (css/player/*.css, css/squad.css).
   ========================================================================== */

:root {
    color-scheme: dark;

    /* Surfaces */
    --bg:          #0b0c0f;
    --surface-1:   #14161b;   /* cards, panels, chart surface */
    --surface-2:   #1b1e25;   /* raised: hover, inputs, nested */
    --surface-3:   #232731;   /* pressed / selected */
    --border:      #262a33;
    --border-strong: #343946;

    /* Text (all >= 4.5:1 on --surface-1) */
    --text:   #eceef2;
    --text-2: #b3b8c4;
    --text-3: #8a90a0;

    /* Brand — UI chrome only (logo, active nav, focus). Never a data color. */
    --accent:     #f99e1a;
    --accent-ink: #1a1206;
    --accent-dim: rgba(249,158,26,.14);

    /* Status — always paired with an icon/sign, never color alone */
    --good:     #3fb950;
    --good-dim: rgba(63,185,80,.14);
    --bad:      #f0605d;
    --bad-dim:  rgba(240,96,93,.14);

    /* Roles — validated categorical set (dark, all pairs) */
    --tank:    #3987e5;
    --damage:  #d95926;
    --support: #199e70;
    --open:    #9085e9;

    /* Players — validated categorical set, assigned in players.json order */
    --p1: #3987e5;
    --p2: #d95926;
    --p3: #199e70;
    --p4: #c98500;
    --p5: #d55181;

    /* Type */
    --font-display: 'Chakra Petch', system-ui, sans-serif;
    --font-body:    'DM Sans', system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', ui-monospace, monospace;
    --fs-xs:  12px;   /* minimum size anywhere */
    --fs-sm:  13px;
    --fs-md:  14px;
    --fs-lg:  16px;
    --fs-xl:  20px;
    --fs-2xl: 28px;
    --fs-3xl: 40px;

    /* Space, radius, motion */
    --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
    --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
    --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px;
    --ease: cubic-bezier(.16,1,.3,1);
    --header-h: 60px;
    --container: 1280px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 56px); }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-body);
    font-size: var(--fs-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--text-3); }
.dim { opacity: .55; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Layout ---------- */
.container {
    width: 100%;
    max-width: var(--container);
    margin-inline: auto;
    padding-inline: var(--sp-4);
}
@media (min-width: 768px) { .container { padding-inline: var(--sp-5); } }

.section { padding-block: var(--sp-6) 0; }
.section:last-child { padding-bottom: var(--sp-7); }
.section-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3); flex-wrap: wrap;
    margin-bottom: var(--sp-4);
}
.section-title {
    font-family: var(--font-display);
    font-size: var(--fs-xl);
    font-weight: 600;
    letter-spacing: .02em;
    margin: 0;
}
.section-sub { color: var(--text-3); font-size: var(--fs-sm); margin: 2px 0 0; }

.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }

/* ---------- Header ---------- */
.site-header {
    position: sticky; top: 0; z-index: 50;
    background: rgba(11,12,15,.88);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.site-header-inner {
    display: flex; align-items: center; gap: var(--sp-4);
    min-height: var(--header-h);
}
.logo {
    display: flex; align-items: center; gap: var(--sp-2);
    font-family: var(--font-display); font-weight: 700;
    font-size: var(--fs-lg); letter-spacing: .06em; white-space: nowrap;
}
.logo-mark {
    display: grid; place-items: center;
    width: 30px; height: 30px; border-radius: 8px;
    background: var(--accent); color: var(--accent-ink);
    font-size: var(--fs-xs); font-weight: 700;
}
.site-nav { display: flex; gap: var(--sp-1); }
.site-nav a {
    padding: 6px 12px; border-radius: var(--radius-sm);
    color: var(--text-2); font-weight: 500;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

.player-switcher {
    display: flex; gap: var(--sp-1);
    margin-left: auto;
    overflow-x: auto; scrollbar-width: none;
}
.player-switcher::-webkit-scrollbar { display: none; }
.player-pill {
    display: flex; align-items: center; gap: var(--sp-2);
    padding: 4px 12px 4px 4px;
    border: 1px solid var(--border); border-radius: 999px;
    color: var(--text-2); font-size: var(--fs-sm); font-weight: 500;
    white-space: nowrap; flex-shrink: 0;
}
.player-pill:hover { border-color: var(--border-strong); color: var(--text); }
.player-pill[aria-current="page"] { border-color: var(--accent); color: var(--text); background: var(--accent-dim); }
.player-pill .avatar { width: 26px; height: 26px; }
.status-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-3); flex-shrink: 0;
}
.status-dot[data-status="active"] { background: var(--good); }
.status-dot[data-status="recent"] { background: var(--accent); }

@media (max-width: 767px) {
    .site-header-inner { flex-wrap: wrap; gap: var(--sp-2); padding-block: var(--sp-2); }
    .player-switcher { order: 3; width: 100%; margin-left: 0; padding-bottom: 2px; }
    .site-nav { margin-left: auto; }
}

/* Sub-navigation (in-page anchors) */
.subnav {
    position: sticky; top: var(--header-h); z-index: 40;
    background: rgba(11,12,15,.88); backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.subnav-inner { display: flex; gap: var(--sp-1); overflow-x: auto; scrollbar-width: none; }
.subnav a {
    padding: 12px 12px; color: var(--text-3); font-weight: 500; white-space: nowrap;
    font-size: var(--fs-sm);
}
.subnav a:hover { color: var(--text); }
.subnav a.active { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
@media (max-width: 767px) { .subnav { top: 0; position: relative; } }

.site-footer {
    border-top: 1px solid var(--border);
    color: var(--text-3); font-size: var(--fs-xs);
    padding-block: var(--sp-4);
    margin-top: var(--sp-6);
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-4);
    min-width: 0;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-2); flex-wrap: wrap;
    margin-bottom: var(--sp-3);
}
.card-title {
    font-size: var(--fs-sm); font-weight: 600; color: var(--text-2);
    text-transform: uppercase; letter-spacing: .08em; margin: 0;
}
.card.is-clickable { cursor: pointer; transition: border-color .15s, background .15s; }
.card.is-clickable:hover { border-color: var(--border-strong); background: var(--surface-2); }

/* ---------- Stats ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-value {
    font-family: var(--font-display); font-weight: 600;
    font-size: var(--fs-2xl); line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.stat-value.sm { font-size: var(--fs-xl); }
.stat-label {
    font-size: var(--fs-xs); color: var(--text-3);
    text-transform: uppercase; letter-spacing: .06em;
}
.stat-row { display: flex; gap: var(--sp-5); flex-wrap: wrap; }

/* ---------- Chips & badges ---------- */
.chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 999px;
    font-size: var(--fs-xs); font-weight: 600;
    background: var(--surface-2); color: var(--text-2);
    white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chip-good { background: var(--good-dim); color: var(--good); }
.chip-bad  { background: var(--bad-dim);  color: var(--bad); }

.role-badge {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: var(--fs-xs); font-weight: 600; color: var(--text-2);
    text-transform: uppercase; letter-spacing: .05em;
}
.role-badge::before {
    content: ""; width: 8px; height: 8px; border-radius: 2px;
    background: var(--role-color, var(--text-3));
}
.role-tank    { --role-color: var(--tank); }
.role-damage  { --role-color: var(--damage); }
.role-support { --role-color: var(--support); }
.role-open    { --role-color: var(--open); }

.mode-badge {
    display: inline-block; padding: 1px 6px; border-radius: 4px;
    font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em;
    border: 1px solid var(--border-strong); color: var(--text-2);
}

/* ---------- Avatars & icons ---------- */
.avatar {
    width: 40px; height: 40px; border-radius: 50%;
    object-fit: cover; background: var(--surface-2); flex-shrink: 0;
}
.avatar.lg { width: 72px; height: 72px; border-radius: 16px; }
.hero-icon {
    width: 36px; height: 36px; border-radius: 8px;
    object-fit: cover; background: var(--surface-2); flex-shrink: 0;
}
.hero-icon.sm { width: 24px; height: 24px; border-radius: 6px; }
.hero-icon.lg { width: 56px; height: 56px; border-radius: 12px; }

/* ---------- Controls ---------- */
.seg {
    display: inline-flex; padding: 3px; gap: 2px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-md);
}
.seg button {
    border: 0; background: transparent; cursor: pointer;
    padding: 5px 12px; border-radius: 7px;
    font-size: var(--fs-sm); font-weight: 500; color: var(--text-3);
    white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong); background: var(--surface-2);
    font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.btn:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.icon-btn {
    display: grid; place-items: center; width: 34px; height: 34px;
    border-radius: var(--radius-sm); border: 0; background: transparent;
    color: var(--text-2); cursor: pointer; font-size: 18px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.input, .select {
    height: 36px; padding: 0 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text);
    font: inherit; font-size: var(--fs-sm);
}
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus { outline: none; border-color: var(--accent); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-1); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th {
    position: sticky; top: 0;
    text-align: right; font-weight: 600; font-size: var(--fs-xs);
    color: var(--text-3); text-transform: uppercase; letter-spacing: .06em;
    padding: 10px 12px; background: var(--surface-1);
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td {
    text-align: right; padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr.is-clickable { cursor: pointer; }
table.data tbody tr.is-clickable:hover td { background: var(--surface-2); }
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[data-sort]:hover { color: var(--text); }
table.data th[aria-sort="ascending"]::after  { content: " ▲"; }
table.data th[aria-sort="descending"]::after { content: " ▼"; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 240px; }
.chart-box.sm { height: 160px; }
.chart-box.lg { height: 320px; }
.legend { display: flex; gap: var(--sp-3); flex-wrap: wrap; font-size: var(--fs-xs); color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-swatch { display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--swatch); }

/* ---------- States ---------- */
.skeleton {
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--surface-1) 0%, var(--surface-2) 50%, var(--surface-1) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
    min-height: 16px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty, .error {
    display: grid; place-items: center; gap: var(--sp-2);
    padding: var(--sp-6) var(--sp-4);
    color: var(--text-3); font-size: var(--fs-sm); text-align: center;
}
.error { color: var(--bad); }

/* ---------- Modal & drawer ---------- */
.overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.6); backdrop-filter: blur(2px);
    opacity: 0; transition: opacity .2s;
}
.overlay.open { opacity: 1; }
.modal {
    position: fixed; z-index: 101;
    left: 50%; top: 50%; transform: translate(-50%, -48%);
    width: min(720px, calc(100vw - 32px));
    max-height: calc(100vh - 64px); overflow-y: auto;
    background: var(--surface-1); border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg); padding: var(--sp-5);
    opacity: 0; transition: opacity .2s, transform .25s var(--ease);
}
.modal.open { opacity: 1; transform: translate(-50%, -50%); }
.drawer {
    position: fixed; z-index: 101; top: 0; right: 0; bottom: 0;
    width: min(560px, 100vw); overflow-y: auto;
    background: var(--surface-1); border-left: 1px solid var(--border-strong);
    padding: var(--sp-5);
    transform: translateX(100%); transition: transform .3s var(--ease);
}
.drawer.open { transform: none; }
.panel-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: var(--sp-3); margin-bottom: var(--sp-4);
}
.panel-title { font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600; margin: 0; }
body.no-scroll { overflow: hidden; }
