:root {
  --bg: #0d1526;
  --surface: rgba(255, 255, 255, .06);
  --surface-hover: rgba(255, 255, 255, .1);
  --border: rgba(255, 255, 255, .13);
  --border-focus: rgba(90, 165, 255, .7);
  --text: #e8edf8;
  --muted: #8fa3c8;
  --accent: #5aa5ff;
  --accent-end: #7ec8ff;
  --green: #7496d8;
  --warn: #ffba5a;
  --err: #ff7b7b;
  --radius-sm: 7px;
  --radius-md: 11px;
  --radius-lg: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 1000px 500px at 10% -5%, rgba(60, 120, 255, .18) 0%, transparent 65%),
    radial-gradient(ellipse 800px 400px at 90% 10%, rgba(116, 150, 216, .12) 0%, transparent 60%),
    linear-gradient(175deg, #0d1526 0%, #0a1020 100%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 20px;
}
.topbar-cell-l { min-width: 0; display: flex; align-items: center; }
.topbar-left-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.topbar-left-cluster .theme-toggle { flex-shrink: 0; }
.topbar-left-cluster > .nav-pill { flex-shrink: 0; }
.brand-slot {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0 6px;
}
.brand-slot .brand { max-width: 100%; }
.topbar-cell-r { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; }
.topbar-login { grid-template-columns: auto; justify-content: start; }
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; gap: 10px; }
  .topbar-cell-r { justify-content: flex-start; }
}
.brand {
  font-weight: 800;
  font-size: clamp(17px, 2.4vw, 20px);
  letter-spacing: .015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.15;
}
.brand .brand-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.nav-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  font-size: 13px; font-weight: 600; line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
}
.nav-pill:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav-pill.active {
  color: #04142a;
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  border-color: transparent;
}

.btn-logout, .theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none; cursor: pointer;
  padding: 0; font-family: inherit;
  flex-shrink: 0;
  transition: background .2s, color .2s;
}
.btn-logout:hover, .theme-toggle:hover { background: var(--surface-hover); color: var(--text); }

.theme-toggle-icons { position: relative; width: 20px; height: 20px; display: block; }
.theme-toggle .ico-moon, .theme-toggle .ico-sun { position: absolute; inset: 0; margin: auto; width: 20px; height: 20px; transition: opacity .2s, transform .2s; }
.theme-toggle .ico-moon { opacity: 1; transform: scale(1); }
.theme-toggle .ico-sun { opacity: 0; transform: scale(.72); }
html.light .theme-toggle .ico-moon { opacity: 0; transform: scale(.72); }
html.light .theme-toggle .ico-sun { opacity: 1; transform: scale(1); }

/* Visitor geo pill */
.visitor-geo {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; line-height: 1;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: min(100%, calc(100vw - 120px));
  cursor: default;
}
.vgeo-dot { flex-shrink: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--green); animation: vgeoPulse 2.2s ease-in-out infinite; }
@keyframes vgeoPulse {
  0%   { box-shadow: 0 0 0 0 rgba(116, 150, 216, .5); }
  70%  { box-shadow: 0 0 0 8px rgba(116, 150, 216, 0); }
  100% { box-shadow: 0 0 0 0 rgba(116, 150, 216, 0); }
}
.vgeo-flag { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1; }
.visitor-geo .vgeo-flag-img { display: block; height: auto; vertical-align: middle; }
.vgeo-ip { font-variant-numeric: tabular-nums; }
.vgeo-sep { opacity: .6; }

html { transition: background-color .3s; }
body { transition: color .3s; }

/* ── Light theme ─────────────────────────────────────────── */
html.light {
  --text: #1a2742;
  --muted: #526080;
  --border: rgba(0, 0, 0, .13);
  --border-focus: rgba(30, 100, 220, .45);
  --surface: rgba(255, 255, 255, .75);
  --surface-hover: rgba(255, 255, 255, .92);
  --accent: #2176c7;
  --accent-end: #3a9bec;
  --green: #2f6eb8;
  --warn: #d97706;
  --err: #dc2626;
  --shadow: 0 4px 20px rgba(0, 0, 0, .10);
}
html.light body { background: url('/assets/bg.webp') center/cover fixed; color: var(--text); }
html.light .card,
html.light .login-card,
html.light .hero-wrap { background: rgba(255, 255, 255, .7); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-color: rgba(255, 255, 255, .95); }
html.light .hero { background: none; }
html.light .hero-bg::after { background: linear-gradient(180deg, rgba(240, 244, 251, .2) 0%, rgba(234, 241, 251, .9) 75%, #eaf1fb 100%); }
html.light .torrent { background: rgba(255, 255, 255, .6); }
html.light .tag { background: rgba(0, 0, 0, .04); color: #4a5c7a; }
html.light .tag.ok { color: #166534; background: rgba(134, 239, 172, .25); border-color: rgba(22, 101, 52, .3); }
html.light .tag.run { color: #1e40af; background: rgba(147, 197, 253, .3); border-color: rgba(30, 64, 175, .3); }
html.light .tag.warn { color: #92400e; background: rgba(253, 224, 71, .3); border-color: rgba(146, 64, 14, .3); }
html.light .flash { background: rgba(147, 197, 253, .2); border-color: rgba(30, 64, 175, .28); color: #1e3a8a; }
html.light input, html.light textarea, html.light select { background: rgba(255, 255, 255, .8); color: var(--text); }
html.light .btn { color: var(--text); }
html.light .btn-primary { color: #fff; }
html.light .nav-pill.active { color: #fff; }
html.light .poster.empty { background: linear-gradient(135deg, rgba(33, 118, 199, .12), rgba(58, 155, 236, .08)); color: rgba(26, 39, 66, .4); }
html.light code { color: #4a5c7a; }
html.light .progress { background: rgba(0, 0, 0, .07); }
html.light .footer { color: rgba(26, 39, 66, .45); }
html.light .hero-badge { background: rgba(33, 118, 199, .08); border-color: rgba(33, 118, 199, .28); color: var(--accent); }

.hero-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  background: linear-gradient(135deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .03));
}
.hero-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  filter: blur(2px) saturate(1.05);
  opacity: .55;
}
.hero-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(13, 21, 38, .3) 0%, rgba(13, 21, 38, .85) 70%, #0d1526 100%);
}
.hero {
  position: relative;
  padding: 28px 24px;
  display: grid; grid-template-columns: 1fr; gap: 16px;
}
@media (min-width: 760px) {
  .hero { grid-template-columns: 150px 1fr; padding: 28px; gap: 22px; align-items: center; }
}
.hero-poster {
  width: 150px; aspect-ratio: 2/3; border-radius: var(--radius-md);
  background: #0a1020; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  background-size: cover; background-position: center; flex-shrink: 0;
  margin: 0 auto;
}
.hero-poster.empty { background: linear-gradient(135deg, rgba(90, 165, 255, .15), rgba(116, 150, 216, .1)); border: 1px dashed var(--border); }
.hero-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--green);
  background: rgba(116, 150, 216, .12);
  border: 1px solid rgba(116, 150, 216, .25);
  border-radius: 999px; padding: 5px 12px;
  margin-bottom: 10px;
}
.hero h1 { font-size: clamp(22px, 4vw, 34px); font-weight: 800; line-height: 1.15; margin-bottom: 6px; }
.hero .hero-meta { color: var(--muted); font-size: 14px; line-height: 1.55; }
.hero .hero-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.card {
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-header { padding: 18px 20px 0; }
.card-header h2 { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.card-header p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.card-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 12px; }

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(116, 150, 216, .08);
  border: 1px solid rgba(116, 150, 216, .25);
  color: #b8c9ef;
  font-size: 14px;
  margin-bottom: 14px;
}

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 7px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: 12px 14px;
  background: rgba(0, 0, 0, .25);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px;
}
textarea { min-height: 88px; resize: vertical; font-family: "Menlo", ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--border-focus); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; font-size: 13px; font-weight: 700; line-height: 1;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer; font-family: inherit;
  text-decoration: none;
}
.btn:hover { background: var(--surface-hover); text-decoration: none; }
.btn-primary {
  color: #04142a;
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  border-color: transparent;
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent-end));
  filter: brightness(1.08);
}
.btn-danger { color: var(--err); border-color: rgba(255, 123, 123, .35); background: rgba(255, 123, 123, .06); }
.btn-danger:hover { background: rgba(255, 123, 123, .12); }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.torrent-grid { display: grid; gap: 14px; }
.torrent {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, .04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
@media (max-width: 520px) { .torrent { grid-template-columns: 72px 1fr; gap: 10px; padding: 12px; } }
.poster {
  width: 100%; aspect-ratio: 2/3;
  background: #0a1020 center/cover no-repeat;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.poster.empty {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, rgba(90, 165, 255, .12), rgba(116, 150, 216, .08));
  color: rgba(232, 237, 248, .4); font-size: 26px; font-weight: 800;
}
.torrent-title { font-size: 16px; font-weight: 700; line-height: 1.25; word-break: break-word; margin-bottom: 4px; }
.torrent-sub { font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-word; }
.torrent-overview {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 10px;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.table-torrent-tech td { word-break: break-word; vertical-align: top; }
.table-torrent-tech code { font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag {
  display: inline-block; padding: 3px 9px;
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  color: var(--muted);
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  border-radius: 999px;
}
/* .tag задаёт display — иначе [hidden] не скрывает пустой бейдж скорости после poll */
.tag[hidden] {
  display: none !important;
}
.tag.ok { color: #a8e0c4; background: rgba(116, 216, 160, .1); border-color: rgba(116, 216, 160, .25); }
.tag.run { color: #9dd0ff; background: rgba(90, 165, 255, .1); border-color: rgba(90, 165, 255, .25); }
.tag.warn { color: #ffd89a; background: rgba(255, 186, 90, .1); border-color: rgba(255, 186, 90, .3); }

.progress {
  position: relative;
  height: 20px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-top: 10px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .18);
}
.progress > i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-end));
  transition: width .5s ease;
  position: relative;
  min-width: 0;
}
.progress > i::after {
  content: "";
  position: absolute; inset: 0;
  background-image: linear-gradient(
    135deg,
    rgba(255, 255, 255, .22) 0, rgba(255, 255, 255, .22) 10px,
    transparent 10px, transparent 20px
  );
  background-size: 28px 28px;
  opacity: 0;
}
.progress.run > i::after { opacity: 1; animation: progStripes 1s linear infinite; }
@keyframes progStripes { from { background-position: 0 0; } to { background-position: 28px 0; } }
.torrent-progress-caption {
  margin-top: 8px;
  text-align: center;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: .01em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
html.light .torrent-progress-caption { color: #3d4f6e; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px;
}
.table th, .table td {
  padding: 9px 12px;
  border-top: 1px solid var(--border);
  text-align: left; vertical-align: top;
}
.table tr:first-child th, .table tr:first-child td { border-top: 0; }
.table th { color: var(--muted); font-weight: 500; width: 42%; }
.table td { color: var(--text); font-weight: 600; word-break: break-word; }

video { width: 100%; max-height: 70dvh; background: #000; border-radius: var(--radius-md); }

.login-page { min-height: 100dvh; display: flex; flex-direction: column; align-items: stretch; }
.login-column { width: 100%; max-width: min(440px, 100%); margin: 0 auto; padding: 0 16px; display: flex; flex-direction: column; flex: 1; }
.login-main { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 0 32px; }
.login-card {
  width: 100%;
  background: rgba(255, 255, 255, .055);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 36px 28px;
}
.login-card h1 { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.login-card > p { color: var(--muted); font-size: 14px; text-align: center; line-height: 1.5; margin-bottom: 22px; }
.err-msg {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 123, 123, .08);
  border: 1px solid rgba(255, 123, 123, .22);
  color: #ffaaaa;
  font-size: 13px;
  margin-bottom: 14px;
}
.field { margin-bottom: 14px; }

.footer { text-align: center; color: rgba(143, 163, 200, .45); font-size: 12px; margin-top: 28px; }

.muted { color: var(--muted); }
.text-small { font-size: 12px; }
code { font-family: "Menlo", ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; color: var(--muted); }

/* —— In-app confirm modal (works on tablets / MIUI browser) —— */
body.fp-modal-open { overflow: hidden; touch-action: none; }
.fp-modal {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.fp-modal[hidden] { display: none !important; }
.fp-modal__backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 12, 28, .58);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.fp-modal__panel {
  position: relative; z-index: 1;
  width: min(420px, 100%);
  padding: 22px 22px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: rgba(22, 32, 52, .97);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .5);
  animation: fpModalIn .22s ease-out;
}
@keyframes fpModalIn {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.fp-modal__title {
  font-size: 17px; font-weight: 700; line-height: 1.35;
  color: var(--text); margin: 0 0 10px;
}
.fp-modal__detail {
  font-size: 14px; line-height: 1.55; color: var(--muted);
  margin: 0 0 22px;
}
.fp-modal__detail[hidden] { display: none !important; }
.fp-modal__actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.fp-modal__btn-cancel { min-width: 96px; }
.fp-modal__btn-ok { min-width: 112px; }
html.light .fp-modal__backdrop { background: rgba(30, 45, 72, .38); }
html.light .fp-modal__panel {
  background: rgba(255, 255, 255, .96);
  border-color: rgba(0, 0, 0, .12);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .14);
}
