:root {
  --bg: #080d13;
  --surface: rgba(20, 27, 36, 0.9);
  --surface-strong: #18212b;
  --surface-soft: rgba(30, 40, 52, 0.72);
  --border: rgba(152, 183, 207, 0.14);
  --text: #f4f8fb;
  --muted: #8fa2b3;
  --accent: #39c8ff;
  --accent-soft: rgba(57, 200, 255, 0.16);
  --outgoing: #136480;
  --incoming: #1a2530;
  --notice: #b89258;
  --danger: #ff7484;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.24);
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 16px;
  line-height: 1.42;
  background-image:
    linear-gradient(rgba(5, 9, 14, 0.48), rgba(5, 9, 14, 0.48)),
    url("/ghost-wallpaper.webp");
  background-repeat: repeat;
  background-size: auto, min(720px, 115vw);
  background-attachment: fixed;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: rgba(7, 12, 18, 0.56);
  backdrop-filter: blur(2px);
}

.app-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 16, 22, 0.9);
  backdrop-filter: blur(18px) saturate(130%);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(57, 200, 255, 0.24);
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(57, 200, 255, 0.2), rgba(57, 200, 255, 0.05));
  box-shadow: inset 0 0 16px rgba(57, 200, 255, 0.08);
}

.brand-mark svg {
  width: 31px;
  height: 31px;
  fill: var(--text);
}

.brand-mark rect {
  fill: var(--accent);
}

.header-copy {
  min-width: 0;
  flex: 1;
}

.header-copy h1,
.header-copy p {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-copy h1 {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-copy p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.83rem;
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #55d884;
  box-shadow: 0 0 0 5px rgba(85, 216, 132, 0.09);
}

.status-dot.offline {
  background: var(--muted);
  box-shadow: none;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--text);
  background: var(--surface-soft);
  cursor: pointer;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.main-content {
  min-height: calc(100dvh - 138px);
}

.subscription-footer {
  position: sticky;
  z-index: 12;
  bottom: 0;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(11, 16, 22, 0.94);
  backdrop-filter: blur(18px) saturate(130%);
}

.subscription-button {
  display: block;
  width: 100%;
  min-height: 46px;
  border: 1px solid rgba(85, 216, 132, 0.3);
  border-radius: 14px;
  color: #f4fff8;
  font-weight: 700;
  background: linear-gradient(145deg, #2d8b4e, #226c3d);
  box-shadow: 0 8px 22px rgba(21, 90, 50, 0.24);
  cursor: pointer;
}

.subscription-button:active {
  transform: scale(0.992);
}

.view,
.thread-view {
  padding: 14px 12px calc(24px + env(safe-area-inset-bottom));
}

.privacy-notice {
  position: relative;
  margin: 2px 2px 14px;
  padding: 18px 46px 18px 18px;
  border: 1px solid rgba(255, 224, 174, 0.17);
  border-radius: 18px;
  color: #fffaf1;
  background: linear-gradient(135deg, rgba(184, 146, 88, 0.95), rgba(133, 102, 61, 0.94));
  box-shadow: var(--shadow);
}

.privacy-notice strong {
  display: block;
  font-size: 1rem;
}

.privacy-notice p {
  margin: 6px 0 0;
  font-size: 0.94rem;
}

.privacy-notice button {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 1.55rem;
  line-height: 1;
  background: transparent;
  cursor: pointer;
}

.chat-list {
  display: grid;
  gap: 8px;
}

.chat-card {
  display: grid;
  width: 100%;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 13px 12px;
  border: 1px solid var(--border);
  border-radius: 17px;
  color: inherit;
  text-align: left;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

.chat-card:active {
  transform: scale(0.992);
  background: var(--surface-strong);
}

.avatar {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  color: #eafaff;
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(145deg, #167e9e, #194c66);
}

.chat-copy {
  min-width: 0;
}

.chat-title-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.chat-title {
  overflow: hidden;
  flex: 1;
  font-size: 1rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-time {
  color: var(--muted);
  font-size: 0.75rem;
}

.chat-preview {
  overflow: hidden;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-badge {
  min-width: 26px;
  padding: 4px 7px;
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  text-align: center;
  background: var(--accent-soft);
}

.thread-view {
  min-height: calc(100dvh - 138px);
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.message-row {
  display: flex;
}

.message-row.out {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(84%, 570px);
  padding: 9px 11px 7px;
  border: 1px solid rgba(255, 255, 255, 0.055);
  border-radius: 16px 16px 16px 5px;
  background: var(--incoming);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.13);
}

.message-row.out .message-bubble {
  border-radius: 16px 16px 5px 16px;
  background: linear-gradient(145deg, #176982, #12566d);
}

.sender-label {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 650;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-meta {
  display: flex;
  gap: 5px;
  justify-content: flex-end;
  margin-top: 4px;
  color: rgba(231, 242, 248, 0.64);
  font-size: 0.7rem;
}

.deleted-label {
  color: #ffabb5;
}

.message-media {
  display: block;
  width: 100%;
  max-width: 480px;
  max-height: 62vh;
  margin: 1px 0 7px;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.22);
}

audio.message-media {
  min-width: min(260px, 70vw);
  height: 42px;
  background: transparent;
}

.message-media.circle {
  width: min(260px, 68vw);
  aspect-ratio: 1;
  border-radius: 50%;
  object-fit: cover;
}

.media-placeholder,
.document-link {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  margin-bottom: 5px;
  padding: 9px 11px;
  border-radius: 11px;
  color: var(--text);
  font-size: 0.86rem;
  text-decoration: none;
  background: rgba(0, 0, 0, 0.18);
}

.media-placeholder {
  color: rgba(235, 244, 249, 0.68);
}

.older-button,
.primary-button {
  display: block;
  min-height: 44px;
  margin: 0 auto 14px;
  padding: 10px 18px;
  border: 1px solid rgba(57, 200, 255, 0.25);
  border-radius: 999px;
  color: #eafaff;
  font-weight: 650;
  background: rgba(19, 100, 128, 0.78);
  cursor: pointer;
}

.state-view {
  display: grid;
  min-height: calc(100dvh - 138px);
  padding: 28px;
  place-content: center;
  justify-items: center;
  text-align: center;
}

.state-view.compact {
  min-height: 52vh;
}

.state-view h2,
.state-view p {
  margin: 0;
}

.state-view h2 {
  font-size: 1.08rem;
}

.state-view p {
  max-width: 320px;
  margin-top: 7px;
  color: var(--muted);
}

.state-icon,
.empty-ghost {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 50%;
  color: var(--danger);
  font-size: 1.5rem;
  font-weight: 700;
  background: rgba(255, 116, 132, 0.12);
}

.empty-ghost {
  color: inherit;
  font-size: 1.8rem;
  background: var(--surface-soft);
}

.ghost-loader svg {
  width: 64px;
  height: 64px;
  fill: rgba(255, 255, 255, 0.08);
  stroke: var(--accent);
  stroke-width: 1.8;
  animation: float 1.8s ease-in-out infinite;
}

.ghost-loader circle {
  fill: var(--accent);
  stroke: none;
}

.is-hidden {
  display: none !important;
}

@keyframes float {
  0%, 100% { transform: translateY(0); opacity: 0.72; }
  50% { transform: translateY(-7px); opacity: 1; }
}

@media (min-width: 700px) {
  .app-shell {
    border-right: 1px solid var(--border);
    border-left: 1px solid var(--border);
  }

  .view,
  .thread-view {
    padding-right: 20px;
    padding-left: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
