:root {
  --bg: #eef3ee;
  --bg-2: #e3ebe4;
  --ink: #14241c;
  --ink-soft: #3d5347;
  --muted: #6b7f72;
  --line: rgba(20, 36, 28, 0.12);
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #f7faf7;
  --accent: #1f6b4a;
  --accent-2: #c6e27a;
  --danger: #a33b2d;
  --shadow: 0 18px 50px rgba(20, 36, 28, 0.08);
  --radius: 18px;
  --font: "Sora", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(198, 226, 122, 0.35), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(31, 107, 74, 0.12), transparent 55%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: rgba(247, 250, 247, 0.78);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  z-index: 40;
}

.brand {
  display: block;
  margin-bottom: 16px;
  line-height: 0;
}
.brand:hover { opacity: 0.92; }
.brand-logo {
  display: block;
  width: 100%;
  max-width: 228px;
  height: auto;
  border-radius: 16px;
  box-shadow: 0 10px 28px rgba(120, 70, 10, 0.18);
}
/* legacy text brand fallback */
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--accent-2);
  font-family: var(--display);
  font-weight: 700;
}
.brand-text {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.rail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.rail-stats div {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.rail-stats strong { font-size: 18px; }
.rail-stats span { color: var(--muted); font-size: 11px; }

.rail-section {
  margin-top: 12px;
  margin-bottom: 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.rail-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 12px;
  color: var(--ink-soft);
  transition: background .15s, color .15s;
}
.rail-link:hover { background: rgba(31, 107, 74, 0.08); color: var(--ink); }
.rail-link.active {
  background: var(--ink);
  color: #f4f8f2;
}
.rail-link em {
  font-style: normal;
  font-size: 11px;
  opacity: 0.7;
}
.rail-cats { display: flex; flex-direction: column; gap: 2px; }
.rail-empty { color: var(--muted); font-size: 12px; padding: 8px; line-height: 1.4; }
.rail-hint {
  font-weight: 400;
  font-size: 10px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  opacity: 0.85;
  margin-left: 4px;
}
.rail-link.drop-cat.drag-over {
  background: rgba(31, 107, 74, 0.16);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.rail-link.drop-cat.drop-busy {
  opacity: 0.55;
  pointer-events: none;
}
body.is-dragging-idea .drop-cat {
  box-shadow: inset 0 0 0 1px rgba(31, 107, 74, 0.25);
}
body.is-dragging-idea .rail {
  z-index: 5;
}

.rail-newcat {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}
.rail-newcat input {
  flex: 1;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 9px 10px;
  outline: none;
}
.rail-newcat button {
  width: 40px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
}

.rail-foot {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}
.rail-foot a { color: var(--accent); }

.main { min-width: 0; padding: 18px 22px 40px; }
.post-main { max-width: 920px; margin: 0 auto; width: 100%; }

.post-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.9fr);
  gap: 16px;
  align-items: start;
}
.post-actions {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.menu-btn {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  cursor: pointer;
}
.search { flex: 1; }
.search input, .add-form input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.8);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
}
.search input:focus, .add-form input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 107, 74, 0.12);
}
.add-form {
  display: flex;
  gap: 8px;
  flex: 1.1;
}
.add-form button, .btn {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary, .add-form button {
  background: var(--ink);
  color: var(--accent-2);
}
.btn-primary:hover, .add-form button:hover { filter: brightness(1.08); }
.btn-ghost {
  width: 100%;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 500;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(163, 59, 45, 0.35);
}
.btn-block { width: 100%; }
.back, .text-link { color: var(--accent); font-weight: 500; }
.user-pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  font-size: 12px;
}
.topbar-spacer { flex: 1; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar-title {
  font-family: var(--display);
  font-size: 28px;
  letter-spacing: -0.03em;
}
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  font-size: 12px;
  margin-right: 6px;
}
.chip-link { color: var(--accent); }
.sort { display: flex; gap: 8px; flex-wrap: wrap; }
.sort a {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
}
.sort a.on {
  background: var(--ink);
  color: #fff;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.idea {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease, opacity .2s ease;
  cursor: grab;
  color: inherit;
  text-decoration: none;
}
.idea:hover {
  transform: translateY(-3px);
  border-color: rgba(31, 107, 74, 0.35);
}
.idea:active { cursor: grabbing; }
.idea.dragging {
  opacity: 0.45;
  transform: scale(0.98);
  border-color: var(--accent);
}
.idea.idea-leaving {
  opacity: 0;
  transform: scale(0.92);
  pointer-events: none;
}
.idea-cat:empty { display: none; }
.idea-media {
  position: relative;
  aspect-ratio: 16/10;
  background: #0f1a14;
}
.idea-media img, .idea-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0f1a14;
}
.idea-media img {
  content-visibility: auto;
}
.play {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent-2);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
}
.idea-body { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.idea-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}
.idea-meta time { margin-left: auto; }
.idea h2, .post-head h1 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  font-size: 18px;
}
.post-head h1 { font-size: 32px; margin: 10px 0 8px; }
.idea-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.idea-tags span {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(31, 107, 74, 0.08);
  color: var(--ink-soft);
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}
.empty-state h2 {
  font-family: var(--display);
  color: var(--ink);
  margin-bottom: 8px;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 28px;
  color: var(--muted);
}
.pager a {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.post {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.post-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}
.post-author { color: var(--ink-soft); margin-bottom: 8px; }
.post-media, .post-gallery a {
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0f1a14;
}
.post-media-stack {
  display: flex;
  flex-direction: row;
  gap: 12px;
  margin-bottom: 14px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: 4px 2px 12px;
  scrollbar-width: thin;
}
.post-media-stack::-webkit-scrollbar {
  height: 6px;
}
.post-media-stack::-webkit-scrollbar-thumb {
  background: rgba(20, 36, 28, 0.25);
  border-radius: 999px;
}
.post-media {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  flex: 0 0 auto;
  scroll-snap-align: start;
  width: min(320px, 78vw);
}
.post-media .media-label {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 12px 0;
  width: 100%;
  box-sizing: border-box;
}
.post-media video {
  width: 100%;
  max-height: min(70vh, 560px);
  height: auto;
  display: block;
  background: #000;
  object-fit: contain;
}
/* Вертикальные ролики (Instagram / Reels) */
.post-media.is-vertical,
.post-media.is-ig {
  width: min(300px, 72vw);
  max-width: min(300px, 72vw);
  margin-inline: 0;
}
.post-media.is-vertical video,
.post-media.is-ig video {
  width: 100%;
  height: auto;
  max-height: min(68vh, 580px);
  aspect-ratio: 9 / 16;
  object-fit: contain;
}
.post-media-hint {
  font-size: 12px;
  color: var(--muted);
  margin: -6px 0 12px;
}
.post-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}
.post-gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.gallery-thumb {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  padding: 0;
  background: #0f1a14;
  cursor: zoom-in;
  transition: transform .15s ease, border-color .15s;
}
.gallery-thumb:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.link-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.link-list a {
  color: var(--accent);
  word-break: break-all;
  font-size: 13px;
}
.links-block {
  border-color: rgba(31, 107, 74, 0.28);
  background: rgba(198, 226, 122, 0.18);
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(8, 14, 11, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 64px;
}
.lightbox[hidden] { display: none !important; }
.lightbox img {
  max-width: min(1100px, 92vw);
  max-height: 86vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
}
.lb-close, .lb-nav {
  position: absolute;
  border: none;
  background: rgba(255,255,255,0.12);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 22px;
  backdrop-filter: blur(6px);
}
.lb-close { top: 18px; right: 18px; }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }
.lb-counter {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  background: rgba(0,0,0,0.35);
  padding: 6px 12px;
  border-radius: 999px;
}

.block, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}
.block h3, .panel h3 {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.pre { white-space: pre-wrap; line-height: 1.6; color: var(--ink-soft); }
.edit-form, .comment-form, .cat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.cat-form { flex-direction: row; flex-wrap: wrap; }
.cat-form select, .cat-form input { flex: 1; min-width: 180px; }
label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--ink-soft);
}
textarea, select, .edit-form input, .cat-form input, .cat-form select {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  resize: vertical;
}
.comments { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.comment {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,0.65);
  border: 1px solid var(--line);
}
.comment time { font-size: 11px; color: var(--muted); }
.comment p { margin-top: 4px; line-height: 1.5; }
.muted { color: var(--muted); font-size: 13px; }
.danger-zone { padding-top: 8px; }
.toast {
  background: var(--ink);
  color: var(--accent-2);
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}

/* Auth */
.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(420px, 100%);
  background: rgba(247, 250, 247, 0.88);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}
.auth-brand {
  font-family: var(--display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.auth-brand-link {
  display: block;
  line-height: 0;
  margin-bottom: 10px;
}
.auth-brand-link:hover { opacity: 0.92; }
.auth-logo {
  display: block;
  width: min(280px, 70vw);
  height: auto;
  margin: 0 auto;
  border-radius: 18px;
  box-shadow: 0 14px 36px rgba(120, 70, 10, 0.2);
}
.auth-title {
  font-family: var(--display);
  font-size: 28px;
  margin-top: 8px;
}
.auth-sub { color: var(--muted); margin: 8px 0 18px; line-height: 1.5; }
.auth-error {
  background: rgba(163, 59, 45, 0.1);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.auth-form .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.auth-form input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #fff;
  outline: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  background: var(--ink);
  color: #f4f8f2;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  max-width: min(90vw, 360px);
  text-align: center;
}
.toast.err { background: #8b2e2e; }

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 14, 0.35);
  z-index: 30;
}
.scrim.open { display: block; }

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    transform: translateX(-105%);
    transition: transform .2s ease;
    width: min(300px, 86vw);
  }
  .rail.open { transform: translateX(0); }
  .menu-btn { display: inline-grid; place-items: center; }
  .add-form { display: none; }
  .topbar { position: sticky; top: 0; z-index: 20; padding: 8px 0; backdrop-filter: blur(10px); }
  .post-head h1 { font-size: 24px; }
  .post-layout { grid-template-columns: 1fr; }
  .post-actions { position: static; max-height: none; }
}
