/* Session stats slideout. Desktop (>= 1200px) only. Spec section f.
   Theme-derived colours only (--t-*). Motion: transform/opacity only. */

.ux-stats-root,
.ux-stats-tab,
.ux-stats-panel { display: none; }

.ux-stats-root [hidden] { display: none !important; }

@media (min-width: 1200px) {
    .ux-stats-anchor { position: relative; }

    /* Right rail (wraps the sidebar ad). Column so the stats panel sits above the ad. */
    .ux-rail { display: flex; flex-direction: column; align-items: flex-start; flex: 0 0 auto; }
    .ux-rail > .ad-sidebar-responsive,
    .ux-rail > .second-ad-container { flex: 0 0 auto !important; }

    .ux-stats-tab {
        position: absolute;
        left: 100%;
        top: 24px;
        z-index: 3;
        width: 32px;
        height: 96px;
        padding: 0;
        border: 0;
        border-radius: 0 12px 12px 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 8px;
        background: var(--t-surface);
        color: var(--t-accent-2);
        box-shadow: var(--ux-inset-top), var(--ux-shadow-1);
        cursor: pointer;
        transition: transform var(--ux-d-fast) var(--ux-ease-out), background-color var(--ux-d-fast) var(--ux-ease-out);
    }

    .ux-stats-tab:hover { transform: translateX(2px); background: var(--t-surface-raised); }
    .ux-stats-tab:active { transform: translateX(0) scale(.97); transition-duration: var(--ux-d-instant); }
    .ux-stats-tab:focus-visible { outline: 2px solid var(--t-accent-2); outline-offset: 2px; }
    html.ux-stats-open .ux-stats-tab { background: var(--t-accent-2); color: var(--t-on-accent-2); }

    .ux-stats-tab-icon { display: block; }

    .ux-stats-tab-badge {
        min-width: 20px;
        padding: 2px 5px;
        border-radius: var(--ux-r-pill);
        font: 12px/1 var(--ux-font-bold);
        font-variant-numeric: tabular-nums;
        text-align: center;
        background: rgb(0 0 0 / .26);
        color: var(--t-on-surface);
    }

    html.ux-stats-open .ux-stats-tab-badge { background: rgb(0 0 0 / .18); color: var(--t-on-accent-2); }

    /* Pulse once after the first solve to invite discovery */
    .ux-stats-tab.is-inviting::after {
        content: "";
        position: absolute;
        inset: 0;
        border-radius: inherit;
        box-shadow: 0 0 0 0 var(--t-glow);
        pointer-events: none;
    }

    .ux-stats-panel {
        display: none;
        box-sizing: border-box;
        width: 300px;
        /* 32px clears the tab (it hangs 32px off the card); +12px so the panel doesn't hug it */
        margin: 0 0 16px 44px;
        align-self: flex-start;
        padding: 18px;
        border-radius: 16px;
        text-align: left;
        flex: 0 0 auto;
        font-family: var(--ux-font);
        color: var(--t-on-surface);
    }

    /* Slow, smooth slide: emphasised ease-out in (720ms); the close is a little quicker (460ms, sessionStats.js waits for it). */
    html.ux-stats-open .ux-stats-panel {
        display: block;
        animation: ux-stats-in 720ms var(--ux-ease-emph) both;
    }

    html.ux-stats-open .ux-stats-panel.is-closing {
        animation: ux-stats-out 460ms var(--ux-ease-in) both;
    }

    /* Room beside the board (sessionStats.js updateFloat): the panel overhangs the rail instead of widening it,
       so the centred board doesn't move. Width 300 + margin-left 44 - 344 = no width contribution. */
    html.ux-stats-float .ux-stats-panel { margin-right: -344px; }

    .ux-stats-head { display: flex; align-items: center; gap: 10px; }

    .ux-stats-title {
        margin: 0;
        flex: 1;
        font: 12px/1 var(--ux-font-bold);
        letter-spacing: .08em;
        text-transform: uppercase;
        color: var(--t-on-surface-muted);
    }

    .ux-stats-clock {
        display: inline-flex;
        align-items: center;
        gap: 5px;
        font: 13px/1 var(--ux-font);
        font-variant-numeric: tabular-nums;
        color: var(--t-on-surface-muted);
    }

    .ux-stats-close {
        width: 26px;
        height: 26px;
        margin: -4px -6px -4px 0;
        display: grid;
        place-items: center;
        border: 0;
        border-radius: 8px;
        background: transparent;
        color: var(--t-on-surface-muted);
        cursor: pointer;
        transition: background-color var(--ux-d-fast) var(--ux-ease-out);
    }

    .ux-stats-close:hover { background: rgb(255 255 255 / .10); color: var(--t-on-surface); }
    .ux-stats-close:focus-visible { outline: 2px solid var(--t-accent-2); }

    .ux-stats-msg {
        margin: 10px 0 14px;
        min-height: 18px;
        font: 14px/1.3 var(--ux-font);
        color: var(--t-on-surface);
        text-wrap: balance;
    }

    .ux-stats-big {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        margin-bottom: 16px;
    }

    .ux-stats-bigcell { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

    .ux-stats-num {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        font: 32px/1 var(--ux-font-bold);
        font-variant-numeric: tabular-nums;
        color: var(--t-on-surface);
        white-space: nowrap;
    }

    .ux-stats-lbl { font: 12px/1 var(--ux-font); color: var(--t-on-surface-muted); }

    .ux-stats-flame { color: var(--t-on-surface-faint); flex: none; transition: color var(--ux-d-base) var(--ux-ease-out); }
    .ux-stats-panel.is-hot .ux-stats-flame { color: var(--t-accent-4); }

    .ux-bump { display: inline-block; animation: ux-stats-bump 360ms var(--ux-ease-spring); }

    /* ---------- graph card ---------- */
    .ux-stats-graph {
        position: relative;
        margin: 0 0 14px;
        padding: 8px 8px 4px;
        min-height: 150px;
        border-radius: 12px;
        background: var(--t-surface-sunken);
    }

    .ux-stats-graph-top { height: 14px; padding-left: 2px; }
    .ux-stats-cap { font: 12px/1 var(--ux-font); color: var(--t-on-surface-muted); }
    .ux-stats-graph.is-empty .ux-stats-cap { visibility: hidden; }

    .ux-stats-graph-svg svg { display: block; width: 100%; height: auto; overflow: visible; }

    .ux-stats-empty { display: none; position: relative; }
    .ux-stats-graph.is-empty .ux-stats-empty { display: block; }
    .ux-stats-graph.is-empty .ux-stats-graph-svg { display: none; }
    .ux-stats-empty svg { display: block; width: 100%; height: auto; }

    .ux-stats-empty p {
        position: absolute;
        left: 0; right: 0; bottom: 10px;
        margin: 0;
        text-align: center;
        font: 14px/1.3 var(--ux-font);
        color: var(--t-on-surface-muted);
    }

    .ux-stats-ghost { fill: none; stroke: var(--t-line-strong); stroke-width: 2; stroke-dasharray: 3 5; stroke-linecap: round; opacity: .8; }

    .ux-sg-label { font: 10px var(--ux-font); fill: var(--t-on-surface-muted); font-variant-numeric: tabular-nums; }
    .ux-sg-base { stroke: var(--t-line-strong); stroke-width: 1; stroke-dasharray: 3 4; }
    .ux-sg-stop { stop-color: var(--t-accent-2); stop-opacity: .28; }
    .ux-sg-stop-end { stop-color: var(--t-accent-2); stop-opacity: 0; }
    .ux-sg-area { fill: url(#uxSgGrad); }
    .ux-sg-line { fill: none; stroke: var(--t-accent-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

    .ux-sg-bead circle, .ux-sg-bead path { stroke-width: 2; }
    .ux-sg-clean circle { fill: var(--t-accent-2); stroke: var(--t-surface); }
    .ux-sg-helped circle { fill: var(--t-surface); stroke: var(--t-accent-2); }
    .ux-sg-skipped path { fill: none; stroke: var(--t-bad); stroke-linecap: round; }
    .ux-sg-bead .ux-sg-halo { fill: var(--t-glow-soft); stroke: none; }

    .ux-sg-pop, .ux-sg-halo { transform-box: fill-box; transform-origin: center; }
    .ux-sg-hit { fill: transparent; stroke: none; cursor: default; outline: none; }
    .ux-sg-hit:focus-visible { stroke: var(--t-accent-2); stroke-width: 1.5; }

    .ux-sg-bead.is-new .ux-sg-pop { animation: ux-sg-pop 360ms 260ms var(--ux-ease-spring) both; }
    .ux-sg-bead.is-new .ux-sg-halo { animation: ux-sg-halo 520ms 300ms var(--ux-ease-out) both; }
    .ux-sg-area.is-new { animation: ux-sg-fade 360ms var(--ux-ease-out) both; }

    .ux-stats-tip {
        position: absolute;
        z-index: 2;
        transform: translate(-50%, -100%);
        padding: 5px 8px;
        border-radius: 8px;
        background: var(--t-surface-strong);
        box-shadow: var(--ux-shadow-1), 0 0 0 1px var(--t-line);
        font: 12px/1 var(--ux-font);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        color: var(--t-on-surface);
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--ux-d-fast) var(--ux-ease-out);
    }

    .ux-stats-tip.is-on { opacity: 1; }

    /* ---------- rows ---------- */
    .ux-stats-rows { margin: 0; display: flex; flex-direction: column; gap: 12px; }
    .ux-stats-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
    .ux-stats-row dt { font: 14px/1.2 var(--ux-font); color: var(--t-on-surface-muted); }
    .ux-stats-row dd { margin: 0; font: 14px/1.2 var(--ux-font-bold); font-variant-numeric: tabular-nums; color: var(--t-on-surface); }
    .ux-stats-delta { margin-left: 6px; font-size: 13px; }
    .ux-stats-delta.is-up { color: var(--t-accent-2); }
    .ux-stats-delta.is-down { color: var(--t-bad); }

    @media (prefers-reduced-motion: no-preference) {
        .ux-stats-tab.is-inviting::after { animation: ux-stats-invite 900ms var(--ux-ease-out) 3; }
    }

    @media (prefers-reduced-motion: reduce) {
        html.ux-stats-open .ux-stats-panel { animation: none; }
        .ux-stats-tab:hover { transform: none; }
        .ux-bump, .ux-sg-bead.is-new .ux-sg-pop, .ux-sg-bead.is-new .ux-sg-halo, .ux-sg-area.is-new { animation: none; }
        .ux-stats-tab.is-inviting { box-shadow: 0 0 0 3px var(--t-accent-2); }
    }
}

@keyframes ux-stats-in { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes ux-stats-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(-12px); } }
@keyframes ux-stats-bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@keyframes ux-sg-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes ux-sg-halo { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes ux-sg-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ux-stats-invite { 0% { box-shadow: 0 0 0 0 var(--t-glow); } 100% { box-shadow: 0 0 0 12px transparent; } }
