:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2330;
  --text: #e8edf3;
  --muted: #8b95a5;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --radius: 14px;
}

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

body {
  background: radial-gradient(1200px 600px at 50% -10%, #1b2440 0%, var(--bg) 55%);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}

.header {
  border-bottom: 1px solid #ffffff12;
  background: rgba(14, 17, 22, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand { display: flex; align-items: center; gap: 14px; }

.brand-logo {
  font-size: 42px;
  line-height: 1;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand h1 { font-size: 22px; letter-spacing: 0.2px; }
.brand p { color: var(--muted); font-size: 13.5px; margin-top: 2px; }

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.2s ease;
  color: var(--text);
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0d12;
}

.btn.ghost { background: var(--panel); border: 1px solid #ffffff1a; color: var(--text); }

.admin-toggle { position: relative; }

.admin-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 400px;
  max-width: 92vw;
  background: var(--panel-2);
  border: 1px solid #ffffff1a;
  border-radius: var(--radius);
  padding: 16px;
  z-index: 30;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.admin-panel h3 {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-block { margin-bottom: 18px; }
.admin-block:last-child { margin-bottom: 0; }

.row { display: flex; gap: 8px; align-items: center; }

.row input[type="url"], .row select {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid #ffffff1a;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

.row input[type="text"], .row input[type="password"] {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid #ffffff1a;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

.row input[type="file"] {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.sub-status {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  min-height: 16px;
  word-break: break-word;
}

.bg-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
  max-height: 220px;
  overflow-y: auto;
}

.bg-item {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid #ffffff14;
}

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

.bg-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 11px;
  cursor: pointer;
  line-height: 1;
  display: grid;
  place-items: center;
}

.bg-empty { font-size: 12.5px; color: var(--muted); padding: 8px 0; }

.vk-img-count {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 10.5px;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
}

.font-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  max-height: 160px;
  overflow-y: auto;
}

.font-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel);
  border: 1px solid #ffffff14;
  border-radius: 8px;
  padding: 8px 10px;
  position: relative;
}

.font-name {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.admin-panel label.row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.admin-panel input[type="text"],
.admin-panel input[type="password"],
.admin-panel textarea,
.panel-card input[type="text"],
.panel-card input[type="password"],
.panel-card textarea {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--panel);
  border: 1px solid #ffffff1a;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
}

.admin-panel textarea, .panel-card textarea { resize: vertical; margin-top: 8px; }

.header-link { text-decoration: none; display: inline-block; }

.page-wrap {
  max-width: 760px;
  margin: 26px auto 30px;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-card {
  background: var(--panel-2);
  border: 1px solid #ffffff14;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.panel-card h2 {
  font-size: 17px;
  margin-bottom: 12px;
}

.panel-card h2 .muted {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.inner-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 16px;
}

.field-label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 10px 0 6px;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.45;
}

.enable-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin-top: 14px;
  font-size: 14px;
}

.enable-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.bg-list-wide { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); max-height: 420px; }

.vk-time-row .bg-del-static {
  position: static;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.vk-time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.vk-time-row .vk-time-label {
  font-size: 12.5px;
  color: var(--muted);
  flex: 0 0 auto;
  width: 52px;
}

.vk-time-row input[type="time"] {
  background: var(--panel);
  border: 1px solid #ffffff1a;
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 13.5px;
  color-scheme: dark;
}

.vk-add-time { margin-top: 10px; padding: 7px 14px; font-size: 13px; }

.fc-col { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }

.hint.steps { margin: 6px 0 2px; padding-left: 20px; display: grid; gap: 4px; }
.vk-login-btn { margin-top: 10px; width: 100%; }
.manual-oauth { margin-top: 14px; font-size: 13px; color: var(--muted); }
.manual-oauth summary { cursor: pointer; user-select: none; }
.manual-oauth .row { margin-top: 8px; }
.fc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid #ffffff1a;
  border-radius: 10px;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.fc-item:hover { border-color: #ffffff40; }
.fc-item.picked { border-color: var(--accent); }
.fc-item .fc-id { opacity: 0.6; font-size: 12px; white-space: nowrap; }

.vk-history {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  max-height: 180px;
  overflow-y: auto;
}

.vk-history-item {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid #ffffff12;
  border-radius: 8px;
  padding: 6px 9px;
  word-break: break-word;
}

.vk-history-item.ok { border-color: rgba(34, 211, 238, 0.35); }
.vk-history-item.fail { border-color: rgba(255, 99, 99, 0.45); }

.themes {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 20px 6px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-chip {
  border: 1px solid #ffffff14;
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.theme-chip:hover { border-color: #ffffff33; }
.theme-chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0a0d12;
  border-color: transparent;
  font-weight: 700;
}

.gallery {
  max-width: 1200px;
  margin: 22px auto 10px;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  aspect-ratio: 3 / 4;
  animation: fadeUp 0.4s ease both;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.card .tag {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  backdrop-filter: blur(4px);
}

.card .download {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: #111;
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  text-decoration: none;
}

.card:hover .download { opacity: 1; transform: translateY(0); }

.card .to-base {
  position: absolute;
  left: 10px;
  bottom: 10px;
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  border: none;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
}
.card:hover .to-base { opacity: 1; transform: translateY(0); }
.card .to-base:disabled { cursor: default; opacity: 0.9; }

.card.downloaded::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  border-radius: var(--radius);
  pointer-events: none;
}

.card.downloaded img { filter: brightness(0.5); }

.card.downloaded .download { opacity: 1; transform: translateY(0); background: rgba(255,255,255,0.5); }

.status {
  max-width: 1200px;
  margin: 14px auto 0;
  padding: 0 20px;
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
}

.load-wrap {
  display: flex;
  justify-content: center;
  padding: 26px 0 40px;
}

.footer {
  border-top: 1px solid #ffffff0f;
  padding: 22px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 640px) {
  .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .brand h1 { font-size: 18px; }
  .header-inner { padding: 12px 16px; }
  .gallery-box { width: 98vw; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 5px; }
  .gallery-prev, .gallery-next { width: 36px; height: 36px; font-size: 22px; }
}

.gallery-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
}
.gallery-box {
  position: relative;
  width: 92vw;
  max-width: 960px;
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.gallery-close {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 3;
  border: none;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 20px;
  color: #fff;
  background: rgba(255,255,255,0.12);
  transition: background 0.15s;
}
.gallery-close:hover { background: rgba(255,255,255,0.28); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  padding: 10px 0;
}
.gallery-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}
.gallery-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.04);
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-carousel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 0 16px;
  min-height: 70vh;
  justify-content: center;
}
.gallery-carousel .gallery-back {
  position: fixed;
  top: 12px;
  left: 14px;
  z-index: 3;
  border: none;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 10px;
  font-size: 13px;
  color: #fff;
  background: rgba(255,255,255,0.12);
  transition: background 0.15s;
}
.gallery-carousel .gallery-back:hover { background: rgba(255,255,255,0.28); }
.gallery-img {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 10px;
  object-fit: contain;
  user-select: none;
}
.gallery-counter {
  color: #aaa;
  font-size: 13px;
}
.gallery-prev,
.gallery-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  cursor: pointer;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 28px;
  color: #fff;
  background: rgba(255,255,255,0.12);
  transition: background 0.15s;
}
.gallery-prev:hover,
.gallery-next:hover { background: rgba(255,255,255,0.28); }
.gallery-prev { left: 14px; }
.gallery-next { right: 14px; }
.gallery-del {
  border: none;
  cursor: pointer;
  padding: 7px 16px;
  border-radius: 10px;
  font-size: 13px;
  color: #fff;
  background: rgba(220,50,50,0.55);
  transition: background 0.15s;
}
.gallery-del:hover { background: rgba(220,50,50,0.85); }

/* ---------- shared navigation ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid #ffffff10;
  flex-wrap: wrap;
}
.site-nav .nav-link {
  text-decoration: none;
  color: var(--muted);
  font-size: 13.5px;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.site-nav .nav-link:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.site-nav .nav-link.active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.site-nav .nav-link.logout { color: #ff6b6b; border-color: #ff6b6b44; }
.site-nav .nav-link.logout:hover { background: rgba(220,50,50,0.15); }

.footer { margin-top: auto; }

/* ---------- rich text editor (MAX) ---------- */
.rich-editor {
  margin-top: 8px;
  border: 1px solid #ffffff1a;
  border-radius: 10px;
  background: var(--panel);
  overflow: hidden;
}
.rich-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid #ffffff14;
  background: rgba(255,255,255,0.03);
}
.rt-btn {
  min-width: 32px;
  height: 30px;
  border: 1px solid #ffffff1a;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}
.rt-btn:hover { background: rgba(255,255,255,0.08); border-color: #ffffff33; }
.rt-btn:active { background: rgba(255,255,255,0.14); }
.rich-content {
  min-height: 72px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--text);
  outline: none;
  line-height: 1.5;
  word-break: break-word;
}
.rich-content:empty::before {
  content: attr(data-placeholder);
  color: rgba(255,255,255,0.35);
  pointer-events: none;
}
.rich-content[contenteditable="false"] { background: rgba(255,255,255,0.03); }
.rich-counter {
  padding: 4px 12px;
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  border-top: 1px solid #ffffff0d;
  text-align: right;
}

/* ---------- MAX multi-channel ---------- */
.max-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}
.max-tab {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid #ffffff1a;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.max-tab:hover { background: rgba(255,255,255,0.09); }
.max-tab.active {
  background: var(--accent, #4f8cff);
  border-color: transparent;
  color: #fff;
}
.max-tab.add {
  font-weight: 700;
  background: transparent;
  border-style: dashed;
}
.ch-panel { margin-top: 14px; }
.ch-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.ch-head .ch-name {
  flex: 1;
  max-width: 420px;
  font-size: 15px;
  font-weight: 700;
}
