:root {
  --stage: #000000;
  --ink: #17141f;
  --paper: #f5f3fa;
  --bubble: #cdbbff;
  --bubble-ink: #241a45;
  --heart: #ff3b6b;
  --sun: #ffe15a;
  --on-stage: #ffffff;
  --on-stage-dim: rgba(255, 255, 255, 0.74);
  --shadow-text: 0 1px 2px rgba(0, 0, 0, 0.55), 0 0 12px rgba(0, 0, 0, 0.35);

  --font-display: "Unbounded", "Manrope", system-ui, sans-serif;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;

  --col: min(100vw, 520px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--stage);
  color: var(--on-stage);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: var(--col);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--sun); outline-offset: 2px; }

/* ---------- екрани входу ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px 20px calc(24px + var(--safe-bottom));
  background: var(--stage);
}
.screen-inner {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.display {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.1rem, 9vw, 2.9rem);
  line-height: 1.02;
  letter-spacing: -0.02em;
}
.lead { margin: 0; font-size: 1.15rem; color: var(--on-stage-dim); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.9rem; color: var(--on-stage-dim); }
.field input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 1.1rem;
}
.field input:focus { border-color: var(--bubble); outline: none; }
.form-error { margin: 0; min-height: 1.4em; color: #ff8fa8; font-size: 0.95rem; }

.btn {
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
}
.btn-primary { background: var(--bubble); color: var(--bubble-ink); font-size: 1.05rem; }
.btn-primary:active { transform: scale(0.98); }
.btn-ghost { background: rgba(255, 255, 255, 0.12); color: var(--on-stage); }

/* ---------- вкладки ---------- */

#tabs {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(10px + var(--safe-top)) 12px 18px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
  pointer-events: none;
}
.tabs { display: flex; justify-content: center; gap: 4px; pointer-events: auto; }
.tab {
  position: relative;
  border: 0;
  background: none;
  padding: 6px 10px;
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--on-stage-dim);
  text-shadow: var(--shadow-text);
}
.tab[aria-current="page"] { color: var(--on-stage); }
.tab[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 30%;
  right: 30%;
  bottom: 0;
  height: 2.5px;
  border-radius: 2px;
  background: var(--on-stage);
}
.count { font-weight: 600; opacity: 0.8; }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 2px;
  border-radius: 9px;
  background: var(--sun);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 800;
  text-shadow: none;
  vertical-align: 2px;
}
.filters {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  pointer-events: auto;
}
.chips { display: flex; gap: 6px; max-width: 100%; overflow-x: auto; scrollbar-width: none; padding: 0 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  background: rgba(0, 0, 0, 0.5);
  color: var(--on-stage);
  font-weight: 700;
  font-size: 0.86rem;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.chip[aria-pressed="true"] { background: var(--on-stage); color: var(--ink); }
.chip-count { font-weight: 600; opacity: 0.7; white-space: pre; }
.chip .badge { margin-left: 6px; vertical-align: 0; }

.new-pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sun);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 800;
}

.sound-chip {
  display: block;
  margin: 8px auto 0;
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  font-weight: 700;
  font-size: 0.85rem;
}

/* ---------- стрічка ---------- */

#feed {
  height: 100%;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
#feed::-webkit-scrollbar { display: none; }

.slide {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  background: var(--stage);
}

.stage { position: absolute; inset: 0; }
.stage > .poster,
.stage video,
.stage .carousel img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.stage > .poster { position: absolute; inset: 0; }
.stage video { position: absolute; inset: 0; background: transparent; }

.carousel {
  position: absolute;
  inset: 0;
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}
.carousel::-webkit-scrollbar { display: none; }
.carousel > * { flex: 0 0 100%; height: 100%; scroll-snap-align: center; }
.dots {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  bottom: calc(14px + var(--safe-bottom));
  display: flex;
  justify-content: center;
  gap: 6px;
  pointer-events: none;
}
.dots i { width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
.dots i.on { background: var(--on-stage); }

.spinner {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 42px;
  height: 42px;
  margin: -21px 0 0 -21px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--on-stage);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.paused-mark {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 72px;
  height: 72px;
  margin: -36px 0 0 -36px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.paused-mark::before {
  content: "";
  position: absolute;
  left: 28px;
  top: 21px;
  border-style: solid;
  border-width: 15px 0 15px 24px;
  border-color: transparent transparent transparent rgba(255, 255, 255, 0.92);
}

/* смуга перемотування, як у TikTok */
.scrub {
  --p: 0;
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: var(--safe-bottom);
  height: 22px;
  display: flex;
  align-items: flex-end;
  touch-action: none;
  cursor: pointer;
}
.scrub-track {
  position: relative;
  width: 100%;
  height: 2px;
  background: rgba(255, 255, 255, 0.25);
  transition: height 0.15s ease;
}
.scrub-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--p) * 100%);
  background: rgba(255, 255, 255, 0.9);
}
.scrub-knob {
  position: absolute;
  top: 50%;
  left: calc(var(--p) * 100%);
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border-radius: 50%;
  background: var(--on-stage);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.15s ease;
}
.scrub.dragging .scrub-track { height: 6px; }
.scrub.dragging .scrub-knob { opacity: 1; }
@media (hover: hover) {
  .scrub:hover .scrub-track { height: 6px; }
  .scrub:hover .scrub-knob { opacity: 1; }
}
.scrub-time {
  position: absolute;
  left: 50%;
  top: 60%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* швидкість: «2×» поки тримаєш палець і меню вибору */
.hold-badge {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(var(--safe-top) + 112px);
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
  pointer-events: none;
  animation: pop-in 0.15s ease-out;
}
@keyframes pop-in { from { opacity: 0; transform: translateX(-50%) scale(0.85); } }

.act .rate {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  text-shadow: none;
}
.act.speed.on .rate { color: var(--sun); }

#speed-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(20, 16, 32, 0.92);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
#speed-menu[hidden] { display: none; }
#speed-menu button {
  min-width: 76px;
  padding: 9px 14px;
  border: 0;
  border-radius: 11px;
  background: none;
  color: var(--on-stage);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: center;
  cursor: pointer;
}
#speed-menu button:hover { background: rgba(255, 255, 255, 0.1); }
#speed-menu button.on { background: var(--bubble); color: var(--bubble-ink); }

/* підпис внизу */
.meta {
  position: absolute;
  z-index: 4;
  left: 14px;
  right: 82px;
  bottom: calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.meta > * { pointer-events: auto; }

/* бульбашка «хто скинув» — як повідомлення в телеграмі */
.from {
  position: relative;
  max-width: 100%;
  padding: 7px 12px 8px;
  border-radius: 16px 16px 16px 4px;
  background: var(--bubble);
  color: var(--bubble-ink);
  line-height: 1.2;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.from::before {
  content: "";
  position: absolute;
  left: -6px;
  bottom: 0;
  width: 12px;
  height: 12px;
  background: var(--bubble);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}
.from b { font-weight: 800; }
.from time { display: block; font-size: 0.78rem; opacity: 0.72; }

.author { font-weight: 800; text-shadow: var(--shadow-text); }
.caption {
  margin: 0;
  max-width: 100%;
  color: var(--on-stage);
  text-shadow: var(--shadow-text);
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
}
.caption.open { -webkit-line-clamp: unset; }

.last-comment {
  max-width: 100%;
  padding: 7px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 0.92rem;
  border: 0;
  text-align: left;
}
.last-comment b { font-weight: 800; }
.last-comment.unread { box-shadow: 0 0 0 2.5px var(--sun); }

/* кнопки справа */
.actions {
  position: absolute;
  z-index: 4;
  right: 4px;
  bottom: calc(28px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 72px;
  border: 0;
  background: none;
  padding: 0;
  color: var(--on-stage);
  font-size: 0.78rem;
  font-weight: 700;
  text-shadow: var(--shadow-text);
  text-decoration: none;
}
.act .ring {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.28);
}
.act svg {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linejoin: round;
  stroke-linecap: round;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.act.like.on svg { fill: var(--heart); stroke: var(--heart); }
.act.dislike.on svg { fill: var(--on-stage); stroke: var(--on-stage); }
.act.like.on .ring { animation: pop 0.32s ease-out; }
.act[disabled] { cursor: default; }
@keyframes pop { 40% { transform: scale(1.22); } }

/* серце на подвійний тап */
.burst {
  position: absolute;
  z-index: 6;
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  pointer-events: none;
  fill: var(--heart);
  filter: drop-shadow(0 4px 14px rgba(255, 59, 107, 0.55));
  animation: burst 0.85s cubic-bezier(0.2, 0.9, 0.3, 1.2) forwards;
}
@keyframes burst {
  0% { transform: scale(0.2) rotate(var(--tilt)); opacity: 0; }
  18% { transform: scale(1.15) rotate(var(--tilt)); opacity: 1; }
  32% { transform: scale(0.95) rotate(var(--tilt)); }
  70% { transform: scale(1) rotate(var(--tilt)) translateY(0); opacity: 1; }
  100% { transform: scale(1.3) rotate(var(--tilt)) translateY(-90px); opacity: 0; }
}

/* ---------- кінцеві слайди ---------- */

.end {
  display: grid;
  place-items: center;
  padding: calc(70px + var(--safe-top)) 24px calc(40px + var(--safe-bottom));
}
.end-inner { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; }
.end-inner h2 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; line-height: 1.12; }
.end-inner p { margin: 0; color: var(--on-stage-dim); }
.end-inner .btn { align-self: flex-start; }

/* фінальний екран — головний момент */
.outro { background: var(--bubble); color: var(--bubble-ink); }
.outro .end-inner { gap: 22px; }
.outro .outro-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.3rem, 11vw, 3.3rem);
  line-height: 1;
  letter-spacing: -0.025em;
}
.outro-title .word { display: inline-block; white-space: nowrap; }
.outro-title .word span { display: inline-block; }
.outro.reveal .outro-title .word span { animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1.1) backwards; animation-delay: calc(var(--i) * 28ms); }
@keyframes rise { from { transform: translateY(0.6em) rotate(6deg); opacity: 0; } }
.outro .outro-text { margin: 0; font-size: 1.12rem; line-height: 1.55; white-space: pre-line; color: var(--bubble-ink); }
.outro .outro-sign {
  margin: 4px 0 14px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.9rem;
  line-height: 1.1;
  color: var(--bubble-ink);
}
.outro.reveal .outro-sign { animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1.1) 0.9s backwards; }
.outro-stats { padding-top: 16px !important; border-top: 1.5px solid rgba(36, 26, 69, 0.18); display: flex; gap: 22px; flex-wrap: wrap; margin: 0; padding: 0; list-style: none; }
.outro-stats li { display: flex; flex-direction: column; }
.outro-stats b { font-family: var(--font-display); font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.outro-stats span { font-size: 0.9rem; opacity: 0.75; }
.outro .btn { background: var(--bubble-ink); color: var(--bubble); }

/* ---------- коментарі ---------- */

#sheet-backdrop { position: absolute; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.4); }
#sheet {
  position: absolute;
  z-index: 21;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
  border-radius: 20px 20px 0 0;
  background: var(--paper);
  color: var(--ink);
  padding-bottom: var(--safe-bottom);
  animation: sheet-in 0.22s ease-out;
}
@keyframes sheet-in { from { transform: translateY(40%); opacity: 0.4; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 10px 6px 18px; }
.sheet-head h2 { margin: 0; font-size: 1.05rem; font-weight: 800; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; }

#sheet-list { flex: 1; overflow-y: auto; margin: 0; padding: 6px 16px 12px; list-style: none; display: flex; flex-direction: column; gap: 8px; min-height: 120px; }
#sheet-list li { max-width: 85%; padding: 8px 12px; border-radius: 16px 16px 16px 4px; background: #fff; box-shadow: 0 1px 2px rgba(23, 20, 31, 0.08); overflow-wrap: anywhere; }
#sheet-list li.mine { align-self: flex-end; border-radius: 16px 16px 4px 16px; background: var(--bubble); color: var(--bubble-ink); }
#sheet-list li .who { display: block; font-size: 0.8rem; font-weight: 800; opacity: 0.7; }
#sheet-list li time { display: block; font-size: 0.72rem; opacity: 0.55; text-align: right; }
#sheet-list .empty { align-self: center; max-width: none; background: none; box-shadow: none; opacity: 0.6; text-align: center; }

#sheet-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid rgba(23, 20, 31, 0.1); }
#sheet-input { flex: 1; min-width: 0; border: 1.5px solid rgba(23, 20, 31, 0.15); border-radius: 999px; padding: 11px 16px; background: #fff; color: var(--ink); }
#sheet-input:focus { outline: none; border-color: #8c72f0; }
.btn-send { background: var(--ink); color: var(--paper); padding: 11px 18px; }

#toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  bottom: calc(110px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; }
}

.slide { touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.carousel { touch-action: pan-x pan-y; }
.last-comment { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.act .label { max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* стрілки каруселі — лише там, де є миша */
.car-nav { display: none; }
@media (hover: hover) and (pointer: fine) {
  .car-nav {
    display: grid;
    place-items: center;
    position: absolute;
    z-index: 3;
    top: 50%;
    width: 40px;
    height: 40px;
    margin-top: -20px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    color: var(--ink);
    font-size: 1.6rem;
    line-height: 1;
    padding-bottom: 3px;
  }
  .car-nav.prev { left: 10px; }
  .car-nav.next { right: 82px; }
}
