:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-header: rgba(15, 23, 42, 0.88);
  --border: rgba(148, 163, 184, 0.16);
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.15);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  line-height: 1.55;
}

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

.hidden {
  display: none !important;
}

/* Шапка и панель навигации */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-header);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-area {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-area h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.controls-area {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Переключатель режима отображения */
.segmented-control {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}

.seg-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 5px 12px;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--accent);
  color: #0f172a;
}

.icon-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn.active-filter {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.icon-btn.active-editor {
  border-color: #facc15;
  color: #facc15;
  background: rgba(250, 204, 21, 0.14);
}

.readme-edit-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

/* Шкала возраста (Таймлайн) */
.timeline-bar {
  max-width: 1180px;
  margin: 0 auto;
  padding: 6px 16px 10px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}

.stage-pill:hover,
.stage-pill.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.stage-pill.timeless-pill {
  background: rgba(250, 204, 21, 0.12);
  color: #fde047;
  border-color: rgba(250, 204, 21, 0.32);
}

.stage-pill.timeless-pill:hover {
  background: rgba(250, 204, 21, 0.22);
  border-color: #facc15;
}

.pill-count {
  font-size: 0.68rem;
  opacity: 0.72;
  background: rgba(15, 23, 42, 0.55);
  padding: 1px 5px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.timeline-sep {
  width: 1px;
  align-self: stretch;
  margin: 2px 4px;
  background: var(--border);
  flex-shrink: 0;
}

/* Основной контейнер */
.main-container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

.root-readme {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
}

/* Режим 1: ЛЕНТА */
.feed-list {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.feed-post {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  scroll-margin-top: 110px;
}

.post-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.post-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.post-date {
  font-weight: 700;
  font-size: 1.05rem;
}

.age-badge {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.topic-badge {
  color: #e2e8f0;
  font-weight: 500;
  font-size: 0.95rem;
}

.post-meta-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.edit-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 6px;
  background: rgba(250, 204, 21, 0.15);
  color: #facc15;
  border: 1px solid rgba(250, 204, 21, 0.3);
  font-size: 0.8rem;
  cursor: pointer;
}

.edit-link:hover {
  background: rgba(250, 204, 21, 0.25);
}

.post-readme {
  padding: 14px 18px;
  font-size: 0.96rem;
  border-bottom: 1px solid var(--border);
}

.post-readme p:first-child {
  margin-top: 0;
}

.post-readme p:last-child {
  margin-bottom: 0;
}

/* Сетка медиа внутри поста */
.post-media-grid {
  display: grid;
  gap: 4px;
  background: #090d16;
}

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

.post-media-grid.count-2 {
  grid-template-columns: repeat(2, 1fr);
}

.post-media-grid.count-3,
.post-media-grid.count-many {
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.media-tile {
  position: relative;
  overflow: hidden;
  background: #0f172a;
  cursor: pointer;
  aspect-ratio: 4 / 3;
}

.post-media-grid.count-1 .media-tile {
  aspect-ratio: auto;
  max-height: 680px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.media-tile img,
.media-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.25s ease;
}

.post-media-grid.count-1 .media-tile img,
.post-media-grid.count-1 .media-tile video {
  object-fit: contain;
  max-height: 680px;
}

.media-tile:hover img {
  transform: scale(1.02);
}

.sprite-layer {
  position: absolute;
  inset: 0;
  background-size: 400% 100%;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 2;
}

.scrub-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding: 0 6px 4px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  z-index: 3;
}

.media-tile:hover .scrub-bar {
  opacity: 1;
}

.scrub-bar span {
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.35);
}

.scrub-bar span.active {
  background: var(--accent);
}

.video-badge {
  position: absolute;
  bottom: 9px;
  right: 8px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  z-index: 4;
}

.tier-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(250, 204, 21, 0.85);
  color: #0f172a;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 0.72rem;
  z-index: 4;
  pointer-events: none;
}

.tile-edit-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 5;
}

.media-tile:hover .tile-edit-actions {
  opacity: 1;
}

.tile-act-btn {
  background: rgba(15, 23, 42, 0.86);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
}

.tile-act-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tile-act-danger:hover {
  border-color: #f87171;
  color: #f87171;
}

.post-footer-actions {
  display: flex;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
}

.expand-more-btn {
  flex: 1;
  min-width: 240px;
  padding: 11px;
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent);
  border: none;
  font-weight: 600;
  cursor: pointer;
}

.expand-tier-btn {
  background: rgba(250, 204, 21, 0.08);
  color: #facc15;
  border-left: 1px solid var(--border);
}

.expand-more-btn:hover {
  background: rgba(56, 189, 248, 0.16);
}

.expand-tier-btn:hover {
  background: rgba(250, 204, 21, 0.16);
}

/* Режим 2: СЕТКА АЛЬБОМОВ */
.albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 20px;
}

.album-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
  scroll-margin-top: 110px;
}

.album-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}

.card-cover {
  aspect-ratio: 16 / 10;
  background: #090d16;
  overflow: hidden;
  position: relative;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-counts {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(15, 23, 42, 0.82);
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 0.78rem;
  color: #e2e8f0;
}

.card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-readme {
  font-size: 0.88rem;
  color: #cbd5e1;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Полноэкранный сквозной просмотрщик (Edge-to-Edge Lightbox) */
.lightbox {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100dvh;
  z-index: 100;
  background: #000;
  overflow: hidden;
}

.lb-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 6px 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.68) 0%, rgba(0, 0, 0, 0.28) 65%, transparent 100%);
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.lb-title-wrap,
.lb-actions {
  pointer-events: auto;
}

.lightbox.hud-hidden .lb-topbar,
.lightbox.hud-hidden .lb-nav {
  opacity: 0;
  pointer-events: none;
}

.lb-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  line-height: 1.2;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.95), 0 2px 8px rgba(0, 0, 0, 0.85);
}

.lb-album-title {
  font-weight: 700;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.lb-counter {
  font-size: 0.76rem;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.lb-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

.lb-editor-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
  padding-right: 5px;
  border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.lb-btn {
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(4px);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 4px 8px;
  min-width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 0.88rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.lb-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.lb-edit-btn {
  border-color: rgba(250, 204, 21, 0.45);
}

.lb-danger-btn {
  border-color: rgba(248, 113, 113, 0.45);
  color: #fca5a5;
}

.lb-close-btn {
  font-size: 1rem;
  font-weight: 700;
}

.lb-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.lb-media-holder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.lb-media-holder img,
.lb-media-holder video {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 0;
  user-select: none;
}

.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 60px;
  background: rgba(15, 23, 42, 0.38);
  backdrop-filter: blur(3px);
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  font-size: 1.9rem;
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.25s ease, background 0.15s ease;
}

.lb-nav:hover {
  background: rgba(15, 23, 42, 0.72);
}

.lb-prev {
  left: 14px;
}

.lb-next {
  right: 14px;
}

.lb-readme-toast {
  position: absolute;
  bottom: 3px;
  right: 4px;
  left: auto;
  transform: none;
  max-width: min(420px, calc(100vw - 8px));
  max-height: 26vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.38) 0%, rgba(15, 23, 42, 0.65) 100%);
  backdrop-filter: blur(3px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 0.84rem;
  line-height: 1.32;
  color: #f8fafc;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 2px 6px rgba(0, 0, 0, 0.85);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 15;
}

.lb-readme-toast p,
.lb-readme-toast ul,
.lb-readme-toast ol,
.lb-readme-toast h1,
.lb-readme-toast h2,
.lb-readme-toast h3 {
  margin: 0 0 4px 0;
}

.lb-readme-toast *:last-child {
  margin-bottom: 0;
}

.lb-status-pill {
  position: absolute;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--accent);
  color: #f8fafc;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 25;
  pointer-events: none;
}

/* Модальное окно Markdown-редактора и входа */
.md-modal {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(5, 8, 15, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.md-dialog {
  width: 100%;
  max-width: 720px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.login-dialog {
  max-width: 400px;
}

.md-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.md-textarea {
  width: 100%;
  min-height: 240px;
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
}

.md-textarea:focus,
.md-input:focus {
  outline: none;
  border-color: var(--accent);
}

.md-input {
  width: 100%;
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 0.96rem;
}

.login-error {
  color: #f87171;
  font-size: 0.85rem;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.3);
  padding: 8px 12px;
  border-radius: 8px;
}

.md-dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.md-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.md-dialog-actions {
  display: flex;
  gap: 8px;
}

.md-save-btn {
  background: var(--accent);
  color: #0f172a;
  font-weight: 700;
  border-color: var(--accent);
}

@media (max-width: 640px) {
  .lb-topbar {
    padding: 4px 8px;
    gap: 6px;
  }

  .lb-album-title {
    font-size: 0.82rem;
  }

  .lb-counter {
    font-size: 0.72rem;
  }

  .lb-btn {
    min-width: 30px;
    height: 30px;
    padding: 3px 6px;
    font-size: 0.84rem;
  }

  .lb-media-holder {
    padding: 0;
  }

  .lb-media-holder img,
  .lb-media-holder video {
    border-radius: 0;
  }

  .lb-nav {
    width: 30px;
    height: 44px;
    font-size: 1.3rem;
  }

  .lb-prev {
    left: 4px;
  }

  .lb-next {
    right: 4px;
  }

  .lb-readme-toast {
    bottom: 2px;
    right: 2px;
    max-width: calc(100vw - 4px);
    max-height: 20vh;
    padding: 4px 7px;
    font-size: 0.78rem;
    line-height: 1.26;
    border-radius: 6px;
  }
}
