:root {
  --bg-primary: #0b0f19;
  --bg-secondary: rgba(17, 24, 39, 0.7);
  --card-bg: rgba(22, 28, 45, 0.45);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --accent-purple: #a855f7;
  --accent-purple-glow: rgba(168, 85, 247, 0.4);
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.4);
  --success: #10b981;
  --error: #ef4444;
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', system-ui, -apple-system, sans-serif;
  --transition-smooth: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, monospace;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: hidden;
  position: relative;
}

/* Background Gradients Glows */
.glow-bg {
  position: fixed;
  width: 45vw;
  height: 45vw;
  border-radius: 50%;
  filter: blur(120px);
  z-index: -1;
  opacity: 0.1;
  pointer-events: none;
  animation: pulse-glow 20s infinite alternate;
}

.glow-purple {
  background: var(--accent-purple);
  top: -10%;
  left: -10%;
}

.glow-cyan {
  background: var(--accent-cyan);
  bottom: -10%;
  right: -10%;
  animation-delay: 5s;
}

@keyframes pulse-glow {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 0.12;
  }
  100% {
    transform: translate(5%, 5%) scale(1.1);
    opacity: 0.22;
  }
}

/* App Container */
.container {
  width: 100%;
  max-width: 900px;
  padding: 2.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  z-index: 1;
}

/* Header */
.app-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 0 20px var(--accent-purple-glow));
}

h1 {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, #ffffff 20%, var(--accent-cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.05rem;
  font-weight: 400;
  max-width: 500px;
  line-height: 1.5;
}

/* Telegram handle pill under subtitle */
.handle-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding: 0.4rem 0.9rem;
  border-radius: 99px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  transition: var(--transition-smooth);
}

.handle-pill:hover {
  color: var(--text-primary);
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.06);
}

/* Main Cards */
.main-card {
  position: relative;
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 20px 50px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
  overflow: hidden;
}

/* Gradient accent line across the card top */
.main-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-cyan), var(--accent-purple), transparent);
  opacity: 0.7;
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.input-label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: 0.02em;
}

textarea {
  background: rgba(10, 15, 30, 0.6);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  line-height: 1.6;
  resize: vertical;
  min-height: 130px;
  transition: var(--transition-smooth);
}

textarea::placeholder {
  color: var(--text-muted);
}

textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.12);
}

/* Action Bar */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

.supported-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 0.5rem 0.85rem;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.06);
  cursor: pointer;
  box-shadow: none;
  font-family: var(--font-main);
  transition: var(--transition-smooth);
}

.supported-badge:hover {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.08);
  transform: none;
}

.badge-chevron {
  transition: transform 0.25s ease;
  opacity: 0.7;
}

.supported-badge[aria-expanded="true"] .badge-chevron {
  transform: rotate(180deg);
}

/* Supported-sites dropdown */
.badge-wrap {
  position: relative;
}

.sites-panel {
  position: absolute;
  bottom: calc(100% + 0.6rem);
  left: 0;
  width: min(340px, 78vw);
  background: rgba(17, 23, 38, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  z-index: 30;
  animation: panel-pop 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes panel-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.sites-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.sites-panel-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.sites-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
  border: 1px solid rgba(6, 182, 212, 0.2);
  padding: 0.1rem 0.5rem;
  border-radius: 99px;
}

.sites-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.site-chip {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  transition: var(--transition-smooth);
}

.site-chip:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.08);
}

.site-chip::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-purple);
  flex-shrink: 0;
}

.sites-panel-foot {
  margin-top: 0.75rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--card-border);
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.badge-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
}

button {
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
  color: white;
  border: none;
  padding: 0.8rem 2rem;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  box-shadow: 0 4px 15px rgba(168, 85, 247, 0.2);
  transition: var(--transition-smooth);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.3);
}

button:active {
  transform: translateY(1px);
}

.hidden {
  display: none !important;
}

/* Loader Spinner */
.btn-loader {
  display: inline-flex;
  align-items: center;
}

.spinner {
  animation: rotate 2s linear infinite;
  width: 20px;
  height: 20px;
}

.spinner .path {
  stroke: #ffffff;
  stroke-linecap: round;
  animation: dash 1.5s ease-in-out infinite;
}

@keyframes rotate {
  100% { transform: rotate(360deg); }
}

@keyframes dash {
  0% {
    stroke-dasharray: 1, 150;
    stroke-dashoffset: 0;
  }
  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -35;
  }
  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -124;
  }
}

/* Status Card */
.status-card {
  background: rgba(10, 15, 30, 0.45);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 99px;
  overflow: hidden;
  position: relative;
}

.progress-bar-glow {
  position: absolute;
  height: 100%;
  width: 30%;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-purple));
  border-radius: 99px;
  animation: loading-bar 1.5s infinite ease-in-out;
}

@keyframes loading-bar {
  0% { left: -30%; }
  100% { left: 110%; }
}

#status-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  animation: pulse-text 1.5s infinite alternate;
}

@keyframes pulse-text {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* Results Container */
.results-container {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin-top: 1rem;
}

/* Site Results Card */
.site-result {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: card-rise 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes card-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Stagger successive result cards */
.site-result:nth-child(2) { animation-delay: 0.06s; }
.site-result:nth-child(3) { animation-delay: 0.12s; }
.site-result:nth-child(4) { animation-delay: 0.18s; }
.site-result:nth-child(n+5) { animation-delay: 0.24s; }

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  padding-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.site-title-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.site-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: white;
}

.site-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  align-items: center;
}

.site-badge {
  background: rgba(6, 182, 212, 0.1);
  color: var(--accent-cyan);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.site-url-link {
  color: var(--text-muted);
  text-decoration: none;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  white-space: nowrap;
}

.site-url-link:hover {
  color: var(--accent-cyan);
}

/* Copy All Button */
.copy-all-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  border-radius: 8px;
  box-shadow: none;
  color: var(--text-primary);
}

.copy-all-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: white;
  box-shadow: none;
}

/* Category Grid */
.category-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.category-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.links-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: rgba(10, 15, 30, 0.4);
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid transparent;
  transition: var(--transition-smooth);
}

.link-row:hover {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

.link-anchor {
  color: var(--accent-cyan);
  text-decoration: none;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 80%;
  font-family: monospace;
}

.link-anchor:hover {
  color: white;
  text-decoration: underline;
}

.row-action-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.3rem 0.65rem;
  font-size: 0.75rem;
  border-radius: 6px;
  box-shadow: none;
  font-weight: 500;
}

.row-action-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  box-shadow: none;
}

/* File Blocks Table */
.file-blocks-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.file-block-card {
  background: rgba(168, 85, 247, 0.03);
  border: 1px solid rgba(168, 85, 247, 0.15);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.file-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(168, 85, 247, 0.1);
  padding-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.file-meta-badges {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.file-size-badge {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.file-quality-badge {
  background: rgba(168, 85, 247, 0.1);
  color: var(--accent-purple);
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  border: 1px solid rgba(168, 85, 247, 0.2);
}

.file-text-title {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
  line-height: 1.4;
}

.file-links-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.file-link-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}

.file-link-title {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: var(--font-main);
}

/* Clean download row — link on top, green copy button below (matches host cards) */
.dl-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
}

.dl-row .link-anchor {
  word-break: break-all;
  font-size: 0.9rem;
}

.dl-row .row-action-btn {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

.dl-row .row-action-btn:hover {
  filter: brightness(1.1);
}

/* Deep-follow resolved links nested under a gateway */
.dl-sub-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: -0.1rem 0 0.3rem 1.25rem;
  padding-left: 0.75rem;
  border-left: 2px solid rgba(168, 85, 247, 0.25);
}

.dl-sub-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  background: rgba(0, 0, 0, 0.18);
  padding: 0.45rem 0.7rem;
  border-radius: 6px;
}

.dl-sub-row .link-anchor {
  word-break: break-all;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.dl-sub-row.direct {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.dl-sub-row.direct .link-anchor {
  color: var(--success);
}

.dl-sub-row .row-action-btn {
  flex-shrink: 0;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
  background: rgba(168, 85, 247, 0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.dl-sub-row.direct .row-action-btn {
  background: var(--success);
  color: #fff;
  border: none;
}

/* Footer styling */
.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.7;
  margin-top: 1rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--card-border);
}

.app-footer strong {
  color: var(--text-secondary);
  font-weight: 600;
}

/* Copy state changes */
.row-action-btn.copied, .copy-all-btn.copied {
  background: var(--success) !important;
  color: white !important;
  border-color: var(--success) !important;
}

/* Scrollbar customization */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Responsive adjustments */
@media (prefers-reduced-motion: reduce) {
  *, .site-result, .glow-bg, .spinner, .progress-bar-glow {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 600px) {
  .action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  button {
    width: 100%;
  }

  .site-header {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .copy-all-btn {
    align-self: flex-end;
  }
}
