:root {
    color-scheme: light;
    --background: #f7f9fc;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --text: #18202c;
    --text-secondary: #5b6575;
    --muted: #7b8595;
    --border: #d8dee8;
    --border-strong: #b7c3d4;
    --primary: #215fdb;
    --primary-hover: #184fb9;
    --primary-soft: rgba(33, 95, 219, 0.12);
    --accent: #0f9f8f;
    --danger: #ba1a1a;
    --shadow: 0 20px 60px rgba(28, 43, 67, 0.14);
    --shadow-soft: 0 10px 28px rgba(28, 43, 67, 0.10);
    --focus: 0 0 0 4px rgba(33, 95, 219, 0.18);
}

[data-theme="dark"] {
    color-scheme: dark;
    --background: #141922;
    --surface: #1d2430;
    --surface-raised: #252d3a;
    --text: #e8edf5;
    --text-secondary: #b4bece;
    --muted: #8994a6;
    --border: #394455;
    --border-strong: #506075;
    --primary: #79a7ff;
    --primary-hover: #a8c5ff;
    --primary-soft: rgba(121, 167, 255, 0.16);
    --accent: #64d8cb;
    --danger: #ffb4ab;
    --shadow: 0 22px 70px rgba(0, 0, 0, 0.36);
    --shadow-soft: 0 12px 34px rgba(0, 0, 0, 0.28);
    --focus: 0 0 0 4px rgba(121, 167, 255, 0.24);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at top left, var(--primary-soft), transparent 34rem),
        var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
textarea {
    font: inherit;
}

button,
a,
input,
textarea {
    outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
    box-shadow: var(--focus);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem clamp(1rem, 3vw, 2rem);
}

.site-header-compact {
    position: sticky;
    top: 0;
    z-index: 20;
    background: color-mix(in srgb, var(--background) 88%, transparent);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.brand-link {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    color: var(--text);
    font-weight: 800;
}

.brand-logo {
    width: 116px;
    height: auto;
    display: block;
}

.site-header-compact .brand-logo {
    width: 92px;
}

.brand-name {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.top-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    min-width: max-content;
}

.theme-toggle,
.sign-in-button,
.primary-button,
.secondary-button,
.tab-link,
.legacy-button {
    min-height: 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.theme-toggle:hover,
.sign-in-button:hover,
.secondary-button:hover,
.tab-link:hover,
.legacy-button:hover {
    border-color: var(--border-strong);
    background: var(--surface-raised);
    text-decoration: none;
    transform: translateY(-1px);
}

.primary-button {
    border-color: var(--primary);
    background: var(--primary);
    color: var(--background);
    font-weight: 700;
}

.primary-button:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.account-shell {
    position: relative;
}

.avatar-button {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--background);
    cursor: pointer;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}

.account-card {
    position: absolute;
    right: 0;
    top: calc(100% + 0.75rem);
    width: min(340px, calc(100vw - 2rem));
    padding: 1.1rem;
    border-radius: 1.35rem;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    box-shadow: var(--shadow);
    z-index: 30;
}

.account-summary {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.account-avatar-large {
    width: 74px;
    height: 74px;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--background);
    display: grid;
    place-items: center;
    font-size: 2rem;
    font-weight: 800;
}

.account-name,
.account-email,
.account-username {
    margin: 0;
}

.account-name {
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 800;
}

.account-email,
.account-username {
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.account-actions {
    display: grid;
    gap: 0.35rem;
    padding-top: 0.85rem;
}

.account-actions a {
    border-radius: 0.8rem;
    color: var(--text);
    padding: 0.75rem 0.8rem;
}

.account-actions a:hover,
.account-actions a:focus-visible {
    background: var(--primary-soft);
    text-decoration: none;
}

.home-main {
    min-height: calc(100vh - 142px);
    display: grid;
    place-items: center;
    padding: 1rem;
}

.home-search-card {
    width: min(680px, 100%);
    text-align: center;
}

.home-logo {
    width: min(260px, 72vw);
    height: auto;
    margin-bottom: 2rem;
}

.search-form-large {
    display: grid;
    gap: 1rem;
}

.search-box,
.header-search-form {
    width: 100%;
}

.search-input,
.form-control,
.textarea-control {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    min-height: 52px;
    padding: 0.85rem 1.15rem;
    box-shadow: var(--shadow-soft);
}

.search-input::placeholder,
.form-control::placeholder,
.textarea-control::placeholder {
    color: var(--muted);
}

.search-input:focus,
.form-control:focus,
.textarea-control:focus {
    border-color: var(--primary);
    box-shadow: var(--focus), var(--shadow-soft);
}

.textarea-control {
    border-radius: 1rem;
    min-height: 180px;
    resize: vertical;
}

.home-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.header-search-form {
    max-width: 720px;
    flex: 1;
}

.results-main,
.content-main {
    width: min(1040px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1.5rem 0 3rem;
}

.search-tabs {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1.5rem;
    overflow-x: auto;
    padding-bottom: 0.35rem;
}

.tab-link {
    color: var(--text-secondary);
}

.tab-link-active {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 800;
}

.results-heading {
    margin: 0 0 1.5rem;
    color: var(--text-secondary);
    font-size: 0.98rem;
    font-weight: 500;
}

.result-list,
.video-list {
    display: grid;
    gap: 1.35rem;
}

.result-item,
.video-item,
.content-card,
.indexer-card {
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    border: 1px solid var(--border);
    border-radius: 1.1rem;
    padding: 1.1rem;
    box-shadow: var(--shadow-soft);
}

.result-url {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.result-title {
    margin: 0 0 0.45rem;
    font-size: clamp(1.18rem, 2vw, 1.45rem);
}

.result-snippet,
.muted-text {
    color: var(--text-secondary);
    line-height: 1.6;
}

.empty-state,
.error-state {
    border: 1px dashed var(--border-strong);
    border-radius: 1.1rem;
    color: var(--text-secondary);
    padding: 1.25rem;
    background: var(--surface);
}

.error-state {
    border-color: var(--danger);
    color: var(--danger);
}

.video-item {
    display: grid;
    grid-template-columns: 168px 1fr;
    gap: 1rem;
    align-items: start;
}

.video-thumb {
    width: 168px;
    aspect-ratio: 16 / 9;
    border-radius: 0.8rem;
    object-fit: cover;
    background: var(--surface);
}

.site-footer {
    display: flex;
    justify-content: center;
    gap: 1rem;
    padding: 1rem;
    color: var(--text-secondary);
}

.indexer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.stack-form {
    display: grid;
    gap: 0.9rem;
}

.field-label {
    color: var(--text-secondary);
    display: grid;
    gap: 0.35rem;
    font-weight: 700;
}

.status-message {
    border-radius: 0.9rem;
    padding: 0.85rem 1rem;
    background: var(--primary-soft);
    color: var(--text);
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.experiments-auth-card {
    max-width: 680px;
}

.experiments-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.85rem;
    margin-top: 1.25rem;
}

.experiment-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: 82px;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--surface);
    color: var(--text);
    padding: 1rem;
    box-shadow: var(--shadow-soft);
    font-weight: 800;
}

.experiment-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    text-decoration: none;
}

.experiment-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 0.85rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: var(--background);
}

@media (max-width: 760px) {
    .site-header,
    .site-header-compact {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .top-actions {
        margin-left: auto;
    }

    .header-search-form {
        order: 3;
        flex-basis: 100%;
        max-width: none;
    }

    .home-main {
        min-height: calc(100vh - 170px);
    }

    .video-item {
        grid-template-columns: 1fr;
    }

    .video-thumb {
        width: 100%;
    }
}
