:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f4f5f7);
  --text: var(--tg-theme-text-color, #14141a);
  --hint: var(--tg-theme-hint-color, #8e8e97);
  --link: var(--tg-theme-link-color, #5b8def);
  --button: var(--tg-theme-button-color, #5b6cf9);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #ffffff);
  --accent-2: #ff9f43;
  --shadow: 0 6px 20px rgba(20, 20, 30, 0.08);
  --shadow-lg: 0 12px 32px rgba(20, 20, 30, 0.14);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #101014);
    --text: var(--tg-theme-text-color, #f2f2f5);
    --hint: var(--tg-theme-hint-color, #8b8b93);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #1c1c22);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body { overflow-x: hidden; }

body {
  margin: 0;
  font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 32px;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: linear-gradient(var(--bg) 65%, transparent);
  padding: 14px 14px 8px;
}

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

.search-icon {
  position: absolute;
  right: 14px;
  width: 18px;
  height: 18px;
  color: var(--hint);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 13px 42px 13px 16px;
  border-radius: 14px;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  text-align: right;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s ease;
}

#search-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--button), var(--shadow);
}

#search-input::placeholder { color: var(--hint); }

body.chrome-hidden .topbar,
body.chrome-hidden .genre-bar {
  display: none;
}

.genre-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 14px 14px;
  white-space: nowrap;
  scrollbar-width: none;
}
.genre-bar::-webkit-scrollbar { display: none; }

.genre-chip {
  flex-shrink: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}

.genre-chip:active { transform: scale(0.94); }

.genre-chip.active {
  background: linear-gradient(135deg, var(--button), #8e6bf5);
  color: #fff;
  box-shadow: 0 6px 16px rgba(91, 108, 249, 0.4);
}

.view {
  padding: 4px 14px;
  animation: fadeIn 0.25s ease;
}
.view.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  margin: 18px 2px 10px;
}

.section-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--button), var(--accent-2));
  flex-shrink: 0;
}

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

.card {
  cursor: pointer;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--secondary-bg);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card:active { transform: scale(0.96); }

.poster-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--secondary-bg);
}

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

.poster-overlay {
  position: absolute;
  inset: auto 0 0 0;
  padding: 20px 8px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.85), rgba(0,0,0,0));
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-year {
  font-size: 10.5px;
  color: rgba(255,255,255,0.75);
  margin-top: 2px;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.05);
  z-index: 20;
}
.loading.hidden { display: none; }

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(128,128,128,0.25);
  border-top-color: var(--button);
  animation: spin 0.8s linear infinite;
}

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

/* Detail view */
#view-detail { padding: 0; }

.hero {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  overflow: hidden;
  border-radius: 0 0 24px 24px;
  box-shadow: var(--shadow-lg);
}

.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hero-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, var(--bg) 0%, rgba(0,0,0,0.35) 45%, rgba(0,0,0,0) 75%);
}

.hero-text {
  position: absolute;
  right: 0;
  left: 0;
  bottom: 0;
  padding: 18px 18px 20px;
}

.hero-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.4);
  line-height: 1.4;
}

.hero-text .en-title {
  display: block;
  font-size: 14px;
  font-weight: 400;
  color: rgba(255,255,255,0.85);
  margin-top: 2px;
}

.hero-text .year {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  margin-top: 6px;
}

.detail-body {
  padding: 18px 16px 4px;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--secondary-bg);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  font-weight: 600;
}

.badge.rating {
  background: linear-gradient(135deg, #ffb648, #ff8a3d);
  color: #201200;
}

.badge.genre {
  background: rgba(91, 108, 249, 0.12);
  color: var(--link);
  font-weight: 500;
}

.info-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.info-row {
  display: flex;
  gap: 8px;
  font-size: 14px;
  line-height: 1.9;
}

.info-row .label {
  color: var(--hint);
  flex-shrink: 0;
  font-weight: 500;
}

.overview-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 18px;
  font-size: 14px;
  line-height: 1.9;
}

.overview-card .overview-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--hint);
  margin-bottom: 8px;
  display: block;
}

.imdb-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 20px;
  padding: 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #f5c518, #e0a800);
  color: #14141a !important;
  text-decoration: none;
  font-size: 14.5px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(245, 197, 24, 0.35);
  transition: transform 0.15s ease;
}
.imdb-link:active { transform: scale(0.97); }

.empty {
  text-align: center;
  color: var(--hint);
  padding: 60px 10px;
  font-size: 14px;
}
