:root {
  color-scheme: dark;
  --bg: #0d0d11;
  --bg-2: #15121c;
  --panel: #191822;
  --panel-2: #232132;
  --line: #2c2a3d;
  --text: #eef0f6;
  --muted: #a2a5b6;
  --accent: #9147ff;
  --accent-2: #772ce8;
  --good: #22c55e;
  --bad: #fa5252;
  --focus: #c38bff;
  --radius: 0.75rem;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  background:
    radial-gradient(60rem 30rem at 15% -10%, rgba(145, 71, 255, 0.18), transparent 60%),
    radial-gradient(50rem 28rem at 90% -10%, rgba(119, 44, 232, 0.14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 0.3rem;
}

/* ---------- Header ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.4rem;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.title {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  font-size: 0.8rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 0.45rem;
  box-shadow: 0 4px 12px rgba(145, 71, 255, 0.45);
}

.title-accent {
  background: linear-gradient(90deg, var(--accent), #c98cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Form ---------- */
.form {
  justify-self: center;
  position: relative;
  display: flex;
  gap: 0.55rem;
  width: 100%;
  max-width: 42rem;
}

.icon {
  position: absolute;
  left: 0.95rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  fill: var(--muted);
  pointer-events: none;
  transition: fill 0.2s;
}

.input {
  flex: 1;
  min-width: 10rem;
  padding: 0.8rem 1rem 0.8rem 2.8rem;
  font-size: 1.0625rem;
  color: var(--text);
  background: color-mix(in srgb, var(--bg) 60%, var(--panel));
  border: 2px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form:focus-within .icon { fill: var(--accent); }
.form:focus-within .input {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(145, 71, 255, 0.16);
}

.input::placeholder { color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(145, 71, 255, 0.35);
  transition: transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}

.btn:hover { box-shadow: 0 6px 20px rgba(145, 71, 255, 0.5); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: wait; box-shadow: none; transform: none; }

.btn-ico { font-size: 0.8rem; }

.right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ---------- Quality dropdown ---------- */
.dropdown { position: relative; }

.quality-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1.05rem;
  font-size: 0.98rem;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}
.quality-btn:hover { border-color: var(--accent); box-shadow: none; transform: none; }
.quality-btn[hidden] { display: none; }

.caret { opacity: 0.75; font-size: 0.7rem; transition: transform 0.2s; }
.quality-btn[aria-expanded="true"] .caret { transform: rotate(180deg); }

.menu {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  z-index: 40;
  min-width: 15rem;
  max-height: min(60vh, 30rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: pop-in 0.15s ease-out;
}
.menu[hidden] { display: none; }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

.menu .q { width: 100%; }

/* ---------- Favorites ---------- */
.qualities {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.6rem;
}

.h2 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.q {
  min-width: 12rem;
  padding: 0.85rem 1.1rem;
  text-align: left;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  background: linear-gradient(180deg, var(--panel), var(--panel-2, var(--panel)));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.q:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.q .sub { display: block; font-size: 0.8rem; font-weight: 500; color: var(--muted); margin-top: 0.15rem; }

.q.selected {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  border-color: var(--accent);
  box-shadow: 0 6px 18px rgba(145, 71, 255, 0.4);
}
.q.selected .sub { color: #e9dcff; }
.q.selected:hover { transform: none; }

/* Favorites cards */
.favorites .q.fav .sub { color: var(--accent); font-weight: 600; }
.q.fav { position: relative; padding-left: 2.9rem; }
.q.fav .dot {
  position: absolute;
  left: 1.15rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  color: var(--muted);
}
.q.fav .dot.online { color: var(--good); text-shadow: 0 0 8px rgba(34, 193, 88, 0.6); }
.q.fav .dot.offline { color: #555862; }

/* ---------- Main / hero ---------- */
.main {
  max-width: 68rem;
  margin: 0 auto;
  padding: 2rem 1.4rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.status {
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1.2rem;
  display: flex;
  gap: 0.7rem;
  align-items: center;
}
.status[hidden] { display: none; }
.status::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(145, 71, 255, 0.8);
  flex: none;
}
.status.error { color: var(--bad); border-color: rgba(250, 82, 82, 0.5); }
.status.error::before { background: var(--bad); box-shadow: 0 0 10px rgba(250, 82, 82, 0.7); }

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.9rem;
  padding: 3rem 1rem 1.5rem;
}
.hero[hidden] { display: none; }

.hero-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.2rem;
  height: 4.2rem;
  font-size: 1.5rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 1.25rem;
  box-shadow: 0 12px 40px rgba(145, 71, 255, 0.5);
  margin-bottom: 0.25rem;
}

.hero-title {
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--text), #cbc4f0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-sub {
  max-width: 34rem;
  font-size: 1.1rem;
  color: var(--muted);
}

/* ---------- Player ---------- */
.player-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.55rem; }
.player-wrap[hidden] { display: none; }

.video {
  width: 100%;
  max-width: min(100%, calc((100vh - 7rem) * 16 / 9));
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

body.has-player .main { max-width: none; padding-top: 1rem; padding-bottom: 1rem; }

.hint { font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.hint:empty { display: none; }

.fs-btn {
  padding: 0.65rem 1.05rem;
  font-size: 0.98rem;
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}
.fs-btn:hover { border-color: var(--accent); box-shadow: none; transform: none; }

@media (max-width: 40rem) {
  .bar {
    grid-template-columns: auto 1fr;
    gap: 0.75rem;
    padding: 0.8rem;
  }
  .title { font-size: 1.1rem; }
  .right { grid-column: 2; grid-row: 1; justify-self: end; }
  .form { grid-column: 1 / -1; grid-row: 2; }
  .hero { padding: 2rem 0.5rem 1rem; }
  .q { min-width: 10rem; }
}