/**
 * CPU Benchmark
 *
 * All values use design tokens from main.css. Only px exception: container
 * max-width. The cbb- prefix keeps styles scoped to this app.
 */

/* ========================================
   App Container Centering (REQUIRED)
   ======================================== */

.cbb-container {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

/* ========================================
   Utilities
   ======================================== */

/* Accessible visually-hidden utility. main.css defines .visually-hidden but
   not .sr-only; this app scopes its own copy so .sr-only elements (live
   regions, table captions, assistive column headers) stay available to screen
   readers while being hidden from sighted users. */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ========================================
   Icon buttons (help toggle + help close)
   ======================================== */

.btn-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    cursor: pointer;
    transition: background var(--transition-base), border-color var(--transition-base), color var(--transition-base);
}

.btn-icon:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-icon:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ========================================
   Panels
   ======================================== */

.cbb-panel {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
}

/* The progress panel is always kept in the flow (see #cbb-progress below) so
   revealing/hiding it never shifts the layout. Spacing therefore uses plain
   adjacent-sibling rules that hold whether or not a run is in progress. */
.cbb-controls + .cbb-progress,
.cbb-progress + .cbb-results,
.cbb-results + .cbb-history {
    margin-top: var(--space-6);
}

/* ========================================
   Controls
   ======================================== */

.cbb-controls__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.cbb-controls__note {
    margin: var(--space-4) 0 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

/* ========================================
   Progress
   A stable vertical slot is always reserved (min-height) so auto-starting the
   benchmark and finishing it never shift the surrounding layout (CLS). The
   panel stays in the flow; its content is faded + hidden when no run is in
   progress via [hidden] (opacity/visibility, not display, so the slot holds).
   ======================================== */

#cbb-progress {
    min-height: 5.75rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity var(--transition-base);
}

#cbb-progress[hidden] {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.cbb-progress__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.cbb-progress__label {
    font-weight: 600;
    font-size: var(--font-size-base);
}

.cbb-progress__pct {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.cbb-progress__track {
    position: relative;
    width: 100%;
    height: var(--space-3);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.cbb-progress__fill {
    height: 100%;
    width: 0;
    background: var(--color-primary);
    transition: width var(--transition-base) linear;
}

.cbb-progress__workload {
    margin: var(--space-3) 0 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    min-height: 1.25em;
}

/* ========================================
   Results
   ======================================== */

/* Reserve a stable vertical footprint so the loading -> result / error state
   switch never shifts the layout (CLS). The result state is the tallest (the
   substats stack vertically on mobile); give the panel a fixed min-height that
   comfortably fits it at every breakpoint, and centre the shorter states. */
.cbb-results {
    min-height: 43rem;
    display: flex;
    flex-direction: column;
}

.cbb-results__state {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* The `hidden` attribute is toggled on the inactive states (#cbb-loading,
   #cbb-error, #cbb-result). Without this rule the `display: flex` above would
   override the user-agent `[hidden] { display: none }` and all three states
   would stack. Explicitly removing a hidden state from the layout fixes it;
   the container's min-height still reserves the space, so no CLS. */
.cbb-results__state[hidden] {
    display: none;
}

.cbb-results__state--loading {
    padding: var(--space-8) 0;
}

.cbb-results__placeholder {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
}

.cbb-error-text {
    margin: 0;
    color: var(--color-error-text);
    font-size: var(--font-size-base);
}

/* Signature readout: large monospace overall score */
.cbb-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-2);
}

.cbb-score__label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cbb-score__value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-4xl);
    line-height: var(--line-height-tight);
    font-weight: 700;
    color: var(--color-text);
}

.cbb-score__tier {
    display: inline-flex;
    align-items: center;
    margin-top: var(--space-1);
}

/* Tier badge — text-first inline pill (color is never the sole carrier). */
.cbb-tier {
    display: inline-flex;
    align-items: center;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 600;
    border: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-text-muted) 15%, transparent);
    color: var(--color-text);
}

.cbb-tier--entry {
    background: color-mix(in srgb, var(--color-error) 15%, transparent);
    border-color: var(--color-error);
    color: var(--color-error-text);
}

.cbb-tier--mid {
    background: color-mix(in srgb, var(--color-warning) 15%, transparent);
    border-color: var(--color-warning);
    color: var(--color-warning-text);
}

.cbb-tier--fast {
    background: color-mix(in srgb, var(--color-primary) 15%, transparent);
    border-color: var(--color-primary);
    color: var(--color-primary-text);
}

.cbb-tier--vfast {
    background: color-mix(in srgb, var(--color-success) 15%, transparent);
    border-color: var(--color-success);
    color: var(--color-success-text);
}

/* ========================================
   Decorative 0-1000 tier-band gauge
   ======================================== */

.cbb-gauge {
    position: relative;
    width: 100%;
    margin-top: var(--space-6);
    height: var(--space-4);
}

.cbb-gauge__bands {
    display: flex;
    gap: 2px;
    height: 100%;
}

.cbb-gauge__band {
    flex: 1 1 0;
    border-radius: var(--radius-full);
}

.cbb-gauge__band--entry {
    background: color-mix(in srgb, var(--color-error) 45%, transparent);
}

.cbb-gauge__band--mid {
    background: color-mix(in srgb, var(--color-warning) 45%, transparent);
}

.cbb-gauge__band--fast {
    background: color-mix(in srgb, var(--color-primary) 45%, transparent);
}

.cbb-gauge__band--vfast {
    background: color-mix(in srgb, var(--color-success) 45%, transparent);
}

.cbb-gauge__needle {
    position: absolute;
    top: calc(var(--space-1) * -1);
    left: 0;
    width: var(--space-2);
    height: calc(100% + var(--space-2));
    background: var(--color-text);
    border-radius: var(--radius-full);
    transform: translateX(-50%);
    transition: left var(--transition-slow) ease;
    box-shadow: var(--shadow-sm);
}

.cbb-gauge__scale {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Secondary figures: single-core, multi-core, detected cores */
.cbb-substats {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

.cbb-substat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.cbb-substat__label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cbb-substat__value {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
}

/* ========================================
   Fixed reference marker on the gauge
   (decorative; aria-hidden). A distinct, thin
   tick so it reads separately from the needle.
   ======================================== */

.cbb-gauge__ref {
    position: absolute;
    top: var(--space-2);
    left: 0;
    width: calc(var(--space-1));
    height: calc(100% - var(--space-2));
    background: var(--color-accent, var(--color-primary));
    border-radius: var(--radius-full);
    transform: translateX(-50%);
    opacity: 0.85;
}

/* ========================================
   Reference comparison block
   (display-only, derived client-side)
   ======================================== */

.cbb-cmp {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
}

.cbb-cmp__title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin: 0 0 var(--space-3);
}

.cbb-cmp__pct {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 var(--space-1);
}

.cbb-cmp__delta {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-md);
    color: var(--color-text-muted);
    margin: 0 0 var(--space-4);
}

.cbb-cmp__delta--up {
    color: var(--color-success-text);
}

.cbb-cmp__delta--down {
    color: var(--color-error-text);
}

.cbb-cmp__table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.cbb-cmp__table th,
.cbb-cmp__table td {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    text-align: center;
}

.cbb-cmp__table thead th {
    background: var(--color-bg-alt);
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cbb-cmp__table tbody th[scope="row"] {
    text-align: left;
    color: var(--color-text-muted);
    font-weight: 600;
    background: var(--color-bg-alt);
}

.cbb-cmp__you,
.cbb-cmp__ref {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--color-text);
}

.cbb-cmp__ref {
    color: var(--color-text-muted);
    font-weight: 500;
}

/* Reference machine hardware (F-007): compact spec list inside the comparison
   block. Labels are translated (PHP); values are filled from JS via textContent. */
.cbb-ref {
    margin-top: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.cbb-ref__title {
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    margin: 0 0 var(--space-2);
}

.cbb-ref__list {
    margin: 0;
}

.cbb-ref__item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-1) 0;
}

.cbb-ref__item + .cbb-ref__item {
    border-top: 1px solid var(--color-border);
}

.cbb-ref__label {
    flex: 0 0 auto;
    width: 42%;
    margin: 0;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.cbb-ref__value {
    flex: 1 1 auto;
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text);
}

/* ========================================
   Run history
   ======================================== */

.cbb-history__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.cbb-history__title {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
}

/* Stable-height slot for the history content. The empty-state message and the
   runs table share this reserved region, so populating history right after a
   run (or clearing it) never pushes the sections below (CLS). The region
   grows naturally if the table exceeds the reserved height. */
.cbb-history__body {
    min-height: 11rem;
}

.cbb-history__empty {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    min-height: 11rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cbb-history__tablewrap {
    overflow-x: auto;
}

.cbb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.cbb-table caption {
    text-align: left;
}

.cbb-table th,
.cbb-table td {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-variant-numeric: tabular-nums;
}

.cbb-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.cbb-table tbody tr:nth-child(even) {
    background: var(--color-bg-alt);
}

/* ========================================
   Responsive
   ======================================== */

@media (min-width: 768px) {
    .cbb-substats {
        grid-template-columns: repeat(3, 1fr);
    }

    /* On desktop the result content is compact (substats in a 3-col grid,
       ~310px tall), so the tall 43rem mobile slot leaves ~350px of empty
       whitespace in the hero card. Reduce it here to fit the result tightly.
       The reserved slot stays stable across the loading -> result transition
       (no CLS). */
    .cbb-results {
        min-height: 26rem;
    }
}

/* ========================================
   Responsive: run history as stacked cards (<768px)
   ========================================
   SPEC §7 requires a stacked list on mobile, not a wide horizontal table. The
   <table> markup is kept for desktop; below 768px each row is restyled into a
   card and every cell shows its column label via a data-label pseudo-element.
   The labels are read from the already-localized <th> at render time, so no
   extra i18n keys are needed and all 6 columns stay visible. */
@media (max-width: 767px) {
    .cbb-history__tablewrap {
        overflow-x: visible;
    }

    .cbb-table,
    .cbb-table thead,
    .cbb-table tbody,
    .cbb-table tr,
    .cbb-table td {
        display: block;
    }

    /* Header row is dropped; each card cell carries its own label instead. */
    .cbb-table thead {
        display: none;
    }

    .cbb-table tbody tr {
        background: var(--color-bg-alt);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        padding: var(--space-3);
        margin-bottom: var(--space-3);
    }

    .cbb-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-3);
        padding: var(--space-1) 0;
        text-align: right;
    }

    /* Last cell of a card needs no separator; the card border closes it. */
    .cbb-table td:last-child {
        border-bottom: none;
    }

    .cbb-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-text-muted);
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-size: var(--font-size-xs);
        flex: 0 0 auto;
        text-align: left;
    }
}

/* ========================================
   Reduced motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .cbb-progress__fill,
    .cbb-gauge__needle {
        transition: none;
    }
}
