/**
 * GPU Benchmark
 *
 * All values use design tokens from main.css. Only px exception: container
 * max-width. The gbb- prefix keeps styles scoped to this app. Structural
 * sibling of cpu-benchmark (cbb-). The GPU-specific signature is the live 3D
 * render preview box (gbb-preview) with a decorative FPS chip overlay.
 */

/* ========================================
   App Container Centering (REQUIRED)
   ======================================== */

.gbb-container {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

/* ========================================
   Utilities
   ======================================== */

/* Accessible visually-hidden utility (scoped copy, mirrors cpu-benchmark). */
.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
   ======================================== */

.gbb-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/preview/results/history panels are always kept in the flow with
   reserved min-heights so auto-start -> completion and history changes never
   shift the layout (CLS). Spacing uses plain adjacent-sibling rules. */
.gbb-controls + .gbb-progress,
.gbb-progress + .gbb-preview,
.gbb-preview + .gbb-graph-panel,
.gbb-graph-panel + .gbb-results,
.gbb-results + .gbb-history {
    margin-top: var(--space-6);
}

/* ========================================
   Controls
   ======================================== */

.gbb-controls__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    align-items: center;
}

.gbb-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).
   ======================================== */

#gpu-benchmark .gbb-progress {
    min-height: 4.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity var(--transition-base);
}

#gpu-benchmark .gbb-progress[hidden] {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.gbb-progress__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.gbb-progress__label {
    font-weight: 600;
    font-size: var(--font-size-base);
}

.gbb-progress__pct {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.gbb-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;
}

.gbb-progress__fill {
    height: 100%;
    width: 0;
    background: var(--color-primary);
    transition: width var(--transition-base) linear;
}

/* ========================================
   Live 3D render preview (signature block)
   Reserved fixed-aspect box so the canvas can resize on load/resize without
   ever reflowing the page. The canvas + FPS chip are decorative (aria-hidden).
   ======================================== */

.gbb-preview__box {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 360px;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.gbb-preview__box canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.gbb-preview__fps {
    position: absolute;
    top: var(--space-3);
    left: var(--space-3);
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text);
    background: color-mix(in srgb, var(--color-bg) 70%, transparent);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    pointer-events: none;
}

/* ========================================
   Per-second FPS chart
   A live SVG bar chart (one bar per second of the ~30s run). A stable
   reserved slot (min-height) keeps the panel in flow so the chart filling in
   during a run never shifts the surrounding layout (CLS).
   ======================================== */

.gbb-graph-panel__head {
    margin-bottom: var(--space-3);
}

.gbb-graph-panel__title {
    margin: 0;
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-text);
}

.gbb-graph {
    display: block;
    width: 100%;
    height: 9rem;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.gbb-graph__bar {
    fill: var(--color-primary);
    transition: height var(--transition-base) linear, y var(--transition-base) linear;
}

.gbb-graph-panel__hint {
    margin: var(--space-2) 0 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* ========================================
   Results
   Reserve a stable vertical footprint so the loading -> result / error state
   switch never shifts the layout (CLS). Inactive states use display:none (not
   stacked); the container min-height still reserves the space (no CLS).
   ======================================== */

.gbb-results {
    min-height: 34rem;
    display: flex;
    flex-direction: column;
}

.gbb-results__state {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.gbb-results__state[hidden] {
    display: none;
}

.gbb-results__state--loading {
    padding: var(--space-8) 0;
}

.gbb-results__placeholder {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
}

.gbb-error-text {
    margin: 0;
    color: var(--color-error-text);
    font-size: var(--font-size-base);
}

/* Signature readout: large monospace overall score */
.gbb-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: var(--space-2);
}

.gbb-score__label {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.gbb-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);
}

.gbb-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). */
.gbb-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);
}

.gbb-tier--entry {
    background: color-mix(in srgb, var(--color-error) 15%, transparent);
    border-color: var(--color-error);
    color: var(--color-error-text);
}

.gbb-tier--mid {
    background: color-mix(in srgb, var(--color-warning) 15%, transparent);
    border-color: var(--color-warning);
    color: var(--color-warning-text);
}

.gbb-tier--fast {
    background: color-mix(in srgb, var(--color-primary) 15%, transparent);
    border-color: var(--color-primary);
    color: var(--color-primary-text);
}

.gbb-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
   ======================================== */

.gbb-gauge {
    position: relative;
    width: 100%;
    margin-top: var(--space-6);
    height: var(--space-4);
}

.gbb-gauge__bands {
    display: flex;
    gap: 2px;
    height: 100%;
}

.gbb-gauge__band {
    flex: 1 1 0;
    border-radius: var(--radius-full);
}

.gbb-gauge__band--entry {
    background: color-mix(in srgb, var(--color-error) 45%, transparent);
}

.gbb-gauge__band--mid {
    background: color-mix(in srgb, var(--color-warning) 45%, transparent);
}

.gbb-gauge__band--fast {
    background: color-mix(in srgb, var(--color-primary) 45%, transparent);
}

.gbb-gauge__band--vfast {
    background: color-mix(in srgb, var(--color-success) 45%, transparent);
}

.gbb-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);
}

.gbb-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: sustained FPS, per-frame ms, engine */
.gbb-substats {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

.gbb-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);
}

.gbb-substat__label {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
}

.gbb-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);
}

/* Detected device facts (authoritative text values). */
.gbb-device {
    margin: var(--space-6) 0 0;
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.gbb-device__item {
    display: flex;
    gap: var(--space-3);
    padding: var(--space-1) 0;
}

.gbb-device__item + .gbb-device__item {
    border-top: 1px solid var(--color-border);
}

.gbb-device__label {
    flex: 0 0 auto;
    width: 40%;
    margin: 0;
    font-size: var(--font-size-xs);
    font-weight: 600;
    color: var(--color-text-muted);
}

.gbb-device__value {
    flex: 1 1 auto;
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    overflow-wrap: anywhere;
}

/* ========================================
   Detected GPU name (shown under the preview)
   A small, muted info line that names the detected GPU (model + vendor).
   Populated on page load and refreshed after each benchmark run.
   ======================================== */

.gbb-gpu-name {
    margin: var(--space-3) 0 0;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text-muted);
    overflow-wrap: anywhere;
}

/* ========================================
   Run history
   ======================================== */

.gbb-history__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.gbb-history__title {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
}

/* Stable-height slot for the history content (CLS guard). */
.gbb-history__body {
    min-height: 11rem;
}

.gbb-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;
}

/* `display: flex` above wins over the UA `[hidden]` rule, so force the
   empty message to disappear once runs exist (renderHistory sets hidden). */
.gbb-history__empty[hidden] {
    display: none;
}

.gbb-history__tablewrap {
    overflow-x: auto;
}

.gbb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.gbb-table caption {
    text-align: left;
}

.gbb-table th,
.gbb-table td {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-variant-numeric: tabular-nums;
}

.gbb-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.gbb-table tbody tr:nth-child(even) {
    background: var(--color-bg-alt);
}

/* ========================================
   Responsive
   ======================================== */

@media (min-width: 768px) {
    .gbb-substats {
        grid-template-columns: repeat(3, 1fr);
    }

    /* On desktop the result content is compact (substats in a 3-col grid), so
       reduce the tall mobile slot to fit the result tightly (no CLS). */
    .gbb-results {
        min-height: 24rem;
    }
}

/* ========================================
   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.
   ======================================== */
@media (max-width: 767px) {
    .gbb-history__tablewrap {
        overflow-x: visible;
    }

    .gbb-table,
    .gbb-table thead,
    .gbb-table tbody,
    .gbb-table tr,
    .gbb-table td {
        display: block;
    }

    .gbb-table thead {
        display: none;
    }

    .gbb-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);
    }

    .gbb-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-3);
        padding: var(--space-1) 0;
        text-align: right;
    }

    .gbb-table td:last-child {
        border-bottom: none;
    }

    .gbb-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) {
    .gbb-progress__fill,
    .gbb-gauge__needle,
    .gbb-graph__bar {
        transition: none;
    }
}
