/* ════════════════════════════════════════════════════════════
   TikiAnime — CSS Design System & Mobile Responsive UI
   Designed specifically for Telegram WebApp Mobile & Desktop
   ════════════════════════════════════════════════════════════ */

:root {
  --bg-primary:    #0a0a16;
  --bg-secondary:  #121226;
  --bg-card:       #181832;
  --bg-glass:      rgba(24, 24, 50, 0.75);
  
  --accent-purple: #8b5cf6;
  --accent-indigo: #6366f1;
  --accent-cyan:   #06b6d4;
  --accent-pink:   #ec4899;
  
  --text-main:     #f8fafc;
  --text-muted:    #94a3b8;
  --text-sub:      #64748b;

  --border-color:  rgba(255, 255, 255, 0.08);
  --border-glow:   rgba(139, 92, 246, 0.4);

  --font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  
  --tg-safe-top:    env(safe-area-inset-top, 0px);
  --tg-safe-bottom: env(safe-area-inset-bottom, 0px);

  --radius-sm:  8px;
  --radius-md:  12px;
  --radius-lg:  20px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.3);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none !important; /* حظر القائمة التفاعلية عند النقر المطول على iOS/Android */
  -webkit-user-select: none !important;   /* حظر تحديد النصوص والروابط */
  user-select: none !important;
}

img, button, a, video, iframe, .anime-card, .genre-card, .pill-btn, .server-btn {
  -webkit-user-drag: none !important;
  user-drag: none !important;
}

html, body {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
}

::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }

/* Splash Screen */
#splash-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(circle at center, #1e1b4b 0%, #0a0a16 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

#splash-screen.fade-out {
  opacity: 0;
  visibility: hidden;
}

.splash-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.logo-icon svg {
  width: 80px;
  height: 80px;
  filter: drop-shadow(0 0 16px rgba(139, 92, 246, 0.6));
  animation: pulse 2s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}

.brand-name {
  display: block;
  font-size: 1.8rem;
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.splash-spinner {
  margin-top: 36px;
}

.spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-ring.small {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

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

/* App Main Layout */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
  padding-top: calc(var(--tg-safe-top) + 0px);
}

.hidden { display: none !important; }

/* Header & Navigation */
#app-header {
  position: relative;
  z-index: 100;
  background: rgba(10, 10, 22, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding-top: max(var(--tg-safe-top), 8px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 16px;
}

.header-back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.header-back-btn:active {
  background: rgba(139, 92, 246, 0.25);
}

.header-back-btn svg { width: 18px; height: 18px; }

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

.brand-icon { width: 28px; height: 28px; }

.brand-label {
  font-weight: 800;
  font-size: 1.25rem;
  background: linear-gradient(135deg, #c4b5fd, #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-main);
  cursor: pointer;
}

.icon-btn svg { width: 20px; height: 20px; }

/* Category Pills Bar */
.pills-scroll-container {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  overflow-x: auto;
  white-space: nowrap;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.pill-btn svg {
  width: 16px;
  height: 16px;
}

.pill-btn.active, .pill-btn:active {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-indigo));
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

/* Search Bar */
.search-bar { padding: 8px 16px 12px; }

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

.search-icon-input {
  position: absolute;
  right: 12px;
  width: 18px;
  height: 18px;
  color: var(--text-sub);
}

#search-input {
  width: 100%;
  height: 42px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0 40px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
}

#search-input:focus {
  border-color: var(--accent-purple);
  box-shadow: var(--shadow-glow);
}

.search-clear {
  position: absolute;
  left: 12px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 1.1rem;
  cursor: pointer;
}

/* Main Content */
#main-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  padding-bottom: 72px;
}

.view {
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease-in-out;
  padding: 16px;
}

.view.active {
  display: block;
  opacity: 1;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
}

.count-badge {
  font-size: 0.8rem;
  font-weight: 700;
  background: rgba(139, 92, 246, 0.2);
  color: var(--accent-purple);
  padding: 2px 10px;
  border-radius: var(--radius-full);
}

/* Anime Grid */
.anime-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 12px;
}

@media (min-width: 600px) {
  .anime-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }
}

.anime-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.anime-card:active {
  transform: scale(0.97);
  border-color: var(--accent-purple);
}

.card-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: #111122;
  overflow: hidden;
}

.card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.card-thumb.loaded { opacity: 1; }

.card-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(10, 10, 22, 0.85);
  backdrop-filter: blur(8px);
  color: var(--text-main);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.anime-card:hover .card-play-icon, .anime-card:active .card-play-icon { opacity: 1; }

.card-play-icon svg {
  width: 36px;
  height: 36px;
  color: #ffffff;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5));
}

.card-info { padding: 10px 8px; }

.card-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
  height: 2.3em;
}

.loader-inline, .loader-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.load-more-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 16px;
  background: rgba(139, 92, 246, 0.15);
  border: 1px solid var(--accent-purple);
  color: var(--accent-purple);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

.end-note {
  text-align: center;
  padding: 16px;
  color: var(--text-sub);
  font-size: 0.85rem;
  font-weight: 600;
}

.error-state {
  padding: 16px;
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: var(--radius-md);
  text-align: center;
  font-size: 0.9rem;
  margin-top: 16px;
}

/* Genres Grid */
.genres-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.genre-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 14px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  text-align: center;
}

.genre-card:active {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent-purple);
  transform: scale(0.96);
}

.genre-badge-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3), rgba(99, 102, 241, 0.3));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-purple);
  margin-bottom: 2px;
}

.genre-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.genre-count {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-sub);
}

.letters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 24px;
}

.tg-fullscreen-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background: linear-gradient(135deg, var(--accent-purple), #6366f1);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.tg-fullscreen-btn svg {
  width: 20px;
  height: 20px;
}

.tg-fullscreen-btn:active {
  transform: scale(0.98);
}

.letter-btn {
  height: 42px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

.letter-btn:active {
  background: var(--accent-purple);
  color: #ffffff;
}

/* Details View Hero */
#view-details { padding: 0; }

.details-hero {
  position: relative;
  width: 100%;
  background: var(--bg-secondary);
  overflow: hidden;
  padding-bottom: 16px;
}

.details-banner-wrap {
  position: relative;
  width: 100%;
  height: 160px;
}

.details-banner {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(12px) brightness(0.5);
  transform: scale(1.1);
}

.details-banner-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, transparent 0%, var(--bg-primary) 100%);
}

.details-header-content {
  position: relative;
  display: flex;
  gap: 14px;
  padding: 0 16px;
  margin-top: -70px;
  z-index: 10;
}

.details-poster-card {
  width: 100px;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 2px solid var(--border-color);
  flex-shrink: 0;
  background: #111;
}

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

.details-main-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
}

.details-title {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.3;
  color: var(--text-main);
}

.details-genres-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 52px;
  overflow: hidden;
}

.genre-tag {
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(139, 92, 246, 0.2);
  color: var(--accent-purple);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.details-meta-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.details-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
}

.section-label {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 10px;
}

.details-story {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.details-story.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.story-toggle-btn {
  background: none;
  border: none;
  color: var(--accent-purple);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 8px;
  cursor: pointer;
}

.episodes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(95px, 1fr));
  gap: 8px;
}

.episode-item-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.episode-item-btn:active {
  background: var(--accent-purple);
  border-color: transparent;
  color: #ffffff;
}

.ep-play-icon { width: 14px; height: 14px; flex-shrink: 0; }

/* Player View */
#view-player { padding: 12px; }
.player-title-bar { margin-bottom: 12px; }
.player-title { font-size: 1.05rem; font-weight: 800; color: var(--text-main); }

.player-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
}

.player-loading {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 22, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
}

.player-video, .player-iframe {
  width: 100%;
  height: 100%;
  border: none;
  object-fit: contain;
}

.servers-section { margin-top: 16px; }

.servers-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.server-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.server-btn.active, .server-btn:active {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-indigo));
  color: #ffffff;
  border-color: transparent;
}

.player-nav {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.nav-ep-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.nav-ep-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.nav-ep-btn svg { width: 16px; height: 16px; }

/* Bottom Nav */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 9900;
  height: calc(60px + var(--tg-safe-bottom));
  padding-bottom: var(--tg-safe-bottom);
  background: rgba(18, 18, 38, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
}

.nav-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-sub);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  width: 33.33%;
  height: 100%;
}

.nav-tab svg { width: 22px; height: 22px; }
.nav-tab.active { color: var(--accent-purple); }


/* وضعية ملء الشاشة الوهمية لتطبيق تيلجرام */
.fake-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 999999 !important;
  background: #000 !important;
  border-radius: 0 !important;
}

