:root {
  color-scheme: dark;
  --page: #1a162d;
  --panel: rgba(27, 22, 39, .73);
  --panel-high: rgba(42, 28, 54, .92);
  --line: rgba(248, 216, 255, .19);
  --text: #fff7fb;
  --muted: #e0cedf;
  --pink: #ffa6ca;
  --peach: #ffd0b1;
  --lavender: #d4baff;
  --mint: var(--pink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100dvh; isolation: isolate; color: var(--text); background: var(--page); font-size: 1rem; }
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(42, 31, 75, .24), rgba(29, 17, 42, .23) 46%, rgba(21, 15, 36, .82)),
    url("./assets/city-dusk.jpg") center 60% / cover no-repeat,
    url("./assets/coast.jpg") center / cover no-repeat;
}
a { color: inherit; text-decoration: none; }
button, select { font: inherit; }
button { color: inherit; cursor: pointer; }
a:focus-visible, button:focus-visible, select:focus-visible { outline: 2px solid var(--peach); outline-offset: 4px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.shell { width: 100%; min-height: 100dvh; padding: clamp(.7rem, 1.8vw, 1.65rem); }
.overview { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .65rem 1rem; margin: 0 0 .9rem; }
.identity, .overview-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem .9rem; }
.logo {
  width: clamp(62px, 7vw, 100px); height: auto;
  clip-path: polygon(0 0, 34.5% 0, 40% 14%, 46% 0, 100% 0, 100% 100%, 72.5% 100%, 72.5% 79%, 43.5% 79%, 36% 100%);
}
.identity h1 { margin: 0; color: var(--text); font-weight: 820; font-size: clamp(1.55rem, 3.4vw, 3rem); line-height: 1; letter-spacing: -.045em; text-shadow: 0 2px 16px #271437; }
.refresh {
  background: #251c37b8; color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: .48rem .82rem; font-size: .875rem;
}
.refresh:hover:not(:disabled) { border-color: var(--pink); }
.refresh:disabled { opacity: .6; }
.notice { margin: 0 0 .8rem; padding: .65rem .85rem; background: #332343db; border: 1px solid var(--line); border-radius: .75rem; color: #f6e6f9; font-size: .875rem; }
h1, h2, p { overflow-wrap: anywhere; }
.freshness { display: flex; align-items: center; gap: .55rem; padding: .48rem .8rem; border-radius: 2rem; border: 1px solid var(--line); background: #251c37b8; color: var(--text); font-size: .875rem; }
.freshness i { width: .48rem; height: .48rem; flex: 0 0 .48rem; background: #9ce1c6; border-radius: 50%; }
.freshness[data-state="waiting"] i { background: #eeb777; }
.freshness[data-state="error"] i { background: #ff8eb1; }
.panel.leader { grid-area: leader; background: linear-gradient(135deg, #35223d9b, #201c37df); }
.leader-preview { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 9; border: 1px solid #f9c2f361; border-radius: 1rem; background: #24182f; }
.leader-preview img { display: block; width: 100%; height: 100%; object-fit: cover; }
.leader-preview[aria-disabled="true"] img { opacity: .55; }
.leader-preview[href]:is(:hover, :focus-visible) { border-color: var(--pink); }
.preview-action { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .45rem; color: white; font-size: .875rem; font-weight: 750; text-shadow: 0 1px 8px #110c1f; background: linear-gradient(transparent, #160f28a6); }
.play { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid #ffe1f2c2; border-radius: 50%; background: #33203bd9; }
.play::before { content: ""; border-style: solid; border-width: 8px 0 8px 13px; border-color: transparent transparent transparent #fff3fb; margin-left: .15rem; }
.leader-preview[href]:hover .play { background: #a7548be8; }
.leader-meta { padding: .8rem .1rem .1rem; }
.leader-title { margin: 0; line-height: 1.35; font-weight: 760; font-size: clamp(1rem, 1.6vw, 1.28rem); }
.leader-channel { margin: .24rem 0 .75rem; color: var(--muted); font-size: .875rem; }
.leader-metric { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .5rem; color: var(--muted); font-size: .875rem; }
.leader-value { color: var(--pink); font-size: clamp(1.65rem, 3.35vw, 3.15rem); font-variant-numeric: tabular-nums; letter-spacing: -.045em; line-height: 1; }
.leader-history { margin-top: .75rem; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: #2218319e; color: var(--text); font-size: .875rem; }
.leader-history:hover { border-color: var(--lavender); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; margin: 0 0 .85rem; }
.stat, .panel { border: 1px solid var(--line); border-radius: 1.35rem; background: var(--panel); box-shadow: 0 12px 35px #180c243b; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.stat { min-width: 0; padding: .75rem 1rem; }
.stat > span, .stat > small { display: block; color: var(--muted); font-size: .875rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.stat strong { display: block; margin: .3rem 0; font-size: clamp(1.55rem, 3vw, 2rem); letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.stat:nth-child(2) strong { color: var(--pink); }
.stat:nth-child(3) strong { color: var(--peach); }
#stat-popular-title[href] { text-decoration: underline; text-underline-offset: .2em; }
#stat-popular-title[href]:hover { color: var(--peach); }
.primary-grid { display: grid; grid-template-columns: minmax(0, 1.03fr) minmax(0, 1.22fr) minmax(0, 1.05fr); grid-template-areas: "ranking leader detail"; gap: .85rem; align-items: start; }
.rankings { grid-area: ranking; }
.detail { grid-area: detail; }
.signals-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; margin-top: .85rem; }
.panel { min-width: 0; padding: clamp(.85rem, 1.35vw, 1.25rem); scroll-margin-top: 1rem; }
.panel-top { display: flex; justify-content: space-between; align-items: start; gap: .8rem; margin-bottom: 1rem; }
h2 { margin: 0; color: var(--text); font-size: 1.44rem; font-weight: 830; letter-spacing: -.035em; }
.panel-top p { color: var(--muted); margin: .28rem 0 0; font-size: .875rem; line-height: 1.45; }
.source-select { position: relative; flex: 0 0 auto; }
.filters { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: .65rem; }
.reset-filters { padding: .46rem .63rem; background: transparent; border: 1px solid var(--line); border-radius: .55rem; color: var(--text); font-size: .875rem; }
.reset-filters:hover:not(:disabled) { border-color: var(--pink); color: var(--pink); }
.reset-filters:disabled { opacity: .55; }
.source-select::after { content: ""; position: absolute; right: .83rem; top: 45%; width: .38rem; height: .38rem; border: solid var(--muted); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); pointer-events: none; }
select { appearance: none; background: #21192e; color: var(--text); border: 1px solid var(--line); border-radius: .5rem; padding: .5rem 1.8rem .5rem .7rem; font-size: .875rem; }
.segmented { display: flex; flex-wrap: wrap; width: fit-content; max-width: 100%; gap: .18rem; border-radius: .65rem; padding: .2rem; background: #110d1b; border: 1px solid #332640; }
.segmented button { border: 1px solid transparent; padding: .45rem .6rem; background: transparent; border-radius: .42rem; color: var(--muted); font-size: .875rem; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: linear-gradient(120deg, #c8a6fc, #f2b9e6); border-color: #e5bbff; color: #211427; }
.topic-filter { margin-top: .65rem; border-radius: .5rem; border: 1px solid #76536c; background: #35243b; color: #ffd3e4; padding: .4rem .65rem; font-size: .875rem; }
.video-list { margin-top: .8rem; }
.video-row {
  display: grid; grid-template-columns: 1.7rem minmax(0, 1fr) auto; gap: .65rem; align-items: center;
  width: 100%; text-align: left; border: 1px solid transparent; border-top-color: var(--line);
  padding: .62rem .4rem; background: transparent; min-height: 63px;
}
.video-row:hover, .video-row[aria-current="true"] { background: #271b34; border-radius: .5rem; border-color: #5b3c5e; }
.rank { color: var(--muted); font-size: .875rem; font-variant-numeric: tabular-nums; }
.video-row:first-child .rank { color: var(--peach); }
.row-main { display: grid; gap: .18rem; min-width: 0; }
.row-title { font-weight: 695; font-size: .94rem; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.row-channel { color: var(--muted); font-size: .875rem; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.row-value { font-weight: 770; color: var(--mint); font-variant-numeric: tabular-nums; font-size: .91rem; }
.row-value.negative { color: #d8c7ef; }
.empty { color: var(--muted); padding: .9rem .25rem; margin: 0; }
.selected-title { margin: 0; font-weight: 760; min-height: 1.4rem; }
.selected-channel { color: var(--muted); margin: .25rem 0 .85rem; font-size: .875rem; min-height: 1.25rem; }
.video-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: #130f20; border: 1px solid #332640; border-radius: .65rem; }
.video-stats > div { padding: .65rem .57rem; min-width: 0; }
.video-stats > div + div { border-left: 1px solid #332640; }
.video-stats span { display: block; font-size: .875rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.video-stats strong { display: block; margin-top: .22rem; font-variant-numeric: tabular-nums; font-size: 1rem; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin: 1.25rem 0 .4rem; color: var(--muted); font-size: .875rem; }
.segmented.small button { padding: .33rem .48rem; }
.chart-box { height: 186px; position: relative; background: #151021; border: 1px solid #332640; border-radius: .7rem; }
canvas { width: 100%; height: 100%; display: block; }
.chart-message { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; margin: 0; padding: 1rem; color: var(--muted); font-size: .875rem; }
.chart-tooltip { pointer-events: none; position: absolute; z-index: 1; top: 9px; white-space: nowrap; padding: .36rem .55rem; border: 1px solid #76536c; border-radius: .4rem; background: #25192f; color: var(--text); font-size: .875rem; }
.chart-summary { min-height: 1.4rem; font-size: .875rem; color: var(--muted); margin: .5rem 0 .15rem; }
.video-link { display: inline-block; margin-top: .65rem; padding: .55rem .8rem; border: 1px solid #855773; border-radius: .5rem; background: #35223d; color: #ffe3ee; font-weight: 730; font-size: .89rem; }
.video-link:hover { background: #4b2e4d; }
.signal-line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .22rem 1rem; min-height: 50px; align-content: center; text-align: left; width: 100%; padding: .42rem 0; border: 0; border-top: 1px solid var(--line); background: transparent; }
.signal-line > span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .9rem; }
.signal-line strong { color: var(--mint); font-size: .9rem; }
.signal-line .channel-trend { grid-column: 1 / -1; color: var(--muted); font-size: .875rem; }
.signal-line .meter { grid-column: 1 / -1; height: 3px; border-radius: 2rem; background: #352743; overflow: hidden; }
.signal-line .meter i { display: block; height: 100%; border-radius: 2rem; background: linear-gradient(90deg, #be75f3, #ff9db6); }
button.signal-line:hover > span, button.signal-line[aria-pressed="true"] > span { color: var(--pink); }
footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem 1rem; padding: 1.5rem 0; color: var(--muted); font-size: .875rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 1160px) {
  .primary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-areas: "leader detail" "ranking ranking"; }
}
@media (max-width: 760px) {
  body::before { background-position: center, 57% center, center; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:last-child { grid-column: 1 / -1; }
  .primary-grid { grid-template-columns: minmax(0, 1fr); grid-template-areas: "leader" "ranking" "detail"; }
  .signals-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 395px) {
  .stat { padding: .7rem .6rem; }
  .panel { padding: .8rem; }
  .source-select select { max-width: 140px; }
  .segmented button { padding-inline: .34rem; }
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
