/* ============================================================
   REEL VIEWER — Full-screen TikTok-style overlay
   ============================================================ */
#cvguru-reel-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #000;
  display: none;
  align-items: center;
  justify-content: center;
  overscroll-behavior: contain;
  touch-action: none;
}
#cvguru-reel-overlay.active {
  display: flex;
  animation: reelFadeIn 240ms ease;
}
@keyframes reelFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Vertical stage — max 540px wide, full height (TikTok-style 9:16) */
.reel-stage {
  position: relative;
  width: 100%;
  max-width: 540px;
  height: 100%;
  height: 100dvh;
  background: #000;
  overflow: hidden;
}

/* Each reel is a vertical card stacked; we show one at a time */
/* Each reel is a vertical card — shown one at a time, independently.
   No slide animation between reels — just a clean fade so each reel
   feels like a standalone TikTok post (not part of a "row"). */
.reel-card {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: none; /* ★ no slide — independent feel */
  transition: opacity 280ms ease;
  pointer-events: none;
}
.reel-card.is-active {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
/* (is-prev class is no longer used but kept for backwards-compat) */
.reel-card.is-prev {
  opacity: 0;
  transform: none;
}

.reel-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  cursor: pointer;
  display: block;
}

/* Mute indicator pill (top-left) */
.reel-mute-pill {
  position: absolute;
  top: 16px;
  left: 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 5;
}
.reel-mute-pill svg { width: 14px; height: 14px; }

/* Close button (top-right) */
.reel-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
  transition: background 200ms ease, transform 200ms ease;
}
.reel-close-btn:hover {
  background: rgba(0, 0, 0, 0.8);
  transform: scale(1.05);
}
.reel-close-btn svg { width: 18px; height: 18px; }

/* Right-side icon rail (TikTok-style) */
.reel-actions {
  position: absolute;
  right: 12px;
  bottom: 90px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 5;
}
.reel-action-btn {
  width: 48px;
  height: 48px;
  border: none;
  background: transparent;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0;
  font-family: inherit;
}
.reel-action-btn svg {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
  transition: transform 200ms ease;
}
.reel-action-btn:hover svg { transform: scale(1.1); }
.reel-action-btn .count {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}
.reel-action-btn.liked svg { color: var(--danger); animation: reelHeartPop 360ms ease; }
@keyframes reelHeartPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.3); }
  100% { transform: scale(1.1); }
}

/* Author avatar circle in the icon rail (above actions) */
.reel-author-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #fff;
  background: var(--card-bg);
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.5));
}

/* Bottom caption block (TikTok-style) */
.reel-caption {
  position: absolute;
  left: 16px;
  right: 80px;
  bottom: 24px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  z-index: 4;
}
.reel-caption .author {
  display: block;
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}
.reel-caption .text {
  font-size: 14px;
  line-height: 1.4;
  opacity: 0.95;
  word-break: break-word;
}
.reel-caption .meta {
  margin-top: 6px;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.05em;
  opacity: 0.7;
}

/* Progress bar segments REMOVED — each reel is now standalone,
   not shown as part of a "row" of segments at the top. */

/* Swipe hint (shown briefly when overlay opens) */
.reel-swipe-hint {
  position: absolute;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 12px;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  z-index: 7;
  pointer-events: none;
  animation: reelHintFade 4s ease forwards;
}
@keyframes reelHintFade {
  0%   { opacity: 0; transform: translate(-50%, 20px); }
  10%  { opacity: 1; transform: translate(-50%, 0); }
  80%  { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* Empty state — no reel yet */
.reel-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: #fff;
  background: radial-gradient(circle at 50% 30%, rgba(0,212,255,0.18) 0%, transparent 60%), #000;
}
.reel-empty .icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  color: rgba(255,255,255,0.7);
}
.reel-empty .icon svg { width: 32px; height: 32px; }
.reel-empty h3 { margin: 0 0 8px; font-size: 18px; }
.reel-empty p  { margin: 0; font-size: 14px; opacity: 0.7; max-width: 320px; line-height: 1.5; }

/* ============================================================
   REEL RECORDER MODAL — opens from account settings
   ============================================================ */
#cvguru-reel-recorder-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#cvguru-reel-recorder-modal.active {
  display: flex;
  animation: reelFadeIn 240ms ease;
}

.reel-recorder-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.reel-recorder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.reel-recorder-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}
.reel-recorder-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: background 200ms ease, color 200ms ease;
}
.reel-recorder-close:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
}

/* Video preview — 9:16 aspect */
.reel-recorder-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.reel-recorder-stage video,
.reel-recorder-stage .placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.reel-recorder-stage .placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 20px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--card-bg) 100%);
}

/* Recording ring + timer overlay */
.reel-recorder-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}
.reel-rec-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
}
.reel-rec-timer .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: recPulse 1s ease-in-out infinite;
}
@keyframes recPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}
.reel-rec-timer.recording .dot { background: var(--danger); }
.reel-rec-timer:not(.recording) .dot { background: var(--success); animation: none; }

/* Big record / stop button (below stage) */
.reel-recorder-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 16px;
}
.reel-record-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 4px solid var(--primary);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms ease, border-color 150ms ease;
}
.reel-record-btn:hover { transform: scale(1.05); }
.reel-record-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.reel-record-btn .inner {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--primary);
  transition: all 200ms ease;
}
.reel-record-btn.recording .inner {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: var(--danger);
}
.reel-record-btn .helper {
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}

/* Caption input */
.reel-caption-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 70px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color 200ms ease;
}
.reel-caption-input:focus {
  border-color: var(--primary);
}
.reel-caption-input::placeholder {
  color: var(--text-muted);
}

/* Save button */
.reel-save-btn {
  width: 100%;
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #8247E5);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 200ms ease, transform 100ms ease;
}
.reel-save-btn:hover { transform: translateY(-1px); }
.reel-save-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Small "delete existing reel" link in recorder modal */
.reel-delete-link {
  display: block;
  margin-top: 12px;
  text-align: center;
  font-size: 12px;
  color: var(--danger);
  cursor: pointer;
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 200ms ease;
}
.reel-delete-link:hover { opacity: 1; text-decoration: underline; }

/* Permission / error toast inside recorder */
.reel-recorder-notice {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
  display: none;
}
.reel-recorder-notice.show { display: block; }
.reel-recorder-notice.error {
  background: rgba(255, 77, 109, 0.12);
  color: var(--danger);
}
.reel-recorder-notice.success {
  background: rgba(0, 255, 157, 0.12);
  color: var(--success);
}

/* Recording progress ring around stage */
.reel-progress-ring {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 12px;
  background: conic-gradient(var(--primary) calc(var(--p, 0) * 1%), transparent 0);
  -webkit-mask: radial-gradient(transparent calc(100% - 4px), #000 calc(100% - 4px));
          mask: radial-gradient(transparent calc(100% - 4px), #000 calc(100% - 4px));
  opacity: 0;
  transition: opacity 200ms ease;
}
.reel-progress-ring.show { opacity: 1; }

/* ============================================================
   PROFILE PICTURE — clickable affordance
   Add a small badge to indicate the profile picture opens a reel
   ============================================================ */
.profile-photo-wrapper {
  position: relative;
  cursor: pointer;
  display: inline-block;
}
.profile-photo-wrapper.has-reel::after {
  content: '';
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8247E5);
  border: 3px solid var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-photo-wrapper.has-reel .reel-badge-icon {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8247E5);
  border: 3px solid var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 2;
}
.profile-photo-wrapper.has-reel .reel-badge-icon svg {
  width: 12px;
  height: 12px;
}
.profile-photo-wrapper.has-reel::after { display: none; }

/* ============================================================
   ACCOUNT SETTINGS — Reel section
   ============================================================ */
.reel-settings-section {
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.reel-settings-section h4 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}
.reel-settings-section p {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.reel-settings-thumb {
  width: 100%;
  max-width: 180px;
  aspect-ratio: 9 / 16;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}
.reel-settings-thumb video,
.reel-settings-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.reel-settings-thumb .play-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.reel-settings-thumb .play-overlay svg { width: 32px; height: 32px; }

.reel-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 200ms ease, color 200ms ease;
}
.reel-add-btn:hover {
  background: var(--primary);
  color: #000;
}
.reel-add-btn svg { width: 14px; height: 14px; }

/* ============================================================
   MOBILE / SMALL VIEWPORT FIXES
   ============================================================
   Problem: On phones the recorder modal was too tall — the 9:16
   video preview + caption + save button couldn't all fit on screen,
   so "Salvesta reel" was below the fold and unclickable.

   Fix:
   1. Modal becomes scrollable (overflow-y: auto), aligned to top.
   2. Card uses full width with reduced padding.
   3. Video preview max-height capped (so it never eats the whole screen).
   4. Caption textarea is shorter (3 rows instead of 5).
   5. Save button gets a min-height + visible hit area.
   ============================================================ */

@media (max-width: 640px) {
  /* Modal sticks to top + scrolls down */
  #cvguru-reel-recorder-modal {
    align-items: flex-start;
    padding: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Card uses full width, tighter padding */
  .reel-recorder-card {
    max-width: 100%;
    padding: 16px;
    margin: 0 auto;
  }
  .reel-recorder-header {
    margin-bottom: 12px;
  }
  .reel-recorder-header h3 {
    font-size: 16px;
  }
  /* ★ Cap video preview height so it never eats the whole screen.
     On a 700px tall phone: max 50vh ≈ 350px is fine. */
  .reel-recorder-stage {
    aspect-ratio: auto;
    height: 50vh;
    max-height: 380px;
    margin-bottom: 12px;
  }
  /* Smaller record button on mobile */
  .reel-record-btn {
    width: 60px;
    height: 60px;
    border-width: 3px;
  }
  .reel-record-btn .inner {
    width: 44px;
    height: 44px;
  }
  .reel-recorder-controls {
    margin-bottom: 12px;
    position: relative;
    min-height: 80px; /* reserve space for the helper label below button */
  }
  /* ★ Caption textarea shorter on mobile so save button stays visible */
  .reel-caption-input {
    min-height: 54px;
    font-size: 13px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }
  /* ★ Save button — always visible, large tap target */
  .reel-save-btn {
    min-height: 48px;
    font-size: 15px;
    padding: 12px 16px;
    /* stick to bottom of viewport so user can always tap it */
    position: sticky;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary), #8247E5);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
  }
  /* Delete link + notice also stay readable */
  .reel-delete-link {
    margin-top: 10px;
    font-size: 13px;
    padding: 6px 0;
  }
  .reel-recorder-notice {
    margin-top: 8px;
    font-size: 12px;
  }
}

/* Extra-tiny phones (< 380px) — even more compact */
@media (max-width: 380px) {
  .reel-recorder-stage {
    height: 44vh;
    max-height: 320px;
  }
  .reel-recorder-card {
    padding: 12px;
  }
}

/* Landscape phone — video on left, controls on right (split layout) */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  #cvguru-reel-recorder-modal {
    padding: 8px;
    align-items: center;
  }
  .reel-recorder-card {
    max-width: 700px;
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
    padding: 16px;
  }
  .reel-recorder-header {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }
  .reel-recorder-stage {
    grid-column: 1;
    aspect-ratio: 9 / 16;
    height: auto;
    max-height: 60vh;
    margin-bottom: 0;
  }
  .reel-recorder-controls,
  .reel-caption-input,
  .reel-save-btn,
  .reel-delete-link,
  .reel-recorder-notice {
    grid-column: 2;
  }
  .reel-caption-input {
    min-height: 60px;
  }
  .reel-save-btn {
    position: static;
    box-shadow: none;
  }
}

/* ★★★ TOUCH DEVICE FIXES ★★★
   Make sure tap targets are large enough and scroll is smooth.
   - prevent iOS double-tap zoom on buttons
   - ensure caption input doesn't trigger zoom on focus (font-size >= 16px) */
@media (hover: none) and (pointer: coarse) {
  .reel-record-btn,
  .reel-save-btn,
  .reel-recorder-close,
  .reel-delete-link {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .reel-caption-input {
    font-size: 16px; /* iOS won't zoom on focus if >= 16px */
  }
}
