/* БЛОК chat-story: сцена-переписка (рабочий чат, мысли, звонок). Движок: js/blocks/chat-story.js.
   Цвета только из theme.css. Оболочка .story-shell, шапка и .story-content — из core.css. */
.cs-scene {
  --cs-dur: 420ms;
  --cs-ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --cs-distance: 10px;
  position: relative;
  display: grid;
  grid-template-columns: 54% 46%;
  align-items: start;
  min-height: 550px;
  border: var(--border-hairline) solid var(--ink);
  border-radius: var(--radius-8);
  background: linear-gradient(110deg, var(--stage-bg), var(--stage-panel));
  overflow: hidden;
}
.cs-scene.is-plain {
  display: block;
  min-height: 0;
  padding: var(--space-26);
}
.cs-visual {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  align-self: center;
}
.cs-strip {
  display: block;
  width: 300%;
  max-width: none;
  height: 100%;
}
.cs-strip.frame-1 { transform: translateX(-33.333333%); }
.cs-strip.frame-2 { transform: translateX(-66.666667%); }
.cs-call-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cs-panel {
  position: relative;
  z-index: 1;
  min-height: 180px;
  margin: var(--space-26) var(--space-26) var(--space-26) calc(-1 * var(--space-26));
  padding: var(--space-16);
  border: var(--border-hairline) solid var(--stage-line);
  border-radius: var(--radius-14);
  background: var(--stage-panel);
  color: var(--ink-on-dark);
  box-shadow: var(--shadow-panel);
}
.cs-scene.is-plain .cs-panel { margin: 0; }
.cs-head {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  padding: 0 0 var(--space-14);
  border-bottom: var(--border-hairline) solid var(--stage-line);
  font-size: var(--text-small);
}
.cs-head > span:last-child {
  margin-left: auto;
  font-size: var(--text-caption);
  color: var(--ink-on-dark-muted);
}
.cs-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  background: var(--positive);
}
.cs-beats {
  display: grid;
  gap: var(--space-12);
  padding-top: var(--space-16);
}
.cs-message {
  padding: var(--space-12) var(--space-14);
  border: var(--border-hairline) solid var(--border-soft);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 0;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-body);
  line-height: 1.45;
}
.cs-message p { margin: 0; }
.cs-message .speaker-label {
  display: block;
  margin-bottom: var(--space-5);
  font-size: var(--text-caption);
}
.cs-message.is-outgoing {
  margin-left: var(--space-22);
  border-radius: var(--radius-lg) var(--radius-lg) 0 var(--radius-lg);
  background: var(--accent-pale);
}
.cs-urgent {
  display: block;
  margin-bottom: var(--space-6);
  color: var(--accent);
}
/* Мысли: пузыри без рамки панели, как в комиксе. */
.cs-thoughts .cs-panel {
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
}
.cs-thoughts .cs-head {
  padding: var(--space-14);
  border: 0;
  border-radius: var(--radius-8);
  background: var(--stage-panel);
}
.cs-message.is-thought {
  position: relative;
  padding: var(--space-16) var(--space-20);
  border: var(--border-frame) solid var(--ink);
  border-radius: var(--radius-24);
  box-shadow: var(--shadow-card);
}
.cs-message.is-thought::before,
.cs-message.is-thought::after {
  content: '';
  position: absolute;
  border: var(--border-hairline) solid var(--ink);
  border-radius: var(--radius-round);
  background: var(--surface);
}
.cs-message.is-thought::after { left: calc(-1 * var(--space-12)); top: 36px; width: 9px; height: 9px; }
.cs-message.is-thought::before { left: calc(-1 * var(--space-22)); top: 49px; width: 5px; height: 5px; }
/* Появление сообщения: снизу вверх с лёгким размытием. */
.cs-line {
  display: block;
  opacity: 0;
  transform: translateY(var(--cs-distance));
  filter: blur(3px);
  transition: opacity var(--cs-dur) var(--cs-ease), transform var(--cs-dur) var(--cs-ease), filter var(--cs-dur) var(--cs-ease);
}
.cs-item.is-shown .cs-line {
  opacity: 1;
  transform: none;
  filter: none;
}
/* Звонок. */
.cs-dialing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-40) var(--space-12);
  text-align: center;
}
.cs-dialing > span:last-child {
  font-size: var(--text-small);
  color: var(--ink-on-dark-muted);
}
.cs-ring {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  border: var(--border-frame) solid var(--positive);
  border-radius: var(--radius-round);
  font-size: var(--text-display);
  color: var(--positive);
  animation: cs-pulse 0.55s ease-in-out 4;
}
@keyframes cs-pulse {
  50% { transform: scale(1.08) rotate(-10deg); box-shadow: 0 0 0 12px var(--stage-line); }
}
/* Телефон на первой сцене: дрожит и подсвечивается на новом сообщении. */
.cs-phone {
  position: absolute;
  inset: 0;
  clip-path: polygon(23% 76%, 37% 73%, 49% 79%, 35% 86%);
  pointer-events: none;
}
.cs-phone img { width: 300%; max-width: none; height: 100%; }
.cs-phone.is-ringing { animation: cs-vibrate 0.1s linear 8; }
.cs-glow {
  position: absolute;
  left: 25%;
  top: 74%;
  width: 22%;
  height: 12%;
  background: radial-gradient(ellipse, var(--screen-bg), transparent 72%);
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
}
.cs-glow.is-ringing { animation: cs-light 0.8s ease-out 1; }
@keyframes cs-vibrate {
  0%, 100% { transform: translate(0); }
  25% { transform: translate(-2px, 1px); }
  75% { transform: translate(2px, -1px); }
}
@keyframes cs-light {
  0%, 100% { opacity: 0; }
  15%, 75% { opacity: 1; }
}
/* Волны мыслей. */
.cs-waves {
  position: absolute;
  left: 44%;
  top: 5%;
  width: 24%;
  height: 24%;
  overflow: visible;
  fill: none;
  stroke: var(--stage-accent);
  stroke-width: 3;
  stroke-linecap: round;
  pointer-events: none;
}
.cs-waves path { transform-origin: 14px 54px; animation: cs-wave 900ms ease-out both; }
.cs-waves path:nth-child(2) { animation-delay: 100ms; }
.cs-waves path:nth-child(3) { animation-delay: 200ms; }
@keyframes cs-wave {
  0% { opacity: 0; transform: translateX(-4px) scale(0.85); }
  20%, 50% { opacity: 1; }
  100% { opacity: 0; transform: translateX(5px) scale(1.08); }
}
/* Строка кнопок под сценой. */
.cs-actions {
  display: flex;
  align-items: center;
  gap: var(--space-14);
  margin-top: var(--space-20);
}
.cs-dots { display: flex; gap: var(--space-8); margin-right: auto; }
.cs-dots i {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-round);
  background: var(--border-soft);
}
.cs-dots i.active { background: var(--accent); }
.cs-actions .quiet { font-size: var(--text-caption); }
.cs-actions .cs-sound { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; background: none; }
.cs-actions .cs-sound:hover { color: var(--ink); }
.cs-actions .cs-sound svg { width: 28px; height: 28px; }
.cs-actions .primary { min-width: 220px; }
/* Пока сообщения идут сами, кнопка перехода занимает место, но не видна. */
.cs-actions .primary.is-waiting { visibility: hidden; }
/* Десктоп: сцена вместе с кнопками умещается в высоту окна без прокрутки страницы.
   Высота сцены — окно минус шапка, отступы и строка кнопок; картинка квадратная, во всю высоту,
   панель занимает остаток ширины. Тот же расчёт держит комикс и финал. */
@media (min-width: 901px) {
  .cs-main {
    --cs-actions-h: 48px;
    --cs-h: max(300px, calc(100dvh - var(--header-h) - var(--space-16) - var(--space-14) - var(--cs-actions-h) - var(--space-20)));
    padding-top: var(--space-16);
  }
  .cs-main .cs-scene:not(.is-plain) {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: stretch;
    height: var(--cs-h);
    min-height: 0;
  }
  .cs-main .cs-visual {
    height: 100%;
    width: auto;
    align-self: stretch;
  }
  .cs-main .cs-panel {
    align-self: start;
    max-height: calc(100% - var(--space-26) - var(--space-26));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .cs-main .cs-actions { margin-top: var(--space-14); }
  .story-shell:has(.cs-main) { padding-bottom: var(--space-20); }
}
/* Невысокое окно (ноутбук, 1280×720 и ниже): реплики плотнее, чтобы вся переписка осталась в кадре. */
@media (min-width: 901px) and (max-height: 760px) {
  .cs-main .cs-panel { margin-block: var(--space-14); max-height: calc(100% - var(--space-14) - var(--space-14)); padding: var(--space-12); }
  .cs-main .cs-head { padding-bottom: var(--space-10); }
  .cs-main .cs-beats { gap: var(--space-8); padding-top: var(--space-12); }
  .cs-main .cs-message { padding: var(--space-8) var(--space-12); font-size: var(--text-small); line-height: 1.4; }
  .cs-main .cs-message.is-thought { padding: var(--space-12) var(--space-16); }
}
@media (max-width: 900px) {
  .cs-scene { grid-template-columns: 48% 52%; min-height: 540px; }
  .cs-panel { margin: var(--space-18) var(--space-18) var(--space-18) calc(-1 * var(--space-10)); padding: var(--space-14); }
  .cs-visual { align-self: start; margin-top: 50px; }
}
@media (max-width: 600px) {
  .cs-scene, .cs-scene.is-plain { display: block; min-height: 0; padding: 0; }
  .cs-visual { margin: 0; }
  .cs-panel, .cs-scene.is-plain .cs-panel { margin: calc(-1 * var(--space-28)) var(--space-12) var(--space-14); padding: var(--space-14); min-height: 120px; }
  .cs-scene.is-plain .cs-panel { margin: var(--space-12); }
  .cs-thoughts .cs-panel { padding: var(--space-14); border: var(--border-hairline) solid var(--stage-line); background: var(--stage-panel); }
  .cs-message.is-thought::before, .cs-message.is-thought::after { display: none; }
  .cs-message.is-outgoing { margin-left: var(--space-12); }
  .cs-actions { flex-wrap: wrap; gap: var(--space-10); }
  .cs-dots { order: 3; flex-basis: 100%; justify-content: center; margin-right: 0; }
  .cs-actions .primary { min-width: 0; flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .cs-line { transition: none; opacity: 1; transform: none; filter: none; }
  .cs-phone, .cs-glow, .cs-ring { animation: none !important; }
  .cs-waves path { animation: none; opacity: 0.8; }
}
