:root {
  --bg: #0f0f0f;
  --bg-elev: #1a1a1a;
  --bg-elev2: #242424;
  --fg: #f1f1f1;
  --fg-dim: #aaa;
  --accent: #ff0033;
  --ok: #2ecc71;
  --border: #2a2a2a;
  --top-h: 52px;
  --tab-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
img { display: block; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 15, 15, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
#topbar-title {
  font-weight: 700;
  font-size: 17px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#topbar-actions { display: flex; gap: 6px; align-items: center; }
.icon-btn {
  background: transparent;
  border: 0;
  color: var(--fg);
  font-size: 26px;
  line-height: 1;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.icon-btn:active { background: var(--bg-elev2); }

/* ---------- layout ---------- */
#view {
  padding-top: calc(var(--top-h) + var(--safe-top) + 8px);
  padding-bottom: calc(var(--tab-h) + var(--safe-bot) + 16px);
  min-height: 100dvh;
}

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tab-h) + var(--safe-bot));
  padding-bottom: var(--safe-bot);
  display: flex;
  background: rgba(15, 15, 15, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 30;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--fg-dim);
  font-size: 10px;
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--fg); }
.tab.active .tab-ico { color: var(--accent); }

/* ---------- video cards ---------- */
.list { display: flex; flex-direction: column; }
.card {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
}
.card:active { background: var(--bg-elev); }
.card .thumb {
  position: relative;
  width: 152px;
  min-width: 152px;
  aspect-ratio: 16 / 9;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elev2);
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.card .meta { flex: 1; min-width: 0; }
.card .title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .sub { color: var(--fg-dim); font-size: 12px; }
.badge {
  position: absolute;
  right: 6px; bottom: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 4px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 8px 12px;
}
.grid .card {
  display: block;
  padding: 0;
}
.grid .thumb { width: 100%; min-width: 0; margin-bottom: 6px; }
.grid .title { font-size: 13px; }

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  padding: 14px 12px 4px;
}

/* ---------- forms / buttons ---------- */
.row { display: flex; gap: 8px; padding: 8px 12px; align-items: center; }
.btn {
  background: var(--bg-elev2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:active { opacity: 0.8; }
.btn[disabled] { opacity: 0.5; }

input[type="search"], input[type="text"], input[type="url"], input[type="number"] {
  flex: 1;
  min-width: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 15px;
}
input:focus { outline: none; border-color: #555; }

/* ---------- channel ---------- */
.channel-head { padding: 12px; display: flex; gap: 12px; align-items: center; }
.channel-head img.avatar {
  width: 64px; height: 64px; border-radius: 50%; background: var(--bg-elev2);
}
.channel-head .name { font-size: 18px; font-weight: 700; }
.channel-head .subs { color: var(--fg-dim); font-size: 13px; }
.tabs { display: flex; gap: 4px; padding: 4px 12px; border-bottom: 1px solid var(--border); }
.tabs button {
  background: transparent; border: 0; color: var(--fg-dim);
  padding: 10px 12px; font-size: 14px; font-weight: 600;
}
.tabs button.active { color: var(--fg); border-bottom: 2px solid var(--fg); }

/* ---------- watch ---------- */
.player-wrap { background: #000; }
.player-wrap video { width: 100%; aspect-ratio: 16 / 9; background: #000; display: block; }
.watch-info { padding: 12px; }
.watch-info h1 { font-size: 16px; margin: 0 0 6px; }
.watch-info .sub { color: var(--fg-dim); font-size: 13px; }
.desc {
  white-space: pre-wrap;
  color: var(--fg-dim);
  font-size: 13px;
  padding: 12px;
  border-top: 1px solid var(--border);
  max-height: 40vh;
  overflow: auto;
}

/* ---------- misc ---------- */
.empty { padding: 40px 24px; text-align: center; color: var(--fg-dim); }
.spinner { padding: 40px; text-align: center; color: var(--fg-dim); }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-bot) + 16px);
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.settings-list { padding: 8px 0; }
.settings-item { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.settings-item .label { font-weight: 600; }
.settings-item .value { color: var(--fg-dim); font-size: 13px; word-break: break-all; }
