:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-card: #222222;
  --bg-hover: #2a2a2a;
  --border: #333333;
  --text-primary: #f1f1f1;
  --text-secondary: #aaaaaa;
  --text-muted: #717171;
  --accent: #3ea6ff;
  --accent-hover: #65b8ff;
  --green: #2ecc71;
  --red: #e74c3c;
  --yellow: #f39c12;
}

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  color: var(--accent-hover);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header .container {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}
.header h1 span {
  color: var(--accent);
}
.header nav {
  display: flex;
  gap: 1rem;
  margin-left: auto;
}
.header nav a {
  color: var(--text-secondary);
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  transition: background 0.15s, color 0.15s;
}
.header nav a:hover,
.header nav a.active {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.header nav a.nav-logout {
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.header nav a.nav-logout:hover {
  color: var(--red);
  background: rgba(231, 76, 60, 0.1);
}

/* Page content */
.page {
  padding: 2rem 0;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

/* Cards grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

/* Channel card */
.channel-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  display: flex;
  gap: 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.channel-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.channel-card img {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.channel-card .info {
  flex: 1;
  min-width: 0;
}
.channel-card .title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.channel-card .custom-url {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}
.channel-card .stats {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
}
.badge-green {
  background: rgba(46, 204, 113, 0.15);
  color: var(--green);
}
.badge-gray {
  background: rgba(113, 113, 113, 0.15);
  color: var(--text-muted);
}

/* Stat cards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}
.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Channel header (detail page) */
.channel-header {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}
.channel-header img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
}
.channel-header .info h2 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}
.channel-header .info .custom-url {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* Video list */
.video-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.video-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  gap: 1rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.video-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}
.video-item img,
.thumb-wrap-sm img {
  width: 160px;
  height: 90px;
  border-radius: 0.5rem;
  object-fit: cover;
}
.thumb-wrap-sm {
  position: relative;
  flex-shrink: 0;
  width: 160px;
  height: 90px;
}
.video-item .info {
  flex: 1;
  min-width: 0;
}
.video-item .title {
  font-weight: 600;
  margin-bottom: 0.375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-item .meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Video detail page */
.video-header {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.video-header > img {
  width: 320px;
  height: 180px;
  border-radius: 0.75rem;
  object-fit: cover;
  flex-shrink: 0;
}
.video-header .info {
  flex: 1;
}
.video-header .info h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  line-height: 1.4;
}
.video-header .info .meta {
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

/* YouTube embed */
.video-embed-wrap {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 16/9;
  border-radius: 0.75rem;
  overflow: hidden;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.video-embed-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* External link to YouTube */
.yt-external-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: color 0.15s;
}
.yt-external-link:hover {
  color: var(--accent);
}

/* Chart container */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.chart-container h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}
.chart-container canvas {
  width: 100% !important;
}

/* Ranking table */
.ranking-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.ranking-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
}
.ranking-controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.ranking-controls select {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
}
.ranking-table {
  width: 100%;
  border-collapse: collapse;
}
.ranking-table th,
.ranking-table td {
  text-align: left;
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.ranking-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.ranking-table tr.current {
  background: rgba(62, 166, 255, 0.08);
}
.ranking-table tr.current td:first-child {
  color: var(--accent);
  font-weight: 700;
}

/* Tracking banner */
.tracking-banner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(46, 204, 113, 0.1);
  border: 1px solid rgba(46, 204, 113, 0.25);
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  color: var(--green);
}
.tracking-banner .pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}
.tracking-banner .tracking-remaining {
  color: var(--text-secondary);
  margin-left: auto;
  font-size: 0.8rem;
}

/* Tracking badge (on video card thumbnails) */
.tracking-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(46, 204, 113, 0.9);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.2rem 0.5rem;
  border-radius: 0.25rem;
  line-height: 1.2;
}
.tracking-badge .pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  animation: pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

/* Duration badge */
.duration-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  line-height: 1.2;
}

/* Scrollable table wrapper */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.breadcrumb a {
  color: var(--text-secondary);
}
.breadcrumb .sep {
  color: var(--text-muted);
}

/* Loading / empty states */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}
.spinner {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 0.75rem;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

/* Skeleton loading */
.skeleton {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
  position: relative;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.skeleton-bar {
  background: var(--bg-hover);
  border-radius: 0.25rem;
  height: 0.875rem;
}
.skeleton-stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.skeleton-stat-card {
  height: 80px;
}
.skeleton-video-card {
  height: 120px;
}
.skeleton-upload-card {
  aspect-ratio: 9/13;
}
.skeleton-channel-card {
  height: 90px;
}

/* Section title */
.section-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* Day navigation */
.day-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.day-nav-center {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}
.day-nav-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  width: 2rem;
  height: 2rem;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.day-nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}
.day-nav-btn:active:not(:disabled) {
  transform: scale(0.9);
}
.day-nav-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.day-nav-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}
.day-nav-title {
  font-size: 1.125rem;
  font-weight: 600;
  white-space: nowrap;
}
.day-nav-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.day-nav-latest {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.625rem;
  border-radius: 9999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.day-nav-latest:hover:not(:disabled) {
  background: rgba(62, 166, 255, 0.1);
  border-color: var(--accent);
}
.day-nav-latest:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.day-nav-latest:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Fade-in for day nav content */
@keyframes dayNavFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.day-nav-fade-in {
  animation: dayNavFadeIn 0.2s ease-out;
}

/* Live stats badge */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: rgba(231, 76, 60, 0.15);
  color: var(--red);
  padding: 0.25rem 0.625rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.live-badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* Time slider */
.time-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.time-slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.time-slider-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}
.time-slider-track {
  position: relative;
  padding: 0.5rem 0;
}
.time-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
.time-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 3px rgba(62, 166, 255, 0.25);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.time-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(62, 166, 255, 0.3);
}
.time-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 3px rgba(62, 166, 255, 0.25);
  cursor: pointer;
}
.time-slider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(62, 166, 255, 0.4);
}
.time-slider-ticks {
  display: flex;
  justify-content: space-between;
  padding: 0 2px;
}
.time-slider-tick {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  width: 0;
  display: flex;
  justify-content: center;
}
.time-slider-tick.active {
  color: var(--accent);
  font-weight: 600;
}
.time-slider-tick.tick-unavailable {
  opacity: 0.3;
}
.time-slider-tick.tick-no-data {
  opacity: 0.5;
  font-style: italic;
}

/* Overview stats */
.overview-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

/* Recent uploads */
.recent-uploads {
  margin-bottom: 2rem;
}
.recent-uploads-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.recent-upload-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.recent-upload-card:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.recent-upload-card .thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  background: var(--bg-secondary);
  flex-shrink: 0;
}
.recent-upload-card .thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.recent-upload-info {
  padding: 0.75rem;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.recent-upload-title {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  min-height: 2.275rem; /* Reserve space for 2 lines */
}
.recent-upload-channel {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  margin-bottom: 0.25rem;
}
.recent-upload-channel img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.recent-upload-channel span {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-upload-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: auto;
}

/* Chart toggle button (1c) */
.chart-toggle {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 2px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.chart-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}
.chart-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.chart-toggle.active {
  background: rgba(155, 89, 182, 0.15);
  color: #9b59b6;
  border-color: #9b59b6;
  box-shadow: 0 0 0 1px rgba(155, 89, 182, 0.3);
}

/* Ranking hero (1d) */
.ranking-hero {
  text-align: center;
  padding: 1rem 0 1.25rem;
}
.ranking-hero .rank-number {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.ranking-hero .rank-total {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Last updated (1d) */
.last-updated {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
  margin-top: 0.25rem;
}

/* Responsive — tablet */
@media (max-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .recent-uploads-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Responsive — mobile */
@media (max-width: 768px) {
  .video-header {
    flex-direction: column;
  }
  .video-header > img {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
  }
  .video-embed-wrap {
    max-width: 100%;
  }
  .video-item img,
  .thumb-wrap-sm img {
    width: 120px;
    height: 68px;
  }
  .thumb-wrap-sm {
    width: 120px;
    height: 68px;
  }
  .channel-header {
    flex-direction: column;
    text-align: center;
  }
  .card-grid {
    grid-template-columns: 1fr;
  }
  .overview-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  .recent-uploads-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .ranking-controls {
    align-items: flex-start;
  }
}

/* Responsive — small mobile */
@media (max-width: 480px) {
  .recent-uploads-grid {
    grid-template-columns: 1fr;
  }
}
