/* ==============================================================================
 *  Opening Explorer (R-06 P0)
 *
 *  Scoped owner for the position-statistics panel on #screen-database. Colours
 *  resolve exclusively through the product theme registry in rewards-themes.css
 *  (--surface-*, --text-*, --accent, --border-subtle), so the screen follows
 *  charcoal-gold / midnight-blue / warm-graphite without a single literal.
 *  The board itself keeps its own palette: it is a playing surface.
 * ============================================================================== */

.tp-opening-stats {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--tp-space-4);
    padding: clamp(12px, 2vw, 18px);
    border: 1px solid var(--border-subtle);
    border-radius: 22px;
    background: var(--surface-1);
    box-shadow: var(--tp-shadow-sm);
}

.tp-opening-stats__heading > span {
    color: var(--accent);
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.tp-opening-stats__heading h2 {
    margin: 2px 0 6px;
    color: var(--text-primary);
    font-size: var(--tp-text-lg);
}

.tp-opening-stats__summary {
    min-height: 20px;
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--tp-text-sm);
    line-height: 1.45;
}

/* ── Educational insight ─────────────────────────────────────────────────────
 * Rendered only when the data genuinely shows popularity and observed score
 * disagreeing. Styled as a note, not as a verdict. */
.tp-openings-insight {
    margin: 0;
    padding: 12px 14px;
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--tp-radius-sm) var(--tp-radius-sm) 0;
    background: color-mix(in srgb, var(--accent) 9%, transparent);
    color: var(--text-secondary);
    font-size: var(--tp-text-sm);
    line-height: 1.5;
}

.tp-openings-insight[hidden] { display: none; }

/* ── Continuations ──────────────────────────────────────────────────────────── */
.tp-openings-moves {
    display: grid;
    gap: var(--tp-space-2);
    /* Long trees scroll inside their own container, never the document. */
    max-height: 520px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.tp-openings-move {
    appearance: none;
    width: 100%;
    min-height: 44px;
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--tp-radius-sm);
    background: var(--surface-2);
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--tp-motion-fast) var(--tp-ease-standard),
                background var(--tp-motion-fast) var(--tp-ease-standard),
                transform var(--tp-motion-fast) var(--tp-ease-standard);
}

.tp-openings-move:hover:not(:disabled) {
    border-color: var(--accent);
    background: var(--surface-raised);
}

.tp-openings-move:focus-visible {
    outline: 3px solid var(--accent-hover);
    outline-offset: 2px;
}

.tp-openings-move:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.tp-openings-move:active:not(:disabled) { transform: translateY(1px) scale(.995); }

.tp-openings-move__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--tp-space-3);
}

.tp-openings-move__pit {
    color: var(--text-primary);
    font-size: var(--tp-text-md);
    font-weight: 700;
}

.tp-openings-move__share {
    color: var(--accent);
    font-family: var(--tp-font-sans);
    font-size: var(--tp-text-md);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.tp-openings-move__bar {
    height: 6px;
    display: block;
    border-radius: var(--tp-radius-pill);
    background: color-mix(in srgb, var(--text-primary) 8%, transparent);
    overflow: hidden;
}

.tp-openings-move__bar-fill {
    height: 100%;
    display: block;
    border-radius: var(--tp-radius-pill);
    background: var(--accent);
}

.tp-openings-move__meta,
.tp-openings-move__wdl {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tp-space-3);
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    font-variant-numeric: tabular-nums;
}

.tp-openings-evidence {
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    font-weight: 650;
}

/* Weak evidence must not read like a recommendation. */
.tp-openings-evidence--no_data,
.tp-openings-evidence--insufficient,
.tp-openings-evidence--very_limited { color: var(--danger); }
.tp-openings-evidence--limited { color: var(--text-secondary); }
.tp-openings-evidence--moderate,
.tp-openings-evidence--substantial { color: var(--success); }

.tp-openings-evidence__note {
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Breadcrumb ─────────────────────────────────────────────────────────────── */
.tp-openings-path {
    margin-top: var(--tp-space-4);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--tp-space-3);
}

.tp-openings-path__list {
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    list-style: none;
    min-width: 0;
}

.tp-openings-path__item { display: flex; align-items: center; }

.tp-openings-path__item + .tp-openings-path__item::before {
    content: '→';
    margin: 0 4px;
    color: var(--text-secondary);
}

.tp-openings-path__crumb {
    appearance: none;
    min-height: 44px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: var(--tp-radius-xs);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    cursor: pointer;
}

.tp-openings-path__crumb:hover { color: var(--text-primary); border-color: var(--border-subtle); }
.tp-openings-path__crumb[aria-current="true"] { color: var(--accent); font-weight: 700; }
.tp-openings-path__crumb:focus-visible { outline: 3px solid var(--accent-hover); outline-offset: 2px; }

.tp-openings-path__controls {
    display: flex;
    gap: var(--tp-space-2);
    flex-shrink: 0;
}

/* The shared inline button is 36px; the explorer is a touch surface, so raise
 * its controls to the 44px minimum without altering the shared component. */
.tp-openings-path__controls .tp-button {
    min-height: 44px;
}

/* ── Corpus disclosure ──────────────────────────────────────────────────────── */
.tp-openings-corpus {
    padding-top: var(--tp-space-3);
    border-top: 1px solid var(--border-subtle);
}

.tp-openings-corpus__title {
    margin: 0 0 6px;
    color: var(--text-primary);
    font-size: var(--tp-text-sm);
    font-weight: 700;
}

.tp-openings-corpus__list {
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px var(--tp-space-3);
    list-style: none;
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    font-variant-numeric: tabular-nums;
}

.tp-openings-corpus__limits {
    margin: 6px 0 0;
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    line-height: 1.45;
}

/* ── Stable loading geometry ───────────────────────────────────────────────── */
.tp-openings-loading {
    min-height: 336px;
    display: grid;
    align-content: start;
    gap: var(--tp-space-2);
}

.tp-openings-skeleton {
    min-height: 88px;
    display: grid;
    gap: 9px;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--tp-radius-sm);
    background: var(--surface-2);
}

.tp-opening-stats .tp-skeleton {
    display: block;
    margin: 0;
    background: color-mix(in srgb, var(--text-primary) 9%, var(--surface-2));
}

.tp-skeleton--opening-title { width: 48%; height: 16px; }
.tp-skeleton--opening-bar { width: 100%; height: 6px; border-radius: var(--tp-radius-pill); }
.tp-skeleton--opening-meta { width: 72%; height: 11px; }
.tp-skeleton--opening-evidence { width: 42%; height: 10px; }
.tp-skeleton--opening-corpus { width: min(100%, 360px); height: 14px; }

.tp-openings-corpus-loading {
    min-height: 58px;
    display: grid;
    align-content: start;
    gap: 10px;
}

.tp-opening-stats[aria-busy="false"] .tp-openings-moves > *,
.tp-opening-stats[aria-busy="false"] .tp-openings-corpus > * {
    animation: tp-openings-reveal var(--tp-motion-base) var(--tp-ease-standard) both;
}

@keyframes tp-openings-reveal {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Empty / error ──────────────────────────────────────────────────────────── */
.tp-openings-empty {
    padding: 16px;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--tp-radius-sm);
    background: color-mix(in srgb, var(--text-primary) 3%, transparent);
    color: var(--text-secondary);
}

.tp-openings-empty strong { display: block; margin-bottom: 4px; color: var(--text-primary); }
.tp-openings-empty p { margin: 0; font-size: var(--tp-text-sm); line-height: 1.45; }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 1023px) {
    .tp-opening-stats { border-radius: 18px; }
    .tp-openings-moves { max-height: none; }
}

@media (max-width: 767px) {
    .tp-opening-stats { padding: 12px; gap: var(--tp-space-3); }
    .tp-openings-path { flex-direction: column; align-items: stretch; }
    .tp-openings-path__controls { justify-content: flex-start; }
    .tp-openings-move { padding: 10px; }
    .tp-openings-move__meta,
    .tp-openings-move__wdl { gap: var(--tp-space-2); }
}

@media (prefers-reduced-motion: reduce) {
    .tp-opening-stats[aria-busy="false"] .tp-openings-moves > *,
    .tp-opening-stats[aria-busy="false"] .tp-openings-corpus > * {
        animation: none;
    }
    .tp-openings-move { transition: none; }
}

/* ── Engine layer (R-06 P1) ──────────────────────────────────────────────────
 * Visually subordinate to the human statistics on purpose. The engine's
 * strength is unproven, so this reads as a side note and a question, never as
 * the answer the page is built around. Colours stay on theme tokens. */
.tp-openings-ai {
    padding: 12px 14px;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--tp-radius-sm);
    background: color-mix(in srgb, var(--text-primary) 3%, transparent);
}

.tp-openings-ai[hidden] { display: none; }

.tp-openings-ai__head {
    margin: 0 0 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--tp-space-2);
}

.tp-openings-ai__kicker {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.tp-openings-ai__value {
    color: var(--text-primary);
    font-size: var(--tp-text-md);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.tp-openings-ai__method,
.tp-openings-ai__note,
.tp-openings-ai__meta,
.tp-openings-ai__caveat,
.tp-openings-ai__stale {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    line-height: 1.45;
}

/* An open question, not a verdict. */
.tp-openings-ai__note--question { color: var(--text-primary); }

.tp-openings-ai__stale { color: var(--danger); }

.tp-openings-ai__meta { font-variant-numeric: tabular-nums; opacity: .85; }

.tp-openings-ai__caveat {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-subtle);
}

/* The engine's pick is a marker on the human row, never a reordering of it:
 * the list stays sorted by human popularity. */
.tp-openings-move__engine {
    padding: 2px 7px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--tp-radius-pill);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.tp-openings-move[data-engine-pick] { border-color: var(--tp-product-border-strong); }

/* ── Arena engine games (R-06 P1) ───────────────────────────────────────────
 * Engine versus engine, kept visually distinct from the human statistics above
 * so the two corpora are never read as one. Theme tokens only. */
.tp-openings-engine-games {
    padding-top: var(--tp-space-3);
    border-top: 1px solid var(--border-subtle);
}

.tp-openings-engine-games__heading > span {
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.tp-openings-engine-games__heading h3 {
    margin: 2px 0 4px;
    color: var(--text-primary);
    font-size: var(--tp-text-md);
}

.tp-openings-engine-games__note {
    margin: 0 0 var(--tp-space-3);
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    line-height: 1.45;
}

.tp-openings-engine-games__filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tp-space-2);
    margin-bottom: var(--tp-space-3);
}

.tp-openings-engine-games__filters .tp-button { min-height: 44px; }
.tp-openings-engine-games__filters .tp-button[aria-pressed="true"] {
    border-color: var(--accent);
    color: var(--accent);
}

.tp-openings-engine-games__list {
    display: grid;
    gap: var(--tp-space-2);
    max-height: 340px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
}

.tp-openings-engine-games__empty {
    margin: 0;
    color: var(--text-secondary);
    font-size: var(--tp-text-sm);
}

.tp-openings-engine-games__more { margin-top: var(--tp-space-2); }
.tp-openings-engine-games__more .tp-button { min-height: 44px; }

.tp-openings-game {
    appearance: none;
    width: 100%;
    min-height: 44px;
    display: grid;
    gap: 4px;
    padding: 9px 11px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--tp-radius-xs);
    background: var(--surface-2);
    color: var(--text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color var(--tp-motion-fast) var(--tp-ease-standard),
                background var(--tp-motion-fast) var(--tp-ease-standard);
}

.tp-openings-game:hover { border-color: var(--accent); background: var(--surface-raised); }
.tp-openings-game:focus-visible { outline: 3px solid var(--accent-hover); outline-offset: 2px; }

.tp-openings-game__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--tp-space-2);
    font-variant-numeric: tabular-nums;
}

.tp-openings-game__result { font-size: 11px; font-weight: 700; }
.tp-openings-game__result--win { color: var(--success); }
.tp-openings-game__result--loss { color: var(--danger); }
.tp-openings-game__result--draw { color: var(--text-secondary); }

.tp-openings-game__meta,
.tp-openings-game__foot {
    display: flex;
    flex-wrap: wrap;
    gap: var(--tp-space-2) var(--tp-space-3);
    color: var(--text-secondary);
    font-size: var(--tp-text-xs);
    font-variant-numeric: tabular-nums;
}

.tp-openings-game__hash { opacity: .8; }

@media (max-width: 767px) {
    .tp-openings-engine-games__list { max-height: none; }
}
