/* ================================================
   DESIGN SYSTEM — bikyoon Live Sub Counter
   ================================================ */

:root {
  --bg-deep:       #0a0612;
  --bg-mid:        #110d1f;
  --accent-pink:   #f472b6;
  --accent-purple: #a855f7;
  --accent-light:  #e879f9;
  --accent-glow:   #c026d3;
  --text-primary:  #fdf4ff;
  --text-muted:    #b8a9c9;
  --card-bg:       rgba(255,255,255,0.04);
  --card-border:   rgba(255,255,255,0.08);
  --font-main:     'Outfit', sans-serif;
  --font-mono:     'Space Grotesk', sans-serif;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ── Video background ── */
.video-bg-wrap {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

.video-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1.5s ease;
}

.video-bg.active {
  opacity: 1;
}

/* ── Animated background overlay (sits on top of video) ── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(10,6,18,0.55) 0%, rgba(10,6,18,0.45) 100%),
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(168,85,247,0.30) 0%, transparent 60%),
    radial-gradient(ellipse 60% 80% at 80% 90%, rgba(244,114,182,0.25) 0%, transparent 60%),
    radial-gradient(ellipse 50% 50% at 50% 50%, rgba(192,38,211,0.12) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* ── Particles ── */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  background: var(--accent-light);
  animation: float-up linear infinite;
  opacity: 0;
}

@keyframes float-up {
  0%   { transform: translateY(0) scale(1); opacity: 0; }
  10%  { opacity: 0.7; }
  90%  { opacity: 0.2; }
  100% { transform: translateY(-110vh) scale(0.3); opacity: 0; }
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,6,18,0.92);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fade-in 0.4s ease;
}

.modal-card {
  background: linear-gradient(135deg, rgba(168,85,247,0.12), rgba(244,114,182,0.08));
  border: 1px solid rgba(168,85,247,0.35);
  border-radius: 24px;
  padding: 48px 40px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 80px rgba(168,85,247,0.2), 0 20px 60px rgba(0,0,0,0.5);
  animation: slide-up 0.5s cubic-bezier(0.34,1.56,0.64,1);
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 12px rgba(244,114,182,0.6));
}

.modal-card h2 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}

.modal-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 16px;
}

.help-link {
  display: inline-block;
  color: var(--accent-pink);
  font-size: 0.85rem;
  text-decoration: none;
  margin-bottom: 20px;
  opacity: 0.85;
  transition: opacity 0.2s;
}
.help-link:hover { opacity: 1; text-decoration: underline; }

#apiKeyInput {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(168,85,247,0.4);
  border-radius: 12px;
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
  letter-spacing: 0.5px;
}

#apiKeyInput:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(168,85,247,0.2);
}

.modal-error {
  color: #f87171;
  font-size: 0.82rem;
  min-height: 20px;
  margin: 8px 0;
  text-align: center;
}

.btn-primary {
  margin-top: 8px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  color: #fff;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 4px 24px rgba(168,85,247,0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(168,85,247,0.55);
}

.btn-primary:active { transform: translateY(0); }

/* ── Main container ── */
.main-container {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px 48px;
  gap: 0;
}

/* ── Topbar ── */
.topbar {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 0;
}

.youtube-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #ff4e45;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.btn-api-change {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 6px 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.btn-api-change:hover {
  color: var(--accent-pink);
  border-color: rgba(168,85,247,0.4);
}

/* ── Hero ── */
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 32px;
  gap: 12px;
}

.avatar-ring {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 0 20px rgba(168,85,247,0.5));
}

.avatar-inner {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(168,85,247,0.3), rgba(244,114,182,0.3));
  border: 2px solid rgba(168,85,247,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  animation: pulse-glow 3s ease-in-out infinite;
  z-index: 1;
}

#channelAvatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(168,85,247,0.4); }
  50%       { box-shadow: 0 0 40px rgba(168,85,247,0.7), 0 0 60px rgba(244,114,182,0.3); }
}

.ring-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: rgba(168,85,247,0.15);
  stroke-width: 4;
}

.ring-progress {
  fill: none;
  stroke: url(#ringGrad);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 565;
  stroke-dashoffset: 565;
  transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 0 4px rgba(168,85,247,0.8));
}

.channel-name {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--accent-light), var(--accent-pink), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-top: 4px;
}

.channel-handle {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.5px;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  margin-top: 4px;
  transition: all 0.3s ease;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: all 0.3s ease;
}

/* Offline state */
.live-badge.offline {
  background: rgba(100, 116, 139, 0.15);
  border: 1px solid rgba(100, 116, 139, 0.35);
  color: #94a3b8;
  cursor: default;
}
.live-badge.offline .live-dot {
  background: #94a3b8;
  box-shadow: 0 0 6px rgba(148, 163, 184, 0.5);
}

/* YouTube state */
.live-badge.youtube {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #f87171;
  cursor: pointer;
}
.live-badge.youtube .live-dot {
  background: #ef4444;
  box-shadow: 0 0 6px #ef4444;
  animation: blink 1.2s ease-in-out infinite;
}

/* Twitch state */
.live-badge.twitch {
  background: rgba(168, 85, 247, 0.15);
  border: 1px solid rgba(168, 85, 247, 0.35);
  color: #c084fc;
  cursor: pointer;
}
.live-badge.twitch .live-dot {
  background: #a855f7;
  box-shadow: 0 0 6px #a855f7;
  animation: blink 1.2s ease-in-out infinite;
}

/* Kick state */
.live-badge.kick {
  background: rgba(83, 252, 24, 0.15);
  border: 1px solid rgba(83, 252, 24, 0.35);
  color: #53fc18;
  cursor: pointer;
}
.live-badge.kick .live-dot {
  background: #53fc18;
  box-shadow: 0 0 6px #53fc18;
  animation: blink 1.2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.2; }
}

/* ── Counter section ── */
.counter-section {
  text-align: center;
  margin-top: 36px;
  position: relative;
}

.counter-label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.counter-wrap {
  position: relative;
  display: inline-block;
}

.counter {
  font-family: var(--font-mono);
  font-size: clamp(3.5rem, 14vw, 7rem);
  font-weight: 700;
  letter-spacing: -2px;
  background: linear-gradient(135deg, #fff 0%, var(--accent-light) 50%, var(--accent-pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
  position: relative;
  z-index: 1;
  transition: transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
  user-select: none;
}

.counter.bump {
  transform: scale(1.06);
}

.counter-glow {
  position: absolute;
  inset: -20px;
  background: radial-gradient(ellipse, rgba(168,85,247,0.25) 0%, transparent 70%);
  pointer-events: none;
  animation: glow-pulse 4s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { opacity: 0.6; }
  50%       { opacity: 1; }
}

.counter-sub {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 10px;
  min-height: 22px;
  transition: color 0.3s;
}

/* ── Stats row ── */
.stats-row {
  display: flex;
  gap: 16px;
  margin-top: 40px;
  width: 100%;
  max-width: 580px;
  justify-content: center;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 20px 16px;
  text-align: center;
  backdrop-filter: blur(8px);
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
  animation: fade-in 0.6s ease both;
}

.stat-card:hover {
  transform: translateY(-4px);
  border-color: rgba(168,85,247,0.3);
  box-shadow: 0 8px 30px rgba(168,85,247,0.12);
}

.stats-single {
  justify-content: center;
}

.stats-single .stat-card {
  max-width: 200px;
  flex: none;
}

.milestone-card {
  background: linear-gradient(135deg, rgba(168,85,247,0.12), rgba(244,114,182,0.08));
  border-color: rgba(168,85,247,0.25);
}

.stat-icon {
  font-size: 1.5rem;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 6px rgba(244,114,182,0.5));
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ════════════════════════════════════════════
   VIDEO TIMELINE BAR
   ════════════════════════════════════════════ */

.milestone-section {
  width: 100%;
  max-width: 580px;
  margin-top: 32px;
}

.milestone-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
  font-family: var(--font-mono);
}

.milestone-pct-inline {
  font-size: 0.78rem;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
}

/* Outer wrapper — the popup card is positioned absolutely inside here */
.timeline-wrap {
  position: relative;
  width: 100%;
  /* Reserve headroom above the bar so the popup has space to appear */
  padding-top: 185px;
  margin-top: -185px;
}

.timeline-scroll-area {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  /* Hide scrollbar for a clean UI */
  -ms-overflow-style: none;
  scrollbar-width: none;
  /* Add padding to account for track height hover expansion */
  padding: 4px 0;
  margin: -4px 0;
  border-radius: 999px;
}

.timeline-scroll-area::-webkit-scrollbar {
  display: none;
}

/* ── Scroll Buttons ── */
.scroll-btn {
  position: absolute;
  top: calc(100% - 14px);
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  background: rgba(12, 8, 24, 0.85);
  border: 1px solid rgba(168,85,247,0.4);
  border-radius: 50%;
  color: var(--text-primary);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, background 0.2s, transform 0.2s;
  backdrop-filter: blur(8px);
}

.timeline-wrap.zoomed:hover .scroll-btn {
  opacity: 1;
  pointer-events: all;
}

.scroll-btn:hover {
  background: rgba(168,85,247,0.3);
  transform: translateY(-50%) scale(1.1);
}

.scroll-btn:active {
  transform: translateY(-50%) scale(0.95);
}

.scroll-btn.left { left: -16px; }
.scroll-btn.right { right: -16px; }

/* ── Progress track ── */
.progress-track {
  width: 100%;
  height: 12px;
  background: rgba(255,255,255,0.07);
  border-radius: 999px;
  overflow: visible;
  position: relative;
  cursor: crosshair;
  transition: height 0.18s ease;
}

.progress-track:hover { height: 16px; }

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink), var(--accent-light));
  transition: width 1.5s cubic-bezier(0.4,0,0.2,1);
  position: relative;
  width: 0%;
  pointer-events: none;
}

.progress-glow {
  position: absolute;
  top: -4px;
  height: 20px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, rgba(244,114,182,0.6));
  transition: width 1.5s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
  width: 0%;
  filter: blur(5px);
}

/* ── Scrub cursor (vertical hairline that follows mouse) ── */
.timeline-cursor {
  position: absolute;
  top: -10px;
  width: 2px;
  height: calc(100% + 20px);
  background: rgba(255,255,255,0.5);
  border-radius: 999px;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  transition: opacity 0.15s;
  box-shadow: 0 0 6px rgba(255,255,255,0.35);
}

/* ── Yellow video marker dots ── */
.video-markers {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  transition: width 1.5s cubic-bezier(0.4,0,0.2,1);
}

.vm-dot {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fbbf24;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 0 7px rgba(251,191,36,0.9), 0 0 0 2px rgba(251,191,36,0.2);
  pointer-events: none;
  animation: dot-pop 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
}

@keyframes dot-pop {
  from { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ══════════════════════════
   HOVER POPUP CARD
   ══════════════════════════ */
.vid-popup {
  position: absolute;
  /* Sits above the bar */
  bottom: calc(100% + 16px);
  width: 234px;
  /* Centre on the anchor X position */
  transform: translateX(-50%) translateY(10px) scale(0.95);
  background: rgba(12, 8, 24, 0.97);
  border: 1px solid rgba(168,85,247,0.5);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.65),
    0 0 0 1px rgba(168,85,247,0.1),
    0 0 50px rgba(168,85,247,0.08);
  backdrop-filter: blur(20px);
  /* Hidden by default */
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.17s ease,
    transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 50;
}

.vid-popup.visible {
  opacity: 1;
  pointer-events: all;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* Thumbnail */
.vid-popup-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  overflow: hidden;
  background: rgba(255,255,255,0.03);
}

.vid-popup-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.vid-popup:hover .vid-popup-thumb-wrap img {
  transform: scale(1.05);
}

/* Play overlay */
.vid-popup-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: #fff;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.2s;
}

.vid-popup:hover .vid-popup-play { opacity: 1; }

/* Text */
.vid-popup-body {
  padding: 11px 14px 13px;
  border-top: 1px solid rgba(168,85,247,0.12);
}

.vid-popup-title {
  font-size: 0.83rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.35;
  margin-bottom: 5px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.vid-popup-meta {
  font-size: 0.69rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  opacity: 0.85;
}

/* Downward-pointing arrow caret */
.vid-popup-arrow {
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 13px;
  height: 13px;
  background: rgba(12, 8, 24, 0.97);
  border-right: 1px solid rgba(168,85,247,0.5);
  border-bottom: 1px solid rgba(168,85,247,0.5);
  border-radius: 0 0 3px 0;
}

/* Clickable link wrapper */
.vid-popup-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

/* ── Hint text under bar ── */
.timeline-hint {
  text-align: center;
  margin-top: 11px;
  font-size: 0.74rem;
  color: rgba(184,169,201,0.45);
  letter-spacing: 0.3px;
  min-height: 16px;
  transition: color 0.4s;
}

.timeline-hint.loading {
  color: rgba(168,85,247,0.55);
  animation: hint-pulse 1.5s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.55; }
  50%       { opacity: 1; }
}

/* ── Footer ── */
.refresh-footer {
  margin-top: 36px;
  font-size: 0.8rem;
  color: rgba(184,169,201,0.5);
  display: flex;
  gap: 8px;
  align-items: center;
}

.refresh-sep { opacity: 0.4; }

/* ── Celebration confetti ── */
.celebration {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  animation: confetti-fall 2.5s ease-in forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ── Animations ── */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .stats-row { gap: 10px; }
  .stat-card  { min-width: 110px; padding: 16px 12px; }
  .modal-card { padding: 36px 24px; }
  .vid-popup  { width: 200px; }
  .counter { font-size: clamp(2.8rem, 12vw, 4.5rem); }
  .channel-name { font-size: 1.8rem; }
  .avatar-ring { width: 110px; height: 110px; }
  .avatar-inner { width: 80px; height: 80px; }
  .stat-value { font-size: 1.1rem; }
  .stat-icon { font-size: 1.3rem; }
}
