/* stories feature styles — rings, detail strip, tray/strip, add flow, viewer. Tokens from theme.css/app.css. */

:root {
  --st-grad: linear-gradient(45deg, #d9a441 0%, #e2583e 48%, #b5677d 100%);
  --st-seen: color-mix(in srgb, var(--ink-3) 75%, transparent);
  --st-danger: #d6452b;
}
/* ring geometry scales with the avatar size (--s from app.css); rules themselves are injected by stories.js */
.av {
  --st-bw: clamp(1.5px, calc(var(--s, 44px) * .06), 3px);
  --st-gap: clamp(1.5px, calc(var(--s, 44px) * .045), 2.5px);
  --st-bw-seen: clamp(1px, calc(var(--s, 44px) * .03), 1.5px);
  --st-gap-seen: clamp(1px, calc(var(--s, 44px) * .035), 2px);
  --st-fill: color-mix(in srgb, var(--c) 22%, var(--card));
  --st-gapc: var(--card);
}
.av.pm-av { --st-gapc: var(--ring); }
.st-viewer .av { --st-gapc: #000; }

html.st-lock, html.st-lock body { overflow: hidden; }

/* ---------- phone top bar button ---------- */
.tb-ext { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.st-tb {
  position: relative; width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink);
  background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow); transition: background-color .15s, transform .1s;
}
.st-tb:active { transform: scale(.96); background: var(--fill); }
.st-dot {
  position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--st-grad); box-shadow: 0 0 0 2px var(--card);
}

/* ---------- desktop: camera in panel head + strip ---------- */
.panel-ext { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.st-pe {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px; background: transparent; color: var(--ink-2);
  display: grid; place-items: center; transition: background-color .15s, color .15s;
}
.st-strip { display: none; }
@media (min-width: 900px) {
  .st-strip:not([hidden]) { display: block; padding: 10px 12px 0; }
}
.st-row {
  display: flex; gap: 4px; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  padding: 4px 4px 2px; margin: 0 -4px; scroll-snap-type: x proximity;
}
.st-row::-webkit-scrollbar { display: none; }
.st-bub {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 5px; width: 64px;
  padding: 4px 0 6px; border: 0; background: none; border-radius: 12px; scroll-snap-align: start;
  transition: background-color .12s;
}
.st-bub > span { font-size: 12px; color: var(--ink-2); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.st-bub.new > span { color: var(--ink); font-weight: 500; }
.st-bub:active .av { transform: scale(.96); }
.st-bub .av { transition: transform .12s; }
.st-tray { margin: 0 -8px 4px; padding: 4px 4px 2px; }
.st-tray .st-bub { width: 72px; }

@media (hover: hover) {
  .st-tb:hover { background: var(--card); }
  .st-pe:hover { background: var(--fill); color: var(--ink); }
  .st-bub:hover { background: var(--fill); }
  .st-link:hover { color: var(--ink); }
  .st-addrow:hover { background: var(--fill); }
  .st-th:hover img { transform: scale(1.03); }
  .st-sx:hover { color: var(--ink); background: var(--fill-hover); }
}

/* ---------- person detail ---------- */
.st-det { margin-top: 4px; }
.st-dh { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 8px; }
.st-dh .sec { margin: 0; }
.st-link {
  display: inline-flex; align-items: center; gap: 2px; border: 0; background: none; padding: 6px 0 6px 8px; min-height: 36px;
  font-weight: 500; font-size: 14px; color: var(--ink-2);
}
.st-ths {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain;
  margin: 0 -20px; padding: 2px 20px 4px; scroll-padding: 0 20px; scroll-snap-type: x proximity;
}
.pv-body .st-ths { margin: 0 -16px; padding: 2px 16px 4px; }
.st-ths::-webkit-scrollbar { display: none; }
.st-th {
  position: relative; flex: none; width: 76px; height: 112px; padding: 0; border: 0; border-radius: 12px; overflow: hidden;
  background: var(--fill); scroll-snap-align: start; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
  box-shadow: inset 0 0 0 1px var(--hair);
}
.st-th img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; transition: transform .25s var(--ease); }
.st-th > span {
  position: absolute; left: 6px; bottom: 6px; font-size: 11.5px; font-weight: 600; color: #fff; line-height: 1;
  padding: 3px 6px; border-radius: 999px; background: rgba(0, 0, 0, .38); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.st-th.new::after {
  content: ""; position: absolute; inset: 0; border-radius: 12px; pointer-events: none;
  padding: 2px; background: var(--st-grad);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
}
.st-th.sel { outline: 2px solid var(--st-danger); outline-offset: 2px; }
.st-th.sel img { opacity: .7; }
.st-th-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--ink-2); font-size: 12.5px; font-weight: 500; background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--hair);
}
.st-th-add > span { position: static; background: none; color: inherit; padding: 0; font-weight: 500; font-size: 12.5px; backdrop-filter: none; -webkit-backdrop-filter: none; }
.st-hint { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-3); }
.st-dconf {
  display: flex; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 8px 8px 14px;
  border-radius: 12px; background: var(--fill); font-size: 14px; animation: st-fade .18s var(--ease);
}
.st-dconf > span { flex: 1; min-width: 0; }
.btn.st-danger, .st-danger { background: var(--st-danger); color: #fff; }
@media (hover: hover) { .btn.st-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--st-danger) 88%, #000); } }
.btn.st-danger.busy::after { border-color: #fff; border-right-color: transparent; }
.st-addrow {
  display: flex; align-items: center; gap: 12px; width: 100%; margin-top: 16px; min-height: 60px; padding: 10px 14px;
  border: 0; border-radius: var(--radius); background: transparent; box-shadow: inset 0 0 0 1px var(--hair);
  text-align: left; color: var(--ink); transition: background-color .12s;
}
.st-addrow > .ic { color: var(--ink-2); }
.st-addrow > span { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.st-addrow b { font-size: 15px; font-weight: 500; }
.st-addrow small { font-size: 13px; color: var(--ink-2); }

/* ---------- add / tray sheet (own overlay; same feel as app sheets) ---------- */
.st-sheet-root { position: fixed; inset: 0; z-index: 950; }
.st-scrim { position: absolute; inset: 0; background: rgba(17, 17, 19, .22); opacity: 0; transition: opacity .2s; }
.st-sheet-root.open .st-scrim { opacity: 1; }
.st-sheet-root.closing .st-scrim { opacity: 0; }
.st-sheet {
  position: absolute; left: env(safe-area-inset-left, 0px); right: env(safe-area-inset-right, 0px); bottom: 0;
  margin: 0 auto; max-width: 560px; max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 24px);
  display: flex; flex-direction: column; background: var(--card); color: var(--ink); border-radius: 20px 20px 0 0;
  box-shadow: 0 -1px 0 var(--hair), 0 -12px 40px -12px rgba(0, 0, 0, .25); overflow: hidden;
  transform: translateY(100%); transition: transform .26s var(--ease);
}
.st-sheet-root.open .st-sheet { transform: none; }
.st-sheet-root.closing .st-sheet { transform: translateY(100%); transition-duration: .18s; transition-timing-function: ease-in; }
.st-grab { width: 36px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: .45; margin: 8px auto 0; flex: none; }
.st-sx {
  position: absolute; top: 12px; right: 12px; z-index: 2; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--fill); color: var(--ink-2); display: grid; place-items: center;
}
.st-sbody { padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; overscroll-behavior: contain; }
.st-sbody h2 { font-size: 22px; font-weight: 600; margin: 8px 48px 16px 0; line-height: 1.2; letter-spacing: -.02em; }
.st-sbody .sec { margin-top: 18px; }
.st-lede { margin: -8px 0 16px; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.st-empty { margin: -4px 0 4px; color: var(--ink-2); font-size: 15px; line-height: 1.45; }
.st-actions { display: flex; flex-direction: column; gap: 8px; }
.st-warn { margin: 10px 2px 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.4; padding-left: 10px; box-shadow: inset 2px 0 0 var(--sun); }
@media (min-width: 600px) {
  .st-sheet { bottom: 16px; left: 16px; right: 16px; border-radius: 20px; transform: translateY(16px); opacity: 0; transition: transform .22s var(--ease), opacity .18s; }
  .st-sheet-root.open .st-sheet { opacity: 1; }
  .st-sheet-root.closing .st-sheet { transform: translateY(16px); opacity: 0; }
}
@media (min-width: 900px) {
  .st-sheet { top: 50%; bottom: auto; max-width: 440px; transform: translateY(-46%); }
  .st-sheet-root.open .st-sheet { transform: translateY(-50%); }
  .st-sheet-root.closing .st-sheet { transform: translateY(-46%); }
  .st-grab { display: none; }
}

/* ---------- shared dark overlay bits (composer + viewer) ---------- */
.st-comp, .st-viewer {
  position: fixed; inset: 0; z-index: 1000; background: #000; color: #fff;
  height: 100vh; height: 100dvh; overflow: hidden; touch-action: none;
  opacity: 0; transition: opacity .2s var(--ease);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.st-comp.open, .st-viewer.open { opacity: 1; }
.st-comp.closing, .st-viewer.closing { opacity: 0; pointer-events: none; }
.st-round {
  width: 44px; height: 44px; flex: none; border: 0; border-radius: 50%; background: transparent; color: #fff;
  display: grid; place-items: center; transition: background-color .15s;
}
.st-round:active { background: rgba(255, 255, 255, .14); }
@media (hover: hover) { .st-round:hover { background: rgba(255, 255, 255, .12); } }
.st-round .ic { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35)); }
.btn.st-ghost { background: rgba(255, 255, 255, .14); color: #fff; }
@media (hover: hover) { .btn.st-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .22); } }
.st-spin {
  position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .7); border-right-color: transparent; animation: st-spin .8s linear infinite;
  opacity: 0; transition: opacity .2s .25s; pointer-events: none;
}
@keyframes st-spin { to { transform: rotate(360deg); } }
@keyframes st-fade { from { opacity: 0; transform: translateY(4px); } }

/* composer */
.st-comp { display: flex; flex-direction: column; }
.st-bar { position: absolute; top: 0; left: 0; right: 0; height: 2px; overflow: hidden; z-index: 3; background: rgba(255, 255, 255, .15); }
.st-bar i { position: absolute; top: 0; bottom: 0; width: 40%; background: #fff; animation: st-indet 1.1s var(--ease) infinite; }
@keyframes st-indet { from { left: -40%; } to { left: 100%; } }
.st-ctop {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) calc(env(safe-area-inset-right, 0px) + 8px) 6px calc(env(safe-area-inset-left, 0px) + 8px);
}
.st-ctop > span { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.st-ctop > i { width: 44px; }
.st-cimg { position: relative; flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px; }
.st-cimg img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 12px; animation: st-fade .2s var(--ease); }
.st-cimg img[hidden] + .st-spin, .st-cimg:has(img[hidden]) .st-spin { opacity: 1; }
.st-comp.uploading .st-cimg img { opacity: .55; transition: opacity .3s; }
.st-cbot { padding: 12px calc(env(safe-area-inset-right, 0px) + 16px) calc(env(safe-area-inset-bottom, 0px) + 14px) calc(env(safe-area-inset-left, 0px) + 16px); }
.st-cmsg { margin: 0 auto 10px; max-width: 520px; font-size: 13.5px; color: rgba(255, 255, 255, .72); text-align: center; line-height: 1.4; }
.st-cmsg.err { color: #ffb4a6; }
.st-cbtns { display: grid; grid-template-columns: 1fr 1.4fr; white-space: nowrap; gap: 10px; max-width: 520px; margin: 0 auto; }
.btn.st-post { background: #fff; color: #18181b; }
.btn.st-post:disabled { opacity: .5; }
.btn.st-post.busy::after { border-color: #18181b; border-right-color: transparent; }
@media (hover: hover) { .btn.st-post:hover:not(:disabled) { background: #ececec; } }

/* viewer */
.st-viewer { --st-fade: 1; display: flex; align-items: center; justify-content: center; }
.st-shade { position: absolute; inset: 0; background: #000; opacity: var(--st-fade); }
.st-viewer { background: transparent; }
.st-stage {
  position: relative; width: 100%; height: 100%; overflow: hidden; background: #000;
  transition: transform .22s var(--ease), opacity .2s var(--ease); touch-action: none; cursor: pointer;
}
.st-bg {
  position: absolute; inset: -40px; background: center / cover no-repeat;
  filter: blur(36px) brightness(.45) saturate(1.2); transform: translateZ(0); opacity: .9;
}
.st-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none;
  transition: opacity .18s;
}
.st-viewer.loading .st-img { opacity: 0; }
.st-viewer.loading .st-spin { opacity: 1; }
.st-top {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) calc(env(safe-area-inset-right, 0px) + 8px) 24px calc(env(safe-area-inset-left, 0px) + 8px);
  background: linear-gradient(rgba(0, 0, 0, .45), rgba(0, 0, 0, 0)); transition: opacity .2s;
}
.st-viewer.held .st-top { opacity: 0; }
.st-prog { display: flex; gap: 3px; padding: 0 4px; }
.st-prog i { flex: 1; height: 2.5px; border-radius: 2px; background: rgba(255, 255, 255, .32); overflow: hidden; }
.st-prog b { display: block; height: 100%; background: #fff; transform-origin: left; transform: scaleX(0); will-change: transform; }
.st-head { display: flex; align-items: center; gap: 4px; margin-top: 8px; min-height: 44px; }
.st-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.st-whob {
  display: flex; align-items: center; gap: 10px; min-width: 0; border: 0; background: none; color: #fff; padding: 4px 6px 4px 4px; border-radius: 999px;
}
.st-whob b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.st-who time { flex: none; font-size: 14px; color: rgba(255, 255, 255, .72); font-variant-numeric: tabular-nums; }
.st-whob .av { --s: 32px; }
.st-tools { display: flex; }
.st-vconf {
  position: absolute; z-index: 3; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  margin: 0 auto; max-width: 420px; padding: 16px; border-radius: 18px; cursor: default;
  background: rgba(28, 28, 31, .92); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  display: flex; flex-direction: column; gap: 4px; animation: st-fade .18s var(--ease);
}
.st-vconf b { font-size: 16px; font-weight: 600; }
.st-vconf span { font-size: 14px; color: rgba(255, 255, 255, .7); }
.st-vconf div { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.st-foot {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; display: flex; justify-content: flex-end; align-items: center;
  padding: 24px calc(env(safe-area-inset-right, 0px) + 12px) calc(env(safe-area-inset-bottom, 0px) + 12px) calc(env(safe-area-inset-left, 0px) + 16px);
  background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, .35)); pointer-events: none; transition: opacity .2s;
}
.st-foot:empty { display: none; }
.st-foot > * { pointer-events: auto; }
.st-viewer.held .st-foot, .st-viewer.confirming .st-foot { opacity: 0; }
.st-like { width: 52px; height: 52px; }
.st-like.on { color: var(--coral); }
.st-like.on .ic { fill: currentColor; }
.st-like.pop .ic { animation: st-pop .32s var(--ease); }
@keyframes st-pop { 40% { transform: scale(1.3); } }
.st-likedby {
  margin-right: auto; display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14.5px; font-weight: 500;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}
.st-likedby .ic { color: var(--coral); fill: currentColor; flex: none; }
.st-nav { display: none; }

/* laptop: a 9:16 card in the middle, person arrows on the sides */
@media (min-width: 700px) and (hover: hover) {
  .st-stage {
    width: min(100vw - 160px, calc((100dvh - 48px) * 9 / 16)); height: calc(100dvh - 48px);
    border-radius: 14px; box-shadow: 0 20px 60px -20px rgba(0, 0, 0, .8);
  }
  .st-shade { background: #0c0c0d; }
  .st-nav {
    display: grid; place-items: center; position: relative; z-index: 2; margin: 0 16px;
    width: 48px; height: 48px; border-radius: 50%; border: 0; color: #fff;
    background: rgba(255, 255, 255, .1); transition: background-color .15s, opacity .15s;
  }
  .st-nav:hover:not(:disabled) { background: rgba(255, 255, 255, .2); }
  .st-nav:disabled { opacity: .25; cursor: default; }
}

@media (prefers-reduced-motion: reduce) {
  .st-stage, .st-sheet, .st-comp, .st-viewer { transition-duration: .01s !important; }
  .st-bar i { animation-duration: 2.5s; }
}
