:root {
    color-scheme: light dark;

    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --border: #e1e4e8;
    --text: #15181c;
    --muted: #5d6570;
    --accent: #0d9488;
    --accent-hover: #0f766e;
    --accent-soft: rgba(13, 148, 136, 0.12);
    --on-accent: #ffffff;
    --danger: #dc2626;
    --danger-soft: rgba(220, 38, 38, 0.1);
    --warn: #b45309;
    --warn-soft: rgba(217, 119, 6, 0.12);
    --ok: #15803d;
    --ok-soft: rgba(22, 163, 74, 0.12);
    --info: #1d4ed8;
    --info-soft: rgba(37, 99, 235, 0.1);
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-lg: 0 20px 40px -12px rgba(16, 24, 40, 0.28);

    --radius: 12px;
    --radius-sm: 8px;
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1012;
        --surface: #16191c;
        --surface-2: #1e2226;
        --border: #2a2f35;
        --text: #e7e9ec;
        --muted: #99a1ab;
        --accent: #2dd4bf;
        --accent-hover: #5eead4;
        --accent-soft: rgba(45, 212, 191, 0.12);
        --on-accent: #042f2a;
        --danger: #f87171;
        --danger-soft: rgba(248, 113, 113, 0.12);
        --warn: #fbbf24;
        --warn-soft: rgba(251, 191, 36, 0.12);
        --ok: #4ade80;
        --ok-soft: rgba(74, 222, 128, 0.12);
        --info: #93c5fd;
        --info-soft: rgba(147, 197, 253, 0.12);
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.6);
    }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; line-height: 1.25; }

a { color: inherit; }

svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

[hidden] { display: none !important; }

/* --- Top bar --- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(1.6) blur(12px);
    -webkit-backdrop-filter: saturate(1.6) blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 650;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.brand svg { color: var(--accent); width: 22px; height: 22px; }

.nav { display: flex; gap: 4px; }

.nav a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}

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

.page {
    max-width: 1040px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

/* --- Buttons and inputs --- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 550;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn:disabled { opacity: 0.6; cursor: default; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-primary.btn-sent { background: var(--accent-soft); color: var(--accent); }
.btn-primary.btn-sent:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }

.btn .spinner { display: none; }
.btn.loading .spinner { display: inline-block; }
.btn.loading svg { display: none; }

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

input[type="text"], input[type="search"], input[type="password"], select {
    height: 38px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font: inherit;
    min-width: 0;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, .btn:focus-visible, .segmented button:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

select { padding-right: 8px; cursor: pointer; }

/* --- Search --- */

.search-area { margin-bottom: 20px; }

.search {
    display: flex;
    gap: 8px;
}

.search-hero {
    max-width: 680px;
    margin: 18vh auto 0;
}

.search-pages {
    height: 46px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.browse {
    display: flex;
    margin-top: 10px;
}

.search-hero .browse { justify-content: center; }

.browse select {
    height: 34px;
    font-size: 14px;
    border-radius: 999px;
    padding: 0 12px;
    background: var(--surface-2);
    border-color: transparent;
}

.search-field {
    position: relative;
    flex: 1;
    display: flex;
    min-width: 0;
}

.search-field svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.search-field input {
    width: 100%;
    height: 46px;
    padding-left: 42px;
    font-size: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.search .btn { height: 46px; padding: 0 20px; border-radius: var(--radius); }

.toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.result-count { color: var(--muted); font-weight: 500; }

.toolbar-controls { display: flex; flex-wrap: wrap; gap: 8px; }

.toolbar-controls select { height: 34px; font-size: 14px; }
.toolbar-controls .btn { height: 34px; }

.exclude-field { flex: 0 1 200px; }
.exclude-field input { height: 34px; width: 100%; padding-left: 34px; font-size: 14px; }
.exclude-field svg { left: 11px; width: 16px; height: 16px; }

.results, .downloads {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result {
    display: grid;
    grid-template-columns: 76px 1fr auto;
    gap: 16px;
    align-items: center;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.cover {
    width: 76px;
    height: 76px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.result-body { min-width: 0; }

.result-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.result-genres {
    margin: -4px 0 8px;
    color: var(--muted);
    font-size: 13px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.chip-muted { background: transparent; color: var(--muted); padding: 0 2px; }

.result-actions { display: flex; gap: 8px; }

.empty {
    text-align: center;
    color: var(--muted);
    padding: 48px 0;
}

.banner {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-weight: 500;
}

.banner-error { background: var(--danger-soft); color: var(--danger); }
.banner-ok { background: var(--ok-soft); color: var(--ok); }

/* --- Dialog --- */

.dialog {
    width: min(480px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
    background: rgba(8, 10, 12, 0.5);
    backdrop-filter: blur(2px);
}

.dialog[open] { animation: dialog-in 0.16s ease-out; }

@keyframes dialog-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
}

.dialog-header { padding: 20px 20px 0; }
.dialog-header h2 { font-size: 18px; }

.dialog-subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.dialog-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; }

.suggestion {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px dashed var(--accent);
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-size: 13px;
    font-weight: 550;
    cursor: pointer;
}

.suggestion::before {
    content: "";
    width: 14px;
    height: 14px;
    background: currentColor;
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E") center / contain no-repeat;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.suggestion:hover { border-style: solid; }

.path-preview {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    font-size: 13px;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.path-preview svg { width: 16px; height: 16px; color: var(--accent); }
.path-preview .sep { opacity: 0.5; }
.path-preview .part { color: var(--text); font-weight: 500; }
.path-preview .part.new::after {
    content: "new";
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 4px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 11px;
    font-weight: 600;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 0 20px 20px;
}

/* --- Toasts --- */

.toasts {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: calc(100vw - 32px);
    max-width: 440px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--bg);
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    pointer-events: auto;
    animation: toast-in 0.2s ease-out;
}

.toast a { color: inherit; font-weight: 600; }
.toast-error { background: var(--danger); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: 0.2s; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Downloads page --- */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-header h1 { font-size: 24px; letter-spacing: -0.02em; }

.segmented {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-2);
    border-radius: 10px;
}

.segmented button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 14px;
    font-weight: 550;
    cursor: pointer;
}

.segmented a {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 550;
    text-decoration: none;
}

.segmented a[aria-current="page"],
.segmented button[aria-selected="true"] {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.segmented .count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.download {
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.download-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.download-name {
    font-size: 15px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.progress {
    height: 6px;
    margin: 12px 0 8px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
    transition: width 0.6s ease;
}

.download[data-state="seeding"] .progress-bar,
.download[data-state="complete"] .progress-bar { background: var(--ok); }
.download[data-state="error"] .progress-bar { background: var(--danger); }
.download[data-state="paused"] .progress-bar,
.download[data-state="stalled"] .progress-bar,
.download[data-state="queued"] .progress-bar { background: var(--muted); }

.download-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.download-meta span { display: inline-flex; align-items: center; gap: 4px; }
.download-meta svg { width: 14px; height: 14px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 24px;
    padding: 0 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--muted);
}

.badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }

.badge-live::before { animation: pulse 1.4s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.3; } }

.import {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    font-size: 13px;
}

.import-path {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex: 1;
    color: var(--text);
    font-weight: 500;
    overflow-wrap: anywhere;
}

.import-path svg { width: 16px; height: 16px; color: var(--muted); }

.import-error { flex-basis: 100%; color: var(--danger); }

.import-actions { display: flex; gap: 6px; }

.skeleton {
    height: 92px;
    background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* --- Accounts --- */

.card {
    padding: 20px;
    margin-bottom: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card h1 { font-size: 22px; letter-spacing: -0.02em; margin-bottom: 16px; }
.card h2 { font-size: 17px; margin-bottom: 4px; }

.card-narrow { max-width: 400px; margin: 10vh auto 0; }
.card-highlight { border-color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 14px; max-width: 400px; }
.form .banner { margin: 0; }
.form .btn { align-self: flex-start; }
.card-narrow .form .btn { align-self: stretch; }

.hint { margin: 12px 0; color: var(--muted); font-size: 14px; }
.hint a { color: var(--accent); font-weight: 550; }
.form .hint { margin: 0; }
.hint code { font-size: 13px; }

.muted { color: var(--muted); font-size: 13px; font-weight: 400; }

.row-form { display: flex; gap: 8px; }
.row-form input[type="text"] { flex: 1; }

.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.lines { list-style: none; margin: 8px 0 0; padding: 0; }

.lines li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.line-main { display: flex; flex-direction: column; min-width: 0; }
.line-title { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; overflow-wrap: anywhere; }
.line-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* --- Small screens --- */

@media (max-width: 640px) {
    .search-hero { margin-top: 10vh; }
    .search .btn span:not(.spinner) { display: none; }
    .search .btn::after {
        content: "";
        width: 18px;
        height: 18px;
        background: currentColor;
        -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
        mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") center / contain no-repeat;
    }
    .search .btn.loading::after { display: none; }
    .search .btn { padding: 0 14px; }

    .result {
        grid-template-columns: 64px 1fr;
        gap: 12px;
    }
    .cover { width: 64px; height: 64px; }
    .result-actions { grid-column: 1 / -1; }
    .result-actions .btn { flex: 1; }

    .toolbar-controls select { flex: 1 1 calc(50% - 4px); }
    .exclude-field { flex: 1 1 100%; }
    .search-pages { flex-shrink: 0; padding: 0 4px 0 10px; }
    .search-field input { padding-left: 38px; }
    .browse select { flex: 1; }

    .brand span { display: none; }
    .nav a { padding: 6px 10px; }
    .nav-user { display: none; }
    .row-form { flex-direction: column; }

    .import-path { flex-basis: 100%; }
}
