:root {
  --bg: #0d0e11; --panel: #16181d; --panel2: #1e2128; --line: #2a2e37; --text: #e8eaee; --dim: #9aa1ad;
  --accent: #1f6feb; --accent2: #388bfd; --good: #2ea043; --warn: #d29922; --bad: #f85149;
  --plate: #f0b429; --face: #ff7ab6; --person: #58a6ff; --manual: #a371f7;
  --r: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
a { color: var(--accent2); text-decoration: none; }
button, .btn, select, input, textarea { font: inherit; color: inherit; }
button, .btn {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap;
  min-height: 40px; touch-action: manipulation;
}
button:hover, .btn:hover { border-color: #3a404c; }
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.good { background: var(--good); border-color: var(--good); color: #fff; }
button.danger { color: var(--bad); }
button.ghost { background: transparent; }
input[type=password], input[type=text], input[type=datetime-local], textarea, select {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
textarea { resize: vertical; min-height: 110px; }

.top { position: sticky; top: 0; z-index: 20; background: rgba(13,14,17,.92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px 16px; }
.brand { color: var(--text); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand img { width: 26px; height: 26px; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs a { color: var(--dim); padding: 7px 12px; border-radius: 999px; font-weight: 500; }
.tabs a.on { color: var(--text); background: var(--panel2); }
.count:not(:empty) { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; margin-left: 2px; }
@media (max-width: 720px) {
  .top { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); }
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; justify-content: space-around; background: rgba(13,14,17,.96);
    border-top: 1px solid var(--line); padding: 8px 6px calc(8px + env(safe-area-inset-bottom)); z-index: 30; }
  .tabs a { flex: 1; text-align: center; padding: 8px 4px; }
}

main { max-width: 1180px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 15px; margin: 18px 0 8px; color: var(--dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.row > .btn, .row > button { flex: 1 1 auto; }
.row > .seg button, .seg button { flex: 0 0 auto; }
.builder > *, .editor > *, .side, .card { min-width: 0; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; }
.empty { text-align: center; color: var(--dim); padding: 48px 16px; border: 1px dashed var(--line); border-radius: var(--r); }
.banner { border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; font-size: 14px; }
.banner.warn { background: rgba(210,153,34,.12); border: 1px solid rgba(210,153,34,.4); }
.banner.bad { background: rgba(248,81,73,.1); border: 1px solid rgba(248,81,73,.4); }
.banner.good { background: rgba(46,160,67,.12); border: 1px solid rgba(46,160,67,.4); }

.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; min-height: 34px; padding: 6px 12px; border-radius: 8px; color: var(--dim); }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { position: relative; border-radius: var(--r); overflow: hidden; background: var(--panel); border: 2px solid transparent; aspect-ratio: 1; cursor: pointer; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px; font-size: 12px;
  background: linear-gradient(transparent, rgba(0,0,0,.8)); display: flex; gap: 4px; flex-wrap: wrap; }
.chip { background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.15); border-radius: 999px; padding: 1px 7px; font-size: 11.5px; }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.tile.sel { border-color: var(--accent2); }
.tile .check { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff;
  background: rgba(0,0,0,.35); display: grid; place-items: center; font-size: 15px; font-weight: 700; min-height: 0; padding: 0; }
.tile.sel .check { background: var(--accent2); border-color: var(--accent2); }
.drop-hint { outline: 2px dashed var(--accent2); outline-offset: 6px; border-radius: var(--r); }
.sticky-cta { position: sticky; bottom: 84px; display: flex; justify-content: center; margin-top: 14px; pointer-events: none; }
.sticky-cta button { pointer-events: auto; box-shadow: 0 6px 24px rgba(0,0,0,.5); }
@media (min-width: 721px) { .sticky-cta { bottom: 16px; } }

/* ---------- editor */
.editor { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .editor { grid-template-columns: 1fr; } }
.stage-wrap { display: flex; justify-content: center; background: #000; border-radius: var(--r); overflow: hidden; }
.stage { position: relative; display: inline-block; touch-action: none; user-select: none; -webkit-user-select: none; line-height: 0; }
.stage img { max-width: 100%; max-height: 68vh; display: block; -webkit-user-drag: none; pointer-events: none; }
.box { position: absolute; border: 2px solid var(--c, #fff); border-radius: 4px; background: rgba(12,12,14,.82); cursor: pointer; }
.box.off { background: transparent; border-style: dashed; opacity: .75; }
.box.sel { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--c); }
.box .lbl { position: absolute; left: -2px; top: -20px; background: var(--c); color: #000; font: 600 10.5px/1 system-ui; padding: 4px 5px; border-radius: 4px 4px 0 0; white-space: nowrap; pointer-events: none; }
.box .h { position: absolute; right: -9px; bottom: -9px; width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 2px solid var(--c); display: none; }
.box.sel .h { display: block; }
.box.plate { --c: var(--plate); } .box.face { --c: var(--face); } .box.person { --c: var(--person); } .box.manual { --c: var(--manual); }
.box.drawing { --c: var(--manual); background: rgba(163,113,247,.25); }
.stage.preview .box { display: none; }
.side { display: flex; flex-direction: column; gap: 12px; }
.side .card { display: flex; flex-direction: column; gap: 10px; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12.5px; color: var(--dim); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* ---------- post builder */
.builder { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .builder { grid-template-columns: 1fr; } }
.igcard { background: #000; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; position: sticky; top: 70px; }
@media (max-width: 860px) { .igcard { position: static; } }
.ighead { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: conic-gradient(#f9ce34, #ee2a7b, #6228d7, #f9ce34); padding: 2px; }
.avatar > div { width: 100%; height: 100%; border-radius: 50%; background: var(--accent); border: 2px solid #000; display: grid; place-items: center; font-size: 13px; color: #fff; }
.slide { position: relative; width: 100%; overflow: hidden; background: #111; touch-action: none; cursor: grab; }
.slide.fit { cursor: default; }
.slide img { position: absolute; inset: 0; width: 100%; height: 100%; -webkit-user-drag: none; user-select: none; pointer-events: none; }
.slide img.fg { object-fit: cover; }
.slide.fit img.fg { object-fit: contain; }
.slide img.bg { object-fit: cover; filter: blur(18px) brightness(.55); transform: scale(1.15); display: none; }
.slide.fit img.bg { display: block; }
.slide .nav { position: absolute; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; min-height: 0; padding: 0; border-radius: 50%;
  background: rgba(255,255,255,.85); color: #000; border: 0; font-size: 18px; line-height: 1; z-index: 2; }
.slide .nav.prev { left: 8px; } .slide .nav.next { right: 8px; }
.slide .idx { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,.65); color: #fff; font-size: 12px; padding: 3px 9px; border-radius: 999px; z-index: 2; }
.slide .panhint { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); font-size: 12px; padding: 3px 10px; border-radius: 999px; z-index: 2; pointer-events: none; }
.slide .emptyslide { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); }
.igactions { display: flex; gap: 14px; padding: 10px 12px 4px; font-size: 22px; align-items: center; }
.dots { display: flex; gap: 4px; justify-content: center; flex: 1; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #555; }
.dots i.on { background: var(--accent2); }
.igcap { padding: 4px 12px 14px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.igcap b { margin-right: 5px; }
.igcap .tag { color: #e0f1ff; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; }
.thumb { position: relative; flex: 0 0 auto; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 2px solid transparent; cursor: grab; background: var(--panel2); }
.thumb.on { border-color: var(--accent2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb .n { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.7); font-size: 11px; padding: 1px 6px; border-radius: 999px; }
.thumb .x { position: absolute; right: 3px; top: 3px; width: 22px; height: 22px; min-height: 0; padding: 0; border-radius: 50%; background: rgba(0,0,0,.75); border: 0; font-size: 13px; }
.thumb.add { display: grid; place-items: center; font-size: 28px; color: var(--dim); border: 2px dashed var(--line); cursor: pointer; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { transform: scale(1.05); }
.counters { display: flex; gap: 12px; font-size: 12.5px; color: var(--dim); justify-content: flex-end; }
.counters .over { color: var(--bad); font-weight: 600; }

/* ---------- posts list */
.plist { display: flex; flex-direction: column; gap: 10px; }
.pitem { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; color: var(--text); }
.pitem img, .pitem .ph { width: 64px; height: 80px; object-fit: cover; border-radius: 8px; background: var(--panel2); flex: 0 0 auto; }
.pitem .t { flex: 1; min-width: 0; }
.pitem .cap { color: var(--dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); }
.status.published { color: var(--good); border-color: rgba(46,160,67,.5); }
.status.scheduled { color: var(--accent2); border-color: rgba(56,139,253,.5); }
.status.failed { color: var(--bad); border-color: rgba(248,81,73,.5); }
.status.publishing { color: var(--warn); }

/* ---------- modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 0 0; width: 100%; max-width: 760px; max-height: 82vh; overflow: auto; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 721px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
#toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px); background: #fff; color: #000; padding: 10px 16px;
  border-radius: 999px; font-weight: 500; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: calc(100vw - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); color: #fff; }
.login { max-width: 360px; margin: 12vh auto; display: flex; flex-direction: column; gap: 12px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 12px; font-size: 14px; }
.kv > :nth-child(odd) { color: var(--dim); }
code { background: var(--panel2); padding: 2px 6px; border-radius: 6px; font-size: 13px; word-break: break-all; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .7s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
