/* Cinematic Modern Dark Design System for Telegram WebApp */
:root {
  --bg-primary: #0a0d14;
  --bg-surface: rgba(18, 24, 38, 0.75);
  --bg-surface-elevated: rgba(26, 35, 54, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.3);

  --accent-primary: #6366f1;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);
  --accent-gold: #f59e0b;
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 24px rgba(99, 102, 241, 0.35);

  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Inherit Telegram WebApp dynamic theme if available */
body.telegram-theme {
  --bg-primary: var(--tg-theme-bg-color, #0a0d14);
  --text-primary: var(--tg-theme-text-color, #f8fafc);
  --text-secondary: var(--tg-theme-hint-color, #94a3b8);
  --accent-primary: var(--tg-theme-button-color, #6366f1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  background-attachment: fixed;
}

/* Background Atmospheric Glow */
.ambient-glow {
  position: fixed;
  top: -20%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15) 0%, rgba(168, 85, 247, 0.08) 40%, transparent 70%);
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}

/* Main Container */
.app-container {
  position: relative;
  max-width: 680px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  z-index: 1;
  padding-bottom: 40px;
}

/* Navigation Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: rgba(10, 13, 20, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-glass);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
}

.brand-logo svg {
  color: #6366f1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.icon-btn:hover, .icon-btn:active {
  background: var(--bg-surface-elevated);
  border-color: var(--border-glow);
  transform: scale(1.05);
}

/* In-App Search Bar Modal/Drawer */
.search-bar-wrapper {
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-glass);
  display: none;
}

.search-bar-wrapper.active {
  display: block;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.search-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-group svg {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition-fast);
}

.search-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

/* Live Search Suggestions Dropdown */
.search-results-dropdown {
  max-height: 300px;
  overflow-y: auto;
  margin-top: 8px;
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  display: none;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-glass);
  transition: var(--transition-fast);
}

.search-item:last-child {
  border-bottom: none;
}

.search-item:hover {
  background: var(--bg-glass);
}

.search-thumb {
  width: 36px;
  height: 52px;
  border-radius: 4px;
  object-fit: cover;
  background: #1e293b;
}

.search-info {
  flex: 1;
}

.search-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.search-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Hero Section */
.hero-wrapper {
  position: relative;
  width: 100%;
  min-height: 280px;
  display: flex;
  align-items: flex-end;
  padding: 24px 20px;
  overflow: hidden;
}

.backdrop-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: brightness(0.4) saturate(1.2);
  z-index: 1;
}

.backdrop-gradient {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, rgba(10, 13, 20, 0.2) 0%, rgba(10, 13, 20, 0.8) 70%, var(--bg-primary) 100%);
  z-index: 2;
}

.hero-content {
  position: relative;
  z-index: 3;
  display: flex;
  gap: 18px;
  width: 100%;
  align-items: flex-end;
}

.poster-card {
  width: 110px;
  min-width: 110px;
  height: 165px;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #1a202c;
  flex-shrink: 0;
}

.poster-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-details {
  flex: 1;
}

.media-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(99, 102, 241, 0.2);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
  margin-bottom: 8px;
}

.media-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.media-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.rating-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  color: var(--accent-gold);
}

/* Action Floating Bar */
.action-section {
  padding: 16px 20px 0 20px;
}

.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 24px;
  background: var(--accent-gradient);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-glow);
  transition: var(--transition-normal);
}

.btn-primary:hover, .btn-primary:active {
  transform: translateY(-2px);
  filter: brightness(1.1);
  box-shadow: 0 0 32px rgba(99, 102, 241, 0.6);
}

/* Details Section */
.content-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.genre-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.genre-chip {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
}

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.tagline-text {
  font-style: italic;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.overview-text {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.6;
}

/* TV Series Hub (Season & Episodes) */
.tv-hub {
  display: none;
}

.tv-hub.active {
  display: block;
}

.season-select-wrapper {
  margin-bottom: 16px;
}

.select-control {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 18px;
}

.select-control:focus {
  border-color: var(--accent-primary);
}

/* Episode List Carousel/Grid */
.episodes-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 480px;
  overflow-y: auto;
  padding-right: 4px;
}

.episode-card {
  display: flex;
  gap: 14px;
  padding: 10px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
}

.episode-card:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: var(--border-glow);
}

.episode-card.active {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--accent-primary);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
}

.episode-still-wrap {
  width: 100px;
  min-width: 100px;
  height: 60px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
  background: #1e293b;
}

.episode-still {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.episode-num-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.7);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
}

.episode-info {
  flex: 1;
  min-width: 0;
}

.episode-title {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.episode-air-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.episode-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Player Section */
.player-container {
  display: none;
  margin-top: 10px;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-lg);
}

.player-container.active {
  display: block;
  animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-glass);
}

.player-header-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.server-selector {
  padding: 4px 8px;
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.75rem;
  outline: none;
}

.player-iframe-wrapper {
  position: relative;
  width: 100%;
  padding-top: 56.25%; /* 16:9 Aspect Ratio */
  background: #05070a;
}

.player-iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* Loading & Skeletons */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: var(--text-secondary);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(99, 102, 241, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error State */
.error-state {
  display: none;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 60px 20px;
  gap: 16px;
}

.error-state.active {
  display: flex;
}

.error-icon {
  font-size: 3rem;
}

.error-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.error-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 360px;
}

/* Empty / Home State */
.empty-home-state {
  padding: 40px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.popular-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

.popular-chip {
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.popular-chip:hover {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* Footer info */
.app-footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 20px;
  margin-top: auto;
}
