:root {
  --bg: #0c0d10;
  --surface: #16181e;
  --surface-elevated: #1e2128;
  --border: #2d3139;
  --text: #f0f1f4;
  --text-muted: #8a8f98;
  --accent: #fe2c55;
  --accent-2: #25f4ee;
  --accent-soft: rgba(254, 44, 85, 0.12);
  --success: #00d26a;
  --font: 'Syne', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  position: relative;
  overflow-x: hidden;
}

.noise {
  position: fixed;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.gradient-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
}
.orb-1 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  top: -100px;
  right: -100px;
}
.orb-2 {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle, var(--accent-2) 0%, transparent 70%);
  bottom: -80px;
  left: -80px;
}

.header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  position: relative;
  z-index: 1;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
}

.logo-symbol {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.logo h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.tagline {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Помітна навігація зверху */
.top-nav {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.top-nav a {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s;
}

.top-nav a:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.top-nav a.active {
  border-color: var(--accent-2);
  color: var(--accent-2);
  background: rgba(37, 244, 238, 0.12);
}

.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 4rem;
  position: relative;
  z-index: 1;
}

.search-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.search-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.search-tab {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
}

.search-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.search-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.search-panel {
  display: none;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.search-panel.active {
  display: flex;
}

.search-panel label {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.25rem;
}

.search-panel select,
.search-panel input {
  flex: 1;
  min-width: 180px;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.search-panel select:focus,
.search-panel input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.btn {
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-search {
  background: linear-gradient(135deg, var(--accent), #ff4d6d);
  color: white;
}

.btn-search:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--accent-soft);
}

.results-section {
  margin-top: 2rem;
}

.results-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.results-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.results-count {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

/* Video card with preview */
.video-card {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  aspect-ratio: 9 / 16;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.video-card:hover {
  transform: scale(1.02);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.video-card:active {
  transform: scale(0.98);
}

.video-card .cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-card .cover-placeholder {
  background: linear-gradient(135deg, var(--surface-elevated), var(--border));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-muted);
}

.video-card .preview-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.video-card.preview-active .preview-video {
  display: block;
}

.video-card.preview-active .cover {
  display: none;
}

/* Превʼю: показувати перший кадр відео без hover (TikTok, локальні) */
.video-card.has-video-thumb .preview-video {
  display: block;
}

.video-card.has-video-thumb .cover-placeholder {
  display: none;
}

.video-card .play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.2s;
}

.video-card:hover .play-icon,
.video-card:focus-within .play-icon,
.video-card.preview-active .play-icon {
  opacity: 1;
}

.video-card .play-icon span {
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--accent);
}

.video-card .meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0.75rem;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.9);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-card .source-tag {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.2rem 0.5rem;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 6px;
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--accent-2);
}

.video-card .video-card-actions {
  position: absolute;
  bottom: 0.5rem;
  left: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s;
}

/* Кнопки завжди видимі на картках TikTok */
.video-card.has-delete .video-card-actions {
  opacity: 1;
}

.video-card .download-btn {
  padding: 0.35rem 0.6rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.7rem;
  cursor: pointer;
  text-decoration: none;
}

.video-card .btn-delete-video {
  padding: 0.35rem 0.6rem;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  font-size: 0.7rem;
  cursor: pointer;
  font-family: var(--font);
}

.video-card .btn-delete-video:hover {
  background: var(--accent-soft);
}

.video-card:hover .video-card-actions,
.video-card:focus-within .video-card-actions {
  opacity: 1;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.loading {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;
  color: var(--text-muted);
}

.loading.visible {
  display: flex;
}

.loader {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.download-section {
  margin-top: 3rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.download-section h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.download-form {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.download-form input,
.download-form textarea {
  flex: 1;
  min-width: 200px;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}

.download-form textarea {
  resize: vertical;
  min-height: 2.5em;
}

.btn-download {
  background: var(--accent-2);
  color: var(--bg);
}

.btn-download:hover {
  background: #3dfff8;
}

.tiktok-video-grid {
  margin-top: 1.5rem;
}

.footer {
  text-align: center;
  padding: 2rem;
}

.footer a {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent);
}

/* Mobile preview overlay - заміна hover на touch */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.preview-overlay.visible {
  display: flex;
}

.preview-overlay video {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 12px;
}

.preview-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

/* Touch: disable hover effects, use tap for preview */
@media (hover: none) {
  .video-card:hover {
    transform: none;
  }
  .video-card .play-icon {
    opacity: 1;
    background: rgba(0, 0, 0, 0.2);
  }
  .video-card .video-card-actions {
    opacity: 1;
  }
}
