/* APEX AI Companion — phone chrome (extends apex-site tokens) */

:root {
  --companion-safe-bottom: max(10px, env(safe-area-inset-bottom));
}

html, body {
  height: 100%;
  background: #000;
  color: #f8fafc;
}

body.companion-app {
  overflow-x: hidden;
}

/* Signed-out: auth only — no bottom nav / TV chrome */
body.companion-locked #app {
  padding-bottom: calc(1.5rem + var(--companion-safe-bottom));
}
body.companion-locked .bottom-nav,
body.companion-locked #tvFab,
body.companion-locked #partyAudioBar {
  display: none !important;
}

/* QR / pairing without a Companion login: Remote + Account only */
body.companion-guest-remote [data-tab="home"],
body.companion-guest-remote [data-tab="search"],
body.companion-guest-remote [data-tab="live"] {
  display: none !important;
}

#app {
  min-height: 100%;
  max-width: 32rem;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(6.5rem + var(--companion-safe-bottom));
}

.companion-header .eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: #6366f1;
}

.companion-header .studio {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: #475569;
}

.bottom-nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: 40;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(0,0,0,0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 0.5rem 0.5rem var(--companion-safe-bottom);
}

.bottom-nav .nav-inner {
  max-width: 32rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(3.4rem, 1fr));
  gap: 0.25rem;
}

.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.75rem;
  padding: 0.5rem 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #94a3b8;
  transition: color .2s, background .2s;
}

.bottom-nav button.is-active {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.08);
}

.tv-fab {
  position: fixed;
  right: 1rem;
  bottom: calc(5.5rem + var(--companion-safe-bottom));
  z-index: 50;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 10px 30px rgba(99,102,241,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .2s, filter .2s;
}

.tv-fab:hover { transform: scale(1.05); filter: brightness(1.08); }
.tv-fab.is-hidden { display: none; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-panel {
  position: relative;
  z-index: 10;
  width: 100%;
  max-width: 32rem;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 1.5rem 1.5rem 0 0;
  border: 1px solid rgba(255,255,255,0.1);
  background: #080810;
  padding: 0.75rem 1rem calc(1.25rem + var(--companion-safe-bottom));
  box-shadow: 0 -20px 60px rgba(0,0,0,0.5);
}

.filter-btn {
  padding: 10px 24px;
  min-height: 44px;
  border-radius: 24px;
  border: 2px solid rgba(255,255,255,0.4);
  background: transparent;
  color: #fff;
  font-size: 16px;
}
.filter-btn--active { background: #E50914; border-color: #E50914; }
.catalog-filter-sheet { max-height: 70vh; padding: 0; }
.filter-tabs { display: flex; flex-wrap: wrap; align-items: center; border-bottom: 1px solid rgba(255,255,255,0.1); padding: 0 8px; }
.filter-tab {
  min-height: 48px;
  padding: 12px 16px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: #aaa;
  font-size: 15px;
}
.filter-tab.active { color: #fff; border-bottom-color: #E50914; }
.filter-clear { margin-left: auto; min-height: 48px; color: #E50914; background: transparent; border: none; padding: 12px; }
.filter-search-input {
  width: calc(100% - 24px);
  margin: 8px 12px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.15);
  background: #12121f;
  color: #fff;
  padding: 0 12px;
}
.filter-content { overflow-y: auto; max-height: 48vh; }
.filter-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: #fff;
  text-align: left;
}
.filter-option__radio {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4); flex-shrink: 0;
}
.filter-option--selected .filter-option__radio { background: #E50914; border-color: #E50914; }
.filter-option--selected .filter-option__label { color: #E50914; }
.filter-option__text { display: flex; flex-direction: column; }
.filter-option__sub { color: #94a3b8; font-size: 12px; }

.pad-btn {
  width: 100%;
  aspect-ratio: 1;
  max-width: 4.5rem;
  border-radius: 1rem;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.65rem;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .1s;
  touch-action: manipulation;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.pad-btn > * { pointer-events: none; }

.pad-btn:active,
.pad-btn.is-pressed { transform: scale(0.94); background: rgba(99,102,241,0.28); }
.pad-btn.is-primary {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-color: transparent;
}
.pad-btn.is-primary.is-pressed { filter: brightness(1.15); }

.remote-pad { display: flex; flex-direction: column; gap: 0.75rem; }
.remote-status {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 0.7rem; font-weight: 600; color: #94a3b8;
}
.remote-dot {
  width: 0.55rem; height: 0.55rem; border-radius: 999px;
  background: #ef4444; flex-shrink: 0;
}
.remote-pad.is-paired .remote-dot {
  background: #10b981; box-shadow: 0 0 10px #10b98188;
}
.dpad {
  width: min(16.5rem, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}
.dpad .pad-btn { max-width: none; aspect-ratio: 1; min-height: 3.4rem; }
.dpad-spacer { visibility: hidden; }
.remote-transport,
.remote-seek,
.remote-live,
.remote-extras {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
}
.remote-transport { grid-template-columns: 1fr 1.35fr 1fr; }
.remote-seek { grid-template-columns: 1fr 1fr; }
.remote-transport .pad-btn,
.remote-seek .pad-btn,
.remote-live .pad-btn,
.remote-extras .pad-btn {
  max-width: none;
  aspect-ratio: auto;
  min-height: 3.1rem;
}
.remote-jump {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
}
.remote-chip {
  flex: 1 1 22%;
  min-height: 2.4rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #e2e8f0;
  font-size: 0.7rem;
  font-weight: 700;
  touch-action: manipulation;
}
.remote-chip:active { background: rgba(99,102,241,0.25); }
.remote-hint {
  text-align: center;
  font-size: 0.65rem;
  color: #64748b;
  line-height: 1.35;
  margin: 0;
}
.remote-advanced summary { list-style: none; }
.remote-advanced summary::-webkit-details-marker { display: none; }
#turnstileHost { min-height: 72px; }
@media (max-width: 380px) {
  .remote-live, .remote-extras { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #94a3b8;
}

.field-input, .field-textarea {
  margin-top: 0.35rem;
  width: 100%;
  border-radius: 0.75rem;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(0,0,0,0.35);
  color: #f8fafc;
  padding: 0.7rem 0.85rem;
  font-size: 0.875rem;
  outline: none;
  transition: border-color .2s;
}

.field-input:focus, .field-textarea:focus {
  border-color: rgba(99,102,241,0.6);
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  border: 1px solid rgba(255,255,255,0.12);
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #e2e8f0;
  background: transparent;
  transition: background .2s, border-color .2s, color .2s;
}

.chip.is-active {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border-color: transparent;
  color: #fff;
}

.chip-gold.is-active {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0a0a0a;
}

.banner {
  border-radius: 0.75rem;
  border: 1px solid;
  padding: 0.6rem 0.85rem;
  font-size: 0.875rem;
}

.banner-ok {
  border-color: rgba(16,185,129,0.35);
  background: rgba(16,185,129,0.12);
  color: #34d399;
}

.banner-danger {
  border-color: rgba(239,68,68,0.35);
  background: rgba(239,68,68,0.12);
  color: #f87171;
}

.poster-card {
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

.poster-score {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 2px 7px;
  border-radius: 8px;
  background: rgba(16, 20, 36, 0.82);
  color: #ffd60a;
  font-size: 11px;
  font-weight: 700;
}

.poster-card img,
.poster-card .poster-fallback {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: #12121f;
}

.poster-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: rgba(99,102,241,0.45);
}

.shelf-row {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.shelf-row > * {
  scroll-snap-align: start;
  width: 8.5rem;
}

/* Cloud library — Continue Watching / My List */
.lib-card { position: relative; }

.lib-card-actions {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  display: flex;
  gap: 0.25rem;
  z-index: 2;
}

.lib-icon-btn {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 9999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(0,0,0,0.65);
  color: #f8fafc;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
}

.lib-icon-btn.lib-bookmark.is-on {
  background: rgba(99,102,241,0.85);
  border-color: transparent;
  color: #fff;
}

.lib-icon-btn.lib-remove:hover {
  background: rgba(239,68,68,0.85);
  border-color: transparent;
}

.cw-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: rgba(0,0,0,0.4);
}

.cw-progress span {
  display: block;
  height: 100%;
  background: #E50914;
  transition: width 0.2s ease;
}

.watched-badge {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  z-index: 2;
  font-size: 0.7rem;
  font-weight: 700;
  color: #E50914;
  background: rgba(16, 20, 36, 0.85);
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
}

.settings-shell .field-label + .field-label,
.settings-shell label.flex + .field-label {
  margin-top: 0.35rem;
}

.toast {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: calc(6rem + var(--companion-safe-bottom));
  z-index: 70;
  max-width: 32rem;
  margin: 0 auto;
  border-radius: 0.75rem;
  border: 1px solid rgba(255,255,255,0.1);
  background: #12121f;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.success-burst {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.success-burst .ring {
  width: 4rem;
  height: 4rem;
  border-radius: 9999px;
  border: 3px solid #10b981;
  animation: burst 0.9s ease-out forwards;
}

@keyframes burst {
  0% { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

.panel-hidden { display: none !important; }

.h-scroll {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

@media (prefers-reduced-motion: reduce) {
  .tv-fab, .pad-btn, .chip, .bottom-nav button { transition: none; }
  .success-burst .ring { animation: none; opacity: 0; }
}

/* Party Hub */
body.in-party #app {
  padding-bottom: calc(9.5rem + var(--companion-safe-bottom));
}

.party-audio-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(3.75rem + var(--companion-safe-bottom));
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 32rem;
  margin: 0 auto;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  background: rgba(8,8,16,0.96);
  backdrop-filter: blur(16px);
}

.party-audio-bar button {
  min-height: 40px;
  border-radius: 0.75rem;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.65rem;
}

.party-audio-bar button[aria-pressed="true"] {
  background: rgba(99,102,241,0.35);
  border-color: transparent;
}

.party-audio-bar button.is-disabled,
.party-audio-bar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.party-voice-status {
  margin-left: auto;
  font-size: 0.75rem;
  color: #94a3b8;
}

.party-msg {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.party-msg .avatar {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  display: grid;
  place-items: center;
  background: #1a1a2e;
  font-weight: 700;
  font-size: 0.75rem;
}

.party-member-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 0.75rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}

.party-member-row .actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
}


/* Plan badges */
.plan-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  border: 1px solid transparent;
}
.plan-free { color: #94a3b8; border-color: #64748b55; background: #64748b22; }
.plan-basic { color: #e2e8f0; border-color: #cbd5e155; background: #94a3b822; }
.plan-plus { color: #93c5fd; border-color: #3b82f655; background: #2563eb22; }
.plan-pro { color: #fbbf24; border-color: #f59e0b55; background: #f59e0b22; }

/* Keyboard focus */
.companion-app :focus {
  outline: none;
}
.companion-app :focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}
.bottom-nav button:focus-visible,
.tv-fab:focus-visible,
.pad-btn:focus-visible,
.chip:focus-visible,
.btn-gold:focus-visible,
.btn-shimmer:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}
.field-input:focus-visible,
.field-textarea:focus-visible {
  border-color: rgba(245, 158, 11, 0.75);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

/* Loading skeletons */
@keyframes companion-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}
.skeleton-hero,
.skeleton-card,
.skeleton-chip {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.1) 45%, rgba(255,255,255,0.04) 90%);
  background-size: 200% 100%;
  animation: companion-shimmer 1.2s ease-in-out infinite;
  border: 1px solid rgba(255,255,255,0.06);
}
.skeleton-hero {
  height: 9.5rem;
  border-radius: 1rem;
}
.skeleton-row {
  display: flex;
  gap: 0.75rem;
  overflow: hidden;
}
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.skeleton-card {
  aspect-ratio: 2 / 3;
  border-radius: 0.85rem;
  min-width: 7.5rem;
  flex: 0 0 7.5rem;
}
.skeleton-chip {
  height: 2rem;
  min-width: 4.5rem;
  border-radius: 9999px;
  flex: 0 0 auto;
}

.home-quick-actions {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
}
.home-quick-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
  border-radius: 9999px;
  padding: 0.65rem 1rem;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #f8fafc;
  font-size: 0.8rem;
  font-weight: 650;
}
.home-connect-card {
  border: 1px solid rgba(99, 102, 241, 0.45);
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.16), rgba(6, 182, 212, 0.08));
}
.home-connected-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border-radius: 9999px;
  padding: 0.45rem 0.85rem;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #ecfdf5;
  font-size: 0.75rem;
  font-weight: 650;
}
.live-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 9999px;
  background: #ef4444;
  animation: livePulse 1.5s ease-in-out infinite;
}
@keyframes livePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.5; }
}

@media (min-width: 768px) {
  #app {
    max-width: 40rem;
  }
  .bottom-nav .nav-inner,
  .sheet-panel {
    max-width: 40rem;
  }
}
