:root {
  --bg: #120e0b;
  --panel: #1a1511;
  --panel-2: #221b16;
  --line: #33291f;
  --line-2: #45382b;
  --text: #ece3d8;
  --muted: #9c8d7c;
  --accent: #c8894e;
  --accent-2: #e0a86e;
  --danger: #d66a5a;
  --ok: #8fb57a;
  --radius: 8px;
  --font: "Inter Tight", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a120b; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn.small { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: var(--radius);
  background: transparent; border: 1px solid transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--panel-2); border-color: var(--line-2); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.on { color: var(--accent); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-group.right { margin-left: auto; }
.draft-name {
  width: 220px; height: 30px; padding: 0 8px;
  background: transparent; border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 600; font-size: 14px;
}
.draft-name:hover, .draft-name:focus { border-color: var(--line-2); background: var(--panel-2); outline: none; }
.save-status { color: var(--muted); font-size: 12px; min-width: 70px; }
.save-status.err { color: var(--danger); }

.seg { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 2px; gap: 2px; }
.seg button { height: 24px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--line-2); color: var(--text); }

.lock-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.lock-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.lock-track { width: 38px; height: 22px; border-radius: 11px; background: var(--line-2); position: relative; transition: background .15s; }
.lock-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.lock-toggle input:checked + .lock-track { background: var(--accent); }
.lock-toggle input:checked + .lock-track .lock-thumb { transform: translateX(16px); background: #1a120b; }
.lock-toggle input:focus-visible + .lock-track { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.lock-label { font-weight: 600; min-width: 92px; }

/* ---------- workspace ---------- */
.workspace { flex: 1; display: flex; min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; }
.code-pane { width: 40%; min-width: 180px; background: var(--panel); }
.workspace.code-hidden .code-pane, .workspace.code-hidden .divider { display: none; }
.pane-head {
  display: flex; justify-content: space-between; align-items: center;
  height: 32px; padding: 0 12px; border-bottom: 1px solid var(--line);
  color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
}
.pane-hint { text-transform: none; letter-spacing: 0; }
.pane-hint.live { color: var(--accent); }
.code-host { flex: 1; min-height: 0; overflow: hidden; }
.code-host .cm-editor { height: 100%; }

.divider { width: 6px; cursor: col-resize; background: var(--line); flex: none; }
.divider:hover, .divider.dragging { background: var(--accent); }

.preview-pane { flex: 1; background: #0d0a08; }
.stage { flex: 1; min-height: 0; display: flex; justify-content: center; padding: 16px; overflow: hidden; }
.frame-wrap { position: relative; height: 100%; width: 100%; overflow: hidden; background: #fff; border-radius: 4px; box-shadow: 0 0 0 1px var(--line), 0 10px 40px rgba(0,0,0,.5); transition: width .2s; }
.frame-wrap iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
body.dragging iframe { pointer-events: none; }

.ov { position: absolute; pointer-events: none; display: none; border-radius: 2px; }
.ov-hover { outline: 1px dashed rgba(200,137,78,.8); }
.ov-select { outline: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(0,0,0,0); }
.ov-select.editing { outline-color: #5aa0e0; }
.ov-tag {
  position: absolute; top: -20px; left: -2px; padding: 1px 6px; border-radius: 3px 3px 3px 0;
  background: var(--accent); color: #1a120b; font: 600 10px/16px var(--mono); white-space: nowrap;
}
.ov-select.editing .ov-tag { background: #5aa0e0; }
.ov-tag.below { top: auto; bottom: -20px; border-radius: 0 3px 3px 3px; }

.empty-state { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 6px; background: var(--panel); color: var(--text); }
.empty-state h2 { margin: 6px 0 0; font-size: 20px; }

/* ---------- inspector ---------- */
.inspector { width: 300px; flex: none; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; height: 32px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 12px; }

.crumbs { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 10px; font: 11px var(--mono); }
.crumbs button { background: none; border: 0; padding: 2px 4px; border-radius: 4px; color: var(--muted); cursor: pointer; }
.crumbs button:hover { background: var(--panel-2); color: var(--text); }
.crumbs button.cur { color: var(--accent); }
.crumbs .sep { color: var(--line-2); padding: 2px 0; }

.section { border-top: 1px solid var(--line); padding: 10px 0; }
.section:first-of-type { border-top: 0; }
.section h4 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.row { display: grid; grid-template-columns: 78px 1fr auto; align-items: center; gap: 6px; margin-bottom: 6px; }
.row > label { color: var(--muted); font-size: 12px; }
.row .clear { width: 20px; height: 20px; border: 0; background: none; color: var(--muted); cursor: pointer; border-radius: 4px; font-size: 14px; line-height: 1; }
.row .clear:hover { color: var(--danger); background: var(--panel-2); }
.row .clear.hide { visibility: hidden; }
.input {
  width: 100%; height: 28px; padding: 0 8px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; outline: none;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: #6d6052; }
.input.mono, textarea.input { font-family: var(--mono); font-size: 12px; }
select.input { padding: 0 4px; }
.color-field { display: flex; gap: 6px; }
.color-field input[type=color] { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; cursor: pointer; flex: none; }
.color-field input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-field input[type=color]::-webkit-color-swatch { border: 0; border-radius: 3px; }
.align-btns { display: flex; gap: 2px; }
.align-btns button { flex: 1; height: 28px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; cursor: pointer; color: var(--muted); }
.align-btns button.on { border-color: var(--accent); color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; margin: 4px 0 8px; cursor: pointer; }
.thumb { max-width: 100%; max-height: 110px; display: block; margin: 0 auto 8px; border-radius: 4px; background: repeating-conic-gradient(#2a221b 0 25%, #1f1914 0 50%) 0 0/14px 14px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.hint b { color: var(--text); font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.placeholder-msg { color: var(--muted); text-align: center; padding: 30px 10px; }
.placeholder-msg svg { width: 28px; height: 28px; margin-bottom: 8px; opacity: .6; }

.swatches { display: flex; flex-direction: column; gap: 6px; }
.swatch-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; }
.swatch-row input[type=color] { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line-2); border-radius: 6px; background: none; cursor: pointer; }
.swatch-row .count { color: var(--muted); font-size: 11px; font-family: var(--mono); }
.font-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }

/* ---------- modals ---------- */
.modal {
  width: min(520px, 92vw); max-height: 80vh; padding: 16px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.modal.wide { width: min(860px, 94vw); }
.modal[open] { display: flex; flex-direction: column; gap: 10px; }
.modal::backdrop { background: rgba(0,0,0,.55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal textarea { height: 50vh; padding: 10px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.draft-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.draft-list li { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; cursor: pointer; }
.draft-list li:hover { background: var(--panel-2); }
.draft-list li.cur { background: var(--panel-2); box-shadow: inset 2px 0 var(--accent); }
.draft-list .dname { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-list .dmeta { color: var(--muted); font-size: 11px; white-space: nowrap; }
.draft-list .empty { color: var(--muted); cursor: default; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line-2); padding: 8px 14px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login-card { width: 300px; display: flex; flex-direction: column; gap: 10px; text-align: center; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 0 0 6px; }
.login-card input { height: 40px; text-align: center; font-size: 20px; letter-spacing: .3em; background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--radius); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .btn { height: 40px; justify-content: center; }
.login-error { color: var(--danger); min-height: 18px; }
.brand-mark { margin: 0 auto; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; background: var(--panel-2); color: var(--accent); font: 700 16px var(--mono); border: 1px solid var(--line-2); }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .inspector { width: 260px; }
  .lock-label { display: none; }
}
