*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* The CSP (style-src 'self') makes browsers ignore inline style attributes,
   so initial hiding uses the hidden attribute; this backstops it against any
   author display rule on the same element. */
[hidden] {
    display: none !important;
}

/* Design tokens (palette, fonts, effects) come from
   theme-liberty-ultra-dark.css, which is loaded before this file. */

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
    padding: 2rem 0;
}

.container {
    width: 100%;
    max-width: 1140px;
    padding: 0 1.5rem;
}

/* Test dashboard: gauge/controls pane beside the live metric cards, so the
   whole test UI fits one viewport with no scrolling. */
.test-dashboard {
    display: grid;
    grid-template-columns: minmax(360px, 440px) 1fr;
    gap: 1.5rem;
    align-items: center;
    margin-bottom: 1.5rem;
}

.test-dashboard .results-grid {
    margin-bottom: 0;
}

.gauge-pane .start-container {
    margin-bottom: 0;
}

.gauge-pane .progress-container {
    max-width: 320px;
    margin: 1rem auto 0;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

.brand {
    display: inline-block;
    margin-bottom: 1.25rem;
    line-height: 0;
}

.brand-logo {
    height: 42px;
    width: auto;
    /* subtle cyan glow to lift the mark off the dark background */
    filter: drop-shadow(0 0 14px var(--accent-glow));
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Gauge */
.gauge-container {
    text-align: center;
    margin-bottom: 1.5rem;
}

#gauge {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

.gauge-label {
    font-size: 3rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin-top: -2rem;
}

.gauge-unit {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.gauge-phase {
    font-size: 0.75rem;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

/* Start button */
.start-container {
    text-align: center;
    margin-bottom: 2rem;
}

.start-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    color: var(--accent-contrast);
    border: none;
    padding: 0.875rem 3rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    letter-spacing: 0.02em;
    box-shadow: 0 0 20px var(--accent-mute);
}

.start-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0 30px var(--accent-glow);
}

.start-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
    box-shadow: none;
}

/* Results grid */
.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.result-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 0.75rem;
    text-align: center;
    transition: border-color 0.3s;
    overflow: visible;
}

.result-card-highlight {
    background: var(--bg-card-highlight);
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.result-icon {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    opacity: 0.7;
}

.result-value {
    font-size: 1.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.result-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 0.25rem;
}

.result-unit {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Explain button + tooltip */
.result-explain {
    position: relative;
    margin-top: 0.5rem;
}

.explain-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.6rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 0.03em;
    transition: color 0.2s, border-color 0.2s;
}

.explain-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.explain-tooltip {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-floating);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--text);
    width: 220px;
    text-align: left;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    pointer-events: none;
}

.explain-tooltip::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-bottom-color: var(--accent);
}

.explain-btn:hover + .explain-tooltip,
.explain-tooltip.open {
    display: block;
}

/* Color classes */
.loss-good { color: var(--green); }
.loss-warn { color: var(--yellow); }
.loss-bad { color: var(--red); }

/* Progress bar */
.progress-container {
    background: var(--bg-card);
    border-radius: 8px;
    height: 6px;
    overflow: hidden;
    position: relative;
    margin-bottom: 1.5rem;
}

.progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 8px;
    width: 0%;
    transition: width 0.3s ease;
}

.progress-text {
    position: absolute;
    top: 12px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ========== Summary Panel ========== */
.summary-panel {
    margin-top: 2rem;
    border-top: 1px solid var(--border);
    padding-top: 2rem;
}

.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.summary-test-id {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.summary-test-id code {
    color: var(--accent);
    background: var(--bg-card);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.summary-timestamp {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.summary-share-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.summary-share-link a {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.8rem;
}

.summary-share-link a:hover { text-decoration: underline; }

.copy-link-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.7rem;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

.copy-link-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* Top block: quality scores beside identity/share card */
.summary-top {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
    align-items: start;
}

.summary-top .summary-section { margin-bottom: 0; }

.summary-side {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.summary-side .share-image-wrap { margin-top: 0; }
.summary-side .share-image { max-width: 300px; width: 100%; }

/* Detail sections flow through CSS columns instead of one long stack */
.summary-grid {
    columns: 3;
    column-gap: 1rem;
}

.summary-grid .summary-section {
    break-inside: avoid;
    margin-bottom: 1rem;
}

.summary-section {
    background: var(--bg-section);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.summary-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    font-size: 0.8rem;
}

.summary-row:not(:last-child) {
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.summary-label {
    color: var(--text-muted);
}

.summary-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

/* Sparklines */
.sparkline-wrap {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.sparkline {
    width: 100%;
    height: 50px;
    display: block;
}

/* Quality grid */
.quality-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.quality-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    text-align: center;
}

.quality-grade {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 0.25rem;
}

.quality-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.35rem;
}

.quality-verdict {
    font-size: 0.75rem;
    color: var(--text);
    line-height: 1.3;
    margin-bottom: 0.25rem;
}

.quality-score {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Grade colors */
.grade-a { color: var(--green); }
.grade-b { color: #66bb6a; }
.grade-c { color: var(--yellow); }
.grade-d { color: var(--red); }

/* Recent-tests table in the History section */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    margin-top: 0.5rem;
}

.history-table th {
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.65rem;
    font-weight: 600;
    text-align: right;
    padding: 0.3rem 0.4rem;
    border-bottom: 1px solid var(--border);
}

.history-table th:first-child,
.history-table td:first-child { text-align: left; }

.history-table td {
    padding: 0.3rem 0.4rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

/* Shared-result page error box */
.share-error {
    background: rgba(255,82,82,0.10);
    border-left: 3px solid var(--red);
    color: var(--text);
    padding: 0.7rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

/* Footer */
footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 2rem;
}

/* db-ip.com Lite attribution (CC BY 4.0 requires the credit link) */
footer a {
    color: var(--text-faint);
    text-decoration: none;
}

footer a:hover {
    color: var(--text-muted);
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 1000px) {
    .summary-grid { columns: 2; }
    .summary-top { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
    .test-dashboard {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .summary-grid { columns: 1; }
    .quality-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .results-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .quality-grid {
        grid-template-columns: 1fr;
    }

    .gauge-label {
        font-size: 2.25rem;
    }

    .result-value {
        font-size: 1.35rem;
    }

    .container {
        padding: 0 1rem;
    }

    .summary-header {
        flex-direction: column;
        gap: 0.5rem;
    }
}
