/* Colours follow the user's Telegram theme (--tg-theme-*), with dark fallbacks for browsers. */
:root {
  --bg: var(--tg-theme-bg-color, #0f0f12);
  --bg2: var(--tg-theme-secondary-bg-color, #18181d);
  --card: var(--tg-theme-section-bg-color, #1e1e24);
  --text: var(--tg-theme-text-color, #f2f2f5);
  --hint: var(--tg-theme-hint-color, #8b8b96);
  --link: var(--tg-theme-link-color, #5eb5f7);
  --accent: var(--tg-theme-button-color, #e53950);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 140, 0.18);
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.search { flex: 1; }
.search input {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.page { max-width: 960px; margin: 0 auto; padding: 12px 16px 40px; }

.tabs, .chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin-bottom: 12px;
}
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tab, .chip {
  flex: none;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--hint);
  font-size: 14px;
  font-weight: 500;
}
.chip { padding: 5px 12px; font-size: 13px; }
.tab.active, .chip.active { background: var(--accent); color: var(--accent-text); }

.hint, .muted { color: var(--hint); }
.hint { margin: 0 0 12px; font-size: 14px; }
.empty { color: var(--hint); text-align: center; padding: 40px 0; grid-column: 1 / -1; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 10px;
}
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card { display: block; min-width: 0; }
.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius);
  overflow: hidden;
  background: linear-gradient(135deg, var(--bg2), var(--card));
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}
.badge-duration { right: 6px; bottom: 6px; }
.badge-lock { left: 6px; top: 6px; }
.card-body { padding: 6px 2px 0; }
.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.meta { margin: 2px 0 0; color: var(--hint); font-size: 12px; }
.meta a { color: var(--link); }

.pager { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-ghost { background: var(--bg2); color: var(--text); }
.btn-sponsor { background: #f5b301; color: #1a1a1a; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ---------- video page ---------- */
.player-wrap {
  position: relative;
  margin: -12px -16px 0;
  aspect-ratio: 16 / 9;
  background: #000 center / cover no-repeat;
  overflow: hidden;
}
@media (min-width: 640px) { .player-wrap { margin: 0; border-radius: var(--radius); } }
.player-wrap video, .player-wrap .fluid_video_wrapper { width: 100% !important; height: 100% !important; }
.player-loading, .lock-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}
.player-loading[hidden], .lock-overlay[hidden] { display: none; }
.lock-overlay { padding: 16px; text-align: center; color: #fff; background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(6px); }
.lock-icon { margin: 0; font-size: 30px; }
.lock-title { margin: 4px 0 2px; font-weight: 700; font-size: 17px; }
.lock-text { margin: 0 0 12px; font-size: 13px; opacity: 0.85; }
.lock-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.lock-actions .btn-ghost { background: rgba(255, 255, 255, 0.15); color: #fff; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.video-info { padding: 12px 0 4px; }
.video-title { margin: 0; font-size: 18px; line-height: 1.3; }
.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}
.action-buttons { display: flex; gap: 8px; }
.stars { display: flex; align-items: center; gap: 2px; }
.stars button {
  padding: 2px;
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--hint);
  opacity: 0.5;
  cursor: pointer;
}
.stars button.on { color: #f5b301; opacity: 1; }
.rating-text { margin-left: 6px; color: var(--hint); font-size: 13px; }
.description { margin: 12px 0 0; padding: 10px 12px; border-radius: var(--radius); background: var(--bg2); font-size: 14px; }

.section-title { margin: 22px 0 10px; font-size: 16px; }

.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea {
  flex: 1;
  min-height: 42px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--bg2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: vertical;
  outline: none;
}
.comment-list { list-style: none; margin: 12px 0 0; padding: 0; }
.comment { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment-head, .comment-body { margin: 0; font-size: 13px; }
.comment-body { margin-top: 2px; font-size: 14px; white-space: pre-line; word-break: break-word; }
.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 14px;
}

/* ---------- ads ---------- */
.ad { display: flex; justify-content: center; margin: 12px 0; overflow: hidden; }
.grid > .ad { grid-column: 1 / -1; margin: 0; }
.modal-ad { display: flex; justify-content: center; margin: 12px 0; max-height: 50vh; overflow: auto; }
.modal-ad:empty, .modal-ad[hidden] { display: none; }

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
}
.modal[hidden] { display: none; }
@media (min-width: 640px) { .modal { align-items: center; } }
.modal-card {
  width: 100%;
  max-width: 420px;
  padding: 18px;
  border-radius: 16px;
  background: var(--card);
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: rise 0.2s ease-out;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.modal-title { margin: 0; font-size: 17px; font-weight: 700; text-align: center; }
.modal-text { margin: 0; color: var(--hint); text-align: center; font-size: 14px; }
.modal-text:empty { display: none; }

.share-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 2px;
  border: 0;
  border-radius: 10px;
  background: var(--bg2);
  font-size: 22px;
  cursor: pointer;
}
.share-btn span { font-size: 11px; color: var(--hint); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 200;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(20, 20, 24, 0.92);
  color: #fff;
  font-size: 14px;
}
.toast[hidden] { display: none; }
