/* MAYA9 Shorts Reels — Facebook Reels / modern short-video style feed.
 * Built for mayanine.com/#shorts per owner directive 2026-10-26.
 *
 * Requirements:
 *  - Vertical full-screen scroll-snap feed (scroll-snap-type: y mandatory)
 *  - 9:16 vertical video centered with ambient soft blur backdrop from frame
 *  - Single-clip playback: only the visible clip plays, old clip pauses on scroll
 *  - Tap-to-pause on video surface with play/pause badge animation
 *  - Right-side vertical action rail: like (bounce), comment, share, save, more
 *  - Bottom-left poster info: avatar, name, follow pill, 2-line caption + read more, audio line, product pill
 *  - Thin progress bar at bottom of clip
 *  - Top-left tabs 'เพื่อคุณ / กำลังติดตาม' + top-right mute toggle
 *  - Tokens-only (no hex, standard breakpoints: 560, 820, 1120, 1380)
 *  - Touch targets >= 44px, text >= 12px, zero horizontal overflow at 320px
 */

/* -------------------------------------------------------------------------- *
 * 1. View shell & Main container overrides when Shorts is active
 * -------------------------------------------------------------------------- */
#legacyShortsCompat,
#view-shorts > .shorts-tabs {
  display: none !important;
}

body:has(#view-shorts.is-active) {
  overflow-x: clip;
}

#view-shorts.is-active {
  display: block !important;
  animation: none;
  width: 100%;
  max-width: 100%;
  margin: var(--m9-space-0) auto;
  padding: var(--m9-space-0);
  background: var(--m9-brand-navy);
  border-radius: var(--m9-radius-2xl);
  overflow: hidden;
  position: relative;
  box-sizing: border-box;
}

body:has(#view-shorts.is-active) main {
  width: 100%;
  max-width: 100%;
  margin: var(--m9-space-0) auto;
  padding: var(--m9-space-0) var(--m9-space-0) var(--m9-space-4);
  box-sizing: border-box;
}

/* -------------------------------------------------------------------------- *
 * 2. Shell & Header Tabs
 * -------------------------------------------------------------------------- */
.shorts-reels-shell {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--m9-topbar-height));
  height: calc(100dvh - var(--m9-topbar-height));
  overflow: hidden;
  background: var(--m9-brand-navy);
  display: flex;
  flex-direction: column;
}

.shorts-feed-header {
  position: absolute;
  top: var(--m9-space-3);
  left: var(--m9-space-0);
  right: var(--m9-space-0);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--m9-space-0) var(--m9-space-4);
  pointer-events: none;
}

.shorts-feed-tabs {
  display: inline-flex;
  align-items: center;
  gap: var(--m9-space-1-5);
  background: rgb(7 26 58 / 55%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: var(--m9-space-1);
  border-radius: var(--m9-radius-pill);
  border: 1px solid rgb(255 255 255 / 14%);
  pointer-events: auto;
}

.shorts-tab-pill {
  min-height: 44px;
  min-width: 80px;
  padding: var(--m9-space-1-5) var(--m9-space-3-5);
  border: var(--m9-space-0);
  background: transparent;
  color: rgb(255 255 255 / 75%);
  font-family: var(--m9-font-sans);
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.4;
  border-radius: var(--m9-radius-pill);
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.shorts-tab-pill:hover {
  color: var(--m9-on-primary);
}

.shorts-tab-pill.is-active {
  background: var(--m9-surface);
  color: var(--m9-brand-navy);
  box-shadow: 0 2px 8px rgb(0 0 0 / 25%);
}

.shorts-header-right {
  pointer-events: auto;
}

.shorts-sound-btn {
  min-width: 44px;
  min-height: 44px;
  padding: var(--m9-space-1) var(--m9-space-3);
  border-radius: var(--m9-radius-pill);
  background: rgb(7 26 58 / 60%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgb(255 255 255 / 16%);
  color: var(--m9-on-primary);
  display: inline-flex;
  align-items: center;
  gap: var(--m9-space-1-5);
  cursor: pointer;
  font-family: var(--m9-font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  transition: transform 0.15s ease, background 0.15s ease;
}

.shorts-sound-btn:hover {
  background: rgb(7 26 58 / 85%);
  transform: scale(1.03);
}

.shorts-sound-btn:active {
  transform: scale(0.97);
}

.shorts-sound-icon {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
}

.shorts-sound-icon .m9-icon {
  width: 18px;
  height: 18px;
}

.shorts-sound-badge {
  font-size: 0.75rem;
  color: var(--m9-on-primary);
}

/* -------------------------------------------------------------------------- *
 * 3. Scroll-snap Feed
 * -------------------------------------------------------------------------- */
.shorts-reels-feed {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.shorts-reels-feed::-webkit-scrollbar {
  width: 4px;
}

.shorts-reels-feed::-webkit-scrollbar-thumb {
  background: rgb(255 255 255 / 20%);
  border-radius: var(--m9-radius-pill);
}

/* -------------------------------------------------------------------------- *
 * 4. Reel Item & Ambient Backdrop
 * -------------------------------------------------------------------------- */
.reel-item {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--m9-brand-navy);
  box-sizing: border-box;
}

.reel-ambient {
  position: absolute;
  inset: -30px;
  background-size: cover;
  background-position: center;
  filter: blur(45px) brightness(0.38) saturate(1.2);
  transform: scale(1.15);
  opacity: 0.85;
  pointer-events: none;
  z-index: 1;
}

/* -------------------------------------------------------------------------- *
 * 5. Reel Center Frame (9:16 vertical card)
 * -------------------------------------------------------------------------- */
.reel-frame {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 420px;
  height: calc(100% - var(--m9-space-4));
  aspect-ratio: 9 / 16;
  max-height: 100%;
  margin: auto;
  border-radius: var(--m9-radius-2xl);
  overflow: hidden;
  background: var(--m9-brand-navy);
  box-shadow: 0 16px 48px rgb(0 0 0 / 40%), 0 0 0 1px rgb(255 255 255 / 8%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.reel-video-wrap {
  position: absolute;
  inset: var(--m9-space-0);
  width: 100%;
  height: 100%;
  cursor: pointer;
  background: var(--m9-brand-navy);
}

.reel-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  background: var(--m9-brand-navy);
}

.reel-vignette {
  position: absolute;
  inset: var(--m9-space-0);
  background: linear-gradient(
    180deg,
    rgb(7 26 58 / 45%) 0%,
    transparent 20%,
    transparent 55%,
    rgb(7 26 58 / 85%) 85%,
    rgb(7 26 58 / 95%) 100%
  );
  pointer-events: none;
  z-index: 3;
}

/* Play/Pause Badge Animation */
.reel-playback-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.65);
  width: 68px;
  height: 68px;
  border-radius: var(--m9-radius-pill);
  background: rgb(7 26 58 / 75%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 25%);
  color: var(--m9-on-primary);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.reel-playback-badge .m9-icon {
  width: 32px;
  height: 32px;
}

.reel-playback-badge.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* -------------------------------------------------------------------------- *
 * 6. Bottom-Left Poster Info
 * -------------------------------------------------------------------------- */
.reel-meta-panel {
  position: absolute;
  left: var(--m9-space-4);
  right: 76px;
  bottom: var(--m9-space-4);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: var(--m9-space-2);
  color: var(--m9-on-primary);
  pointer-events: auto;
}

.reel-creator-row {
  display: flex;
  align-items: center;
  gap: var(--m9-space-2);
  flex-wrap: wrap;
}

.reel-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: var(--m9-radius-pill);
  background: var(--m9-gradient-brand);
  color: var(--m9-on-primary);
  display: grid;
  place-items: center;
  font-family: var(--m9-font-sans);
  font-weight: 800;
  font-size: 1.0rem;
  box-shadow: 0 2px 6px rgb(0 0 0 / 30%);
}

.reel-creator-handle {
  font-family: var(--m9-font-sans);
  font-size: 0.9375rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--m9-on-primary);
  text-shadow: 0 1px 3px rgb(0 0 0 / 60%);
}

.reel-follow-pill {
  min-height: 44px;
  padding: var(--m9-space-1) var(--m9-space-3);
  border-radius: var(--m9-radius-pill);
  background: rgb(255 255 255 / 20%);
  border: 1px solid rgb(255 255 255 / 35%);
  color: var(--m9-on-primary);
  font-family: var(--m9-font-sans);
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.16s ease;
}

.reel-follow-pill:hover {
  background: rgb(255 255 255 / 30%);
  transform: translateY(-1px);
}

.reel-follow-pill.is-following {
  background: var(--m9-surface);
  color: var(--m9-brand-navy);
  border-color: var(--m9-surface);
}

/* Caption Block with 2-line clamp & read more */
.reel-caption-wrap {
  width: 100%;
}

.reel-caption {
  margin: var(--m9-space-0);
  font-family: var(--m9-font-sans);
  font-size: 0.875rem;
  line-height: 1.45;
  color: rgb(255 255 255 / 95%);
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
}

.reel-caption.is-collapsed .reel-caption-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.reel-read-more {
  display: inline-block;
  min-height: 44px;
  min-width: 44px;
  padding: var(--m9-space-0-5) var(--m9-space-1);
  background: transparent;
  border: var(--m9-space-0);
  color: rgb(255 255 255 / 85%);
  font-family: var(--m9-font-sans);
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reel-read-more:hover {
  color: var(--m9-on-primary);
}

/* Audio Line */
.reel-audio-row {
  display: flex;
  align-items: center;
  gap: var(--m9-space-1-5);
  font-family: var(--m9-font-sans);
  font-size: 0.75rem;
  color: rgb(255 255 255 / 80%);
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
}

.reel-audio-row .m9-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.reel-audio-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Shoppable Product Chip */
.reel-product-chip {
  min-height: 44px;
  width: 100%;
  max-width: 310px;
  background: rgb(7 26 58 / 75%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: var(--m9-radius-lg);
  padding: var(--m9-space-1-5) var(--m9-space-3);
  color: var(--m9-on-primary);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s ease, background 0.15s ease;
  font-family: var(--m9-font-sans);
}

.reel-product-chip:hover {
  background: rgb(7 26 58 / 90%);
  transform: translateY(-1px);
}

.reel-chip-tag {
  font-size: 0.75rem;
  color: var(--m9-teal);
  font-weight: 700;
  line-height: 1.2;
}

.reel-chip-name {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--m9-on-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  line-height: 1.3;
}

.reel-chip-price {
  font-size: 0.75rem;
  color: rgb(255 255 255 / 80%);
  line-height: 1.2;
}

/* -------------------------------------------------------------------------- *
 * 7. Right Action Rail (>=44px buttons, vertical)
 * -------------------------------------------------------------------------- */
.reel-action-rail {
  position: absolute;
  right: var(--m9-space-2-5);
  bottom: var(--m9-space-4);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--m9-space-2-5);
  pointer-events: auto;
}

.reel-rail-btn {
  min-width: 44px;
  min-height: 48px;
  padding: var(--m9-space-0);
  background: transparent;
  border: var(--m9-space-0);
  color: var(--m9-on-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: var(--m9-font-sans);
  transition: transform 0.15s ease;
}

.reel-rail-btn:hover {
  transform: scale(1.08);
}

.reel-rail-btn:active {
  transform: scale(0.92);
}

.reel-rail-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--m9-radius-pill);
  background: rgb(7 26 58 / 65%);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgb(255 255 255 / 20%);
  display: grid;
  place-items: center;
  transition: all 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.reel-rail-icon .m9-icon {
  width: 22px;
  height: 22px;
}

.reel-rail-count {
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--m9-on-primary);
  text-shadow: 0 1px 3px rgb(0 0 0 / 70%);
}

/* Like Bounce Keyframes & Active State */
@keyframes m9-reel-bounce {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); }
  65% { transform: scale(0.88); }
  100% { transform: scale(1); }
}

.reel-rail-btn.is-liked .reel-rail-icon {
  background: var(--m9-pink);
  border-color: var(--m9-pink);
  color: var(--m9-on-primary);
  animation: m9-reel-bounce 0.36s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.reel-rail-btn.is-saved .reel-rail-icon {
  background: var(--m9-teal);
  border-color: var(--m9-teal);
  color: var(--m9-brand-navy);
  animation: m9-reel-bounce 0.36s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* -------------------------------------------------------------------------- *
 * 8. Thin Progress Bar
 * -------------------------------------------------------------------------- */
.reel-progress-track {
  position: absolute;
  left: var(--m9-space-0);
  right: var(--m9-space-0);
  bottom: var(--m9-space-0);
  height: 3px;
  background: rgb(255 255 255 / 22%);
  z-index: 20;
}

.reel-progress-bar {
  width: 0%;
  height: 100%;
  background: var(--m9-primary);
  transition: width 0.12s linear;
}

/* -------------------------------------------------------------------------- *
 * 9. Honest Empty State for 'กำลังติดตาม'
 * -------------------------------------------------------------------------- */
.shorts-following-empty {
  position: absolute;
  inset: var(--m9-space-0);
  z-index: 25;
  background: var(--m9-brand-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--m9-space-4);
  box-sizing: border-box;
}

.shorts-empty-card {
  max-width: 400px;
  background: rgb(15 23 42 / 92%);
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: var(--m9-radius-2xl);
  padding: var(--m9-space-8) var(--m9-space-6);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--m9-space-3);
  color: var(--m9-on-primary);
  box-shadow: 0 12px 36px rgb(0 0 0 / 50%);
}

.shorts-empty-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--m9-radius-pill);
  background: rgb(255 255 255 / 10%);
  display: grid;
  place-items: center;
  color: var(--m9-teal);
}

.shorts-empty-icon .m9-icon {
  width: 28px;
  height: 28px;
}

.shorts-empty-title {
  font-family: var(--m9-font-sans);
  font-size: 1.125rem;
  font-weight: 800;
  margin: var(--m9-space-0);
}

.shorts-empty-desc {
  font-family: var(--m9-font-sans);
  font-size: 0.875rem;
  line-height: 1.5;
  color: rgb(255 255 255 / 75%);
  margin: var(--m9-space-0);
}

.shorts-switch-to-foryou {
  min-height: 44px;
  padding: var(--m9-space-2) var(--m9-space-5);
  font-size: 0.875rem;
  font-weight: 700;
  border-radius: var(--m9-radius-pill);
  margin-top: var(--m9-space-2);
}

/* -------------------------------------------------------------------------- *
 * 10. Responsive Breakpoints: 1380, 1120, 820, 560
 * -------------------------------------------------------------------------- */
@media (max-width: 1380px) {
  .reel-frame {
    max-width: 400px;
  }
}

@media (max-width: 1120px) {
  .reel-frame {
    max-width: 390px;
  }
}

@media (max-width: 820px) {
  #view-shorts.is-active {
    border-radius: var(--m9-space-0);
    min-height: calc(100dvh - var(--m9-topbar-height));
  }

  .shorts-reels-shell {
    height: calc(100vh - var(--m9-topbar-height));
    height: calc(100dvh - var(--m9-topbar-height));
  }

  .reel-frame {
    width: 100%;
    max-width: 420px;
    height: 100%;
    border-radius: var(--m9-space-0);
  }

  /* Clear the mobile navigation at bottom */
  .reel-meta-panel {
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px) + 12px);
    right: 72px;
  }

  .reel-action-rail {
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px) + 12px);
    right: var(--m9-space-2);
  }

  .reel-progress-track {
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px));
  }
}

@media (max-width: 560px) {
  /* True full-screen 100dvh on mobile */
  #view-shorts.is-active {
    position: fixed;
    inset: var(--m9-space-0);
    z-index: 40;
    width: 100%;
    height: 100dvh;
    height: 100vh;
    border-radius: var(--m9-space-0);
    margin: var(--m9-space-0);
    padding: var(--m9-space-0);
  }

  body:has(#view-shorts.is-active) main {
    padding: var(--m9-space-0);
  }

  .shorts-reels-shell {
    height: 100dvh;
    height: 100vh;
  }

  .shorts-feed-header {
    top: max(10px, env(safe-area-inset-top, 10px));
    padding-inline: var(--m9-space-3);
  }

  .reel-frame {
    max-width: 100%;
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: var(--m9-space-0);
    box-shadow: none;
  }

  .reel-video {
    object-fit: cover;
  }

  .reel-meta-panel {
    left: var(--m9-space-3);
    right: 68px;
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px) + 10px);
    gap: var(--m9-space-1-5);
  }

  .reel-action-rail {
    right: var(--m9-space-1-5);
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px) + 10px);
    gap: var(--m9-space-2);
  }

  .reel-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    font-size: 0.875rem;
  }

  .reel-creator-handle {
    font-size: 0.875rem;
  }

  .reel-follow-pill {
    min-height: 44px;
    padding: var(--m9-space-1) var(--m9-space-2-5);
    font-size: 0.75rem;
  }

  .reel-caption {
    font-size: 0.8125rem;
  }

  .reel-product-chip {
    max-width: 240px;
    padding: var(--m9-space-1) var(--m9-space-2-5);
  }

  .reel-chip-name {
    font-size: 0.75rem;
  }

  .reel-progress-track {
    bottom: calc(var(--phone-nav, 68px) + var(--phone-bottom, 0px));
  }
}
