:root {
    --bg-primary: light-dark(#fafafa, #0a0a0a);
    --text-primary: light-dark(#1a1a1a, #e0e0e0);
    --text-secondary: light-dark(#666666, #a0a0a0);
    --text-tertiary: light-dark(#999999, #666666);
    --border: light-dark(#e0e0e0, rgba(255, 255, 255, 0.08));
    --border-light: light-dark(#eeeeee, rgba(255, 255, 255, 0.04));
    --accent: light-dark(#000000, #ffffff);
    --accent-hover: light-dark(#333333, #e0e0e0);
    --accent-light: light-dark(rgba(0, 0, 0, 0.04), rgba(255, 255, 255, 0.04));
    --filter-border: light-dark(rgba(0, 0, 0, 0.12), rgba(255, 255, 255, 0.12));
    --filter-bg-any: light-dark(rgba(0, 0, 0, 0.02), rgba(255, 255, 255, 0.02));
    --success: light-dark(#000000, #000000);
    --error: light-dark(#c0392b, #ff6b6b);
    --warning: light-dark(#ff8c00, #ffb84d);
    --badge-border: light-dark(rgba(0, 0, 0, 0.12), rgba(255, 255, 255, 0.12));

    --space-xs: 0.25rem;
    --space-sm: 0.375rem;
    --space-md: 0.75rem;
    --space-lg: 1rem;
    --space-xl: 1.5rem;

    --font-size-xs: 0.7rem;
    --font-size-sm: 0.75rem;
    --font-size-base-sm: 0.8125rem;
    --font-size-base: 0.875rem;
    --font-size-base-lg: 0.9375rem;
    --font-size-md: 0.9rem;
    --font-size-lg: 1em;
    --font-size-xl: 1.15em;
    --font-size-2xl: 1.2em;
    --font-size-3xl: 1.25em;
    --font-size-4xl: 1.4em;
    --font-size-5xl: 1.5em;

    --font-family-mono: 'SF Mono', 'Monaco', monospace;
}

[data-theme="dark"] {
    color-scheme: dark;
}

[data-theme="light"] {
    color-scheme: light;
}

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

body {
    font-family: var(--font-family-mono);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 15px;
}

.hidden {
    display: none !important;
}

.infinite-scroll-sentinel {
    width: 100%;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.no-scroll {
    overflow: hidden !important;
}

/* ============================================================================
   Buttons & Icons
   ============================================================================ */

.icon-btn {
    background: transparent;
    border: 1px solid transparent;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;

    &:hover {
        background: var(--bg-primary);
        color: var(--text-primary);
        border-color: var(--border);
    }

    svg {
        width: 16px;
        height: 16px;
    }
}

[data-theme="dark"] .sun-icon {
    display: none;
}

[data-theme="light"] .moon-icon {
    display: none;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) .sun-icon {
        display: none;
    }
}

:root:not([data-theme]) .moon-icon {
    display: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: var(--space-md) var(--space-xl);
    border: 1px solid var(--border);
    font-size: var(--font-size-base);
    font-weight: 500;
    font-family: var(--font-family-mono);
    cursor: pointer;

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    &.btn-primary {
        background: var(--accent);
        color: var(--bg-primary);
        border-color: var(--accent);

        &:hover:not(:disabled) {
            background: var(--accent-hover);
            border-color: var(--accent-hover);
        }
    }

    &.btn-secondary {
        background: transparent;
        color: var(--text-primary);
        border-color: var(--border);

        &:hover:not(:disabled) {
            background: var(--accent-light);
        }
    }

    &.btn-danger {
        background-color: var(--error);
        color: var(--bg-primary);
        border-color: var(--error);

        &:hover:not(:disabled) {
            background-color: #a93226;
            border-color: #a93226;
        }
    }
}


/* ============================================================================
   Input Fields
   ============================================================================ */

input[type="text"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea,
select {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.8125rem;
    font-family: var(--font-family-mono);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    outline: none;

    &:focus {
        border-color: var(--accent);
        background: var(--bg-primary);
    }
}

:is(input[type="text"], input[type="number"], input[type="url"], textarea)::placeholder {
    color: var(--text-tertiary);
}

/* ============================================================================
   Custom Select
   ============================================================================ */

.custom-select-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.custom-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 4px 8px;
    padding-right: 24px;
    font-size: var(--font-size-sm);
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease;
    font-family: var(--font-family-mono);
    line-height: 1.5;
    border-radius: 0;
    /* Reset default border radius */

    &:hover {
        background: var(--bg-primary);
        border-color: var(--border-light);
    }

    &:focus {
        outline: none;
        border-color: var(--accent);
        background: var(--bg-primary);
    }
}

.custom-select-icon {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;

    svg {
        width: 100%;
        height: 100%;
    }
}



/* ============================================================================
   Toggle Switches
   ============================================================================ */

.toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    width: 40px;
    height: 20px;
    cursor: pointer;
}

.toggle-input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    margin: 0;
    cursor: pointer;
    z-index: 2;

    &:focus+.toggle-slider {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    &:checked+.toggle-slider {
        background: var(--accent);

        &::after {
            transform: translateX(20px);
        }
    }
}

.toggle-slider {
    position: relative;
    display: inline-block;
    width: 100%;
    height: 100%;
    background: var(--border);
    border-radius: 10px;
    pointer-events: none;
    transition: background-color 0.15s ease;

    &::after {
        content: '';
        position: absolute;
        left: 2px;
        top: 2px;
        width: 16px;
        height: 16px;
        background: var(--bg-primary);
        border-radius: 50%;
        transition: transform 0.15s ease;
    }
}

/* ============================================================================
   Badges
   ============================================================================ */

.badge {
    background: transparent;
    padding: 2px 4px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    display: inline-block;
    border: 1px solid var(--badge-border);
    white-space: nowrap;

    &.summary-language,
    .summary-tags & {
        background: var(--bg-primary);
    }
}

/* ============================================================================
   Scrollbar
   ============================================================================ */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

::-webkit-scrollbar-corner {
    background: var(--bg-primary);
}

/* ============================================================================
   Typography & Content
   ============================================================================ */

.snippet-summary {
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    width: 100%;

    .summary-title {
        font-size: var(--font-size-base-lg);
        font-weight: 600;
        color: var(--text-primary);
        margin: 0;
        line-height: 1.4;
        display: block;
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;

        &.clickable-title {
            display: inline-block;
            width: fit-content;
            max-width: 100%;
            cursor: pointer;
            text-decoration: underline;
            text-decoration-color: transparent;
            text-underline-offset: 3px;

            &:hover {
                text-decoration-color: var(--text-primary);
            }
        }
    }

    .summary-description {
        font-size: var(--font-size-base-sm);
        color: var(--text-secondary);
        margin: 0;
        line-height: 1.5;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .summary-meta {
        display: flex;
        gap: var(--space-xs);
        align-items: center;
        flex-wrap: wrap;
        margin-top: 1px;

        .summary-language {
            color: var(--text-primary);
            font-weight: 500;
        }

        .summary-tags {
            display: flex;
            gap: var(--space-xs);
            flex-wrap: wrap;
            flex: 1;
            align-items: center;
        }
    }
}

.loading-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    min-height: 200px;
    text-align: center;
    color: var(--text-secondary);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--space-md);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.error-state {
    .error-message {
        color: var(--error);
        margin-bottom: var(--space-md);
    }

    .retry-btn {
        margin-top: var(--space-md);
    }
}

.infinite-scroll-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    color: var(--text-secondary);

    .loading-spinner {
        width: 24px;
        height: 24px;
        border-width: 2px;
        margin-bottom: var(--space-sm);
    }

    p {
        margin: 0;
        font-size: var(--font-size-sm);
    }
}