:root {
  --bg: #0f1115;
  --bg-soft: #161a22;
  --panel: rgba(24, 28, 36, 0.92);
  --panel-solid: #181c24;
  --ink: #eef1f6;
  --muted: #98a2b3;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #ff3b30;
  --accent-soft: rgba(255, 59, 48, 0.14);
  --accent-ink: #ffffff;
  --tg: #24a1de;
  --tg-hover: #1b8cc4;
  --error-bg: rgba(255, 59, 48, 0.12);
  --error-ink: #ffb4ae;
  --ok: #34d399;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f8;
    --bg-soft: #e9edf3;
    --panel: rgba(255, 255, 255, 0.94);
    --panel-solid: #ffffff;
    --ink: #12151c;
    --muted: #667085;
    --line: rgba(16, 24, 40, 0.1);
    --accent-soft: rgba(255, 59, 48, 0.08);
    --error-bg: #fff1f0;
    --error-ink: #b42318;
    --shadow: 0 18px 40px rgba(16, 24, 40, 0.08);
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 1.5rem 1rem 3rem;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 10%, rgba(255, 59, 48, 0.12), transparent 28%),
    radial-gradient(circle at 90% 0%, rgba(36, 161, 222, 0.12), transparent 24%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
  z-index: -1;
}

.shell { max-width: 760px; margin: 0 auto; }

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: .55rem;
  min-width: 0;
  flex-wrap: wrap;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: .04em;
}

.brand-sep { color: var(--muted); }

.brand-host {
  color: var(--muted);
  font-size: .92rem;
  overflow-wrap: anywhere;
}

.nav {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: .45rem .85rem;
  font-size: .85rem;
}

.nav-btn-active {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: rgba(255, 59, 48, 0.18);
}

.nav-btn-ghost {
  color: var(--muted);
}

h2, h3 { margin: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.row { display: flex; gap: .65rem; }
.row input, .row button { min-height: 46px; }
.row input { flex: 1; min-width: 0; }

input, button, textarea {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
}

input, textarea {
  background: var(--panel-solid);
  color: var(--ink);
}

input:focus-visible, button:focus-visible, textarea:focus-visible {
  outline: 2px solid rgba(255, 59, 48, 0.45);
  outline-offset: 1px;
}

button {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  cursor: pointer;
  white-space: nowrap;
  padding: .65rem 1rem;
  font-weight: 600;
}

button:disabled { opacity: .55; cursor: progress; }

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.muted { color: var(--muted); margin: 0; }

.yt-status {
  margin: 0 0 1rem;
  padding: .65rem .85rem;
  border-radius: 12px;
  font-size: .88rem;
  background: var(--accent-soft);
  border: 1px solid rgba(255, 59, 48, 0.16);
}

.yt-status-warn {
  background: var(--error-bg);
  color: var(--error-ink);
  border-color: rgba(255, 59, 48, 0.22);
}

.error {
  background: var(--error-bg);
  color: var(--error-ink);
  border: 1px solid rgba(255, 59, 48, 0.18);
  border-radius: 12px;
  padding: .85rem 1rem;
  margin: 0 0 1rem;
}

.error a {
  color: inherit;
  font-weight: 700;
}

.login-screen {
  display: flex;
  justify-content: center;
  padding-top: .5rem;
}

.login-card {
  width: min(100%, 460px);
  padding: 1.35rem 1.25rem 1.2rem;
}

.login-kicker {
  margin: 0 0 .35rem;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.login-title {
  margin: 0 0 .55rem;
  font-size: 1.55rem;
  line-height: 1.15;
}

.login-lead { margin-bottom: 1.1rem; }

.login-actions {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.login-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1rem 0;
  color: var(--muted);
  font-size: .82rem;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.login-hint {
  margin-bottom: .85rem;
  font-size: .88rem;
  line-height: 1.5;
}

.login-form {
  display: flex;
  gap: .5rem;
  align-items: stretch;
}

.login-form input,
.login-form button {
  min-height: 38px;
  padding: .45rem .75rem;
  font-size: .88rem;
}

.login-form button {
  min-width: 5.5rem;
}

#login code {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 .35em;
}

#code {
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .84rem;
  font-variant-numeric: tabular-nums;
}

#code::placeholder {
  text-transform: none;
  letter-spacing: normal;
  font-size: .84rem;
}

#tg-widget:empty { display: none; }

.tg-login-btn,
.tg-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  min-width: min(100%, 240px);
  background: linear-gradient(180deg, #2aabee, var(--tg));
  color: #fff !important;
  text-decoration: none;
  font-weight: 600;
  font-size: .9rem;
  border-radius: 12px;
  padding: .55rem 1rem;
  box-shadow: 0 6px 18px rgba(36, 161, 222, 0.22);
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

.tg-login-btn span,
.tg-button span {
  color: #fff;
}

.tg-login-btn:hover,
.tg-button:hover {
  background: linear-gradient(180deg, #2499d8, var(--tg-hover));
  color: #fff !important;
  transform: translateY(-1px);
}

.tg-icon { width: 1.05rem; height: 1.05rem; flex: none; }

.search-bar { padding: .75rem; }

.video {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  margin-top: 0;
}

.video img {
  border-radius: 12px;
  flex: none;
  background: var(--line);
  object-fit: cover;
}

.video .meta { min-width: 0; }
.video h2 { margin: 0 0 .35rem; overflow-wrap: anywhere; font-size: 1.05rem; }

.profile-hero { padding: 1.1rem; }

.profile-identity {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  border: 2px solid var(--line);
}

.avatar-fallback {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent-soft), rgba(36, 161, 222, 0.18));
  color: var(--ink);
  font-size: 1.35rem;
  font-weight: 800;
}

.profile-name { margin: 0 0 .2rem; font-size: 1.25rem; }
.profile-id { font-size: .85rem; font-variant-numeric: tabular-nums; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: .65rem;
}

.ext-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: var(--tg);
  text-decoration: none;
  font-size: .85rem;
  font-weight: 700;
  border: 1px solid rgba(36, 161, 222, 0.25);
  border-radius: 999px;
  padding: .4rem .75rem;
  background: rgba(36, 161, 222, 0.08);
}

.ext-link:hover { background: rgba(36, 161, 222, 0.14); }

.cookies-steps {
  margin: .75rem 0 1rem;
  padding-left: 1.15rem;
  font-size: .88rem;
}

.profile-cookies textarea {
  width: 100%;
  margin: .25rem 0 .75rem;
  padding: .75rem .85rem;
  font: .78rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  min-height: 9rem;
}

.cookies-message.error { color: var(--error-ink); }
.cookies-message.ok { color: var(--ok); }

.options, .jobs { list-style: none; padding: 0; margin: 0; }

.options { padding: .25rem .85rem; }

.options li {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem .15rem;
  border-bottom: 1px solid var(--line);
}

.options li:last-child { border-bottom: 0; }

.options .label { flex: 1; font-weight: 600; }
.options .size { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.options .hint {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.jobs li { margin-top: 1rem; }

progress { width: 100%; height: .5rem; accent-color: var(--accent); }

.job-line {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: .9rem;
}

.job-done a { color: var(--ok); font-weight: 700; text-decoration: none; }
.job-done a:hover { text-decoration: underline; }

.history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.history-title {
  margin: 0 0 .25rem;
  font-size: 1.1rem;
}

.history-lead { font-size: .88rem; }

.history-empty {
  text-align: center;
  padding: 1.5rem 1rem;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: .75rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .75rem;
  margin: 0;
}

.history-item button.history-open {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .85rem;
  min-width: 0;
  background: transparent;
  color: inherit;
  border: 0;
  padding: 0;
  text-align: left;
  font-weight: 400;
  white-space: normal;
}

.history-item button.history-open:hover {
  opacity: .88;
}

.history-thumb {
  width: 88px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
  background: var(--line);
}

.history-meta { min-width: 0; flex: 1; }

.history-meta h3 {
  margin: 0 0 .15rem;
  font-size: .95rem;
  overflow-wrap: anywhere;
}

.history-meta p {
  margin: 0;
  font-size: .82rem;
}

.history-when {
  color: var(--muted);
  font-size: .75rem;
  flex: none;
}

.history-remove {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: .35rem .55rem;
  font-size: .78rem;
}

#login .login-hint a { color: var(--tg); }

@media (max-width: 640px) {
  .head { align-items: flex-start; flex-direction: column; }
  .nav { width: 100%; justify-content: flex-start; }
  .login-form, .row { flex-direction: column; }
  .video { flex-direction: column; }
}
