*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #0c0c0c;
    --bg-raised: #141414;
    --bg-hover: #1a1a1a;
    --border: #222;
    --border-light: #2a2a2a;
    --text: #e8e8e8;
    --text-muted: #888;
    --text-dim: #555;
    --accent: #c8c8c8;
    --accent-neon: #bc13fe;
    --accent-hover: #fff;
    --radius: 6px;
    --radius-lg: 10px;
    --sidebar-w: 220px;
    --font: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.15s ease;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    background: var(--bg);
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 28px;
}

.brand-icon {
    flex-shrink: 0;
    display: block;
}

.brand-name {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-hover);
    text-shadow: 0 0 12px rgba(188, 19, 254, 0.35);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
    overflow-y: auto;
    padding: 0 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.87rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.nav-item.active {
    background: var(--bg-raised);
    color: var(--accent-hover);
}

.nav-meta {
    font-size: 0.72rem;
    color: var(--text-dim);
    font-weight: 400;
}

.nav-item.active .nav-meta {
    color: var(--text-muted);
}

.sidebar-foot {
    display: none;
}

.sidebar-bottom {
    padding: 12px 10px 0;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 9px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.87rem;
    font-weight: 500;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    text-align: left;
    margin-bottom: 4px;
}

.sidebar-link:hover,
.sidebar-link.active {
    background: var(--bg-hover);
    color: var(--text);
}

.sidebar-link-icon {
    font-size: 0.7rem;
    opacity: 0.5;
}

.sidebar-link-count {
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--text-dim);
}

.sidebar-account {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-top: 4px;
}

.account-name {
    font-size: 0.82rem;
    color: var(--text);
    font-weight: 500;
}

.account-logout {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 0;
}

.account-logout:hover {
    color: var(--text-muted);
}

/* Main */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 32px 40px 60px;
    max-width: 1400px;
}

.header {
    margin-bottom: 16px;
}

.search-form {
    max-width: 640px;
}

.search-field {
    display: flex;
    align-items: center;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition);
    overflow: hidden;
}

.search-field:focus-within {
    border-color: var(--border-light);
}

.search-input {
    flex: 1;
    padding: 10px 14px;
    background: transparent;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.93rem;
    outline: none;
}

.search-input::placeholder {
    color: var(--text-dim);
}

.search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: 3px;
    padding: 0;
    background: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}

.search-btn:hover {
    color: var(--text);
    background: var(--bg-hover);
}

.search-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Recent search */
.recent-section {
    margin-bottom: 24px;
}

.recent-label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* Tags */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-wrap {
    position: relative;
    display: inline-flex;
}

.tag-wrap:hover .tag-remove {
    opacity: 1;
}

.tag {
    padding: 5px 12px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition);
}

.tag:hover {
    border-color: var(--border-light);
    color: var(--text);
}

.tag-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-raised);
    color: var(--text-muted);
    font-size: 0.65rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.tag-remove:hover {
    color: var(--text);
    border-color: var(--border-light);
}

/* Status */
.status {
    margin-bottom: 20px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Empty */
.empty {
    padding: 80px 0;
    text-align: center;
}

.empty-title {
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.empty-desc {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.7;
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.grid--banner {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.grid--icon {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.card {
    position: relative;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--transition);
    aspect-ratio: 1;
}

.card--wide {
    aspect-ratio: 16 / 9;
}

.card--small {
    aspect-ratio: 1;
}

.card:hover {
    border-color: var(--border-light);
}

.card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-save {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition), color var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.card:hover .card-save {
    opacity: 1;
}

.card-save.saved {
    opacity: 1;
    color: var(--accent-hover);
}

.card-save:hover {
    color: var(--text);
}

.view-header {
    margin-bottom: 24px;
}

.view-title {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.view-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
}

/* Auth */
.auth-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 24px;
}

.auth-top-brand {
    position: absolute;
    top: 24px;
    left: 0;
    padding: 0 20px;
}

.auth-overlay[hidden] {
    display: none;
}

.auth-card {
    width: 100%;
    max-width: 360px;
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--bg-raised);
}

.auth-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-bottom: 24px;
    line-height: 1.6;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 8px 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: -1px;
    transition: color var(--transition), border-color var(--transition);
}

.auth-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent-hover);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-form[hidden] {
    display: none;
}

.auth-inline {
    display: flex;
    gap: 8px;
}

.auth-inline .auth-input {
    flex: 1;
}

.auth-input {
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.88rem;
    outline: none;
}

.auth-send-code {
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}

.auth-send-code:hover {
    border-color: var(--border-light);
}

#turnstileWidget {
    margin-top: 6px;
}

.auth-input:focus {
    border-color: var(--border-light);
}

.auth-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid #3a3a3a;
    border-radius: 7px;
    background: #1a1a1a;
    color: #f1f1f1;
    font-size: 0.8rem;
    line-height: 1.4;
}

.auth-error::before {
    content: '!';
    width: 16px;
    height: 16px;
    border-radius: 3px;
    background: #ff8a00;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
    flex-shrink: 0;
}

.auth-error[hidden] {
    display: none;
}

.auth-submit {
    margin-top: 4px;
    padding: 10px;
    background: var(--accent-hover);
    color: var(--bg);
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity var(--transition);
}

.auth-submit:hover {
    opacity: 0.88;
}

.card-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 7px;
    background: rgba(0, 0, 0, 0.65);
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.card-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 10px 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0;
    transition: opacity var(--transition);
}

.card:hover .card-label {
    opacity: 1;
}

/* Loading skeleton */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.skeleton {
    aspect-ratio: 1;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
}

.modal-panel {
    position: relative;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    max-width: 720px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    z-index: 2;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text);
}

.modal-preview {
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    max-height: 55vh;
    overflow: hidden;
}

.modal-preview img {
    max-width: 100%;
    max-height: 55vh;
    object-fit: contain;
}

.modal-info {
    padding: 20px 24px 24px;
}

.modal-title {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 16px;
    color: var(--text);
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.btn {
    padding: 8px 16px;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: opacity var(--transition);
}

.btn:hover {
    opacity: 0.85;
}

.btn-primary {
    background: var(--accent-hover);
    color: var(--bg);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.modal-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: static;
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 16px 0;
    }

    .layout {
        flex-direction: column;
    }

    .main {
        margin-left: 0;
        padding: 20px 16px 40px;
    }

    .nav {
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 0 12px;
        gap: 4px;
    }

    .nav-item {
        flex-shrink: 0;
        white-space: nowrap;
    }

    .nav-meta {
        display: none;
    }

    .sidebar-bottom {
        display: none;
    }

    .grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}
