:root {
  --bg: #121418;
  --surface: #1b1e24;
  --surface-2: #252932;
  --text: #e8eaee;
  --muted: #9aa1ad;
  --accent: #5b8cff;
  --accent-text: #fff;
  --ok: #3ecf8e;
  --err: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #e9ecf1;
    --text: #1a1d23;
    --muted: #5f6672;
    --accent: #2f6bff;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.3rem; margin: 0 0 .2rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .8rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
main { padding: 0 max(16px, env(safe-area-inset-left)) 40px; max-width: 1600px; margin: 0 auto; }

button, .button, select, input {
  font: inherit; color: inherit; border-radius: 8px; border: 1px solid transparent;
}
button, .button {
  background: var(--accent); color: var(--accent-text); padding: .45rem .9rem; cursor: pointer;
  display: inline-block; line-height: 1.3;
}
button.secondary, .button.secondary { background: var(--surface-2); color: var(--text); }
button.link { background: none; color: var(--muted); padding: .3rem .5rem; }
button.danger { background: var(--err); }
.button:hover { text-decoration: none; }
select, input[type=search], input[type=text], input[type=password], textarea {
  background: var(--surface-2); border: 1px solid var(--surface-2); padding: .4rem .6rem;
}
textarea { font: inherit; color: inherit; border-radius: 8px; width: 100%; resize: vertical; }

header.top {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .7rem max(16px, env(safe-area-inset-left)); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.logo { font-weight: 700; color: var(--text); font-size: 1.05rem; }
header nav { display: flex; gap: .2rem; }
header nav a { color: var(--muted); padding: .3rem .6rem; border-radius: 8px; }
header nav a[aria-current=page] { color: var(--text); background: var(--surface-2); }
header .search { flex: 1; display: flex; justify-content: flex-end; min-width: 140px; }
header .search input { width: 100%; max-width: 320px; }
header form.logout { margin: 0; }

.section-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.section-head h2 { margin-right: auto; }
.section-head form { margin: 0; }

.grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.grid.folders { margin-bottom: 24px; }
@media (max-width: 520px) { .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
.card { color: var(--text); display: block; min-width: 0; }
.card:hover { text-decoration: none; }
.card .thumb {
  position: relative; aspect-ratio: 16 / 9; background: var(--surface-2); border-radius: var(--radius);
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card:hover .thumb img { filter: brightness(1.1); }
.card.watched .thumb img { opacity: .55; }
.card .icon { font-size: 2.4rem; opacity: .7; }
.card .name {
  margin-top: .4rem; font-size: .93rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.card .sub { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.folder .name { font-weight: 600; }
.dur, .badge {
  position: absolute; font-size: .75rem; padding: .1rem .4rem; border-radius: 6px; background: rgb(0 0 0 / .7); color: #fff;
}
.dur { right: 6px; bottom: 8px; }
.badge { left: 6px; top: 6px; }
.badge.ok { background: var(--ok); color: #062; }
.badge.err { background: var(--err); }
.bar { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: rgb(255 255 255 / .2); }
.bar span { display: block; height: 100%; background: var(--accent); }

.crumbs { margin: 1.2rem 0 1rem; font-size: 1.05rem; word-break: break-word; }
.crumbs .sep { color: var(--muted); margin: 0 .4rem; }

.watch { max-width: 1280px; margin: 16px auto 0; }
.player-wrap { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 16 / 9; }
.player-wrap video { width: 100%; height: 100%; display: block; background: #000; }
@media (max-width: 700px) {
  .watch { margin: 0 calc(-1 * max(16px, env(safe-area-inset-left))); }
  .player-wrap { border-radius: 0; }
  .watch-head, .controls, #info, #notice { padding: 0 16px; }
}
.player-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  padding: 2rem; background: rgb(0 0 0 / .75); color: #fff;
}
.watch-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-top: 14px; }
.nav-buttons { display: flex; gap: .5rem; align-items: flex-start; }
.controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.controls label { display: flex; gap: .4rem; align-items: center; color: var(--muted); }
.controls form { margin: 0; }
.controls select { max-width: 70vw; }

body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { background: var(--surface); padding: 2rem; border-radius: 14px; width: min(340px, 92vw); display: grid; gap: 1rem; }
.login-box h1 { text-align: center; }
.login-box label { display: grid; gap: .4rem; color: var(--muted); }
.error { color: var(--err); margin: 0; }
.error-page { text-align: center; margin-top: 4rem; }

/* Торренты */
.torrent-add { background: var(--surface); padding: 1rem; border-radius: var(--radius); display: grid; gap: .7rem; margin: 1rem 0; }
.torrent-add .row { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; }
table.list { width: 100%; border-collapse: collapse; }
table.list td, table.list th { padding: .55rem .5rem; border-bottom: 1px solid var(--surface-2); text-align: left; vertical-align: middle; }
table.list th { color: var(--muted); font-weight: 500; font-size: .85rem; }
table.list td.num { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
table.list .tname { word-break: break-word; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; min-width: 80px; }
.progress span { display: block; height: 100%; background: var(--accent); }
.progress.done span { background: var(--ok); }
.state { font-size: .8rem; padding: .1rem .45rem; border-radius: 6px; background: var(--surface-2); white-space: nowrap; }
.state.error { background: var(--err); color: #fff; }
.state.seeding, .state.done { background: var(--ok); color: #062; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.actions form { margin: 0; }
.actions button { padding: .3rem .6rem; font-size: .85rem; }
@media (max-width: 700px) { table.list .hide-sm { display: none; } }

/* Теги */
.tag {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; padding: .15rem .55rem;
  border-radius: 999px; background: var(--surface-2); color: var(--text); white-space: nowrap;
}
a.tag:hover { text-decoration: none; filter: brightness(1.15); }
.tag.active { background: var(--accent); color: var(--accent-text); }
.tag.active .muted { color: inherit; opacity: .8; }
.tag-bar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0 0 1rem; }
.card .tags {
  display: flex; gap: .25rem; margin-top: .3rem; overflow: hidden;
  mask-image: linear-gradient(to right, #000 85%, transparent);
}
.card .tags .tag { font-size: .72rem; padding: .05rem .45rem; color: var(--muted); }
.folder-tags summary { cursor: pointer; padding: .15rem .3rem; }
.folder-tags form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .5rem; }
.tags-edit { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: 12px; }
.tags-edit form { margin: 0; display: inline-flex; }
.tags-edit .tag a { color: inherit; }
.tags-edit .tag-x { background: none; color: var(--muted); padding: 0 .1rem; line-height: 1; font-size: 1rem; }
.tags-edit .tag-x:hover { color: var(--err); }
.tags-edit input { width: 9rem; padding: .2rem .55rem; font-size: .85rem; border-radius: 999px; }
@media (max-width: 700px) { .tags-edit { padding: 0 16px; } }
