:root {
  --bg: #f3f3f2;
  --paper: #ffffff;
  --ink: #111111;
  --muted: #70757d;
  --line: rgba(17, 24, 39, 0.12);
  --soft: #f8f8f7;
  --shadow: rgba(15, 23, 42, 0.05);
  --accent: #0a66ff;
  --sans: "Inter", "Segoe UI", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  scrollbar-width: none;
}
html::-webkit-scrollbar { display: none; width: 0; height: 0; }
body {
  margin: 0;
  width: 100%;
  min-height: 100vh;
  padding-top: 72px;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 var(--sans);
}

a { color: var(--ink); text-decoration: none; }
a:hover { opacity: 0.8; }
::selection { background: var(--ink); color: #fff; }

.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 40px;
}

.masthead {
  position: fixed;
  inset: 0 0 auto;
  z-index: 30;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(17,17,17,0.02);
}

.masthead-top {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 72px;
}

.brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 180px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-name {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--ink);
}

.main-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  flex: 1;
}

.main-nav a {
  position: relative;
  color: #2b2f35;
  font-size: 1.08rem;
  font-weight: 500;
  padding: 10px 0;
}

.main-nav a.active {
  color: var(--accent);
  font-weight: 700;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.header-search { position: relative; }

.search-toggle,
.result-nav,
.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper);
  color: #384456;
  cursor: pointer;
}

.search-toggle { position: relative; }
.search-toggle::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
  transform: translate(-2px, -2px);
}
.search-toggle::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 2px;
  top: 24px;
  left: 22px;
  transform: rotate(45deg);
  background: currentColor;
}

.header-search-panel {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px 34px;
  grid-template-rows: auto auto;
  width: min(520px, calc(100vw - 24px));
  min-height: 54px;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 12px 32px rgba(20, 30, 45, 0.16);
}

.header-search-panel[hidden] { display: none; }
.search-clear[hidden] { display: none; }
.header-search-panel input {
  grid-row: 1;
  grid-column: 1 / -1;
  min-width: 80px;
  height: 38px;
  padding: 0 3px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: 500 0.95rem/1.3 var(--sans);
}
.search-count { grid-row: 2; grid-column: 1; min-width: 0; color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.result-nav, .search-clear { width: 34px; height: 34px; font-size: 1.1rem; }
.result-prev { grid-row: 2; grid-column: 2; }
.result-next { grid-row: 2; grid-column: 3; }
.search-clear { grid-row: 2; grid-column: 4; }
.result-nav:disabled { cursor: default; opacity: 0.35; }
.search-clear { border: 0; font-size: 1.35rem; }

.channel-picker { position: relative; min-width: 245px; }
.channel-picker-toggle {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.channel-picker-current { display: flex; min-width: 0; flex: 1; align-items: center; gap: 9px; }
.channel-picker-current .channel-avatar { width: 38px; height: 38px; }
.picker-chevron { color: var(--muted); font-size: 1.1rem; }
.all-channels-avatar {
  display: inline-flex;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #e9eef6;
  color: #315384;
  font-size: 1.4rem;
}
.channel-picker-menu {
  position: absolute;
  z-index: 35;
  top: calc(100% + 7px);
  left: 0;
  width: min(360px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 12px 32px rgba(20, 30, 45, 0.16);
}
.channel-picker-menu[hidden] { display: none; }
.channel-picker-menu > input {
  width: 100%;
  min-height: 40px;
  margin-bottom: 5px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.channel-picker-options { max-height: min(360px, 60vh); overflow-y: auto; }
.channel-option {
  display: flex;
  width: 100%;
  min-height: 62px;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.channel-option:hover,
.channel-option.selected { background: #edf3fc; }
.channel-option[hidden] { display: none; }
.channel-option .channel-avatar { width: 42px; height: 42px; }
.channel-option .channel-post-count { margin-left: auto; }
.channel-option .all-channels-avatar { width: 42px; height: 42px; }

.search-result-current { outline: 2px solid rgba(10, 102, 255, 0.5); outline-offset: 2px; }
}

.login-btn {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 700;
  cursor: pointer;
  margin-left: 10px;
}

.page-header {
  padding-top: 28px;
}

.page-kicker {
  color: #6a707a;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  margin-bottom: 12px;
}

.page-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 18px;
}

h1 {
  margin: 0;
  font-size: clamp(2.6rem, 4vw, 4rem);
  line-height: 1.05;
  letter-spacing: -0.06em;
  font-weight: 800;
}

.count-pill {
  display: inline-flex;
  min-width: 64px;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 1rem;
  padding: 8px 10px;
}

.toolbar {
  display: block;
  margin: 0 0 18px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.toolbar[hidden],
.channels-view[hidden],
.current-channel[hidden] { display: none !important; }

.search { position: relative; }

#q {
  display: block;
  width: 100%;
  padding: 10px 42px 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

#clear {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  cursor: pointer;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.filters input,
.filters button {
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: 500 0.9rem/1.3 var(--sans);
}

.filters input[type="number"] { width: 145px; }
.filters button { cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { padding: 4px 8px; border-radius: 999px; background: #e9eef6; color: #29384f; font-size: 0.82rem; }
.chip b { padding-left: 8px; cursor: pointer; }

.current-channel { margin: 8px 0 12px; }
.current-channel-link { display: inline-flex; align-items: center; gap: 10px; }

.channel-avatar {
  display: inline-flex;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  background: #e8eef7;
  color: #315384;
}

.channel-avatar-fallback { font-weight: 800; text-transform: uppercase; }
.channel-identity { display: flex; min-width: 0; flex-direction: column; line-height: 1.25; }
.channel-identity strong { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.channel-identity small { margin-top: 3px; color: var(--muted); font-size: 0.8rem; }

.channels-view { display: flex; flex-direction: column; }
.channel-row {
  display: flex;
  min-height: 72px;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.channel-row:hover { background: #f8faff; opacity: 1; }
.channel-post-count { margin-left: auto; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }

#feed {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.post {
  min-width: 0;
  max-width: 100%;
  background: rgba(255,255,255,0.5);
  border: 1px solid rgba(17,24,39,0.08);
  border-radius: 18px;
  padding: 22px 18px 18px;
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
}

.post-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.src {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.src .channel-avatar { width: 42px; height: 42px; }
.src .channel-identity strong {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.92rem;
  text-overflow: clip;
  white-space: normal;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.when {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
  text-align: right;
  white-space: nowrap;
}

.when strong { color: #4c5665; font-weight: 600; }
.when small { margin-top: 3px; color: #858c96; font-size: 0.76rem; }

.post-author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.post-author .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d7aff, #0c4dd8);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}

.author-name {
  font-size: 0.98rem;
  font-weight: 700;
}

.post-time {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}

.copy-btn {
  border: 1px solid rgba(17,24,39,0.12);
  background: transparent;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  color: #637081;
}

.body {
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 10px 0 0;
}

.body p {
  margin: 0 0 12px;
}

.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }

.body ul,
.body ol {
  margin: 0 0 10px 1.3rem;
  padding: 0;
}

.body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.body blockquote {
  margin: 10px 0;
  padding-left: 12px;
  border-left: 3px solid #b9c3d0;
}

.body code,
.body pre {
  background: var(--soft);
  border-radius: 4px;
  font-family: ui-monospace, Consolas, monospace;
}

.body code { padding: 1px 4px; }
.body pre { padding: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }

.body tg-spoiler {
  border-radius: 3px;
  background: #d9dde3;
  color: transparent;
  cursor: pointer;
}

.body tg-spoiler.open {
  background: transparent;
  color: inherit;
}

.media {
  margin-top: 14px;
}

.m-single img,
.m-single video {
  display: block;
  width: auto;
  max-width: min(100%, 320px);
  max-height: 360px;
  object-fit: contain;
}

.m-single img,
.m-cell img {
  cursor: zoom-in;
}

.m-grid {
  display: grid;
  width: min(100%, 480px);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.m-grid.many {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.m-grid.n3 .m-cell:first-child {
  grid-column: span 2;
}

.m-cell {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
}

.m-cell img,
.m-cell video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status {
  padding: 20px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.95rem;
}

.post-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.post-foot svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.website-views {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.88rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.post-foot .go {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-left: auto;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
}

.telegram-icon { color: var(--accent); }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.9);
}

.lightbox[hidden] { display: none; }
.lb-body { display: flex; align-items: center; justify-content: center; }
.lb-body img { max-width: 92vw; max-height: 88vh; object-fit: contain; }
.lb-close, .lb-nav {
  position: absolute;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 40px;
  cursor: pointer;
  padding: 12px 18px;
}
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 14px; top: 50%; transform: translateY(-50%); }

@media (max-width: 640px) {
  .masthead-top {
    width: calc(100% - 20px);
    height: 72px;
    gap: 10px;
  }

  .brand-wrap {
    min-width: unset;
    gap: 6px;
  }

  .brand-name { font-size: 1.2rem; }
  .brand-mark { width: 30px; height: 30px; }

  .main-nav {
    width: auto;
    justify-content: center;
    gap: 10px;
  }

  .main-nav a { font-size: 0.82rem; }

  .header-actions { gap: 7px; }
  .login-btn { padding: 8px 10px; margin-left: 0; }
  .search-toggle { width: 36px; height: 36px; }
  .search-toggle::after { top: 22px; left: 20px; }
  .channel-picker { min-width: 0; flex: 1 1 100%; }
  .channel-picker-toggle { min-height: 48px; }
  .filters { display: flex; flex-wrap: wrap; }
  .filters input[type="number"] { width: calc(50% - 4px); flex: 1 1 130px; }
  .filters > button { flex: 1 1 auto; }
  .header-search-panel {
    position: fixed;
    top: 68px;
    right: 12px;
    width: min(520px, calc(100vw - 40px));
    grid-template-columns: minmax(0, 1fr) 30px 30px 30px;
  }
  .search-count { font-size: 0.72rem; }
  .result-nav, .search-clear { width: 30px; height: 30px; }
  .page-shell {
    width: min(1280px, calc(100% - 20px));
  }

  .page-title-row {
    flex-wrap: wrap;
  }

  .post-head { align-items: flex-start; }
  .when { max-width: 42%; white-space: normal; }
  .post-foot .go { margin-left: auto; }

  h1 {
    font-size: clamp(2.1rem, 9vw, 3rem);
  }
}

@media (max-width: 360px) {
  .masthead-top { gap: 6px; }
  .brand-wrap { flex: 0 0 auto; }
  .brand-name { display: none; }
  .main-nav { gap: 7px; }
  .main-nav a { font-size: 0.72rem; }
  .header-actions { gap: 5px; }
  .search-toggle { width: 32px; height: 32px; }
  .search-toggle::after { top: 20px; left: 18px; }
  .login-btn { padding: 6px 8px; font-size: 0.72rem; }
}

@media (max-width: 480px) {
  .telegram-label { display: none; }
  .post-foot .go {
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 50%;
  }
}
