/* ─── Site Header ─── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg-header);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border-default);
}

.top-bar {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--header-height);
    padding: 0 24px;
    max-width: 1600px;
    margin: 0 auto;
}

.site-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.site-logo {
    height: 28px;
    width: 28px;
    display: block;
    border-radius: 6px;
    transition: opacity 0.15s var(--ease);
}

.site-brand:hover .site-logo {
    opacity: 0.8;
}

/* Keep the dark logo tile visible against the dark header */
:root[data-theme="dark"] .site-logo {
    box-shadow: 0 0 0 1px var(--border-default);
}

.top-bar-right {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: auto;
    flex-shrink: 0;
}

.theme-icon-dark {
    display: none;
}

.btn-upload {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 14px;
    margin-left: 8px;
    font-size: 13px;
    font-weight: 600;
}

/* ─── Category Navigation ─── */
.category-nav {
    flex: 1;
    min-width: 0;
}

.category-scroller {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.category-scroller::-webkit-scrollbar {
    display: none;
}

.category-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 14px 0 7px;
    border: 1px solid var(--border-default);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
}

.category-btn .tag-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.category-btn:hover:not(.active) {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.category-btn.active {
    background: var(--chip-active);
    border-color: var(--chip-active);
    color: #fff;
}

/* Fade the edges so chips scrolled out of view don't cut off abruptly */
.category-scroller {
    padding: 0 24px 0 12px;
    -webkit-mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(to right, transparent, #000 12px, #000 calc(100% - 24px), transparent);
}

/* ─── Subcategory Bar ─── */
.subcategory-bar {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px 10px;
}

.subcategory-buttons {
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-hover);
    border-radius: var(--radius-md);
}

.subcategory-btn {
    height: 28px;
    padding: 0 14px;
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
}

.subcategory-btn:hover:not(.active) {
    color: var(--text-primary);
}

.subcategory-btn.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

:root[data-theme="dark"] .subcategory-btn.active {
    background: var(--bg-muted);
}

/* ─── Dropdown Menus ─── */
.user-dropdown,
.more-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 24px;
    min-width: 220px;
    padding: 4px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    animation: dropIn 0.14s var(--ease);
}

.user-menu-btn.active ~ .user-dropdown,
.more-dropdown.open {
    display: block;
}

.user-menu-btn.active,
.more-menu-btn.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.user-email-btn,
.logout-btn,
.more-dropdown-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.user-email-btn {
    flex-direction: column;
    align-items: flex-start;
    color: var(--text-secondary);
    font-weight: 400;
    word-break: break-all;
}

.user-email-btn::before {
    content: 'My uploads';
    color: var(--text-primary);
    font-weight: 500;
}

.user-email-btn:hover,
.logout-btn:hover,
.more-dropdown-item:hover {
    background: var(--bg-hover);
}

.logout-btn,
.more-dropdown-logout {
    color: var(--danger);
}

.more-dropdown-divider {
    height: 1px;
    margin: 4px -4px;
    background: var(--border-default);
}

.more-dropdown-email {
    display: block;
    padding: 8px 10px 4px;
    font-size: 12px;
    color: var(--text-muted);
    word-break: break-all;
}

.theme-label-dark {
    display: none;
}

:root[data-theme="dark"] .theme-label-light {
    display: none;
}

:root[data-theme="dark"] .theme-label-dark {
    display: inline;
}

/* On desktop, account and theme have dedicated buttons in the header */
@media (min-width: 641px) {
    .more-dropdown-account,
    .more-dropdown-theme {
        display: none !important;
    }
}

/* ─── Modals ─── */
.upload-overlay,
.patchnotes-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: var(--overlay);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    animation: fadeIn 0.15s ease;
}

.patchnotes-overlay {
    z-index: 200;
}

.upload-modal,
.patchnotes-modal {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    padding: 24px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.2s var(--ease);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -4px 0 16px;
}

.upload-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.modal-close-btn,
.patchnotes-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    margin-right: -6px;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
}

.modal-close-btn:hover,
.patchnotes-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ─── Upload: Dropzone ─── */
.file-input-wrapper {
    position: relative;
    width: 100%;
}

input[type="file"] {
    display: none;
}

.file-input-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 180px;
    padding: 28px 24px;
    border: 1px dashed var(--border-default);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.file-input-label:hover,
.file-input-label.dragover {
    border-color: var(--accent);
    background: var(--accent-subtle);
}

.upload-icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-bottom: 6px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

.file-input-label p {
    color: var(--text-secondary);
    font-size: 14px;
}

.file-input-link {
    color: var(--text-primary);
    font-weight: 600;
}

.file-input-label small {
    color: var(--text-muted);
    font-size: 12px;
}

.file-preview {
    max-width: 100%;
    max-height: 220px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    object-fit: contain;
}

.file-input-label.has-file {
    border-style: solid;
    padding: 16px;
}

.file-input-label.has-file .upload-icon-wrap,
.file-input-label.has-file p,
.file-input-label.has-file small {
    display: none;
}

#fileName {
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
    margin-top: 6px;
    word-break: break-all;
}

#fileName:empty {
    display: none;
}

/* ─── Upload: Options ─── */
.upload-options {
    display: flex;
    flex-direction: column;
    margin-top: 16px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
}

.upload-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    cursor: pointer;
    user-select: none;
}

.upload-option + .upload-option {
    border-top: 1px solid var(--border-default);
}

.upload-option-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.upload-option-info svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.upload-option-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
}

.upload-option-desc {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.3;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--bg-muted);
    border-radius: 999px;
    transition: background 0.2s var(--ease);
    flex-shrink: 0;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s var(--ease);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

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

.toggle-input:checked + .toggle-slider::after {
    transform: translateX(16px);
}

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

.button-group {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

#uploadBtn {
    min-width: 110px;
}

/* ─── Status ─── */
.status {
    display: none;
    padding: 10px 12px;
    margin-bottom: 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
}

.status.show { display: block; }

.status.success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.status.error {
    background: rgba(239, 68, 68, 0.08);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.status.loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    opacity: 0.97;
}

.status.loading::before {
    content: '';
    width: 22px;
    height: 22px;
    border: 2px solid var(--border-default);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ─── Patch Notes Modal ─── */
.patchnotes-modal {
    padding: 28px;
    max-width: 440px;
}

.patchnotes-close {
    position: absolute;
    top: 16px;
    right: 22px;
    font-size: 20px;
    line-height: 1;
}

.patchnotes-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.patchnotes-version {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.patchnotes-subtitle {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 10px;
}

.patchnotes-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}

.patchnotes-list li {
    position: relative;
    padding-left: 18px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.patchnotes-list li::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 8px;
    width: 5px;
    height: 5px;
    background: var(--text-muted);
    border-radius: 50%;
}

.patchnotes-ack {
    width: 100%;
}

/* ─── Mobile ─── */
@media (max-width: 640px) {
    :root {
        --header-height: 56px;
    }

    .top-bar {
        gap: 4px;
        padding: 0 8px 0 16px;
    }

    .user-menu-btn,
    .theme-toggle-btn {
        display: none;
    }

    .category-nav {
        margin-left: 0;
    }

    /* Phones: emoji only, label on the selected chip */
    .category-btn {
        height: 34px;
        gap: 6px;
        padding: 0 6px;
    }

    .category-btn:not(.active) .category-label {
        display: none;
    }

    .category-btn.active {
        padding-right: 12px;
    }

    .category-btn .tag-icon {
        width: 20px;
        height: 20px;
    }

    .subcategory-bar {
        padding: 0 16px 10px;
    }

    .btn-upload {
        width: 40px;
        height: 40px;
        padding: 0;
        margin-left: 4px;
        justify-content: center;
    }

    .btn-upload-text {
        display: none;
    }

    .user-dropdown,
    .more-dropdown {
        right: 8px;
    }

    .upload-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .upload-modal {
        max-width: none;
        max-height: 92dvh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: none;
        padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
    }

    .file-input-label {
        min-height: 150px;
    }

    .button-group button {
        flex: 1;
    }
}
