/* ============================================
   SpeedTest Pro — GTMetrix-style Speed Analyzer
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f111a;
    --bg-card: #1a1d2e;
    --bg-card-hover: #222640;
    --border: #2a2e42;
    --text: #e2e8f0;
    --text-muted: #8892b0;
    --primary: #4F46E5;
    --primary-light: #6366F1;
    --green: #22C55E;
    --green-bg: rgba(34,197,94,.12);
    --orange: #F59E0B;
    --orange-bg: rgba(245,158,11,.12);
    --red: #EF4444;
    --red-bg: rgba(239,68,68,.12);
    --ring-bg: #2a2e42;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,.35);
    --transition: .25s ease;
}

html { scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 24px; width: 100%; }

.hidden { display: none !important; }

/* --- Header --- */
.header {
    background: rgba(15,17,26,.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.logo-highlight { color: var(--primary-light); }

.nav { display: flex; gap: 24px; }

.nav-link {
    color: var(--text-muted);
    font-size: .875rem;
    font-weight: 500;
    transition: color var(--transition);
}

.nav-link:hover, .nav-link.active {
    color: var(--text);
    text-decoration: none;
}

/* --- Hero --- */
.hero {
    padding: 100px 0 80px;
    text-align: center;
    background: radial-gradient(ellipse at 50% 0%, rgba(79,70,229,.15) 0%, transparent 60%);
}

.hero-title {
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #e2e8f0, #a5b4fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero-subtitle {
    color: var(--text-muted);
    font-size: 1.125rem;
    max-width: 520px;
    margin: 0 auto 40px;
}

/* --- Search Form --- */
.search-form { max-width: 640px; margin: 0 auto; }

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 60px;
    padding: 6px 6px 6px 20px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,.25);
}

.input-icon { color: var(--text-muted); flex-shrink: 0; }

.url-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 1rem;
    padding: 12px 12px;
    font-family: inherit;
}

.url-input::placeholder { color: var(--text-muted); }

.btn-analyze {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 12px 28px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.btn-analyze:hover { background: var(--primary-light); transform: translateY(-1px); }
.btn-analyze:active { transform: scale(.97); }
.btn-analyze:disabled { opacity: .6; cursor: not-allowed; transform: none; }

.input-hint {
    margin-top: 12px;
    font-size: .8rem;
    color: var(--text-muted);
}

.api-key-section {
    margin-top: 16px;
    text-align: left;
}

.api-key-toggle {
    font-size: .82rem;
    color: var(--primary-light);
    cursor: pointer;
    list-style: none;
    text-align: center;
}

.api-key-toggle::-webkit-details-marker { display: none; }

.api-key-toggle::before {
    content: '\25B6  ';
    font-size: .65rem;
    transition: transform var(--transition);
    display: inline-block;
}

details[open] .api-key-toggle::before {
    transform: rotate(90deg);
}

.api-key-inner {
    margin-top: 10px;
}

.api-key-input {
    width: 100%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: .875rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition);
}

.api-key-input:focus {
    border-color: var(--primary);
}

.api-key-input::placeholder { color: var(--text-muted); }

.api-key-help {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 8px;
    line-height: 1.5;
}

/* --- Loading --- */
.loading-section { padding: 80px 0; }

.loading-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    box-shadow: var(--shadow);
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    margin: 0 auto 24px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.loading-title span { color: var(--primary-light); word-break: break-all; }

.loading-subtitle {
    color: var(--text-muted);
    font-size: .9rem;
    margin-bottom: 24px;
}

.progress-bar-track {
    height: 4px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 32px;
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 4px;
    transition: width .4s ease;
}

.loading-steps {
    display: flex;
    justify-content: center;
    gap: 32px;
    flex-wrap: wrap;
}

.step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .85rem;
    color: var(--text-muted);
    transition: color var(--transition);
}

.step.active { color: var(--primary-light); }
.step.done { color: var(--green); }

.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: background var(--transition);
}

.step.active .step-dot { background: var(--primary-light); box-shadow: 0 0 6px var(--primary); }
.step.done .step-dot { background: var(--green); }

/* --- Error --- */
.error-section { padding: 80px 0; }

.error-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    box-shadow: var(--shadow);
}

.error-card h2 {
    font-size: 1.5rem;
    margin: 16px 0 8px;
    color: var(--red);
}

.error-card p {
    color: var(--text-muted);
    margin-bottom: 24px;
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
}

.btn-retry {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 12px 32px;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition);
}

.btn-retry:hover { background: var(--primary-light); }

/* --- Results Header --- */
.results-section { padding: 50px 0 80px; }

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 32px;
}

.results-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.results-url {
    display: block;
    font-size: .9rem;
    color: var(--primary-light);
    margin-top: 4px;
    word-break: break-all;
}

.results-date {
    display: block;
    font-size: .78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.btn-retest {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 10px 22px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition), border-color var(--transition);
}

.btn-retest:hover { background: var(--bg-card-hover); border-color: var(--primary); }

/* --- Score Grid --- */
.score-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 40px;
}

.score-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 20px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: border-color var(--transition);
}

.score-card:hover { border-color: var(--primary); }

.score-label {
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 16px;
}

.score-ring-container {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 0 auto 12px;
}

.score-ring-container.small {
    width: 90px;
    height: 90px;
}

.score-ring {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.score-ring-bg { stroke: var(--ring-bg); }

.score-ring-fill {
    stroke: var(--green);
    stroke-linecap: round;
    transition: stroke-dashoffset 1.2s ease, stroke .4s ease;
}

.score-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.75rem;
    font-weight: 800;
}

.score-ring-container.small .score-value { font-size: 1.35rem; }

.score-grade {
    display: inline-block;
    font-size: .8rem;
    font-weight: 700;
    padding: 4px 14px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* --- Section Blocks --- */
.section-block {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.section-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
}

.section-title.collapsible {
    cursor: pointer;
    user-select: none;
}

.section-title .chevron {
    margin-left: auto;
    transition: transform var(--transition);
}

.section-title.collapsible.open .chevron { transform: rotate(180deg); }

.passed-count {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--border);
    padding: 2px 10px;
    border-radius: 20px;
}

/* --- Metrics Grid --- */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.metric-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 20px;
    transition: border-color var(--transition);
}

.metric-card:hover { border-color: var(--primary); }

.metric-name {
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .4px;
    margin-bottom: 8px;
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 800;
}

.metric-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 10px;
    overflow: hidden;
}

.metric-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 1s ease;
}

/* --- Audit Items --- */
.audit-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
}

.audit-item:last-child { border-bottom: none; }

.audit-icon {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.audit-icon.fail { background: var(--red-bg); color: var(--red); }
.audit-icon.warn { background: var(--orange-bg); color: var(--orange); }
.audit-icon.pass { background: var(--green-bg); color: var(--green); }

.audit-icon svg { width: 12px; height: 12px; }

.audit-content { flex: 1; min-width: 0; }

.audit-title {
    font-size: .9rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.audit-description {
    font-size: .8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.audit-savings {
    flex-shrink: 0;
    font-size: .8rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.collapsed { max-height: 0; overflow: hidden; transition: max-height .4s ease; }
.collapsed.open { max-height: 5000px; }

/* --- Screenshot --- */
.screenshot-wrapper {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fff;
}

.screenshot-img {
    width: 100%;
    display: block;
}

/* --- Footer --- */
.footer {
    margin-top: auto;
    padding: 24px 0;
    text-align: center;
    font-size: .8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

/* --- Color Utilities --- */
.color-green { color: var(--green) !important; }
.color-orange { color: var(--orange) !important; }
.color-red { color: var(--red) !important; }
.bg-green { background: var(--green-bg); }
.bg-orange { background: var(--orange-bg); }
.bg-red { background: var(--red-bg); }
.fill-green { background: var(--green); }
.fill-orange { background: var(--orange); }
.fill-red { background: var(--red); }

/* --- Responsive --- */
@media (max-width: 768px) {
    .score-grid {
        grid-template-columns: 1fr 1fr;
    }
    .score-card.main-score {
        grid-column: 1 / -1;
    }
    .hero { padding: 60px 0 50px; }
    .loading-steps { gap: 16px; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .results-header { flex-direction: column; }
}

@media (max-width: 480px) {
    .score-grid { grid-template-columns: 1fr; }
    .metrics-grid { grid-template-columns: 1fr; }
    .btn-analyze { padding: 12px 20px; }
    .loading-steps { flex-direction: column; align-items: center; }
}
