*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --color-bg: #A8C8E8;
  --color-bubble-own: #EBEBF0;
  --color-bubble-other: #FFFFFF;
  --color-accent: #0084FF;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: transparent;
  color: #111;
  height: 100%;
  overflow: hidden;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.hidden {
  display: none !important;
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #e5e5e5;
  border-top-color: #333;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 0.75rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.muted {
  color: #666;
  font-size: 0.9rem;
  margin: 0;
}

.error-text {
  color: #b00020;
  text-align: center;
  max-width: 22rem;
  line-height: 1.4;
}

#screen-main {
  height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  background-color: #8BB8D8;
  background-image: url('/bg-full.webp');
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center top;
  background-attachment: scroll;
}

.header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 6px 12px 4px;
  background: transparent;
  pointer-events: none;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

.pill {
  display: flex;
  align-items: center;
  gap: 5px;
  border-radius: 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  white-space: nowrap;
  pointer-events: none;
}

.pill--comments {
  background: rgba(255,255,255,0.75);
  color: #1C1C1E;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

.pill--comments svg {
  color: #636366;
  flex-shrink: 0;
}

.pill-count {
  font-size: 13px;
  font-weight: 400;
  color: #636366;
}

.notify-group {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.pill--desc {
  background: rgba(255,255,255,0.65);
  color: #3C3C43;
  padding: 5px 12px;
  font-size: 11px;
  font-weight: 400;
  pointer-events: none;
}

.notify-bell {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: #007AFF;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: transform 0.12s ease;
  -webkit-tap-highlight-color: transparent;
}
.notify-bell:active {
  transform: scale(0.88);
}

.notify-bell svg {
  display: block;
}

.notify-bell.active {
  background: #3880ff;
}

.notify-bell.active svg {
  color: #ffffff;
}

.comment-count {
  font-size: 13px;
  font-weight: 400;
  color: #636366;
}

.thread {
  height: 100%;
  overflow-y: auto;
  padding: 48px 8px 124px 16px;
  background: transparent;
  -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 78%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 10%, black 78%, transparent 100%);
}

.pull-indicator {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  z-index: 9;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 0;
  opacity: 0;
  pointer-events: none;
  transition: height 0.2s ease, opacity 0.2s ease;
}

.pull-indicator.visible {
  opacity: 1;
}

.pull-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(0, 132, 255, 0.2);
  border-top-color: #0084FF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.msg-group {
  margin-bottom: 12px;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}
.msg-group.animate-in > .msg-row {
  animation: bubbleIn 0.24s cubic-bezier(0.34, 1.25, 0.64, 1);
}

.msg-meta {
  font-size: 12px;
  color: #888;
  margin-bottom: 4px;
  padding-left: 40px;
}

.msg-meta.own {
  text-align: right;
  padding-left: 0;
  padding-right: 0;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-row.own {
  flex-direction: row-reverse;
}

.bubble {
  max-width: 72%;
  padding: 8px 12px;
  border-radius: 18px;
  word-break: break-word;
  user-select: none;
  -webkit-user-select: none;
  white-space: pre-wrap;
  line-height: 1.4;
}

.bubble.own {
  background: var(--color-bubble-own);
  color: #1C1C1E;
  border-bottom-right-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.bubble.other {
  background: var(--color-bubble-other);
  color: #1C1C1E;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.12);
}

.bubble-sender {
  font-size: 12px;
  font-weight: 600;
  color: #0084FF;
  margin-bottom: 2px;
}

.bubble-time {
  font-size: 11px;
  color: #8E8E93;
  text-align: right;
  margin-top: 2px;
}

.msg-edited {
  display: block;
  font-size: 11px;
  opacity: 0.5;
  margin-top: 2px;
}

.bubble.own .bubble-time {
  color: #8E8E93;
}

.reply-quote {
  border-left: 3px solid var(--color-accent);
  padding-left: 8px;
  margin-bottom: 6px;
  font-size: 12px;
  color: #555;
  cursor: pointer;
}

.reply-quote-author {
  font-weight: 600;
  color: var(--color-accent);
  margin-bottom: 2px;
}

.reply-quote-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight .bubble {
  animation: highlightFlash 1.5s ease;
}

@keyframes highlightFlash {
  0% { background-color: #FFF3BF; }
  100% { background-color: inherit; }
}

.bubble-error {
  border: 1px solid #d93025;
}
[data-pending="1"] {
  opacity: 0.65;
}

.avatar,
.avatar-placeholder,
.avatar-spacer {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.avatar-spacer {
  border-radius: 50%;
}

.date-divider { text-align: center; margin: 16px 0; }

.date-divider span { display: inline-block; font-size: 12px; color: #555; background: rgba(255,255,255,0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); padding: 3px 12px; border-radius: 12px; }

.empty-state {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #888;
  gap: 12px;
  font-size: 15px;
  text-align: center;
}

.composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: transparent;
}

.reply-preview {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.reply-preview.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.edit-preview {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 11;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.edit-preview.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.edit-preview-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.edit-preview-label {
  font-size: 12px;
  color: #0084FF;
  font-weight: 600;
  line-height: 1.2;
}

.edit-preview-text {
  font-size: 12px;
  color: #4A4A4A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.reply-preview-author {
  font-size: 12px;
  font-weight: 600;
  color: #0084FF;
  line-height: 1.2;
}

.reply-preview-text {
  font-size: 12px;
  color: #4A4A4A;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-cancel {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  color: #3A3A3C;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

#msg-text {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 20px;
  padding: 8px 14px;
  font: inherit;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.4;
}

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-accent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  transition: transform 0.12s ease, opacity 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn-send:active:not(:disabled) {
  transform: scale(0.88);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  padding: 8px 8px 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
}

#toast.show {
  opacity: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.composer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  background: #0084FF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  align-self: flex-end;
  margin-bottom: 2px;
}
.composer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.composer-avatar:empty { display: none; }

/* === Skeleton (внутри thread) === */
.thread-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
}

.sk-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.sk-row.sk-own {
  flex-direction: row-reverse;
}

.sk-row.sk-no-avatar {
  padding-left: 40px;
}

.sk-row.sk-own.sk-no-avatar {
  padding-right: 40px;
}

.sk-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.45);
  flex-shrink: 0;
}

.sk-bubble {
  height: 38px;
  border-radius: 18px;
  background: rgba(255,255,255,0.45);
  position: relative;
  overflow: hidden;
}

.sk-bubble::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255,255,255,0.45) 45%,
    rgba(255,255,255,0.65) 50%,
    rgba(255,255,255,0.45) 55%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

/* Context menu (long press) */
.ctx-menu {
  position: fixed;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  z-index: 1000;
  overflow: hidden;
  min-width: 150px;
}
.ctx-menu.hidden { display: none; }
@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.85) translateY(4px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);   }
}
.ctx-menu:not(.hidden) {
  animation: ctxIn 0.18s cubic-bezier(0.34, 1.2, 0.64, 1);
  transform-origin: center bottom;
}
.ctx-menu-item {
  display: block;
  width: 100%;
  padding: 14px 18px;
  background: none;
  border: none;
  text-align: left;
  font-size: 16px;
  color: #1C1C1E;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ctx-menu-item:active { background: rgba(0,0,0,0.06); }
