/* Telegram's channel look: the light theme with its green wallpaper, or Night
   when the system is dark. */

@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Medium.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --text: #000;
  --muted: #8a979e;
  --accent: #3390ec;
  --header: rgba(255, 255, 255, 0.92);
  --bubble: #fff;
  --shadow: 0 1px 2px rgba(16, 35, 47, 0.15);
  --pill: rgba(70, 110, 60, 0.45);
  --tint: rgba(51, 144, 236, 0.08);
  --code: rgba(0, 0, 0, 0.05);
  --highlight: rgba(51, 144, 236, 0.3);
  --wall-a: #dbddbb;
  --wall-b: #6ba587;
  --wall-c: #d5d88d;
  --wall-d: #88b884;
  --dots: rgba(0, 0, 0, 0.05);
  --panel: #fff;
  --menu: rgba(255, 255, 255, 0.96);
  --hover: rgba(0, 0, 0, 0.06);
  --divider: #f1f1f1;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f5f5f5;
    --muted: #6d7f8f;
    --accent: #6ab3f3;
    --header: rgba(23, 33, 43, 0.92);
    --bubble: #182533;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    --pill: rgba(0, 0, 0, 0.35);
    --tint: rgba(106, 179, 243, 0.1);
    --code: rgba(255, 255, 255, 0.06);
    --highlight: rgba(106, 179, 243, 0.25);
    --wall-a: #1c2a38;
    --wall-b: #0e1621;
    --wall-c: #13202d;
    --wall-d: #0f1b26;
    --dots: rgba(255, 255, 255, 0.03);
    --panel: #17212b;
    --menu: rgba(33, 47, 63, 0.96);
    --hover: rgba(255, 255, 255, 0.06);
    --divider: #0e1621;
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  /* app.js keeps the reading position itself when older posts arrive above. */
  overflow-anchor: none;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 15px/1.45 "Vazirmatn", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Fixed layer rather than background-attachment: fixed, which iOS ignores. */
.wallpaper {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(var(--dots) 1px, transparent 1px) 0 0 / 22px 22px,
    radial-gradient(at 0% 0%, var(--wall-a), transparent 60%),
    radial-gradient(at 100% 10%, var(--wall-c), transparent 55%),
    radial-gradient(at 100% 100%, var(--wall-b), transparent 60%),
    radial-gradient(at 0% 100%, var(--wall-d), transparent 60%),
    var(--wall-b);
}

/* Header */

.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: 56px;
  background: var(--header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* The whole bar opens the channel info, as in Telegram. */
.channel {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
  border: 0;
  color: inherit;
  background: none;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

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

.channel-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.channel-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.channel-sub {
  font-size: 13px;
  color: var(--muted);
}

/* Feed */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 68px 12px 20px;
}

#posts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sentinel { height: 1px; }

.day, .pill {
  position: sticky;
  top: 64px;
  z-index: 2;
  display: flex;
  justify-content: center;
  margin: 8px 0 4px;
  pointer-events: none;
}
.day span, .pill {
  padding: 2px 10px;
  border-radius: 14px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  background: var(--pill);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.pill { position: static; width: fit-content; margin: 16px auto; }

/* A post */

.post {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border-radius: 14px;
}
.post.highlight { animation: highlight 2.5s ease-out; }
@keyframes highlight {
  0%, 30% { background: var(--highlight); }
  100% { background: transparent; }
}

.post > .avatar { width: 38px; height: 38px; cursor: pointer; }

/* Round forward button beside the bubble: on hover with a mouse, always on touch. */
.forward {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: var(--pill);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
}
.forward svg { width: 18px; height: 18px; fill: currentColor; }
@media (hover: hover) {
  .forward { opacity: 0; transition: opacity 0.15s; }
  .post:hover .forward, .forward:focus-visible { opacity: 1; }
}
/* A long press opens the message menu, not the system's text selection. */
@media (hover: none) {
  .bubble { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

.bubble {
  position: relative;
  min-width: 0;
  max-width: min(100%, 520px);
  padding: 6px 10px 6px;
  background: var(--bubble);
  border-radius: 12px;
  border-end-start-radius: 0;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.bubble:has(img) { flex: 1 1 520px; }

/* The tail at the bottom corner on the avatar's side, Telegram's own path. */
.bubble::before {
  content: "";
  position: absolute;
  inset-inline-start: -8px;
  bottom: 0;
  width: 9px;
  height: 17px;
  background: var(--bubble);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M3 17h6V0c-.193 2.84-.876 5.767-2.05 8.782-.904 2.325-2.446 4.485-4.625 6.48A1 1 0 0 0 3 17z'/%3E%3C/svg%3E") no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M3 17h6V0c-.193 2.84-.876 5.767-2.05 8.782-.904 2.325-2.446 4.485-4.625 6.48A1 1 0 0 0 3 17z'/%3E%3C/svg%3E") no-repeat;
}

/* Right to left, the tail sits on the right and turns the other way. */
[dir="rtl"] .bubble::before { transform: scaleX(-1); }

.author {
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}

.text > :first-child { margin-top: 0; }
.text > :last-child { margin-bottom: 0; }
.text p { margin: 0 0 0.6em; }
.text a { color: var(--accent); text-decoration: none; }
.text a:hover { text-decoration: underline; }
.text h1, .text h2, .text h3, .text h4 { margin: 0.4em 0; font-size: 1.1em; font-weight: 700; }
.text ul, .text ol { margin: 0.3em 0; padding-inline-start: 1.4em; }
.text blockquote {
  margin: 0.3em 0;
  padding: 2px 10px;
  border-inline-start: 3px solid var(--accent);
  border-radius: 4px;
  background: var(--tint);
}
.text code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--code);
  font: 0.9em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.text pre {
  margin: 0.3em 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--code);
  overflow-x: auto;
  direction: ltr;
}
.text pre code { padding: 0; background: none; }
.text table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.text th, .text td { padding: 4px 8px; border: 1px solid var(--code); }
.text hr { border: 0; border-top: 1px solid var(--code); }
.text img {
  display: block;
  width: calc(100% + 20px);
  max-width: none;
  height: auto;
  margin: 4px -10px;
  cursor: zoom-in;
}

.meta {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  margin: 2px -2px -2px 0;
  color: var(--muted);
  font-size: 12px;
  direction: ltr;
  user-select: none;
}
[dir="rtl"] .meta { justify-content: flex-start; }
.meta a { color: inherit; text-decoration: none; }
.meta a:hover { text-decoration: underline; }
.views { display: inline-flex; align-items: center; gap: 3px; }
.views svg { width: 16px; height: 16px; fill: currentColor; }

/* Chrome */

.down {
  position: fixed;
  inset-inline-end: max(16px, calc(50vw - 344px));
  bottom: 20px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: var(--bubble);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}
.down[hidden] { display: none; }
.down svg { width: 28px; height: 28px; fill: currentColor; }

/* Message menu: right click, or a long press on touch. */
.menu {
  position: fixed;
  z-index: 25;
  min-width: 180px;
  padding: 4px 0;
  border-radius: 12px;
  background: var(--menu);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.menu[hidden] { display: none; }
.menu button {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 8px 16px;
  border: 0;
  color: inherit;
  background: none;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  text-align: start;
  cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu svg { width: 20px; height: 20px; fill: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 30;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 10px;
  color: #fff;
  background: rgba(0, 0, 0, 0.75);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}
.toast[hidden] { display: none; }

/* Channel info: a column beside the feed on a wide screen, over it on a
   narrower one, the whole screen on a phone. */
.info {
  position: fixed;
  top: 0;
  inset-inline-end: 0;
  bottom: 0;
  z-index: 15;
  width: min(360px, 100%);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  box-shadow: -1px 0 3px rgba(0, 0, 0, 0.12);
}
[dir="rtl"] .info { box-shadow: 1px 0 3px rgba(0, 0, 0, 0.12); }
.info[hidden] { display: none; }
.info-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
  padding: 0 8px;
  background: var(--panel);
  font-size: 18px;
  font-weight: 500;
}
.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: none;
  cursor: pointer;
}
.icon-button:hover { background: var(--hover); }
.icon-button svg { width: 24px; height: 24px; fill: currentColor; }
#info-close .back { display: none; }
[dir="rtl"] #info-close .back { transform: scaleX(-1); }
.info-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 16px 16px;
  text-align: center;
  border-bottom: 8px solid var(--divider);
}
.info-photo {
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: zoom-in;
}
.info-head .avatar { display: block; width: 120px; height: 120px; }
.info-head h1 { margin: 12px 0 2px; font-size: 20px; font-weight: 700; }
.info-head p { margin: 0; color: var(--muted); font-size: 14px; }
.info-share {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 8px 20px;
  border: 0;
  border-radius: 20px;
  color: var(--accent);
  background: var(--tint);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.info-share svg { width: 20px; height: 20px; fill: currentColor; }
.info-rows { padding: 8px; }
.info-row {
  display: flex;
  align-items: center;
  gap: 24px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  color: inherit;
  background: none;
  font: inherit;
  text-align: start;
}
button.info-row { cursor: pointer; }
button.info-row:hover { background: var(--hover); }
.info-row svg { flex: none; width: 24px; height: 24px; fill: var(--muted); }
.info-row div { min-width: 0; }
.info-row p { margin: 0; white-space: pre-line; overflow-wrap: anywhere; }
.info-row span { color: var(--muted); font-size: 13px; }

@media (min-width: 1000px) {
  .info-open { padding-inline-end: 360px; }
  .info-open .top { inset-inline-end: 360px; }
  .info-open .down { inset-inline-end: calc(360px + max(16px, 50vw - 524px)); }
  .info, [dir="rtl"] .info { box-shadow: none; border-inline-start: 1px solid var(--divider); }
}

/* The channel photo, full screen, as Telegram opens a profile picture. */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.9);
}
.viewer[hidden] { display: none; }
.viewer-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding-inline: 16px 8px;
  color: #fff;
}
.viewer-bar .avatar { width: 40px; height: 40px; }
.viewer-bar span { flex: 1; font-size: 16px; font-weight: 500; }
.viewer-bar .icon-button { color: rgba(255, 255, 255, 0.75); }
.viewer-bar .icon-button:hover { background: rgba(255, 255, 255, 0.1); }
.viewer-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 16px;
}
.viewer-stage img { max-width: 100%; max-height: 100%; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.9);
  cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

@media (max-width: 480px) {
  main { padding-left: 8px; padding-right: 8px; }
  .post > .avatar { display: none; }
  .bubble { margin-inline-start: 8px; }
  .info, [dir="rtl"] .info { width: 100%; box-shadow: none; }
  #info-close .x { display: none; }
  #info-close .back { display: block; }
}
