/* The look of a Telegram Web chat, narrowed to a single message: the same dark
   canvas, the same left-hand bubble with its tail, media above text, views and
   time tucked into the last line. */

:root {
  --canvas: #0e1621;
  --canvas-deep: #0a121b;
  --bubble: #182533;
  --head: #17212b;
  --text: #f5f5f5;
  --text-dim: #8b9aa8;
  --link: #62bcf9;
  --accent: #64b5ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.36);
  --radius: 12px;
}

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

html {
  background: var(--canvas-deep);
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: clamp(12px, 4vw, 40px) clamp(10px, 3vw, 24px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto,
    'Helvetica Neue', sans-serif;
  font-size: 15px;
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
  /* The chat backdrop: a soft radial wash over the dark canvas, the way the
     web client paints its pattern. */
  background-color: var(--canvas);
  background-image:
    radial-gradient(at 20% 12%, rgba(84, 122, 165, 0.22), transparent 45%),
    radial-gradient(at 82% 78%, rgba(52, 89, 132, 0.2), transparent 48%),
    radial-gradient(at 55% 45%, rgba(29, 55, 84, 0.35), transparent 60%);
  background-attachment: fixed;
}

.chat {
  width: min(640px, 100%);
}

/* ── header ─────────────────────────────────────────────────────────── */

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin-bottom: 16px;
  background: var(--head);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: #2b3a4a;
  flex: none;
}

.chat-titles {
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-right: auto;
}

.chat-name {
  font-weight: 500;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-name:hover {
  text-decoration: underline;
}

.chat-status {
  font-size: 13px;
  color: var(--text-dim);
}

.chat-open {
  flex: none;
  padding: 7px 12px;
  border-radius: 8px;
  background: rgba(100, 181, 239, 0.12);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.16s ease;
}

.chat-open:hover {
  background: rgba(100, 181, 239, 0.2);
}

/* ── bubble ─────────────────────────────────────────────────────────── */

.bubble {
  position: relative;
  width: fit-content;
  max-width: 100%;
  min-width: 180px;
  padding: 7px 10px 6px;
  background: var(--bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}

/* The tail, drawn the way the web client draws it. */
.bubble::before {
  content: '';
  position: absolute;
  left: -7px;
  bottom: 0;
  width: 11px;
  height: 20px;
  background: var(--bubble);
  clip-path: path('M11 20 C 4 20, 0 14, 0 8 L 0 20 Z');
}

.forwarded {
  margin-bottom: 4px;
  font-size: 14px;
  color: var(--accent);
}

.forwarded span {
  color: var(--text-dim);
}

.forwarded a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}

.forwarded a:hover {
  text-decoration: underline;
}

.post-text {
  white-space: pre-wrap;
}

.post-text a {
  color: var(--link);
  text-decoration: none;
}

.post-text a:hover {
  text-decoration: underline;
}

.post-text code,
.post-text pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 4px;
}

.post-text code {
  padding: 1px 4px;
}

.post-text pre {
  display: block;
  padding: 8px 10px;
  margin: 6px 0;
  overflow-x: auto;
  white-space: pre;
}

.post-text blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  color: #dfe6ec;
}

/* Hidden until asked for, like a spoiler in the app. */
.tg-spoiler {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  color: transparent;
  text-shadow: 0 0 8px rgba(245, 245, 245, 0.75);
  cursor: pointer;
}

.tg-spoiler.revealed {
  background: none;
  color: inherit;
  text-shadow: none;
  cursor: auto;
}

/* ── media ──────────────────────────────────────────────────────────── */

.media {
  display: grid;
  gap: 2px;
  margin: -7px -10px 6px;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}

.media.single {
  grid-template-columns: 1fr;
}

.media.pair {
  grid-template-columns: 1fr 1fr;
}

.media.many {
  grid-template-columns: 1fr 1fr;
}

.media.many > :first-child:nth-last-child(3) {
  grid-column: span 2;
}

.media img,
.media video {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 62vh;
  object-fit: cover;
  background: #0c1620;
}

.media.single img {
  object-fit: contain;
  max-height: 66vh;
}

/* When a post is nothing but pictures, the bubble has no text to sit under. */
.media.only {
  margin-bottom: -6px;
  border-radius: var(--radius);
}

/* ── link preview ───────────────────────────────────────────────────── */

.preview {
  display: block;
  margin-top: 6px;
  padding-left: 10px;
  border-left: 3px solid var(--accent);
  color: inherit;
  text-decoration: none;
}

.preview-site {
  font-weight: 500;
  font-size: 14px;
  color: var(--accent);
}

.preview-title {
  font-weight: 500;
  font-size: 14px;
}

.preview-text {
  font-size: 14px;
  color: #dfe6ec;
}

.preview-image {
  display: block;
  width: 100%;
  margin-top: 6px;
  max-height: 44vh;
  object-fit: cover;
  border-radius: 6px;
}

/* ── footer line ────────────────────────────────────────────────────── */

.meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1;
}

.meta svg {
  width: 16px;
  height: 10px;
  fill: currentColor;
  opacity: 0.85;
}

.meta .views {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

/* ── states ─────────────────────────────────────────────────────────── */

.bubble-skeleton {
  width: min(420px, 100%);
}

.skeleton-line {
  height: 12px;
  margin: 7px 0;
  border-radius: 6px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 25%,
    rgba(255, 255, 255, 0.12) 37%,
    rgba(255, 255, 255, 0.06) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

.skeleton-line.short {
  width: 45%;
}

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

.notice {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--bubble);
  color: var(--text-dim);
  box-shadow: var(--shadow);
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line {
    animation: none;
  }
}
