/* ==========================================================================
   StoryMap player — the public "stories" viewer (view/embed + editor preview)
   Also defines map pins and content blocks shared with the editor.
   ========================================================================== */

/* ---------- Pins (Leaflet divIcons) ---------- */
.sm-pin-wrap { background: none !important; border: none !important; }
.sm-pin {
  position: relative; width: 52px; height: 60px;
  display: flex; justify-content: center;
  transform-origin: 50% 100%;
  transition: transform 420ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 300ms, filter 300ms;
  cursor: pointer;
}
.sm-pin-bubble {
  position: relative; z-index: 1;
  width: 44px; height: 44px; margin-top: 2px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: #fff;
  border: 2.5px solid #140f2b;
  box-shadow: 3px 3px 0 var(--pin, #ff4fa3);
  font-size: 22px; line-height: 1;
}
.sm-pin-bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -11px; transform: translateX(-50%);
  border-left: 7px solid transparent; border-right: 7px solid transparent; border-top: 11px solid #140f2b;
}
.sm-pin-emoji { display: block; transform: translateY(1px); }
.sm-pin-num {
  position: absolute; top: -7px; right: -9px;
  min-width: 21px; height: 21px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 999px; border: 2px solid #140f2b;
  background: var(--pin, #ff4fa3); color: var(--pin-ink, #fff);
  font: 800 11px/1 'Bricolage Grotesque', 'DM Sans', sans-serif;
}
.sm-pin-ring {
  position: absolute; left: 50%; bottom: -4px;
  width: 34px; height: 12px; margin-left: -17px;
  border-radius: 50%;
  background: var(--pin, #ff4fa3);
  opacity: 0;
}
.sm-pin.is-active { transform: scale(1.22); z-index: 1000; }
.sm-pin.is-active .sm-pin-ring { animation: pinRing 1.6s ease-out infinite; }
.sm-pin.is-future { opacity: 0.6; transform: scale(0.84); filter: saturate(0.5); }
.sm-pin.is-pop { animation: pinPop 700ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.sm-pin.is-dragging { transform: scale(1.3) rotate(-8deg); }
.sm-pin:hover { transform: scale(1.12) rotate(-4deg); }
.sm-pin.is-active:hover { transform: scale(1.28); }
@keyframes pinRing { 0% { opacity: 0.7; transform: scale(0.5); } 100% { opacity: 0; transform: scale(2.6); } }
@keyframes pinPop { 0% { transform: translateY(-40px) scale(0.3); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1.22); } }

/* Animated "marching ants" route */
.sm-route-flow { animation: routeFlow 1.2s linear infinite; }
@keyframes routeFlow { to { stroke-dashoffset: -22; } }

/* ---------- Content blocks ---------- */
.sm-b-title { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: 21px; letter-spacing: -0.02em; line-height: 1.15; margin: 18px 0 8px; }
.sm-b-text { margin: 0 0 14px; font-size: 16px; line-height: 1.65; opacity: 0.88; overflow-wrap: anywhere; }
.sm-b-figure { margin: 0 0 16px; }
.sm-b-figure img { width: 100%; border-radius: 18px; border: 2px solid currentColor; }
.sm-b-figure figcaption { margin-top: 6px; font-family: 'Caveat', cursive; font-size: 19px; opacity: 0.8; }
.sm-b-media { position: relative; margin: 0 0 16px; border-radius: 18px; overflow: hidden; }
.sm-b-media iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.sm-b-media.is-vertical { max-width: 340px; margin-left: auto; margin-right: auto; }
.sm-b-media.is-fixed iframe, .sm-b-media.is-fixed video { position: static; display: block; }
.sm-b-html { margin: 0 0 16px; }
.sm-b-button {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 16px;
  padding: 11px 20px; border-radius: 999px;
  background: var(--accent, #ff4fa3); color: var(--accent-ink, #fff);
  border: 2px solid currentColor;
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; text-decoration: none;
  transition: transform 160ms;
}
.sm-b-button:hover { transform: translate(-2px, -2px) rotate(-1deg); }

/* ==========================================================================
   Player shell
   ========================================================================== */
.smp {
  --accent: #ff4fa3; --accent-ink: #fff;
  --bg: #1b0f2e; --panel: #2a1745; --text: #fff2fa;
  --edge: color-mix(in srgb, var(--text) 18%, transparent);
  position: absolute; inset: 0; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: 'DM Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.smp *, .smp *::before, .smp *::after { box-sizing: border-box; }
.smp-map { position: absolute; inset: 0; z-index: 1; background: var(--bg); }
.smp .leaflet-container { font-family: inherit; background: var(--bg); }
.smp .leaflet-control-zoom { border: 2px solid #140f2b !important; border-radius: 14px !important; overflow: hidden; box-shadow: 3px 3px 0 #140f2b !important; }
.smp .leaflet-control-zoom a { width: 34px !important; height: 34px !important; line-height: 32px !important; color: #140f2b !important; }
.smp .leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, 0.7) !important; border-radius: 8px 0 0 0; }

/* ---------- Top bar: progress + header ---------- */
.smp-top {
  position: absolute; z-index: 850; top: 0; left: 0; right: 0;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 26px;
  background: linear-gradient(to bottom, rgba(10, 6, 24, 0.62), rgba(10, 6, 24, 0));
  color: #fff;
  pointer-events: none;
  transition: opacity 300ms;
}
.smp-top > * { pointer-events: auto; }
.smp-bars { display: flex; gap: 4px; margin-bottom: 10px; }
.smp-bar { flex: 1; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.32); overflow: hidden; cursor: pointer; }
.smp-bar i { display: block; height: 100%; width: 0; background: #fff; border-radius: inherit; }
.smp-bar.done i { width: 100%; }
.smp-bar.active i { width: 100%; }
.smp.autoplaying .smp-bar.active i { width: 0; animation: barFill var(--dur, 7s) linear forwards; }
@keyframes barFill { to { width: 100%; } }
.smp-head { display: flex; align-items: center; gap: 10px; }
.smp-avatar {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 50%;
  display: grid; place-items: center; overflow: hidden;
  background: var(--accent); color: var(--accent-ink);
  border: 2px solid #fff; font-size: 18px;
}
.smp-avatar img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.smp-head-text { min-width: 0; flex: 1; line-height: 1.15; }
.smp-head-title { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4); }
.smp-head-sub { font-size: 12.5px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.smp-icon-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(20, 15, 43, 0.35); color: #fff;
  cursor: pointer; font-size: 16px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  transition: transform 160ms, background 160ms;
  text-decoration: none;
}
.smp-icon-btn:hover { transform: translateY(-2px); background: rgba(20, 15, 43, 0.6); }
.smp-icon-btn.on { background: var(--accent); color: var(--accent-ink); border-color: #fff; }
.smp-icon-btn svg { width: 18px; height: 18px; }

/* ---------- Story card ---------- */
.smp-card {
  position: absolute; z-index: 650;
  left: 20px; top: 96px; bottom: 20px;
  width: min(430px, 42vw);
  display: flex; flex-direction: column;
  background: var(--panel); color: var(--text);
  border: 2.5px solid #140f2b;
  border-radius: 28px;
  box-shadow: 7px 7px 0 var(--accent);
  overflow: hidden;
  transform: translateX(calc(-100% - 40px));
  transition: transform 520ms cubic-bezier(0.22, 1, 0.36, 1);
}
.smp.has-card .smp-card { transform: none; }
.smp-handle { display: none; }
.smp-card-scroll { flex: 1; overflow-y: auto; padding: 24px 24px 12px; overscroll-behavior: contain; }
.smp-card-scroll::-webkit-scrollbar { width: 6px; }
.smp-card-scroll::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 6px; }
.smp-card-body.enter { animation: cardIn 520ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.smp-card-body.enter-back { animation: cardInBack 520ms cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes cardIn { from { opacity: 0; transform: translateX(36px); } }
@keyframes cardInBack { from { opacity: 0; transform: translateX(-36px); } }

.smp-stop-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.smp-stop-emoji {
  width: 62px; height: 62px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 20px; border: 2.5px solid #140f2b;
  background: var(--accent); font-size: 32px;
  box-shadow: 3px 3px 0 #140f2b;
  transform: rotate(-6deg);
  animation: emojiWiggle 700ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.smp-stop-emoji img { width: 38px; height: 38px; object-fit: contain; }
@keyframes emojiWiggle { 0% { transform: rotate(-30deg) scale(0.4); } 100% { transform: rotate(-6deg) scale(1); } }
.smp-stop-meta { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 2px; }
.smp-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  border: 1.5px solid var(--edge);
  font-size: 12.5px; font-weight: 600; line-height: 1.3;
  white-space: nowrap;
}
.smp-chip.accent { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.smp-stop-title {
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800;
  font-size: clamp(26px, 3vw, 34px); line-height: 1.02; letter-spacing: -0.035em;
  margin: 0 0 14px; overflow-wrap: anywhere;
}
.smp-empty { font-family: 'Caveat', cursive; font-size: 22px; opacity: 0.7; }

.smp-card-nav {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1.5px solid var(--edge);
}
.smp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: 999px;
  border: 2px solid #140f2b;
  background: var(--panel); color: var(--text);
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; font-size: 15px;
  cursor: pointer;
  transition: transform 160ms, box-shadow 160ms, opacity 160ms;
  text-decoration: none; white-space: nowrap;
}
.smp-btn:hover { transform: translate(-2px, -2px); box-shadow: 3px 3px 0 #140f2b; }
.smp-btn:active { transform: translate(1px, 1px); box-shadow: none; }
.smp-btn[disabled] { opacity: 0.35; pointer-events: none; }
.smp-btn.primary { background: var(--accent); color: var(--accent-ink); flex: 1; }
.smp-btn.ghost { border-color: var(--edge); }
.smp-counter { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 700; font-size: 14px; opacity: 0.75; min-width: 46px; text-align: center; }

/* ---------- Intro / outro screens ---------- */
.smp-screen {
  position: absolute; inset: 0; z-index: 800;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 90px 24px 40px; text-align: center;
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
  opacity: 0; visibility: hidden;
  transition: opacity 500ms, visibility 500ms;
}
.smp-screen.show { opacity: 1; visibility: visible; }
.smp-screen > *:not(.smp-screen-bg):not(.smp-blobs) { position: relative; z-index: 2; }
.smp-screen-bg { position: absolute; inset: 0; z-index: 0; overflow: hidden; }
.smp-screen-bg img, .smp-screen-bg video { width: 100%; height: 100%; object-fit: cover; }
.smp-screen-bg iframe { position: absolute; top: 50%; left: 50%; width: 177.78vh; min-width: 100%; height: 56.25vw; min-height: 100%; transform: translate(-50%, -50%); border: 0; pointer-events: none; }
.smp-screen-bg::after { content: ''; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 6, 24, 0.35), rgba(10, 6, 24, 0.7)); }
.smp-screen.has-bg { color: #fff; }
.smp-blobs { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; }
.smp-blobs i { position: absolute; width: 46vmax; height: 46vmax; border-radius: 50%; filter: blur(70px); opacity: 0.4; background: var(--accent); animation: blob 16s ease-in-out infinite alternate; }
.smp-blobs i:nth-child(1) { top: -20vmax; left: -12vmax; }
.smp-blobs i:nth-child(2) { bottom: -24vmax; right: -16vmax; background: #7c5cff; animation-delay: -6s; }
.smp-screen.has-bg .smp-blobs { display: none; }
@keyframes blob { to { transform: translate(8vmax, 6vmax) scale(1.15); } }

.smp-logo { max-width: 180px; max-height: 70px; object-fit: contain; margin-bottom: 18px; }
.smp-kicker { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-bottom: 18px; }
.smp-kicker .smp-chip { background: color-mix(in srgb, var(--panel) 80%, transparent); border-color: var(--edge); font-size: 13.5px; padding: 6px 12px; }
.smp-screen.has-bg .smp-kicker .smp-chip { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.4); color: #fff; }
.smp-screen-title {
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800;
  font-size: clamp(40px, 8.5vw, 96px); line-height: 0.92; letter-spacing: -0.045em;
  margin: 0 0 16px; max-width: 14ch; overflow-wrap: anywhere;
  animation: titleIn 900ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
@keyframes titleIn { from { opacity: 0; transform: translateY(30px) rotate(-2deg); } }
.smp-screen-desc { font-size: clamp(16px, 2vw, 19px); line-height: 1.55; max-width: 520px; margin: 0 0 8px; opacity: 0.88; }
.smp-author { font-family: 'Caveat', cursive; font-size: 24px; margin: 4px 0 28px; opacity: 0.9; }
.smp-author-handle { font-family: 'DM Sans', sans-serif; font-size: 15px; font-weight: 700; }
.smp-handle-link { color: inherit; font-weight: 700; text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; }
.smp-handle-link:hover { color: var(--accent); }
.smp-play {
  position: relative;
  display: inline-flex; align-items: center; gap: 12px;
  padding: 16px 30px 16px 18px; border-radius: 999px;
  border: 2.5px solid #140f2b;
  background: var(--accent); color: var(--accent-ink);
  font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: 20px;
  box-shadow: 5px 5px 0 #140f2b;
  cursor: pointer;
  transition: transform 180ms, box-shadow 180ms;
}
.smp-play:hover { transform: translate(-2px, -2px) rotate(-1deg); box-shadow: 7px 7px 0 #140f2b; }
.smp-play-icon { width: 40px; height: 40px; border-radius: 50%; background: #140f2b; color: #fff; display: grid; place-items: center; font-size: 15px; padding-left: 3px; }
.smp-play::before { content: ''; position: absolute; inset: -8px; border-radius: inherit; border: 2px solid var(--accent); animation: playPulse 2s ease-out infinite; }
@keyframes playPulse { from { opacity: 0.9; transform: scale(0.95); } to { opacity: 0; transform: scale(1.18); } }
.smp-hint { margin-top: 18px; font-size: 13px; opacity: 0.65; }

/* Wrapped */
.smp-wrapped-label { font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; margin-bottom: 10px; color: var(--accent); }
.smp-screen.has-bg .smp-wrapped-label { color: #fff; }
.smp-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: min(520px, 100%); margin: 18px 0 22px; }
.smp-stat {
  padding: 16px 14px; border-radius: 22px;
  border: 2.5px solid #140f2b; box-shadow: 4px 4px 0 #140f2b;
  color: #140f2b; text-align: left;
  opacity: 0; transform: translateY(20px) rotate(var(--r, -2deg));
}
.smp-screen.show .smp-stat { animation: statIn 600ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards; }
.smp-stat:nth-child(1) { background: #c8ff2e; --r: -2deg; animation-delay: 150ms !important; }
.smp-stat:nth-child(2) { background: #ffc93c; --r: 2deg; animation-delay: 260ms !important; }
.smp-stat:nth-child(3) { background: #3dd6ff; --r: 1.5deg; animation-delay: 370ms !important; }
.smp-stat:nth-child(4) { background: #ff9ccf; --r: -1.5deg; animation-delay: 480ms !important; }
@keyframes statIn { to { opacity: 1; transform: rotate(var(--r)); } }
.smp-stat b { display: block; font-family: 'Bricolage Grotesque', sans-serif; font-weight: 800; font-size: clamp(24px, 4vw, 34px); line-height: 1; letter-spacing: -0.03em; margin-bottom: 4px; overflow-wrap: anywhere; }
.smp-stat span { font-size: 13px; font-weight: 600; opacity: 0.75; }
.smp-share { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-bottom: 18px; }
.smp-share a, .smp-share button {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid #140f2b; background: #fff; color: #140f2b;
  cursor: pointer; transition: transform 180ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.smp-share a:hover, .smp-share button:hover { transform: translateY(-3px) rotate(-6deg) scale(1.08); }
.smp-share svg { width: 20px; height: 20px; }
.smp-share .wa { background: #25d366; color: #fff; }
.smp-share .fb { background: #1877f2; color: #fff; }
.smp-share .li { background: #0a66c2; color: #fff; }
.smp-share .x { background: #000; color: #fff; }
.smp-share .tg { background: #29a9eb; color: #fff; }
.smp-share .native { background: var(--accent); color: var(--accent-ink); }
.smp-outro-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.smp-cta { background: #c8ff2e !important; color: #140f2b !important; }

/* Made-with badge (viral loop) */
.smp-badge {
  position: absolute; z-index: 690; right: 62px; bottom: 26px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  border: 2px solid #140f2b; background: #c8ff2e; color: #140f2b;
  font: 700 12.5px/1 'Bricolage Grotesque', sans-serif; text-decoration: none;
  box-shadow: 2px 2px 0 #140f2b;
  transform: rotate(-2deg);
  transition: transform 180ms;
}
.smp-badge:hover { transform: rotate(2deg) scale(1.05); }

/* ---------- Mobile: card becomes a bottom sheet ---------- */
@media (max-width: 760px) {
  .smp-top { padding-left: 12px; padding-right: 12px; }
  .smp-card {
    left: 8px; right: 8px; top: auto; bottom: 8px; width: auto;
    max-height: 50%;
    border-radius: 26px;
    box-shadow: 0 -2px 0 var(--accent), 4px 4px 0 var(--accent);
    transform: translateY(calc(100% + 30px));
    transition: transform 520ms cubic-bezier(0.22, 1, 0.36, 1), max-height 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  .smp-card.expanded { max-height: calc(100% - 90px); }
  .smp-handle { display: block; width: 100%; padding: 9px 0 2px; border: 0; background: none; cursor: pointer; }
  .smp-handle::before { content: ''; display: block; width: 44px; height: 5px; margin: 0 auto; border-radius: 5px; background: var(--edge); }
  .smp-card-scroll { padding: 10px 18px 10px; }
  .smp-stop-head { margin-bottom: 10px; }
  .smp-stop-emoji { width: 50px; height: 50px; font-size: 26px; border-radius: 16px; }
  .smp-stop-title { font-size: 25px; margin-bottom: 10px; }
  .smp-card-nav { padding-top: 10px; }
  .smp-badge { display: none; }
  .smp .leaflet-control-zoom { display: none; }
  .smp .leaflet-bottom.leaflet-right { bottom: auto; top: calc(66px + env(safe-area-inset-top, 0px)); }
  .smp-stats { gap: 10px; }
}

/* ---------- Embed tweaks ---------- */
.smp.is-embed .smp-screen-title { font-size: clamp(32px, 7vw, 64px); }
@media (min-width: 761px) { .smp.is-embed .smp-card { top: 84px; } }

@media (prefers-reduced-motion: reduce) {
  .smp *, .sm-pin, .sm-pin * { animation: none !important; transition: none !important; }
  .smp-stat { opacity: 1; transform: none; }
}
