.stories-rail {
  position: relative;
  z-index: 7;
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 2px 8px 2px;
  border-top: 0;
  border-bottom: 1px solid rgba(191, 204, 215, 0.48);
  background: linear-gradient(180deg, rgba(250, 252, 254, 0.92), rgba(245, 248, 251, 0.72));
  overflow: hidden;
}

.chat-area.has-stories-rail > .stories-rail {
  display: flex;
}

.chat-area.stories-rail-collapsed > .stories-rail {
  display: none;
}

.stories-rail-inline {
  border-top: 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.stories-rail-track {
  display: flex;
  gap: 6px;
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.stories-rail-track::-webkit-scrollbar {
  display: none;
}

.story-rail-item {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  width: 46px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.story-rail-avatar-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  padding: 2px;
  background: linear-gradient(135deg, rgba(203, 213, 225, 0.7), rgba(203, 213, 225, 0.25));
}

.story-rail-item.is-unseen .story-rail-avatar-wrap,
.private-header-avatar.has-story::after {
  background: linear-gradient(135deg, #ff6a3d, #ff2d7d 52%, #7c3aed);
}

.story-rail-item.is-own.has-story .story-rail-avatar-wrap {
  background: linear-gradient(135deg, #34d399, #22c55e 56%, #16a34a);
}

.story-rail-item.is-own .story-rail-plus {
  position: absolute;
  right: -2px;
  bottom: -1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  touch-action: manipulation;
}

.story-rail-item.is-own .story-rail-plus::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 999px;
}

.story-owner-menu {
  position: fixed;
  z-index: 310;
  display: grid;
  gap: 3px;
  min-width: 188px;
  max-width: min(240px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid rgba(148, 163, 184, 0.36);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.16);
}

.story-owner-menu-item {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #1f2d3a;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  padding: 7px 9px;
}

.story-owner-menu-item:hover:not(:disabled),
.story-owner-menu-item:focus-visible:not(:disabled) {
  background: rgba(37, 99, 235, 0.1);
  color: #0f3f91;
  outline: none;
}

.story-owner-menu-item:disabled {
  color: rgba(71, 85, 105, 0.46);
  cursor: not-allowed;
}

.story-owner-menu-hint {
  padding: 4px 9px 3px;
  color: rgba(71, 85, 105, 0.72);
  font-size: 10px;
  line-height: 1.3;
}

.story-rail-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  object-fit: cover;
  background: #e2e8f0;
  border: 1.5px solid rgba(255, 255, 255, 0.96);
}

.story-rail-label {
  width: 100%;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(30, 41, 59, 0.76);
}

.private-header-avatar {
  position: relative;
}

.private-header-avatar.has-story::after {
  content: "";
  position: absolute;
  inset: -2px;
  z-index: 0;
  border-radius: 999px;
  padding: 2px;
  opacity: 0.98;
}

.private-header-avatar.has-story img,
.private-header-avatar.has-story .private-header-avatar-fallback {
  position: relative;
  z-index: 1;
  border: 2px solid rgba(255, 255, 255, 0.96);
}

.private-header-avatar.has-unseen-story::after {
  filter: saturate(1.15);
}

.stories-viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 280;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at center, rgba(31, 41, 55, 0.26), rgba(2, 6, 23, 0.86)),
    rgba(3, 7, 18, 0.82);
  backdrop-filter: blur(14px);
}

.stories-viewer-shell {
  position: relative;
  width: min(92vw, 430px);
  height: min(92dvh, 780px);
  padding: 0;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  display: block;
  background:
    linear-gradient(180deg, rgba(14, 21, 39, 0.96), rgba(5, 9, 22, 0.99));
  color: #fff;
  box-shadow:
    0 30px 90px rgba(15, 23, 42, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.stories-viewer-bars {
  position: absolute;
  top: calc(8px + env(safe-area-inset-top, 0px));
  left: 10px;
  right: 10px;
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 5px;
  margin: 0;
}

.stories-viewer-bar {
  height: 2.5px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  overflow: hidden;
}

.stories-viewer-bar-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.96);
  transform: scaleX(0);
  transform-origin: left center;
}

.stories-viewer-head {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top, 0px));
  left: 10px;
  right: 10px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
}

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

.stories-viewer-avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  background: rgba(226, 232, 240, 0.2);
}

.stories-viewer-meta {
  display: grid;
  min-width: 0;
}

.stories-viewer-nick,
.stories-viewer-time {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stories-viewer-time {
  font-size: 11px;
  color: rgba(226, 232, 240, 0.78);
}

.stories-viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stories-viewer-close,
.stories-viewer-delete,
.stories-viewer-like {
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.stories-viewer-close svg,
.stories-viewer-delete svg,
.stories-viewer-like svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stories-viewer-close {
  width: 46px;
  height: 46px;
}

.stories-viewer-delete {
  width: 46px;
  height: 46px;
}

.stories-viewer-like {
  width: 46px;
  height: 46px;
  color: #ffd1dc;
}

.stories-viewer-like.is-active {
  color: #ff6b91;
  border-color: rgba(255, 107, 145, 0.5);
  background: rgba(255, 107, 145, 0.2);
  box-shadow: 0 10px 24px rgba(255, 84, 131, 0.22);
}

.stories-viewer-stage {
  position: absolute;
  inset: 0;
  height: 100%;
  min-height: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: rgba(7, 12, 24, 0.96);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.stories-viewer-image,
.stories-viewer-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: #000;
  pointer-events: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.stories-viewer-nav {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28%;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 4;
}

.stories-viewer-nav.prev {
  left: 0;
}

.stories-viewer-nav.next {
  right: 0;
}

.stories-viewer-footer {
  position: absolute;
  right: 10px;
  bottom: calc(98px + env(safe-area-inset-bottom, 0px));
  left: 10px;
  z-index: 6;
}

.stories-viewer-caption {
  display: inline-block;
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 14px;
  background: rgba(12, 19, 34, 0.68);
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
}

.stories-viewer-viewers {
  --stories-insights-max-height: min(42vh, 260px);
  position: absolute;
  right: 10px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 10px;
  z-index: 7;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgb(30 10 24);
  padding: 8px 10px;
  max-height: min(42dvh, var(--stories-insights-max-height));
  overflow: auto;
}

.stories-viewer-viewers-summary {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.96);
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  border-radius: 0;
  box-shadow: none;
  min-height: 0;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
}

.stories-viewer-viewers-summary.is-disabled {
  opacity: 0.72;
  cursor: default;
}

.stories-viewer-viewers-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stories-viewer-viewers-more {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 11px;
  color: #9ad5ff;
  font-weight: 600;
}

.stories-viewer-viewers-pop {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  max-height: calc(var(--stories-insights-max-height) - 68px);
  overflow: auto;
}

.stories-viewer-likes {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  max-height: calc(var(--stories-insights-max-height) - 68px);
  overflow: auto;
}

.stories-viewer-viewers-title {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stories-viewer-viewers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: none;
  overflow: visible;
}

.stories-viewer-viewer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.stories-viewer-viewer-nick {
  color: rgba(255, 255, 255, 0.96);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stories-viewer-viewer-time {
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  flex: 0 0 auto;
}

.stories-viewer-viewer-item.is-empty {
  color: rgba(255, 255, 255, 0.7);
  justify-content: flex-start;
  font-style: italic;
}

@media (min-width: 721px) {
  .stories-rail {
    min-height: 59px;
    padding: 4px 10px 4px;
  }

  .story-rail-item {
    width: 56px;
    gap: 3px;
  }

  .story-rail-avatar-wrap {
    width: 36px;
    height: 36px;
  }

  .story-rail-label {
    font-size: 9px;
  }

  .story-rail-item.is-own .story-rail-plus {
    width: 17px;
    height: 17px;
    font-size: 12px;
  }
}

@media (max-width: 1024px) {
  .stories-viewer-overlay {
    position: fixed;
    inset: 0;
    place-items: stretch;
    padding: 0;
  }

  .stories-viewer-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    padding: 0;
    border-radius: 0;
    border: 0;
    display: block;
    background: #000;
  }

  .stories-viewer-stage {
    position: absolute;
    inset: 0;
    height: 100%;
    min-height: 100%;
    border-radius: 0;
    box-shadow: none;
  }

  .stories-viewer-image,
  .stories-viewer-video {
    object-fit: contain;
    object-position: center;
  }

  .stories-viewer-bars {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    margin: 0;
    z-index: 6;
  }

  .stories-viewer-head {
    position: absolute;
    top: calc(18px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    margin: 0;
    z-index: 6;
  }

  .stories-viewer-nav {
    top: 0;
    bottom: 0;
    width: 28%;
    z-index: 4;
  }

  .stories-viewer-footer {
    left: 10px;
    right: 10px;
    bottom: calc(98px + env(safe-area-inset-bottom, 0px));
    z-index: 6;
  }

  .stories-viewer-viewers {
    right: 10px;
    left: 10px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    max-height: min(42dvh, 280px);
    z-index: 7;
  }
}

@media (max-width: 720px) {
  .stories-viewer-overlay {
    place-items: stretch;
  }

  .stories-rail {
    min-height: 46px;
    padding: 4px 6px 4px;
  }

  .chat-area.has-stories-rail > .stories-rail {
    width: calc(100% + 16px);
    margin: 3px -8px 0;
    padding: 0 8px;
  }

  .story-rail-item {
    width: 42px;
    gap: 2px;
  }

  .story-rail-avatar-wrap {
    width: 30px;
    height: 30px;
  }

  .story-rail-avatar {
    width: 26px;
    height: 26px;
  }

  .story-rail-label {
    font-size: 8px;
  }

  .story-rail-item.is-own .story-rail-plus {
    width: 18px;
    height: 18px;
    font-size: 12px;
  }

  .stories-viewer-shell {
    padding-top: 0;
  }
}

:root[data-appearance-mode="dark"] .stories-rail,
:root[data-appearance-mode="dark"] .stories-rail-inline {
  border-bottom-color: rgba(63, 89, 110, 0.6);
  background: linear-gradient(180deg, rgba(20, 34, 47, 0.96), rgba(16, 28, 39, 0.92));
}

:root[data-appearance-mode="dark"] .story-rail-avatar-wrap {
  background: linear-gradient(135deg, rgba(76, 97, 116, 0.8), rgba(76, 97, 116, 0.28));
}

:root[data-appearance-mode="dark"] .story-rail-item.is-own.has-story .story-rail-avatar-wrap {
  background: linear-gradient(135deg, #2fb384, #1f9a63 56%, #15804d);
}

:root[data-appearance-mode="dark"] .story-rail-avatar {
  background: #1a2a3a;
  border-color: rgba(13, 23, 34, 0.92);
}

:root[data-appearance-mode="dark"] .story-rail-label {
  color: rgba(206, 223, 237, 0.86);
}

:root[data-appearance-mode="dark"] .story-rail-item.is-own .story-rail-plus {
  border-color: #132232;
}

:root[data-appearance-mode="dark"] .story-owner-menu {
  border-color: rgba(63, 89, 110, 0.82);
  background: rgba(20, 34, 47, 0.98);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.36);
}

:root[data-appearance-mode="dark"] .story-owner-menu-item {
  color: #d9e7f2;
}

:root[data-appearance-mode="dark"] .story-owner-menu-item:hover:not(:disabled),
:root[data-appearance-mode="dark"] .story-owner-menu-item:focus-visible:not(:disabled) {
  background: rgba(92, 167, 255, 0.14);
  color: #8fc7ff;
}

:root[data-appearance-mode="dark"] .story-owner-menu-item:disabled,
:root[data-appearance-mode="dark"] .story-owner-menu-hint {
  color: rgba(206, 223, 237, 0.56);
}

:root[data-appearance-mode="dark"] .private-header-avatar.has-story img,
:root[data-appearance-mode="dark"] .private-header-avatar.has-story .private-header-avatar-fallback {
  border-color: #132232;
}
