/* ============ Design tokens ============ */
:root {
    --bg: #0f172a;
    --bg-soft: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #6366f1;
    --primary-2: #8b5cf6;
    --primary-hover: #4f46e5;
    --danger: #ef4444;
    --success: #10b981;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 10px 30px -12px rgb(15 23 42 / 0.25);
    --shadow-sm: 0 2px 8px -2px rgb(15 23 42 / 0.15);
    --gradient: linear-gradient(135deg, var(--primary), var(--primary-2));
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 100% -10%, rgb(139 92 246 / 0.12), transparent 60%),
        radial-gradient(900px 500px at -10% 0%, rgb(99 102 241 / 0.12), transparent 55%),
        var(--bg-soft);
}

a { color: inherit; text-decoration: none; }

/* ============ Top navigation ============ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgb(255 255 255 / 0.75);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand {
    font-weight: 800;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand .dot {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--gradient);
    box-shadow: var(--shadow-sm);
}

.nav {
    display: flex;
    gap: 4px;
    margin-left: auto;
    flex-wrap: wrap;
}

.nav a {
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    transition: all 0.2s ease;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }

.nav a.active {
    color: white;
    background: var(--gradient);
    box-shadow: var(--shadow-sm);
}

/* ============ Layout ============ */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 24px 64px;
}

.container-narrow {
    max-width: 640px;
    margin: 0 auto;
    padding: 48px 24px 64px;
}

.page-head { margin-bottom: 28px; }

.page-head h1 {
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin: 0 0 4px;
}

.page-head p { margin: 0; color: var(--muted); }

/* ============ Card / surfaces ============ */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px;
}

/* ============ Buttons ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary {
    background: var(--gradient);
    color: white;
    border: none;
}

.btn-block { width: 100%; }

/* ============ Forms ============ */
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }

.label { font-weight: 600; font-size: 0.9rem; }

.select, .input {
    padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
    transition: all 0.2s ease;
    width: 100%;
}

.select:focus, .input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgb(99 102 241 / 0.12);
}

.hint { font-size: 0.82rem; color: var(--muted); }

/* Dropzone */
.dropzone {
    padding: 44px 20px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    transition: all 0.25s ease;
    background: var(--surface-2);
    margin-bottom: 22px;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgb(99 102 241 / 0.06);
}

.dropzone .icon { font-size: 2rem; }
.dropzone p { margin: 8px 0 0; color: var(--muted); }

/* Progress */
.progress {
    display: none;
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-bar {
    width: 0%;
    height: 100%;
    background: var(--gradient);
    transition: width 0.3s ease;
}

.status { color: var(--muted); font-size: 0.92rem; text-align: center; min-height: 1.2em; }

/* ============ Media grid ============ */
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
}

.card:hover { transform: translateY(-4px); box-shadow: var(--shadow); }

.card .thumb {
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: var(--surface-2);
    display: block;
}

.card-body { padding: 14px 16px; }

.card-title {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta { font-size: 0.82rem; color: var(--muted); }

.card .download-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgb(15 23 42 / 0.72);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease;
    backdrop-filter: blur(4px);
}

.card:hover .download-btn { opacity: 1; }

.overlay {
    position: absolute;
    inset: 0;
    background: rgb(15 23 42 / 0.55);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    backdrop-filter: blur(2px);
}

.empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--muted);
    padding: 60px 0;
}

/* ============ Toolbar / search ============ */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 28px;
}

.toolbar .search {
    display: flex;
    gap: 8px;
    flex: 1;
    min-width: 220px;
}

/* ============ Pagination ============ */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 36px;
    padding: 0;
    list-style: none;
}

.pagination button {
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--gradient); color: white; border: none; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============ Result list ============ */
.result-list { list-style: none; padding: 0; margin: 16px 0 0; font-size: 0.85rem; color: var(--muted); }
.result-list li { padding: 8px 12px; background: var(--surface-2); border-radius: var(--radius-sm); margin-bottom: 6px; word-break: break-all; }

/* Preview grid (upload) */
.preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.preview-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface-2);
}

.preview-item img { width: 100%; height: 110px; object-fit: cover; display: block; }
.preview-item .preview-name { font-size: 0.72rem; color: var(--muted); padding: 6px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 640px) {
    .container, .container-narrow { padding: 28px 16px 48px; }
    .panel { padding: 22px; }
    .topbar-inner { padding: 12px 16px; }
    .nav a { padding: 6px 10px; }
}
