:root {
  --bg: #0f1115;
  --bg2: #161922;
  --bg3: #1e2230;
  --line: #2a2f3f;
  --text: #e6e8ee;
  --muted: #8b92a6;
  --accent: #7c6cff;
  --accent2: #9d90ff;
  --danger: #e5484d;
  --nsfw: #e5484d;
  --ok: #3dd68c;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .4em; }
h3 { margin: .2em 0 .6em; }
small, .small { font-size: .82em; }
.muted { color: var(--muted); }
code, .mono, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
label { display: block; margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
label > input, label > select, label > textarea, label > .tagbox { margin-top: 4px; color: var(--text); font-size: .95rem; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
label.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 0 0 14px; }
legend { color: var(--muted); padding: 0 6px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg3); color: var(--text); cursor: pointer; text-decoration: none !important; white-space: nowrap; font-size: .92rem; }
.btn:hover { border-color: var(--accent); }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent2); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn.disabled { opacity: .6; cursor: default; }
.danger { color: var(--danger); }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(15,17,21,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1600px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.logo { font-weight: 700; font-size: 1.2rem; color: var(--text); white-space: nowrap; }
.logo-mark { color: var(--accent); }
.search { flex: 1; max-width: 560px; }
.nav { display: flex; gap: 10px; align-items: center; margin-left: auto; }
.nav > a:not(.btn) { color: var(--text); }
.usermenu, .dl-more { position: relative; }
.usermenu summary, .dl-more summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker, .dl-more summary::-webkit-details-marker { display: none; }
.usermenu summary { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg3); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px;
  min-width: 190px; padding: 6px; display: flex; flex-direction: column; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.5); }
.menu a { padding: 7px 10px; border-radius: 6px; color: var(--text); }
.menu a:hover { background: var(--bg3); text-decoration: none; }

.container { max-width: 1600px; margin: 0 auto; padding: 18px 16px 60px; }
.narrow { max-width: 760px; margin: 0 auto; }

/* browse */
.browse { display: grid; grid-template-columns: 230px 1fr; gap: 22px; }
.sidebar { position: sticky; top: 70px; align-self: start; max-height: calc(100vh - 90px); overflow: auto; }
.sidebar h3 { font-size: 1rem; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tags-col { margin-bottom: 10px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--bg3); border: 1px solid var(--line);
  color: var(--text); font-size: .78rem; text-decoration: none !important; }
.tag:hover { border-color: var(--accent); }
.tag small { color: var(--muted); }
.tag-on { background: var(--accent); border-color: var(--accent); }
.tag-nsfw { border-color: rgba(229,72,77,.6); color: #ff9ea1; }
.tag-more { color: var(--muted); }
.tagpick { display: inline-flex; }
.tagpick .tag { border-radius: 999px 0 0 999px; }
.tag-x { padding: 2px 6px; border: 1px solid var(--line); border-left: 0; border-radius: 0 999px 999px 0; background: var(--bg3); color: var(--muted); font-size: .78rem; }
.tag-x:hover { color: var(--danger); text-decoration: none; }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; background: var(--bg2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; }
.filters label { margin: 0; min-width: 140px; }
.filters label.grow { flex: 1; min-width: 180px; }
.resultbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 14px; color: var(--muted); }
.chip { padding: 2px 10px; border-radius: 999px; background: var(--accent); color: #fff; font-size: .8rem; }
.chip-ex { background: var(--danger); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.tile { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column;
  transition: transform .15s, border-color .15s; }
.tile:hover { transform: translateY(-2px); border-color: #3b4260; }
.tile-img { position: relative; display: block; aspect-ratio: 3 / 4; overflow: hidden; background: var(--bg3); }
.tile-img img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; transition: filter .2s; }
.badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: .72rem; font-weight: 600; }
.badge-nsfw { background: var(--nsfw); }
.tile-stats { position: absolute; bottom: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: 18px 10px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.85)); font-size: .78rem; color: #ddd; }
.tile-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.tile-name { font-weight: 650; color: var(--text); font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-by { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-tagline { margin: 0; font-size: .85rem; color: #c3c7d4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* NSFW blur */
.nsfw-blur .is-nsfw .tile-img img, .nsfw-blur .cardpage.is-nsfw .cp-img img { filter: blur(22px) brightness(.8); }
.nsfw-blur .is-nsfw .tile-img:hover img { filter: blur(10px) brightness(.9); }
.nsfw-blur .is-nsfw.revealed .tile-img img, .nsfw-blur .cardpage.is-nsfw.revealed .cp-img img { filter: none; }

.pager { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 26px 0; }
.pager a, .pager span { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); }
.pager .cur { background: var(--accent); border-color: var(--accent); }
.pager .gap { border: 0; background: none; }
.empty { padding: 60px; text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

/* card page */
.cardpage { display: grid; grid-template-columns: 360px 1fr; gap: 28px; }
.cp-left { position: sticky; top: 70px; align-self: start; }
.cp-img { display: block; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); position: relative; background: var(--bg3); }
.cp-img img { width: 100%; display: block; }
.cp-badge { position: absolute; top: 10px; left: 10px; }
.cp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.dl { display: flex; gap: 6px; }
.fav.on { color: #ffd166; border-color: #ffd166; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 10px 0; font-size: .9rem; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }
.cp-owner { display: flex; gap: 8px; margin-top: 10px; }
.cp-main h1 { font-size: 2rem; margin-top: 0; }
.tagline { font-size: 1.05rem; color: #c3c7d4; margin: 0 0 6px; }
.by { color: var(--muted); margin: 0 0 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin: 18px 0 14px; }
.tabs button, .tabs-links a { background: none; border: 0; border-bottom: 2px solid transparent; padding: 9px 14px; cursor: pointer; color: var(--muted); }
.tabs button.on, .tabs-links a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs-links a:hover { text-decoration: none; color: var(--text); }
.tabs small { color: var(--muted); }
.tabpane { display: none; }
.tabpane.on { display: block; }
.field { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.field summary { padding: 10px 14px; cursor: pointer; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.pre { white-space: pre-wrap; word-break: break-word; margin: 0; padding: 4px 14px 14px; font-size: .88rem; line-height: 1.55; color: #d6d9e2; }
.greet { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px; }
.greet h4 { margin: 0 0 8px; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.md { overflow-wrap: anywhere; }
.md img { max-width: 100%; height: auto; border-radius: 6px; }
.md p:first-child { margin-top: 0; }
.md blockquote { border-left: 3px solid var(--line); margin: 0; padding-left: 12px; color: var(--muted); }
.md pre { background: var(--bg); padding: 10px; border-radius: 6px; overflow: auto; }
.rp em { color: #b9b3ff; }
.macro { color: #ffd166; font-family: ui-monospace, monospace; font-size: .9em; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 8px; }
.table th, .table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; }
.table .actions a { margin-right: 10px; }
tr.banned td { opacity: .55; }
.comment { border-bottom: 1px solid var(--line); padding: 10px 0; }
.comment-head { display: flex; gap: 10px; align-items: baseline; margin-bottom: 4px; }
.comment-form { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

/* editor */
.ed-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; position: sticky; top: 57px;
  background: var(--bg); z-index: 20; padding: 8px 0; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.ed-head h1 { margin: 0; }
.ed-head-actions { display: flex; gap: 8px; }
.ed-grid { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.ed-side { position: sticky; top: 130px; align-self: start; }
.avatar-drop { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px; text-align: center; margin-bottom: 14px; }
.avatar-drop.drag { border-color: var(--accent); }
.avatar-drop img { width: 100%; border-radius: 8px; display: block; margin-bottom: 8px; max-height: 420px; object-fit: contain; background: var(--bg3); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tagbox { display: flex; flex-wrap: wrap; gap: 5px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); position: relative; }
.tagbox input { flex: 1; min-width: 140px; border: 0 !important; padding: 3px; background: none; margin: 0 !important; }
.tagbox .tag { cursor: pointer; }
.tagbox .tag::after { content: " ✕"; color: var(--muted); }
.suggest { position: absolute; top: 100%; left: 0; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; z-index: 30; min-width: 220px; }
.suggest div { padding: 6px 10px; cursor: pointer; color: var(--text); }
.suggest div:hover, .suggest div.on { background: var(--bg3); }
.listitem { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; background: var(--bg2); }
.listitem-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; gap: 10px; }
.listitem-head .checks { display: flex; gap: 14px; }
.listitem-head label { margin: 0; }

/* import */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 180px; border: 2px dashed var(--line);
  border-radius: var(--radius); cursor: pointer; padding: 20px; margin-bottom: 16px; text-align: center; }
.dropzone.drag, .dropzone:hover { border-color: var(--accent); }
.dz-big { font-size: 1.2rem; color: var(--text); }
#import-results { margin-top: 18px; }
.res { padding: 8px 12px; border-radius: 8px; margin-bottom: 6px; background: var(--bg2); border-left: 3px solid var(--ok); }
.res.err { border-left-color: var(--danger); }

/* auth & misc */
.authbox { max-width: 400px; margin: 50px auto; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.notice { background: rgba(124,108,255,.12); border: 1px solid rgba(124,108,255,.4); padding: 10px 12px; border-radius: 8px; }
.error { color: var(--danger); min-height: 1.2em; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.statrow { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; }
.stat b { font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.profile-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.profile-ava { width: 72px; height: 72px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 2rem; font-weight: 700; }
.profile-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.tagcloud { gap: 8px; margin-top: 14px; }
.tag-filter { max-width: 360px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--line); padding: 10px 16px;
  border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; }
#toast.err { border-color: var(--danger); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); display: grid; place-items: center; z-index: 200; cursor: pointer; }
.lightbox img { max-width: 95vw; max-height: 95vh; }

@media (max-width: 900px) {
  .browse, .cardpage, .ed-grid { grid-template-columns: 1fr; }
  .sidebar, .cp-left, .ed-side { position: static; max-height: none; }
  .sidebar { order: 2; }
  .cp-left { max-width: 420px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .topbar-inner { flex-wrap: wrap; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .row2 { grid-template-columns: 1fr; }
  .ed-head { top: 0; position: static; }
}
.ed-head-actions label.btn { margin: 0; color: var(--text); font-size: .92rem; }
.tagpick { max-width: 100%; }
.tagpick .tag { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.tile .tag { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---- v2 */
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form input, .inline-form select { width: auto; margin: 0; min-width: 160px; }
.bulkbar { position: sticky; top: 56px; z-index: 20; }
.progress { height: 12px; background: var(--bg3); border-radius: 6px; overflow: hidden; margin: 16px 0 8px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.res.skip { border-left-color: var(--muted); }
fieldset.panel { margin: 0 0 16px; }
fieldset.panel legend { padding: 0 6px; color: var(--muted); }
.mailgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 14px; align-items: end; }
.mailgrid .inline-form { grid-column: 1 / -1; margin-top: 8px; }

/* v9: панель фильтров — всё в один ряд, элементы выровнены по низу */
.filters [hidden] { display: none !important; }
.filters label { min-width: 130px; }
.filters label.per { min-width: 120px; flex: 0 0 auto; }
.filters input.per-n { width: 90px; flex: 0 0 auto; margin: 0; }
.filters .btn { align-self: end; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }

/* v10: в полноэкранном просмотре курсор всегда виден (системный «zoom-out» чёрный и терялся на тёмном фоне) */
.lightbox, .lightbox img { cursor: pointer; }
.lightbox-close { position: fixed; top: 14px; right: 18px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.5);
  background: rgba(30,30,36,.85); color: #fff; font-size: 1.2rem; line-height: 1; cursor: pointer; }
.lightbox-close:hover { background: var(--accent); }
