:root {
  --bg: #0d1017;
  --bg2: #151a23;
  --bg3: #1d2430;
  --line: #28303f;
  --text: #e8ecf3;
  --muted: #8b95a7;
  --red: #ff5c5c;
  --amber: #ffb84d;
  --blue: #58a6ff;
  --green: #3fb970;
  --accent: var(--red);
  --row-h: 64px;
  --gold: #ffd166;
  --silver: #c0c9d6;
  --bronze: #d99a6c;
}
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background:
    radial-gradient(1100px 380px at 50% -220px, rgba(255, 92, 92, .12), transparent 70%),
    var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--line); }

.top { padding: 18px 16px 0; max-width: 1060px; width: 100%; margin: 0 auto; }
.masthead { text-align: center; }
.masthead h1 { font-size: 27px; letter-spacing: .3px; }
.masthead .yt { color: var(--red); }
.tagline { color: var(--muted); font-size: 13px; margin-top: 2px; }

.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.tile {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 10px 8px; text-align: center; border-top: 3px solid var(--line);
}
.tile.t-red    { border-top-color: var(--red); }
.tile.t-amber  { border-top-color: var(--amber); }
.tile.t-blue   { border-top-color: var(--blue); }
.tile.t-green  { border-top-color: var(--green); }
.tile h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.tile h5 { font-size: 17px; font-variant-numeric: tabular-nums; }

.controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.controls input[type=search] { flex: 1; min-width: 140px; }
input, select, button, textarea {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font: inherit; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 92, 92, .15); }
button { cursor: pointer; white-space: nowrap; transition: background .12s, transform .06s; }
button:hover { background: var(--bg3); }
button:active { transform: translateY(1px); }
button.accent { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.accent:hover { filter: brightness(1.12); background: var(--accent); }

.colhead {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 12px; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .6px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.c-rank { width: 44px; }
.c-channel { flex: 1; }
.c-num { width: 110px; text-align: right; }

#scroller { flex: 1; overflow-y: auto; }
#spacer { position: relative; max-width: 1060px; margin: 0 auto; }
#rows { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }

.row {
  position: absolute; left: 0; right: 0; height: var(--row-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px; border-bottom: 1px solid var(--line);
  cursor: pointer; contain: strict;
}
.row:hover { background: var(--bg2); box-shadow: inset 3px 0 0 var(--accent); }
.r-rank {
  width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px;
}
.r-rank .medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; font-weight: 700; font-size: 12px; color: #1a1205;
}
.medal.m1 { background: var(--gold); }
.medal.m2 { background: var(--silver); }
.medal.m3 { background: var(--bronze); }
.r-logo { width: 42px; height: 42px; border-radius: 50%; background: var(--bg3); flex: none; }
.r-main { flex: 1; min-width: 0; }
.r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-num { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.r-num small { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.r-num.subs small   { color: var(--amber); }
.r-num.views small  { color: var(--blue); }
.r-num.videos small { color: var(--green); }
.gainpill {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px;
  background: var(--bg3); color: var(--muted); font-variant-numeric: tabular-nums;
}
.gainpill.up { background: rgba(63, 185, 112, .15); color: var(--green); }
.gainpill.down { background: rgba(255, 92, 92, .15); color: var(--red); }
.row.missing { opacity: .45; }

#empty { text-align: center; color: var(--muted); padding: 48px 0; }

footer {
  padding: 6px 16px; color: var(--muted); font-size: 12px; text-align: center;
  border-top: 1px solid var(--line); background: var(--bg2);
}

dialog {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: 14px; padding: 0; max-width: 640px; width: calc(100vw - 32px);
  max-height: 88vh;
}
dialog::backdrop { background: rgba(5, 8, 14, .65); backdrop-filter: blur(2px); }
.d-banner { height: 110px; background: linear-gradient(120deg, #2b1620, #16202b) center/cover no-repeat; border-radius: 14px 14px 0 0; }
.d-body { padding: 16px 20px 20px; position: relative; }
.d-logo {
  width: 72px; height: 72px; border-radius: 50%; border: 3px solid var(--bg2);
  position: absolute; top: -36px; left: 20px; background: var(--bg3);
}
.d-head { margin-left: 88px; min-height: 44px; }
.d-head h2 { font-size: 20px; }
.d-head a { color: var(--blue); font-size: 13px; text-decoration: none; }
.d-head a:hover { text-decoration: underline; }
.muted { color: var(--muted); font-size: 13px; }
.d-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.d-stats div { background: var(--bg3); border-radius: 8px; padding: 8px; text-align: center; border-top: 2px solid var(--line); }
.d-stats div:nth-child(1) { border-top-color: var(--amber); }
.d-stats div:nth-child(2) { border-top-color: var(--blue); }
.d-stats div:nth-child(3) { border-top-color: var(--green); }
.d-stats h4 { font-size: 16px; font-variant-numeric: tabular-nums; }
.d-stats h5 { font-size: 11px; color: var(--muted); font-weight: 500; }
.d-stats .g { font-size: 11px; color: var(--muted); }
.d-stats .g.up { color: var(--green); }
.d-stats .g.down { color: var(--red); }

.d-chart { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 6px; margin-bottom: 14px; }
.d-chart-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.d-chart-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }
.d-chart-value { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text); }
#d-spark { width: 100%; display: block; cursor: crosshair; }
.d-chart-note { font-size: 11px; margin-top: 2px; }

#d-desc {
  white-space: pre-wrap; font: 13px/1.5 inherit; color: var(--muted);
  max-height: 180px; overflow-y: auto; background: var(--bg); border-radius: 8px;
  padding: 10px; margin-bottom: 14px;
}

.tabs { display: flex; gap: 6px; margin: 10px 0; }
.tab { padding: 6px 14px; border-radius: 999px; font-size: 13px; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tabpane { display: none; }
.tabpane.active { display: block; }
.searchrow { display: flex; gap: 8px; }
.searchrow input { flex: 1; }
#yt-results { margin-top: 10px; max-height: 320px; overflow-y: auto; }
.result {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px;
}
.result:hover { background: var(--bg3); }
.result img { width: 40px; height: 40px; border-radius: 50%; background: var(--bg3); }
.result .r-main { flex: 1; min-width: 0; }
.result .r-name { font-size: 14px; }
.result button { padding: 5px 12px; font-size: 13px; }
.result button[disabled] { opacity: .5; cursor: default; }
#addbox textarea { width: 100%; height: 110px; resize: vertical; margin: 10px 0 8px; }
.d-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

@media (max-width: 720px) {
  .c-num, .r-num { width: 86px; }
  .hide-sm { display: none !important; }
  .totals { grid-template-columns: repeat(2, 1fr); }
}
