:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --ink-dim: rgba(248, 250, 252, 0.72);
  --ink-faint: rgba(248, 250, 252, 0.38);
  --night: #020406;
  --glass: rgba(0, 0, 0, 0.42);
  --glass-border: rgba(248, 250, 252, 0.14);
  --accent: #a78bfa;
  --accent-dim: rgba(167, 139, 250, 0.18);
  --danger: #f87171;
  --panel-radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--night);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  cursor: pointer;
}

/* ─── Layout ─────────────────────────────────────────── */

.shorts-shell,
.shorts-player {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--night);
}

.shorts-player {
  isolation: isolate;
}

.clip-stage,
.preload-stage,
.empty-player,
.gesture-layer,
.edge-shade {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ─── Video stage ─────────────────────────────────────── */

.clip-stage {
  z-index: 0;
  will-change: transform;
}

.clip-stage.is-dragging {
  transition: none;
}

.clip-stage.is-settling {
  transition: transform 220ms cubic-bezier(0.2, 0.72, 0.18, 1);
}

#clip-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #000;
}

#clip-frame,
#preload-frame,
#preload-frame iframe {
  border: 0;
  background: #000;
}

/* Center 9:16 on wide screens */
@media (min-aspect-ratio: 10 / 16) {
  #clip-frame {
    width: min(100vw, calc(100vh * 9 / 16));
    left: 50%;
    transform: translateX(-50%);
  }
}

/* ─── Preload stage ───────────────────────────────────── */

.preload-stage {
  z-index: -1;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translate3d(-200vw, -200vh, 0);
}

.preload-stage iframe {
  width: 1px;
  height: 1px;
}

/* ─── Edge vignette ───────────────────────────────────── */

.edge-shade {
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0,0,0,0.22) 0%, transparent 14%, transparent 72%, rgba(0,0,0,0.52) 100%),
    linear-gradient(90deg, rgba(0,0,0,0.10) 0%, transparent 22%, transparent 78%, rgba(0,0,0,0.10) 100%);
}

/* ─── Gesture layer ───────────────────────────────────── */

.gesture-layer {
  z-index: 3;
  display: block;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.gesture-layer:active {
  cursor: grabbing;
}

/* ─── Empty / loading state ───────────────────────────── */

.empty-player {
  z-index: 1;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--ink-dim);
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
  background: var(--night);
}

/* ─── Video meta (category chip) ─────────────────────── */

.video-meta {
  position: absolute;
  left: max(14px, var(--safe-left));
  bottom: calc(max(90px, var(--safe-bottom)) + 56px);
  z-index: 5;
  pointer-events: none;
}

.category-chip {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--ink-dim);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 240ms ease, transform 240ms ease;
}

.category-chip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ─── Volume chip ─────────────────────────────────────── */

.volume-chip {
  position: absolute;
  top: max(14px, var(--safe-top));
  left: 50%;
  z-index: 5;
  margin: 0;
  min-width: 54px;
  padding: 7px 12px;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--ink-dim);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 160ms ease, transform 160ms ease;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.volume-chip.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ─── Action buttons ──────────────────────────────────── */

.action-bar {
  position: absolute;
  right: max(14px, var(--safe-right));
  bottom: max(24px, var(--safe-bottom));
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.action-btn {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: var(--glass);
  color: var(--ink-dim);
  padding: 0;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 160ms ease, color 160ms ease, transform 120ms ease;
}

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

.action-btn:hover {
  background: rgba(248, 250, 252, 0.12);
  color: var(--ink);
}

.action-btn:active {
  transform: scale(0.92);
}

.action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.dislike-button.is-fired {
  background: rgba(248, 113, 113, 0.18);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.32);
}

/* ─── Scroll cue ──────────────────────────────────────── */

.scroll-cue {
  position: absolute;
  left: 50%;
  bottom: max(24px, var(--safe-bottom));
  z-index: 4;
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.38);
  color: var(--ink-dim);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.scroll-cue.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ─── Preferences backdrop ────────────────────────────── */

.prefs-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.prefs-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ─── Preferences panel ───────────────────────────────── */

.prefs-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 11;
  max-height: 82vh;
  border-radius: var(--panel-radius) var(--panel-radius) 0 0;
  background: #0d0f12;
  border-top: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 320ms cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  /* Constrain width on wide screens */
  max-width: min(480px, 100vw);
  margin: 0 auto;
}

@media (min-aspect-ratio: 10 / 16) {
  .prefs-panel {
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    margin: 0;
  }

  .prefs-panel.is-open {
    transform: translateX(-50%) translateY(0);
  }
}

.prefs-panel.is-open {
  transform: translateY(0);
}

.prefs-drag-handle {
  width: 36px;
  height: 4px;
  margin: 12px auto 0;
  border-radius: 2px;
  background: rgba(248, 250, 252, 0.2);
  flex-shrink: 0;
}

.prefs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
  flex-shrink: 0;
}

.prefs-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.prefs-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  background: rgba(248, 250, 252, 0.06);
  color: var(--ink-dim);
  padding: 0;
  transition: background 160ms ease;
}

.prefs-close svg {
  width: 16px;
  height: 16px;
}

.prefs-close:hover {
  background: rgba(248, 250, 252, 0.12);
  color: var(--ink);
}

.prefs-close:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.prefs-subtitle {
  margin: 0 20px 16px;
  font-size: 0.8rem;
  color: var(--ink-faint);
  line-height: 1.4;
  flex-shrink: 0;
}

.prefs-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px calc(max(8px, var(--safe-bottom)));
  -webkit-overflow-scrolling: touch;
}

/* ─── Preferences category section ───────────────────── */

.prefs-section-label {
  padding: 8px 4px 6px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.prefs-category-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.prefs-category-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  background: rgba(248, 250, 252, 0.04);
  transition: background 160ms ease;
}

.prefs-category-row.is-blocked {
  background: rgba(248, 113, 113, 0.06);
  border-color: rgba(248, 113, 113, 0.18);
}

.prefs-category-info {
  flex: 1;
  min-width: 0;
}

.prefs-category-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prefs-category-row.is-blocked .prefs-category-name {
  color: var(--ink-dim);
}

.prefs-category-meta {
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--ink-faint);
}

/* Toggle switch */
.prefs-toggle {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 26px;
  border: none;
  border-radius: 999px;
  background: rgba(248, 250, 252, 0.14);
  cursor: pointer;
  padding: 0;
  transition: background 200ms ease;
}

.prefs-toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1), background 200ms ease;
}

.prefs-toggle[aria-pressed="true"] {
  background: var(--accent);
}

.prefs-toggle[aria-pressed="true"]::after {
  transform: translateX(18px);
  background: #fff;
}

.prefs-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ─── Preferences empty hint ──────────────────────────── */

.prefs-empty-hint {
  margin: 32px 0;
  font-size: 0.85rem;
  color: var(--ink-faint);
  text-align: center;
}

/* ─── Preferences footer ──────────────────────────────── */

.prefs-footer {
  flex-shrink: 0;
  padding: 12px 16px calc(max(16px, var(--safe-bottom)));
  border-top: 1px solid var(--glass-border);
}

.prefs-reset-btn {
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.08);
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 160ms ease;
}

.prefs-reset-btn:hover {
  background: rgba(248, 113, 113, 0.14);
}

.prefs-reset-btn:focus-visible {
  outline: 2px solid var(--danger);
  outline-offset: 2px;
}

/* ─── Onboarding screen ───────────────────────────────── */

.onboarding {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--night);
  padding: 32px max(24px, var(--safe-left));
  animation: onboarding-in 360ms cubic-bezier(0.2, 0.72, 0.18, 1) both;
}

.onboarding.is-dismissing {
  animation: onboarding-out 260ms ease forwards;
  pointer-events: none;
}

@keyframes onboarding-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes onboarding-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(1.04); }
}

.onboarding-inner {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.onboarding-eyebrow {
  margin: 0 0 10px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.onboarding-prompt {
  margin: 0 0 36px;
  font-size: clamp(1.6rem, 6vw, 2rem);
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--ink);
  text-align: center;
  line-height: 1.15;
}

.onboarding-picks {
  width: 100%;
  display: flex;
  gap: 12px;
  min-height: 160px;
  align-items: stretch;
}

.onboarding-loading {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--ink-faint);
  margin: 0;
}

.onboarding-pick-btn {
  flex: 1;
  min-height: 160px;
  padding: 24px 16px;
  border: 1px solid var(--glass-border);
  border-radius: 18px;
  background: rgba(248, 250, 252, 0.04);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: background 180ms ease, border-color 180ms ease, transform 140ms ease, color 180ms ease;
  animation: pick-in 320ms cubic-bezier(0.2, 0.72, 0.18, 1) both;
}

.onboarding-pick-btn:nth-child(2) {
  animation-delay: 60ms;
}

@keyframes pick-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.onboarding-pick-btn:hover {
  background: var(--accent-dim);
  border-color: rgba(167, 139, 250, 0.4);
  color: var(--ink);
}

.onboarding-pick-btn:active {
  transform: scale(0.96);
}

.onboarding-pick-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* ─── Screen reader only ──────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}
