:root {
  color-scheme: dark;
  --chrome: #0f172a;
  --bg: #070a12;
  --panel: #0f172a;
  --panel-2: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.35);
  --cyan: #06b6d4;
  --mint: #10b981;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  max-width: 100vw;
  color: var(--text);
  background:
    radial-gradient(circle at 85% 5%, rgba(139, 92, 246, 0.18), transparent 32%),
    radial-gradient(circle at 12% 20%, rgba(6, 182, 212, 0.12), transparent 28%),
    linear-gradient(180deg, #0b1120 0%, #070a12 40%, #05070e 100%);
}

button {
  font: inherit;
}

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(6px + env(safe-area-inset-top)) 6px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

#homeScreen.screen.is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100%;
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px 6px;
  align-content: start;
  flex: 1;
  margin-bottom: 8px;
}

.video-grid.watched-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px 4px;
}

.watched-grid .video-card {
  border-radius: 6px;
}

.watched-grid .card-info {
  padding: 2px 4px 4px;
}

.watched-grid .video-card-title {
  font-size: 0.62rem;
  line-height: 1.15;
  -webkit-line-clamp: 1;
}

.watched-grid .duration-badge {
  font-size: 0.52rem;
  padding: 1px 3px;
  bottom: 2px;
  right: 2px;
}

.watched-grid .view-badge {
  font-size: 0.52rem;
  padding: 1px 3px;
  bottom: 2px;
  left: 2px;
}

.watched-grid .view-badge svg {
  width: 7px;
  height: 7px;
}

.video-card {
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s cubic-bezier(0.4, 0, 0.2, 1), border-color 0.18s ease, box-shadow 0.18s ease;
  user-select: none;
}

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

.video-card:hover {
  border-color: rgba(139, 92, 246, 0.5);
  box-shadow: 0 6px 18px rgba(139, 92, 246, 0.2);
}

.poster-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #1e293b;
  overflow: hidden;
}

.poster-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.video-card:hover .poster-wrap img {
  transform: scale(1.05);
}

.duration-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  padding: 1px 4px;
  font-size: 0.62rem;
  font-weight: 700;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(4px);
  border-radius: 3px;
  letter-spacing: 0.3px;
  line-height: 1.2;
}

.view-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 1px 4px;
  font-size: 0.60rem;
  font-weight: 600;
  color: #f1f5f9;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  border-radius: 3px;
  line-height: 1.2;
}

.view-badge svg {
  width: 9px;
  height: 9px;
  fill: currentColor;
}

.card-info {
  padding: 4px 6px 6px;
}

.video-card-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.22;
  color: #f1f5f9;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  font-size: 0.95rem;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
  padding: 8px 0 6px;
}

.pager-button {
  min-width: 32px;
  min-height: 32px;
  padding: 0 6px;
  font-size: 0.78rem;
  font-weight: 700;
  color: #cbd5e1;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pager-button:hover:not(:disabled) {
  background: #334155;
  color: #ffffff;
}

.pager-button.is-active {
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 8px rgba(139, 92, 246, 0.4);
}

.pager-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Fluid Video Player Screen */
.player-screen {
  background: #000000;
  min-height: 100vh;
  position: relative;
  padding: 0;
}

.player-header {
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(8px);
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: #f8fafc;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.back-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.player-wrapper {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.player-details {
  padding: 14px 12px;
}

.player-title {
  margin: 0 0 8px;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  line-height: 1.35;
}

.player-watched-note {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
  background: rgba(30, 41, 59, 0.6);
  padding: 8px 10px;
  border-radius: 6px;
  border-left: 3px solid var(--accent);
}

/* Ad Loading Overlay */
.ad-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
}

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

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