:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #eef0f4;
    --border: #dfe3ea;
    --text: #151821;
    --muted: #646b7a;
    --accent: #ef4444;
    --accent-hover: #dc2626;
    --accent-text: #ffffff;
    --ok: #15803d;
    --ok-bg: #dcfce7;
    --err: #b91c1c;
    --err-bg: #fee2e2;
    --focus: #6366f1;
    --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 12px rgb(0 0 0 / .05);
    --radius: 12px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1115;
        --surface: #171a21;
        --surface-2: #1f232c;
        --border: #2a2f3a;
        --text: #e8eaef;
        --muted: #9097a6;
        --ok: #4ade80;
        --ok-bg: #11291a;
        --err: #f87171;
        --err-bg: #2d1414;
        --shadow: 0 1px 2px rgb(0 0 0 / .4);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: inherit; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
code.break { word-break: break-all; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pad { padding: .25rem .75rem; }
.spacer { flex: 1; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- form controls ---------- */

input, select, textarea {
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .5rem .7rem;
    min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
    border: 1px solid transparent; border-radius: 8px; padding: .5rem .95rem;
    background: var(--surface-2); color: var(--text);
    transition: background .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover:not(:disabled), .btn-ghost.on { background: var(--surface-2); }
.btn-danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn-danger:hover:not(:disabled) { background: var(--err-bg); }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-icon { padding: .2rem .55rem; font-size: 1.1rem; line-height: 1; }
.btn-block { width: 100%; }

.stack { display: flex; flex-direction: column; gap: .85rem; }
.stack label, label.stack-item { display: flex; flex-direction: column; gap: .3rem; }
.stack label > span, .label { font-weight: 600; font-size: .9rem; }
.stack.narrow { max-width: 360px; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }

.alert { border-radius: 8px; padding: .55rem .8rem; margin: .5rem 0; }
.alert-error { background: var(--err-bg); color: var(--err); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- shell ---------- */

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1.5rem;
    padding: .6rem 1.25rem;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.15rem; text-decoration: none; letter-spacing: .02em; }
.topnav { display: flex; gap: .25rem; }
.topnav a { text-decoration: none; padding: .35rem .75rem; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topnav a.active { color: var(--text); background: var(--surface-2); }
.topbar-user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.topbar-user form { margin: 0; }

.content { padding: 1.25rem; max-width: 1600px; margin: 0 auto; }

/* ---------- auth ---------- */

.auth-card {
    max-width: 380px; margin: 8vh auto; padding: 2rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
    text-align: center;
}
.auth-card h1 { margin: .75rem 0 1rem; }
.auth-card form { text-align: left; margin-top: 1rem; }

/* ---------- library ---------- */

.library { display: grid; grid-template-columns: 260px 1fr; gap: 1.5rem; align-items: start; }

.sidebar { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: .75rem; }
.add-form { display: flex; gap: .4rem; }
.add-form input { flex: 1; }

.folders { display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem; }
.folders-head { display: flex; align-items: center; justify-content: space-between; padding: .6rem .6rem .25rem; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.folder {
    display: flex; align-items: center; gap: .55rem; padding: .45rem .65rem; border-radius: 8px;
    text-decoration: none; border: 2px dashed transparent;
}
.folder:hover { background: var(--surface-2); }
.folder.active { background: var(--surface-2); font-weight: 650; }
.folder.drop { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.dot { width: .7rem; height: .7rem; border-radius: 50%; flex: none; }

.main-head { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.title-row { display: flex; align-items: center; gap: .6rem; }
.title-row .dot { width: .9rem; height: .9rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.bulkbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.bulkbar span { font-weight: 600; margin-right: auto; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1.1rem; }

.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: visible; display: flex; flex-direction: column; box-shadow: var(--shadow);
    transition: transform .12s, opacity .12s;
}
.card.dragging { opacity: .45; }
.card.selected { outline: 3px solid var(--accent); outline-offset: -1px; }

.thumb { position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; overflow: hidden; cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.badge { position: absolute; font-size: .75rem; font-weight: 700; padding: .1rem .4rem; border-radius: 5px; background: rgb(0 0 0 / .78); color: #fff; }
.badge.duration { right: .45rem; bottom: .45rem; }
.badge.watched { left: .45rem; bottom: .45rem; background: rgb(21 128 61 / .9); }
.resume { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.pick { position: absolute; top: .5rem; left: .5rem; width: 1.3rem; height: 1.3rem; }

.overlay {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .6rem;
    background: rgb(0 0 0 / .6); color: #fff; font-weight: 600; font-size: .9rem; padding: 1rem; text-align: center;
}
.overlay.failed { background: rgb(127 29 29 / .75); }
.bar { width: 80%; height: 6px; border-radius: 3px; background: rgb(255 255 255 / .25); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); transition: width .5s; }

.card-body { padding: .65rem .75rem .6rem; display: flex; flex-direction: column; gap: .3rem; flex: 1; }
.card-title {
    font-weight: 650; text-decoration: none; line-height: 1.3; overflow-wrap: anywhere;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
a.card-title[href]:hover { text-decoration: underline; }
.card-meta { display: flex; gap: .5rem; flex-wrap: wrap; }
.card-meta span + span::before { content: "·"; margin-right: .5rem; }
.error-text { color: var(--err); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-actions { display: flex; align-items: center; gap: .4rem; margin-top: auto; padding-top: .35rem; }
.card-actions .move { flex: 1; padding: .25rem .4rem; font-size: .82rem; }
.chip { font-size: .75rem; font-weight: 650; padding: .1rem .5rem; border-radius: 999px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); white-space: nowrap; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }

.menu { position: relative; }
.menu-pop {
    position: absolute; right: 0; bottom: calc(100% + 4px); z-index: 30; min-width: 190px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .2);
    padding: .3rem; display: flex; flex-direction: column;
}
.menu-pop a, .menu-pop button {
    font: inherit; text-align: left; background: none; border: 0; color: inherit; text-decoration: none;
    padding: .45rem .65rem; border-radius: 6px; cursor: pointer;
}
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); }
.menu-pop .danger { color: var(--err); }
.click-catcher { position: fixed; inset: 0; z-index: 25; }

.empty { text-align: center; padding: 4rem 1rem; }
.empty h1, .empty h2 { margin-bottom: .5rem; }

/* ---------- modal ---------- */

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .5); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: 16px; padding: 1.4rem; box-shadow: 0 20px 50px rgb(0 0 0 / .35); }
.modal-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.swatches { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .35rem; }
.swatch { width: 1.8rem; height: 1.8rem; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--text); }

/* ---------- watch ---------- */

.watch { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.5rem; align-items: start; }
.player { background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player.placeholder { display: flex; align-items: center; justify-content: center; color: #ccc; }
.watch-title { margin: 1rem 0 .4rem; font-size: 1.35rem; }
.watch-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .75rem; align-items: center; }
.watch-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.description { margin-top: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.description summary { cursor: pointer; font-weight: 600; }
.description p { white-space: pre-wrap; margin: .75rem 0 0; overflow-wrap: anywhere; }

.up-next { display: flex; flex-direction: column; gap: .4rem; max-height: calc(100vh - 6rem); overflow-y: auto; position: sticky; top: 4.5rem; }
.up-next-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.up-next-head h2 { margin: 0; }
.next-item { display: flex; gap: .6rem; text-decoration: none; padding: .35rem; border-radius: 10px; }
.next-item:hover { background: var(--surface-2); }
.next-item.current { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.next-thumb { position: relative; width: 140px; flex: none; aspect-ratio: 16 / 9; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.next-thumb img { width: 100%; height: 100%; object-fit: cover; }
.next-thumb .badge { right: .25rem; bottom: .25rem; font-size: .7rem; }
.next-text { display: flex; flex-direction: column; min-width: 0; }
.next-title { font-weight: 600; font-size: .9rem; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- settings ---------- */

.settings { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.25rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.panel p { margin: .4rem 0; }
.copy-row code { display: inline-block; font-size: 1.05rem; padding: .4rem .7rem; user-select: all; }
.table { width: 100%; border-collapse: collapse; margin: .75rem 0; }
.table th, .table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; color: var(--muted); font-weight: 650; }
.table td.right { text-align: right; }
.table td .btn + .btn { margin-left: .25rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
details summary { cursor: pointer; }

/* ---------- blazor chrome ---------- */

#blazor-error-ui {
    display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: var(--err-bg); color: var(--err); padding: .7rem 1.25rem; box-shadow: 0 -1px 4px rgb(0 0 0 / .2);
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .6rem; }
#blazor-error-ui .reload { margin-left: .5rem; font-weight: 600; }

/* ---------- small screens ---------- */

@media (max-width: 1000px) {
    .watch { grid-template-columns: 1fr; }
    .up-next { position: static; max-height: none; }
}

@media (max-width: 760px) {
    .content { padding: .9rem; }
    .topbar { gap: .75rem; padding: .5rem .9rem; }
    .topbar-user .muted { display: none; }
    .library { grid-template-columns: 1fr; gap: 1rem; }
    .sidebar { position: static; }
    .folders { flex-direction: row; overflow-x: auto; padding: .3rem; }
    .folders-head { padding: .45rem .5rem; flex: none; }
    .folders-head span { display: none; }
    .folders .muted.pad { display: none; }
    .folder { flex: none; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
    .table th:nth-child(2), .table td:nth-child(2) { display: none; }
}
