/* ============================================================
   piratchain.com — единый файл стилей
   CSS Custom Properties, Nesting, Container Queries, :has(),
   Scroll-driven Animations, View Transitions, backdrop-filter
   ============================================================ */

/* ── Custom Properties (темы) ──────────────────────────────── */
:root {
  --bg-primary:      #0d1117;
  --bg-secondary:    #161b22;
  --bg-card:         #1c2333;
  --bg-card-hover:   #242d3d;
  --text-primary:    #e6edf3;
  --text-secondary:  #8b949e;
  --accent:          #e94560;
  --accent-hover:    #ff6b81;
  --accent-soft:     rgba(233, 69, 96, 0.15);
  --link:            #53d8fb;
  --border:          #30363d;
  --shadow:          0 8px 32px rgba(0,0,0,0.3);
  --shadow-sm:       0 2px 8px rgba(0,0,0,0.2);
  --radius:          12px;
  --radius-sm:       8px;
  --radius-xs:       4px;
  --transition:      0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --header-height:   60px;
  --container-max:   1400px;
  color-scheme: dark light;
}

[data-theme="light"] {
  --bg-primary:      #f6f8fa;
  --bg-secondary:    #ffffff;
  --bg-card:         #ffffff;
  --bg-card-hover:   #f0f4f8;
  --text-primary:    #1f2328;
  --text-secondary:  #656d76;
  --border:          #d1d9e0;
  --shadow:          0 4px 16px rgba(0,0,0,0.08);
  --shadow-sm:       0 2px 6px rgba(0,0,0,0.06);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

img { max-width: 100%; height: auto; display: block; }

button { cursor: pointer; font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

/* ── Утилиты ───────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-height);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  background: rgba(13, 17, 23, 0.82);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  transition: background var(--transition);

  [data-theme="light"] & {
    background: rgba(255, 255, 255, 0.88);
    border-bottom-color: var(--border);
  }
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 100%;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex-shrink: 0;

  & .logo-img { width: 32px; height: 32px; }
  & .logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
  }
  & .logo-dot { color: var(--accent); }
}

.header-search {
  flex: 1;
  max-width: 400px;

  & .search-wrap {
    position: relative;
    display: flex;
    align-items: center;
  }

  & .search-icon {
    position: absolute; left: 10px;
    color: var(--text-secondary);
    pointer-events: none;
  }

  & .search-input {
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 7px 36px 7px 34px;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color var(--transition), box-shadow var(--transition);

    &::placeholder { color: var(--text-secondary); }
    &:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
    &::-webkit-search-cancel-button { display: none; }
  }

  & .search-clear {
    position: absolute; right: 10px;
    background: none; border: none;
    color: var(--text-secondary);
    font-size: 0.75rem; padding: 2px;
    &:hover { color: var(--text-primary); }
  }
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;

  @media (max-width: 900px) { display: none; }
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color var(--transition), background var(--transition);

  &:hover {
    color: var(--text-primary);
    background: var(--bg-card);
    text-decoration: none;
  }

  &.nav-link--active {
    color: var(--text-primary);
    background: var(--bg-card);
  }

  & .nav-icon { font-size: 1rem; }
}

.nav-upload {
  margin-left: 4px;
  color: #fff !important;
  background: var(--accent) !important;

  &:hover { background: var(--accent-hover) !important; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.1rem;
  transition: color var(--transition), border-color var(--transition), background var(--transition);

  &:hover {
    color: var(--text-primary);
    background: var(--bg-card);
    border-color: var(--border);
  }
}

.theme-icon--light { display: none; }
[data-theme="light"] {
  & .theme-icon--dark  { display: none; }
  & .theme-icon--light { display: block; }
}

.burger-btn { @media (min-width: 901px) { display: none; } }

/* ── Mobile menu ───────────────────────────────────────────── */
.mobile-menu {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 8px 0;

  &:not([hidden]) { display: block; }
}

.mobile-nav {
  display: flex;
  flex-direction: column;
}

.mobile-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  transition: color var(--transition), background var(--transition);

  &:hover { color: var(--text-primary); background: var(--bg-card); text-decoration: none; }
  &.mobile-nav-link--accent { color: var(--accent); }
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  transition: background var(--transition), color var(--transition),
              transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  cursor: pointer;
  line-height: 1.4;

  &:active { transform: scale(0.97); }
}

.btn-accent {
  background: var(--accent);
  color: #fff;
  &:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  &:hover { background: var(--bg-card); border-color: var(--text-secondary); text-decoration: none; }
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  &:hover { background: #e74c3c; text-decoration: none; color: #fff; }
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  &:hover { color: var(--text-primary); background: var(--bg-card); text-decoration: none; }
}

.btn-sm  { padding: 5px 12px; font-size: 0.8rem; }
.btn-lg  { padding: 12px 24px; font-size: 1rem; }

/* ── Main ──────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px 0 60px;
}

/* ── Feed / masonry ────────────────────────────────────────── */
.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.feed-header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.feed-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.feed-count {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.feed-upload-btn {
  flex-shrink: 0;
}

.feed {
  columns: 4 260px;
  column-gap: 12px;
}

@supports (grid-template-rows: masonry) {
  .feed {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    grid-template-rows: masonry;
    gap: 12px;
    columns: initial;
    column-gap: initial;
  }
}

/* ── Карточка ──────────────────────────────────────────────── */
.card-wrapper {
  container-type: inline-size;
  break-inside: avoid;
  margin-bottom: 12px;

  @supports (grid-template-rows: masonry) { margin-bottom: 0; }
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: fadeSlideUp linear both;
  animation-timeline: view();
  animation-range: entry 0% entry 100%;
  position: relative;

  &:hover {
    transform: translateY(-6px) scale(1.01);
    box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 0 0 1px var(--accent);
    border-color: var(--accent);
    z-index: 2;
  }

  & .card-link { display: block; text-decoration: none; }

  & .card-img-wrap { position: relative; overflow: hidden; }

  & .card-img {
    width: 100%;
    display: block;
    aspect-ratio: auto;
    max-height: 560px;
    min-height: 120px;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-secondary);
  }

  &:hover .card-img { transform: scale(1.04); }

  & .card-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(
      to top,
      rgba(0,0,0,0.85) 0%,
      rgba(0,0,0,0.3) 40%,
      transparent 70%
    );
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 14px;
    opacity: 0;
    transition: opacity var(--transition);
  }

  &:hover .card-overlay { opacity: 1; }

  & .card-title {
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    text-shadow: 0 1px 6px rgba(0,0,0,0.9);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 5px;
  }

  & .card-stats {
    display: flex;
    gap: 10px;
  }

  & .card-stat {
    color: rgba(255,255,255,0.92);
    font-size: 0.75rem;
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0,0,0,0.9);
    background: rgba(0,0,0,0.35);
    padding: 2px 8px;
    border-radius: 10px;
    backdrop-filter: blur(4px);
  }

  /* Горячий бейдж для популярных постов */
  &.card--hot::after {
    content: '🔥';
    position: absolute;
    top: 8px; right: 8px;
    font-size: 1.1rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
  }

  @container (max-width: 200px) {
    & .card-title { font-size: 11px; }
    & .card-stats { display: none; }
  }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(40px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Skeleton ──────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card) 25%,
    var(--bg-card-hover) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

.skeleton-card {
  height: 240px;
  margin-bottom: 12px;
}

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

/* ── Feed end / sentinel ───────────────────────────────────── */
#feed-sentinel { height: 40px; }

.feed-end {
  text-align: center;
  padding: 40px 0;
  color: var(--text-secondary);

  & p { margin-bottom: 16px; }
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 20px;

  & .empty-icon { font-size: 4rem; margin-bottom: 16px; }
  & h2 { font-size: 1.5rem; margin-bottom: 8px; }
  & p  { color: var(--text-secondary); margin-bottom: 24px; }
}

/* ── Post page ─────────────────────────────────────────────── */
.post-container {
  max-width: 960px;
  margin: 0 auto;
}

.post-image-wrap {
  position: relative;
  margin-bottom: 20px;
  text-align: center;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.post-image {
  max-width: 100%;
  max-height: 80vh;
  margin: 0 auto;
  display: block;
}

.post-image--expired {
  opacity: 0.6;
  filter: grayscale(0.4);
}

.expired-badge, .expire-badge {
  position: absolute;
  bottom: 12px; right: 12px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.post-meta { padding: 8px 0; }

.post-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.post-description {
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.7;
}

.post-stats-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

/* ── Лайк ──────────────────────────────────────────────────── */
.like-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: color var(--transition), border-color var(--transition), background var(--transition);

  &:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  &.liked {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
    animation: heartPulse 0.4s ease-out;
  }

  & .like-icon { font-size: 1rem; }
}

@keyframes heartPulse {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.3); }
  50%  { transform: scale(0.95); }
  100% { transform: scale(1); }
}

.view-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.post-date {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ── Share bar ─────────────────────────────────────────────── */
.share-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 32px;

  & .share-label { color: var(--text-secondary); font-size: 0.875rem; }
}

.share-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);

  &:hover { opacity: 0.85; transform: translateY(-1px); }
  &:active { transform: scale(0.97); }
}

.share-btn--vk   { background: #4a76a8; color: #fff; }
.share-btn--tg   { background: #0088cc; color: #fff; }
.share-btn--copy { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-primary); }
.share-btn--embed { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary); }

/* ── Comments ──────────────────────────────────────────────── */
.post-comments {
  border-top: 1px solid var(--border);
  padding-top: 24px;
  margin-top: 24px;

  & .comments-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 16px; }
  & .comments-placeholder { color: var(--text-secondary); font-style: italic; }
}

/* ── Upload page ───────────────────────────────────────────── */
.upload-container {
  max-width: 700px;
  margin: 0 auto;
}

.page-header {
  text-align: center;
  margin-bottom: 32px;

  & .page-title { font-size: 2rem; font-weight: 700; margin-bottom: 8px; }
  & .page-subtitle { color: var(--text-secondary); }
}

.upload-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
}

.upload-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.upload-tab {
  flex: 1;
  padding: 14px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition), background var(--transition), box-shadow var(--transition);
  border-bottom: 2px solid transparent;

  &.upload-tab--active {
    color: var(--text-primary);
    border-bottom-color: var(--accent);
    background: var(--bg-card);
  }

  &:hover:not(.upload-tab--active) { color: var(--text-primary); background: var(--bg-card); }
}

.upload-panel { padding: 24px; }
.upload-panel[hidden] { display: none; }

/* ── Dropzone ──────────────────────────────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  cursor: pointer;
  position: relative;  /* важно для позиционирования input */

  &.dropzone--active {
    border-color: var(--accent);
    background: var(--accent-soft);
    box-shadow: 0 0 0 4px var(--accent-soft);
  }

  &:hover {
    border-color: var(--text-secondary);
    background: rgba(255,255,255,0.02);
  }

  & .dropzone-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
    display: block;
    filter: drop-shadow(0 4px 12px rgba(233,69,96,0.3));
  }
  & .dropzone-text  { font-size: 1.1rem; font-weight: 600; margin-bottom: 4px; }
  & .dropzone-hint  { color: var(--text-secondary); font-size: 0.8rem; margin-bottom: 16px; }
  & .dropzone-btn   { pointer-events: auto; }
  & .dropzone-formats { color: var(--text-secondary); font-size: 0.75rem; margin-top: 12px; }
}

.dropzone-input {
  display: none;
}

.dropzone--gallery {
  margin-bottom: 24px;
  padding: 24px;
}

/* ── Preview ───────────────────────────────────────────────── */
.preview-section {
  padding: 16px 24px 0;

  &[hidden] { display: none; }
}

.preview-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.preview-img {
  max-width: 100%;
  max-height: 400px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.preview-remove {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px;
  background: rgba(0,0,0,0.7);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 0.875rem;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);

  &:hover { background: var(--accent); }
}

/* ── Progress bar ──────────────────────────────────────────── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;

  &[hidden] { display: none; }
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* ── Forms ─────────────────────────────────────────────────── */
.publish-form { padding: 20px 24px 24px; }

.form-group {
  margin-bottom: 16px;

  &.form-group--sm { margin-bottom: 10px; }
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 6px;

  &.form-label--sm { font-size: 0.8rem; margin-bottom: 4px; }

  & .form-optional { color: var(--text-secondary); font-weight: 400; }
}

.form-input {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);

  &::placeholder { color: var(--text-secondary); }
  &:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }

  &.form-input--sm { padding: 6px 10px; font-size: 0.8rem; }
}

.form-textarea {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--transition), box-shadow var(--transition);

  &::placeholder { color: var(--text-secondary); }
  &:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }

  &.form-textarea--sm { padding: 6px 10px; font-size: 0.8rem; }
}

.form-select {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;

  &.form-select--sm { padding: 5px 8px; font-size: 0.8rem; }
  &:focus { border-color: var(--accent); outline: none; }
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* Publish form smart disable :has() */
.publish-form:has(input:not(:placeholder-shown)) .btn-accent,
.publish-form:has(textarea:not(:placeholder-shown)) .btn-accent {
  opacity: 1;
}

/* ── Publish result ────────────────────────────────────────── */
.publish-result {
  padding: 24px;
  text-align: center;

  &[hidden] { display: none; }

  & .result-icon { font-size: 3rem; margin-bottom: 12px; }
  & h3 { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; }
  & p  { color: var(--text-secondary); margin-bottom: 12px; }
}

.result-link {
  display: block;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 20px;
  word-break: break-all;
}

.result-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── Tips ──────────────────────────────────────────────────── */
.upload-tips {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;

  & .tips-title { font-size: 1rem; font-weight: 600; margin-bottom: 12px; }
  & .tips-list { padding-left: 20px; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.9; }
}

/* ── Gallery grid ──────────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.gallery-item {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  aspect-ratio: 1;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);

  &:hover {
    transform: scale(1.03);
    box-shadow: var(--shadow);
    border-color: var(--accent);
  }

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

  & .gallery-item-overlay {
    position: absolute; inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 60%);
    opacity: 0;
    transition: opacity var(--transition);
    display: flex;
    align-items: flex-end;
    padding: 8px;
  }

  &:hover .gallery-item-overlay { opacity: 1; }

  & .gallery-item-name {
    color: #fff;
    font-size: 0.75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* ── Modal ─────────────────────────────────────────────────── */
dialog.modal {
  background: none;
  border: none;
  padding: 0;
  max-width: 100vw;
  max-height: 100vh;
  /* Центрирование нативного <dialog> */
  margin: auto;
  position: fixed;
  inset: 0;

  &::backdrop {
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
  }
}

dialog.modal[open] {
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  width: 90vw;
  position: relative;
  box-shadow: var(--shadow);
  color: var(--text-primary);

  & h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 16px; color: var(--text-primary); }
  & p  { color: var(--text-secondary); margin-bottom: 16px; line-height: 1.6; }
}

.modal-box--image {
  display: flex;
  max-width: min(95vw, 1100px);
  width: 95vw;
  padding: 0;
  overflow: hidden;
  gap: 0;

  & .modal-image-wrap {
    flex: 1;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    overflow: hidden;
  }

  & .modal-full-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
  }

  & .modal-sidebar {
    width: 280px;
    flex-shrink: 0;
    padding: 20px;
    overflow-y: auto;
    border-left: 1px solid var(--border);
  }

  @media (max-width: 700px) {
    flex-direction: column;
    & .modal-sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  }
}

.modal-close {
  position: absolute; top: 12px; right: 12px;
  background: none; border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: color var(--transition), background var(--transition);

  &:hover { color: var(--text-primary); background: var(--bg-card); }
}

.modal-meta {
  margin-bottom: 16px;

  & .modal-size, & .modal-date { color: var(--text-secondary); font-size: 0.75rem; margin-top: 4px; }
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-name-input {
  width: 100%;
  margin-bottom: 8px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ── Meme generator ────────────────────────────────────────── */
.meme-main { padding: 0; }

.meme-workspace {
  display: flex;
  height: calc(100dvh - var(--header-height));
  overflow: hidden;

  @media (max-width: 900px) {
    flex-direction: column;
    height: auto;
    overflow: visible;
  }
}

.meme-canvas-area {
  flex: 1;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  position: relative;
}

.canvas-wrap {
  position: relative;
  max-width: 100%;
  max-height: 100%;

  & canvas {
    max-width: 100%;
    max-height: calc(100dvh - var(--header-height) - 32px);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    display: block;
  }
}

.canvas-empty-state {
  position: absolute; inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 2px dashed var(--border);

  & .canvas-empty-icon { font-size: 3rem; }
  & p { color: var(--text-secondary); }
}

.meme-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 0;

  @media (max-width: 900px) {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 60vh;
  }
}

.meme-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--bg-secondary);
  z-index: 1;

  & h2 { font-size: 1rem; font-weight: 700; }
}

.meme-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);

  & .meme-section-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
    margin-bottom: 10px;
  }
}

.meme-load-btns { display: flex; gap: 8px; margin-bottom: 8px; }

.meme-dropzone {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
  transition: border-color var(--transition), background var(--transition);

  &.drag-over {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
}

.meme-classic-text { margin-bottom: 10px; }

.meme-add-text-btn { margin-bottom: 10px; width: 100%; }

.text-layers-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }

.text-layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 0.75rem;

  &.active { border-color: var(--accent); }

  & .layer-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
  }

  & .layer-del {
    background: none; border: none;
    color: var(--text-secondary); font-size: 0.8rem;
    &:hover { color: var(--accent); }
  }
}

.text-style-panel { padding-top: 8px; }

.style-row, .filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.range-input {
  flex: 1;
  accent-color: var(--accent);
  height: 4px;
  min-width: 80px;
}

.color-input {
  width: 32px; height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 2px;
  background: none;
  cursor: pointer;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 36px; height: 20px;
  flex-shrink: 0;

  & input { opacity: 0; width: 0; height: 0; }

  & .toggle-slider {
    position: absolute; inset: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: background var(--transition);

    &::before {
      content: '';
      position: absolute;
      width: 14px; height: 14px;
      left: 2px; top: 2px;
      background: var(--text-secondary);
      border-radius: 50%;
      transition: transform var(--transition), background var(--transition);
    }
  }

  & input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);

    &::before { transform: translateX(16px); background: #fff; }
  }
}

.align-btns {
  display: flex;
  gap: 3px;

  & .align-btn {
    width: 28px; height: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 0.8rem;
    display: flex; align-items: center; justify-content: center;
    transition: color var(--transition), border-color var(--transition), background var(--transition);

    &.align-btn--active, &:hover {
      color: var(--text-primary);
      border-color: var(--accent);
      background: var(--accent-soft);
    }
  }
}

.edit-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

.filters-panel { margin-top: 8px; }
.filters-title { font-size: 0.8rem; font-weight: 600; margin-bottom: 8px; }

.filter-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 8px;

  & .filter-preset-btn {
    padding: 4px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: color var(--transition), border-color var(--transition), background var(--transition);

    &:hover, &.active {
      color: var(--text-primary);
      border-color: var(--accent);
      background: var(--accent-soft);
    }
  }
}

.meme-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;

  & .btn { justify-content: flex-start; }
}

.meme-actions-section { padding-bottom: 40px; }

.meme-pub-btns { display: flex; gap: 8px; margin-top: 8px; }

.meme-result-embed { margin-top: 10px; }

/* ── Gallery picker ────────────────────────────────────────── */
.gallery-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 12px;
  max-height: 60vh;
  overflow-y: auto;

  & .picker-empty { grid-column: 1/-1; color: var(--text-secondary); text-align: center; padding: 20px; }
}

.gallery-picker-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color var(--transition), transform var(--transition);

  &:hover {
    border-color: var(--accent);
    transform: scale(1.05);
  }

  & img { width: 100%; height: 100%; object-fit: cover; }
}

/* ── Publish mini-form ─────────────────────────────────────── */
.publish-mini-form {
  display: flex;
  flex-direction: column;
  gap: 8px;

  &[hidden] { display: none; }

  & h4 { font-size: 0.875rem; font-weight: 600; }
}

/* ── Litterbox result ──────────────────────────────────────── */
.litterbox-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8rem;

  &[hidden] { display: none; }
  & p { color: var(--text-secondary); }
}

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-width: 340px;
  pointer-events: auto;
  animation: slideInRight 0.3s ease-out, fadeOut 0.3s ease-in 2.7s forwards;
  font-size: 0.875rem;

  &.toast--error   { border-left-color: #c0392b; }
  &.toast--success { border-left-color: #27ae60; }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(100%); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; pointer-events: none; }
}

/* ── Help button ───────────────────────────────────────────── */
.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition), border-color var(--transition);

  &:hover { color: var(--text-primary); border-color: var(--accent); }
}

.help-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;

  & li { font-size: 0.875rem; line-height: 1.6; }
}

/* ── Onboarding ────────────────────────────────────────────── */
.onboarding {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;

  &[hidden] { display: none; }
}

.onboarding-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: modalIn 0.3s ease-out;

  & h2 { font-size: 1.4rem; margin: 16px 0 8px; }
  & p  { color: var(--text-secondary); margin-bottom: 20px; }
}

.onboarding-logo { margin-bottom: 4px; & img { margin: 0 auto; } }

.onboarding-list {
  list-style: none;
  text-align: left;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;

  & li { font-size: 0.875rem; }
}

/* ── Footer ────────────────────────────────────────────────── */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  margin-top: auto;
}

.footer-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.footer-brand {
  flex: 1;
  min-width: 160px;

  & .footer-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 700;
    margin-bottom: 4px;
  }

  & .footer-tagline { color: var(--text-secondary); font-size: 0.8rem; }
}

.footer-nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;

  & a {
    color: var(--text-secondary);
    font-size: 0.875rem;
    &:hover { color: var(--text-primary); }
  }
}

.footer-info {
  display: flex;
  align-items: center;
  gap: 10px;
  & .footer-copy { color: var(--text-secondary); font-size: 0.8rem; }
}

/* ── URL panel ─────────────────────────────────────────────── */
.url-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Search section ────────────────────────────────────────── */
.search-section {
  &[hidden] { display: none; }
  & .section-title { font-size: 1.2rem; margin-bottom: 16px; }
}

/* ── Page header (gallery, etc) ────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;

  &.page-header { text-align: left; }
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── Embed code ────────────────────────────────────────────── */
.embed-code {
  width: 100%;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  color: var(--text-secondary);
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  resize: none;
  margin-bottom: 12px;
}

/* ── Expire countdown ──────────────────────────────────────── */
#expire-countdown {
  font-size: 0.75rem;
}

/* ── View transitions ──────────────────────────────────────── */
@keyframes fade-and-scale-out {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.97); }
}

@keyframes fade-and-scale-in {
  from { opacity: 0; transform: scale(1.03); }
  to   { opacity: 1; transform: scale(1); }
}

::view-transition-old(root) { animation: 0.25s ease-out both fade-and-scale-out; }
::view-transition-new(root) { animation: 0.25s ease-in  both fade-and-scale-in; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --container-max: 100%; }
  .header-search { max-width: 200px; }

  .feed { columns: 2 180px; }
}

@media (max-width: 600px) {
  .header-search { display: none; }
  .feed { columns: 2 140px; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .post-title { font-size: 1.3rem; }
  .upload-tips { display: none; }
}

@media (max-width: 400px) {
  .feed { columns: 1; }
}
