/* Desiflicks Mini App — Apple-style dark theme */

:root {
  --bg: #000000;
  --bg-elev-1: #0e0e0e;
  --bg-elev-2: #1a1a1a;
  --surface: #141414;
  --surface-hover: #1d1d1d;
  --text: #f5f5f7;
  --text-dim: #98989d;
  --text-faint: #6e6e73;
  --accent: #ff453a;
  --accent-hover: #ff5e54;
  --premium: #ffd60a;
  --free: #30d158;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --shadow-card: 0 1px 0 0 rgba(255, 255, 255, 0.04) inset,
                 0 12px 32px -16px rgba(0, 0, 0, 0.6);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 22px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
               "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  padding-top: var(--safe-top);
  padding-bottom: calc(24px + var(--safe-bottom));
  overscroll-behavior-y: contain;
}

a { color: inherit; text-decoration: none; }
button {
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0;
}
img { display: block; max-width: 100%; }

/* ===== Header ===== */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: linear-gradient(180deg, rgba(0,0,0,0.92) 0%, rgba(0,0,0,0.85) 70%, rgba(0,0,0,0) 100%);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}

.app-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.app-title-mark {
  color: var(--accent);
  font-size: 10px;
  transform: translateY(-1px);
}
.app-title-text {
  background: linear-gradient(180deg, #ffffff 30%, #b0b0b5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.app-status {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
}
.app-status.is-paid { color: var(--premium); border-color: rgba(255, 214, 10, 0.3); }

/* ===== Hero ===== */

.hero {
  padding: 24px 20px 8px;
}
.hero-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.05;
  background: linear-gradient(180deg, #ffffff 30%, #8e8e93 110%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero-sub {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 15px;
}

/* ===== Filters ===== */

.catalog-filters {
  display: flex;
  gap: 8px;
  padding: 16px 20px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.catalog-filters::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.chip.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip:active { transform: scale(0.96); }

/* ===== Movie grid ===== */

.movie-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px 14px;
  padding: 8px 20px 24px;
}

.movie-card {
  display: block;
  transition: transform 0.15s ease;
}
.movie-card:active { transform: scale(0.97); }

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 0.2s ease;
}
.poster img[data-loading="1"] { opacity: 0; }
.poster-fallback {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #1e1e1e 0%, #0a0a0a 60%, #161616 100%);
}
.poster-fallback::after {
  content: "";
  position: absolute;
  inset: 35% 30% 35% 30%;
  border: 2px solid var(--text-faint);
  border-radius: 4px;
  opacity: 0.4;
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border-radius: 6px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.badge[data-kind="premium"] {
  background: rgba(255, 214, 10, 0.18);
  color: var(--premium);
  border: 1px solid rgba(255, 214, 10, 0.3);
}
.badge[data-kind="free"] {
  background: rgba(48, 209, 88, 0.15);
  color: var(--free);
  border: 1px solid rgba(48, 209, 88, 0.3);
}

.card-meta {
  margin-top: 10px;
  padding: 0 2px;
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
}

/* ===== Empty / loading state ===== */

.loading, .empty-state {
  padding: 80px 24px;
  text-align: center;
  color: var(--text-dim);
}
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  color: var(--text-faint);
}
.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.empty-state p { font-size: 14px; }

/* ===== Detail view ===== */

.detail { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.detail-hero {
  position: relative;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  width: 100vw;
  margin-left: calc(50% - 50vw);
}
.detail-hero.no-poster {
  aspect-ratio: unset;
  height: 200px;
  background: linear-gradient(135deg, #1e1e1e 0%, #0a0a0a 100%);
}
.detail-poster {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}
.detail-hero-grad {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(0,0,0,0.5) 0%,
    rgba(0,0,0,0) 30%,
    rgba(0,0,0,0) 50%,
    rgba(0,0,0,0.9) 92%,
    var(--bg) 100%);
  z-index: 1;
}

.back-btn {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.back-btn:active { transform: scale(0.92); }

.detail-body {
  padding: 0 20px;
  margin-top: -32px;
  position: relative;
  z-index: 2;
}
.detail-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.detail-meta {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.detail-meta .dot { color: var(--text-faint); }
.detail-genres {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.detail-genres .g {
  font-size: 11px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 6px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-desc {
  margin-top: 18px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

.detail-cta {
  padding: 28px 20px 12px;
}
.cta-primary {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-md);
  font-size: 16px;
  font-weight: 600;
  transition: all 0.15s ease;
}
.cta-primary:active { transform: scale(0.98); background: var(--accent-hover); }
.cta-primary[disabled] { opacity: 0.55; pointer-events: none; }
.cta-primary .cta-icon { font-size: 13px; }
.cta-primary .cta-sub {
  font-size: 14px;
  font-weight: 600;
  padding-left: 10px;
  margin-left: 6px;
  border-left: 1px solid rgba(255, 255, 255, 0.3);
  opacity: 0.95;
}
.cta-note {
  margin-top: 12px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ===== Toast ===== */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(40, 40, 42, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  max-width: calc(100% - 40px);
  text-align: center;
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
  animation: toastIn 0.25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
.toast.error { color: #ff5e54; border-left: 3px solid #ff5e54; padding-left: 16px; }
.toast.success { color: var(--free); border-left: 3px solid var(--free); padding-left: 16px; }

/* ===== View transitions ===== */

[data-view-scope="list"] { display: flex; }
body[data-view="detail"] [data-view-scope="list"] { display: none; }

@media (min-width: 520px) {
  .movie-grid { grid-template-columns: repeat(3, 1fr); gap: 20px 16px; }
  .hero-title { font-size: 40px; }
}
