/*
 * Stories viewer — Phase 5 of docs/features/stories-feature.md.
 *
 * Full-screen overlay opened from the home tray. Singleton; hidden
 * by default via the `hidden` attribute on .story_viewer_overlay.
 * Layout is a centred 9:16 stage with a header, frame body, tap
 * zones, and a footer with reactions + reply.
 *
 * Tray entry button-reset lives here (Phase 4 used <a>; Phase 5
 * switched to <button> for accessibility + to avoid the
 * empty-href click problem when JS hasn't loaded yet).
 */

/* Reset the button shape so the Phase-4 tray styling still applies
   when the entry is rendered as <button data-story-action="open">. */
button.story_tray_item {
  appearance: none;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* ---------- Overlay ---------- */

.story_viewer_overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story_viewer_overlay[hidden] { display: none; }

body.story_viewer_open { overflow: hidden; }

.story_viewer_backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  cursor: pointer;
}

/* ---------- Stage ---------- */

.story_viewer_stage {
  position: relative;
  width: min(420px, 100vw);
  height: min(746px, 100vh);
  aspect-ratio: 9 / 16;
  background: #000;
  color: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

/* ---------- Progress bar ---------- */

.story_viewer_progress {
  position: relative;
  z-index: 4;
  display: flex;
  gap: 4px;
  padding: 8px 12px 4px;
}

.story_viewer_progress_seg {
  flex: 1 1 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
  overflow: hidden;
}

.story_viewer_progress_fill {
  height: 100%;
  width: 0;
  background: #fff;
}

/* ---------- Head ---------- */

.story_viewer_head {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px 10px;
}

.story_viewer_who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.story_viewer_who_avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
}

.story_viewer_who_avatar img,
.story_viewer_who_avatar .prof_img_fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story_viewer_who_text { min-width: 0; }

.story_viewer_who_name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.story_viewer_who_time {
  font-size: 12px;
  opacity: 0.7;
}

.story_viewer_close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

/* ---------- Frame body ---------- */

.story_viewer_frame {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
}

.story_viewer_frame > .story_viewer_image,
.story_viewer_frame > .story_viewer_video,
.story_viewer_frame > .story_viewer_text { display: none; }

.story_viewer_frame[data-kind="image"] > .story_viewer_image { display: block; }
.story_viewer_frame[data-kind="video"] > .story_viewer_video { display: block; }
.story_viewer_frame[data-kind="text"]  > .story_viewer_text  { display: flex; }

.story_viewer_image,
.story_viewer_video {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story_viewer_text {
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 22px;
  line-height: 1.35;
  font-weight: 500;
  word-break: break-word;
  width: 100%;
  height: 100%;
}

/* ---------- Tap zones ---------- */

.story_viewer_tap {
  position: absolute;
  z-index: 3;
  top: 0;
  bottom: 80px; /* leave room for the foot bar */
  background: transparent;
  border: none;
  cursor: pointer;
}

.story_viewer_tap_prev { left: 0; width: 33%; }
.story_viewer_tap_next { right: 0; width: 67%; }

/* ---------- Foot: reply + reactions ---------- */

.story_viewer_foot {
  position: absolute;
  z-index: 4;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Hide the reply field when viewing one's own story (data-self="1"). */
.story_viewer_foot[data-self="1"] .story_viewer_reply { display: none; }

.story_viewer_reply {
  display: flex;
  gap: 8px;
  align-items: center;
}

.story_viewer_reply_input {
  flex: 1;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 22px;
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
}

.story_viewer_reply_input::placeholder { color: rgba(255, 255, 255, 0.6); }
.story_viewer_reply_input:focus { border-color: rgba(255, 255, 255, 0.7); }

.story_viewer_reply_send {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
}

.story_viewer_reactions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.story_viewer_react_btn {
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  border-radius: 18px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.story_viewer_react_btn:hover { background: rgba(255, 255, 255, 0.18); }

/* ---------- Toast ---------- */

.story_viewer_toast {
  position: absolute;
  z-index: 5;
  bottom: 110px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  padding: 8px 14px;
  border-radius: 14px;
  font-size: 13px;
  white-space: nowrap;
}

.story_viewer_toast_err {
  background: rgba(180, 30, 30, 0.85);
  border-color: rgba(255, 120, 120, 0.45);
}
