/* ==========================================================================
   Shoot to Send — Micro-Interaction, Backdrop Blur & Optimistic Attachments
   Scoped strictly to #shoot-to-send-overlay and .moment-attachment-*
   ========================================================================== */

:root {
  --sts-blur-radius: 12px;
  --sts-tint-opacity: 0.30;
  --sts-tint-dark-opacity: 0.35;
}

#shoot-to-send-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: transparent;
  pointer-events: none;
  z-index: 200000;
  box-sizing: border-box;
}

#shoot-to-send-overlay.on {
  display: flex;
  pointer-events: auto;
}

/* ── PART 1: Single Full-screen Backdrop Layer (between chat and canvas) ── */
.sts-backdrop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 1;
  backdrop-filter: blur(var(--sts-blur-radius, 12px)) saturate(1.1);
  -webkit-backdrop-filter: blur(var(--sts-blur-radius, 12px)) saturate(1.1);
  background: rgba(238, 241, 246, var(--sts-tint-opacity, 0.30));
  opacity: 0;
  transition: opacity 180ms ease-out;
  pointer-events: none;
}

@media (prefers-color-scheme: dark) {
  .sts-backdrop {
    background: rgba(16, 20, 29, var(--sts-tint-dark-opacity, 0.35));
  }
}

/* Fallback for browsers without backdrop-filter */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .sts-backdrop {
    background: rgba(238, 241, 246, 0.55);
  }
  @media (prefers-color-scheme: dark) {
    .sts-backdrop {
      background: rgba(16, 20, 29, 0.65);
    }
  }
}

.sts-backdrop.is-visible {
  opacity: 1;
}

.sts-backdrop.is-closing {
  opacity: 0;
  transition: opacity 150ms ease-in;
}

@media (prefers-reduced-motion: reduce) {
  .sts-backdrop {
    transition: none !important;
  }
}

/* ── Direct Mascot & Room Softening (Guarantees blur on all devices & in-app browsers) ── */
body.sts-active #moment-stage,
body.sts-active .moment-stage,
body.sts-active #moment-char-wrap,
body.sts-active .held-emoji-wrap {
  filter: blur(12px) !important;
  opacity: 0.45 !important;
  transition: filter 180ms ease-out, opacity 180ms ease-out !important;
  pointer-events: none !important;
}

body.sts-active .moment-bg {
  opacity: 0.4 !important;
  filter: blur(8px) !important;
  transition: filter 180ms ease-out, opacity 180ms ease-out !important;
}

@media (prefers-reduced-motion: reduce) {
  body.sts-active #moment-stage,
  body.sts-active .moment-stage,
  body.sts-active #moment-char-wrap,
  body.sts-active .held-emoji-wrap,
  body.sts-active .moment-bg {
    transition: none !important;
  }
}

/* ── Interactive Card & Stage (In front of backdrop) ── */
.sts-card {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 440px;
  background: transparent;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: stsSlideUp 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  box-sizing: border-box;
}

@keyframes stsSlideUp {
  from { transform: translateY(35px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sts-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}

.sts-title-badge {
  font-size: 13.5px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.95);
  color: #1b2233;
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}

.sts-close-btn {
  width: 44px;
  height: 44px;
  border: 0;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
  color: #1b2233;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sts-close-btn:hover {
  background: #ffffff;
  transform: scale(1.05);
}

.sts-close-btn:active {
  transform: scale(0.95);
}

.sts-close-btn:focus-visible,
.sts-actions button:focus-visible {
  outline: 3px solid #e8702a;
  outline-offset: 2px;
}

.sts-stage {
  position: relative;
  margin-top: 2px;
  width: 100%;
}

canvas#sts-canvas {
  width: 100%;
  aspect-ratio: 320 / 400;
  display: block;
  touch-action: none;
  background: transparent;
  cursor: grab;
}

canvas#sts-canvas:active {
  cursor: grabbing;
}

.sts-status {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  white-space: nowrap;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
  pointer-events: none;
  font-weight: 700;
  font-size: 13px;
  color: #1b2233;
  opacity: 0;
  transition: opacity 0.15s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sts-status.on {
  opacity: 1;
}

.sts-file {
  text-align: center;
  margin: 8px auto 6px;
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
  background: rgba(255, 255, 255, 0.95);
  color: #1b2233;
  padding: 6px 16px;
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
  width: fit-content;
  max-width: 90%;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sts-file span {
  color: #64748b;
  font-weight: 400;
  margin-left: 6px;
}

.sts-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 48px;
  align-items: center;
}

.sts-actions button {
  border: 0;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.16);
  color: #1b2233;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  transition: transform 0.12s ease, background 0.12s ease;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sts-actions button:hover {
  background: #ffffff;
  transform: translateY(-1px);
}

.sts-actions button:active {
  transform: translateY(1px);
}

.sts-actions button.sts-btn-primary {
  background: #1b2233;
  color: #ffffff;
}

.sts-actions button.sts-btn-primary:hover {
  background: #0f172a;
}

@media (prefers-reduced-motion: reduce) {
  .sts-card {
    animation: none !important;
  }
}

/* ==========================================================================
   Chat Bubble Attachments & Optimistic Pending States
   ========================================================================== */

.moment-attachment-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  width: 100%;
}

/* ~150ms Land in Bubble transition */
.moment-bubble.sts-landing {
  animation: stsLandInBubble 0.18s cubic-bezier(0.2, 1.2, 0.4, 1) forwards;
}

@keyframes stsLandInBubble {
  from {
    transform: scale(0.85) translateY(-14px);
    opacity: 0.6;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.moment-attachment-img-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  max-width: 240px;
  max-height: 220px;
  background: rgba(0, 0, 0, 0.04);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.moment-attachment-img {
  width: 100%;
  height: 100%;
  max-height: 220px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.moment-attachment-img:hover {
  opacity: 0.92;
}

.moment-attachment-file-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease, transform 0.12s ease;
  max-width: 260px;
}

.moment-attachment-file-box:hover {
  background: rgba(255, 255, 255, 1);
  transform: translateY(-1px);
}

.moment-attachment-icon-badge {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  text-transform: uppercase;
}

.moment-attachment-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.moment-attachment-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #1e293b;
}

.moment-attachment-size {
  font-size: 11px;
  color: #64748b;
  margin-top: 1px;
}

.moment-attachment-download-icon {
  flex-shrink: 0;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Pending / Uploading Indicator inside Bubble ── */
.moment-attachment-pending-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: #e8702a;
  font-weight: 600;
  margin-top: 4px;
}

.moment-attachment-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(232, 112, 42, 0.25);
  border-top-color: #e8702a;
  border-radius: 50%;
  animation: stsSpin 0.75s linear infinite;
}

@keyframes stsSpin {
  to { transform: rotate(360deg); }
}

/* ── Failed State with Retry and Remove ── */
.moment-attachment-failed-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.moment-attachment-failed-text {
  font-size: 11px;
  color: #ef4444;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.moment-attachment-failed-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.moment-attachment-retry-btn,
.moment-attachment-remove-btn {
  background: transparent;
  border: none;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  transition: background 0.15s ease;
}

.moment-attachment-retry-btn {
  color: #ef4444;
  text-decoration: underline;
}

.moment-attachment-retry-btn:hover {
  background: rgba(239, 68, 68, 0.15);
}

.moment-attachment-remove-btn {
  color: #64748b;
}

.moment-attachment-remove-btn:hover {
  background: rgba(100, 116, 139, 0.15);
}

/* ── Expired File State ── */
.moment-attachment-expired-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  border-radius: 10px;
  color: #64748b;
  max-width: 260px;
}

.moment-attachment-expired-badge {
  background: #94a3b8;
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.moment-attachment-expired-text {
  font-size: 12px;
  font-weight: 500;
}
