:root {
  --bg: #0f1419;
  --bg-elev: #161c24;
  --bg-elev-2: #1e2631;
  --fg: #e7ecef;
  --fg-dim: #8b98a5;
  --accent: #4aa1e0;
  --border: #222b37;
  --danger: #d9534f;
  --radius: 14px;
  --max: 680px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fa;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef1f5;
    --fg: #13181f;
    --fg-dim: #5b6876;
    --border: #dde3ea;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--fg);
}

#channels {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow-x: auto;
}

.chip {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  color: var(--fg);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.chip.err {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
}

#feed {
  max-width: var(--max);
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.post {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--fg-dim);
}
.post-head .ch {
  color: var(--fg);
  font-weight: 600;
}
.post-head .sep { opacity: 0.5; }
.post-head time { margin-left: auto; }
.post-head a { color: inherit; }

.fwd, .reply {
  font-size: 13px;
  color: var(--fg-dim);
  border-left: 3px solid var(--accent);
  padding-left: 8px;
}

.text {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.text tg-spoiler {
  background: var(--fg);
  color: var(--fg);
  border-radius: 3px;
}
.text tg-spoiler:hover, .text tg-spoiler:focus { color: var(--bg); }
.text pre, .text code {
  background: var(--bg-elev-2);
  border-radius: 6px;
  padding: 2px 6px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.text pre { padding: 10px; overflow-x: auto; }

.media-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr;
}
.media-grid.n2 { grid-template-columns: 1fr 1fr; }
.media-grid.n3, .media-grid.n4 { grid-template-columns: 1fr 1fr; }
.media-grid img, .media-grid video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg-elev-2);
  aspect-ratio: 4/3;
}
.media-single img, .media-single video {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px;
  background: #000;
  aspect-ratio: auto;
}

.sticker img {
  max-width: 256px;
  max-height: 256px;
}

audio { width: 100%; }

.preview {
  display: flex;
  gap: 10px;
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}
.preview img {
  width: 76px;
  height: 76px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg);
}
.preview .site { font-size: 12px; color: var(--fg-dim); }
.preview .title { font-weight: 600; }
.preview .desc { font-size: 14px; color: var(--fg-dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.poll {
  background: var(--bg-elev-2);
  border-radius: 10px;
  padding: 10px 12px;
}
.poll-q { font-weight: 600; margin-bottom: 4px; }
.poll-type { font-size: 12px; color: var(--fg-dim); margin-bottom: 8px; }
.poll-opt { margin: 6px 0; }
.poll-opt-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 3px; }
.poll-bar { height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; }
.poll-bar span { display: block; height: 100%; background: var(--accent); }

.reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.reaction {
  font-size: 13px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
}

.post-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--fg-dim);
}

#sentinel { height: 1px; }

#status {
  text-align: center;
  padding: 18px;
  color: var(--fg-dim);
  font-size: 14px;
}

.landing {
  max-width: var(--max);
  margin: 40px auto;
  padding: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.landing h1 { margin-top: 0; }
.landing .example { color: var(--fg-dim); }
.landing form { display: flex; gap: 8px; margin-top: 14px; }
.landing input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font-size: 16px;
}
.landing button {
  padding: 10px 16px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
