/* =========================================================
   PULSE — css/create-moment.css
   Phase 2: Full-screen Moments creation/editor experience
   Mobile-first, WhatsApp Status-inspired, Pulse-branded.
   ========================================================= */

/* Root immersive layout */
.moment-create-root,
.moment-create-root * { box-sizing: border-box; }

.moment-create-view {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: #000;
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.moment-create-view.light-ui { background: var(--bg, #f5f3f0); color: var(--text, #222); }

.mc-hidden { display: none !important; }

.mc-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 8px;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), rgba(0,0,0,0));
  pointer-events: none;
}
.mc-topbar > * { pointer-events: auto; }
.mc-topbar.compact { background: none; }
.mc-topbar-title {
  font-size: 15px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.5);
  flex: 1; text-align: center;
}

.mc-icon-btn, .mc-chip-btn, .mc-pill-btn {
  appearance: none; border: 0; cursor: pointer; color: #fff;
  background: rgba(0,0,0,.35); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.mc-icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-grid; place-items: center; font-size: 18px; line-height: 1;
}
.mc-icon-btn:active, .mc-chip-btn:active, .mc-pill-btn:active { transform: scale(.96); }
.mc-icon-btn[disabled], .mc-pill-btn[disabled] { opacity: .45; pointer-events: none; }

.mc-toolbar {
  display: flex; align-items: center; gap: 6px;
}
.mc-toolbar.vertical { flex-direction: column; gap: 10px; }

.mc-chip-btn {
  height: 34px; padding: 0 12px; border-radius: 999px;
  font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px;
}
.mc-chip-btn.active { background: rgba(255,255,255,.22); box-shadow: inset 0 0 0 1px rgba(255,255,255,.35); }

.mc-pill-btn {
  min-height: 40px; padding: 0 16px; border-radius: 999px;
  font-size: 14px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.mc-pill-btn.primary {
  background: linear-gradient(135deg, var(--primary, #7c3aed), var(--primary-2, #a855f7));
  color: #fff; box-shadow: 0 6px 18px rgba(124,58,237,.35);
}
.mc-pill-btn.secondary { background: rgba(255,255,255,.14); }
.light-ui .mc-icon-btn, .light-ui .mc-chip-btn, .light-ui .mc-pill-btn.secondary {
  background: var(--surface, #fff); color: var(--text, #222); box-shadow: var(--clay-raised, 0 2px 8px rgba(0,0,0,.08));
}
.light-ui .mc-topbar-title { color: var(--text, #222); text-shadow: none; }

/* Main stage */
.mc-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #000;
  touch-action: none;
}
.mc-stage-inner {
  position: relative;
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.mc-preview-media {
  max-width: 100%; max-height: 100%;
  width: 100%; height: 100%;
  object-fit: contain;
  user-select: none; -webkit-user-select: none;
  transform-origin: center center;
}
.mc-preview-video { background: #000; }

.mc-overlay-layer, .mc-draw-layer {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}
.mc-overlay-layer.interactive, .mc-draw-layer.interactive { pointer-events: auto; }
.mc-draw-layer canvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* Overlay objects (text, stickers, emoji) */
.mc-object {
  position: absolute;
  transform-origin: center center;
  user-select: none; -webkit-user-select: none;
  touch-action: none;
  cursor: grab;
}
.mc-object.selected { outline: 2px solid rgba(255,255,255,.95); outline-offset: 4px; }
.mc-object .mc-delete-badge {
  position: absolute; top: -12px; right: -12px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #ef4444; color: #fff; font-size: 14px; font-weight: 700;
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.3); border: 2px solid #fff;
}
.mc-object.selected .mc-delete-badge { display: flex; }

.mc-text-obj {
  padding: 4px 8px;
  white-space: pre-wrap;
  line-height: 1.2;
  text-align: center;
  max-width: 86vw;
  word-break: break-word;
}
.mc-sticker-obj { font-size: 56px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.mc-sticker-obj img { width: 96px; height: 96px; object-fit: contain; display: block; }

/* Bottom area */
.mc-bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  padding: 10px 10px calc(env(safe-area-inset-bottom, 0px) + 10px);
  background: linear-gradient(to top, rgba(0,0,0,.72), rgba(0,0,0,0));
  display: flex; flex-direction: column; gap: 10px;
}
.mc-bottom-row {
  display: flex; align-items: center; gap: 8px;
}
.mc-caption-input {
  flex: 1; min-width: 0;
  height: 42px; border-radius: 999px; border: 0;
  padding: 0 14px;
  background: rgba(255,255,255,.14); color: #fff;
  font-size: 14px; outline: none;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.mc-caption-input::placeholder { color: rgba(255,255,255,.7); }
.light-ui .mc-caption-input { background: var(--surface,#fff); color: var(--text,#222); box-shadow: var(--clay-inset, inset 0 1px 3px rgba(0,0,0,.08)); }
.light-ui .mc-caption-input::placeholder { color: var(--text-2,#777); }

.mc-meta-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.mc-meta-pill {
  height: 30px; padding: 0 10px; border-radius: 999px;
  background: rgba(255,255,255,.14); color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
}
.mc-meta-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

/* Picker screen */
.mc-picker {
  position: absolute; inset: 0; z-index: 30;
  background: var(--bg, #0f0f12); color: var(--text, #fff);
  display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top, 0px);
}
.mc-picker-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; gap: 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.2);
}
.mc-picker-header h2 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; text-align: center; }
.mc-picker-body { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; padding: 12px; }

.mc-source-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px;
}
.mc-source-card {
  border: 0; border-radius: 16px; padding: 14px; text-align: left;
  background: var(--surface, #1a1a22); color: var(--text, #fff);
  box-shadow: var(--clay-raised, 0 4px 14px rgba(0,0,0,.18));
  display: flex; flex-direction: column; gap: 6px; min-height: 92px; cursor: pointer;
}
.mc-source-card strong { font-size: 15px; }
.mc-source-card span { font-size: 12px; color: var(--text-2, #a1a1aa); }
.mc-source-card .mc-source-icon { font-size: 22px; }

.mc-tabs { display: flex; gap: 6px; margin: 4px 0 10px; }
.mc-tab {
  flex: 1; border: 0; border-radius: 999px; height: 34px; font-weight: 700; font-size: 13px;
  background: var(--bg-2, #23232c); color: var(--text-2, #a1a1aa); cursor: pointer;
}
.mc-tab.active { background: linear-gradient(135deg, var(--primary,#7c3aed), var(--primary-2,#a855f7)); color: #fff; }

.mc-thumb-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
}
.mc-thumb {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; margin: 0;
  background: #222; overflow: hidden; cursor: pointer; border-radius: 6px;
}
.mc-thumb img, .mc-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.mc-thumb .mc-badge {
  position: absolute; top: 6px; right: 6px;
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
  background: rgba(0,0,0,.55); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.mc-thumb.selected { outline: 3px solid var(--primary,#7c3aed); outline-offset: -3px; }
.mc-thumb.selected .mc-badge { background: var(--primary,#7c3aed); }
.mc-empty { color: var(--text-2,#a1a1aa); font-size: 14px; text-align: center; padding: 24px 8px; }

/* Sheets / panels */
.mc-sheet-backdrop {
  position: absolute; inset: 0; z-index: 40; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.mc-sheet {
  width: 100%; max-height: 82vh;
  background: var(--surface, #17171d); color: var(--text, #fff);
  border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  box-shadow: 0 -10px 30px rgba(0,0,0,.35);
  overflow: auto; -webkit-overflow-scrolling: touch;
}
.mc-sheet-handle { width: 42px; height: 4px; border-radius: 99px; background: rgba(255,255,255,.25); margin: 4px auto 10px; }
.mc-sheet h3 { margin: 0 0 10px; font-size: 16px; font-weight: 800; }
.mc-sheet-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.mc-sheet label { font-size: 12px; font-weight: 700; color: var(--text-2,#a1a1aa); display: block; margin-bottom: 4px; }
.mc-input, .mc-select, .mc-textarea {
  width: 100%; border-radius: 12px; border: 1px solid rgba(255,255,255,.12);
  background: var(--bg-2,#23232c); color: var(--text,#fff);
  padding: 10px 12px; font-size: 14px; outline: none;
}
.mc-textarea { min-height: 84px; resize: vertical; }
.mc-range { width: 100%; }

.mc-grid-emojis {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px;
}
.mc-emoji-btn {
  height: 40px; border: 0; border-radius: 10px; background: var(--bg-2,#23232c);
  font-size: 22px; cursor: pointer;
}
.mc-emoji-btn:active { transform: scale(.94); }

.mc-color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mc-color-swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); cursor: pointer;
}
.mc-color-swatch.active { outline: 3px solid var(--primary,#7c3aed); outline-offset: 2px; }

.mc-font-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mc-font-btn {
  border: 1px solid rgba(255,255,255,.15); background: var(--bg-2,#23232c); color: var(--text,#fff);
  border-radius: 10px; padding: 8px 10px; font-size: 13px; font-weight: 700; cursor: pointer;
}
.mc-font-btn.active { border-color: var(--primary,#7c3aed); box-shadow: 0 0 0 1px var(--primary,#7c3aed) inset; }

/* Trim timeline */
.mc-trim {
  background: rgba(0,0,0,.45); border-radius: 14px; padding: 10px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.mc-trim-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: rgba(255,255,255,.85); margin-bottom: 8px; }
.mc-trim-track {
  position: relative; height: 44px; border-radius: 8px; overflow: hidden;
  background: rgba(255,255,255,.12);
}
.mc-trim-selected {
  position: absolute; top: 0; bottom: 0;
  border-top: 3px solid #fff; border-bottom: 3px solid #fff;
  box-shadow: 0 0 0 999px rgba(0,0,0,.45);
  pointer-events: none;
}
.mc-trim-handle {
  position: absolute; top: 0; bottom: 0; width: 16px;
  margin-left: -8px;
  background: #fff; border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  cursor: ew-resize; touch-action: none;
}
.mc-trim-handle::after {
  content: ""; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: 3px; height: 16px; border-radius: 2px; background: #666;
}
.mc-trim-playhead {
  position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px;
  background: var(--primary,#7c3aed); box-shadow: 0 0 0 1px rgba(255,255,255,.4);
  pointer-events: none;
}

/* Text-only editor */
.mc-textonly-stage {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  padding: 80px 20px 180px; position: relative;
}
.mc-textonly-card {
  width: 100%; max-width: 520px; min-height: 55vh;
  border-radius: 24px; padding: 28px 22px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--clay-raised, 0 10px 30px rgba(0,0,0,.18));
  position: relative; overflow: hidden;
}
.mc-textonly-input {
  width: 100%; min-height: 40vh;
  border: 0; background: transparent; outline: none; resize: none;
  font-size: 34px; font-weight: 800; line-height: 1.2; text-align: center;
  color: inherit;
}
.mc-textonly-input::placeholder { color: currentColor; opacity: .55; }

/* Category/audience bars */
.mc-context-bar {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
}
.mc-context-label { font-size: 11px; font-weight: 700; opacity: .8; margin-right: 2px; }

/* Crop overlay */
.mc-crop-mask {
  position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55);
  pointer-events: none;
}

/* Music results */
.mc-music-result {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 12px; background: var(--bg-2,#23232c); margin-bottom: 8px;
}
.mc-music-result img { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: #333; }
.mc-music-meta { flex: 1; min-width: 0; }
.mc-music-meta strong { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mc-music-meta span { display: block; font-size: 11px; color: var(--text-2,#a1a1aa); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Drawing toolbar */
.mc-draw-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mc-size-dot { border-radius: 50%; background: currentColor; display: inline-block; }

/* Toast/inline status */
.mc-inline-status { font-size: 12px; color: rgba(255,255,255,.85); text-align: center; }

/* Desktop adaptation */
@media (min-width: 900px) {
  .moment-create-view { align-items: center; justify-content: center; background: #0b0b0f; }
  .mc-editor-frame {
    position: relative; width: min(420px, 100%); height: min(92vh, 860px);
    border-radius: 24px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.5);
    background: #000;
  }
  .mc-picker { align-items: center; }
  .mc-picker-panel {
    width: min(720px, 100%); height: 100%; background: var(--bg,#111); margin: 0 auto;
  }
  .mc-thumb-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Safe-area & keyboard friendliness */
.mc-safe-bottom-pad { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px); }
@supports (height: 100dvh) {
  .moment-create-view { height: var(--vvh, 100dvh); }
}

/* Keep bottom controls reachable when on-screen keyboard reduces viewport (WebView/Android) */
.moment-create-view { min-height: var(--vvh, 100dvh); }
.mc-bottom { max-height: 58dvh; overflow: auto; -webkit-overflow-scrolling: touch; }
.mc-textonly-stage { padding-bottom: max(180px, calc(env(safe-area-inset-bottom, 0px) + 220px)); }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .mc-icon-btn:active, .mc-chip-btn:active, .mc-pill-btn:active { transform: none; }
}
