:root {
  --bg: #14161b;
  --bg-2: #1b1e24;
  --bg-3: #232830;
  --bg-4: #2d3340;
  --border: #2b313a;
  --border-2: #3a4250;
  --text: #e7ebf2;
  --text-2: #9aa3b2;
  --text-3: #6b7380;
  --accent: #5b8dff;
  --accent-2: #7aa3ff;
  --danger: #ff6464;
  --success: #42c78a;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --panel-left: 260px;
  --panel-right: 360px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: var(--panel-left) 4px 1fr 4px var(--panel-right);
  height: 100vh;
}

.resizer {
  background: var(--border);
  cursor: col-resize;
  user-select: none;
  transition: background 0.12s;
}
.resizer:hover, .resizer.dragging { background: var(--accent); }

/* Panels */
.panel {
  background: var(--bg-2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--border);
}
.brand h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand .muted { margin: 2px 0 0; font-size: 11px; }

.muted { color: var(--text-3); }

/* Sections */
.section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.section.grow { flex: 1; overflow-y: auto; }
.section.status { margin-top: auto; }
.section h2 {
  margin: 0 0 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  font-weight: 600;
}
.section h3 {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-2);
  font-weight: 600;
}

/* Buttons */
.actions { padding: 12px 16px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); align-items: center; }
.actions.col { flex-direction: column; align-items: stretch; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  text-align: center;
  font-family: inherit;
}
.btn:hover:not(:disabled) { background: var(--bg-4); border-color: #4a5366; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.btn.tiny { padding: 5px 10px; font-size: 11px; }
.btn.icon { padding: 4px 8px; font-size: 14px; line-height: 1; min-width: 28px; }
.btn.vp { padding: 4px 8px; font-size: 13px; line-height: 1; min-width: 28px; }
.btn.vp.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); border-color: transparent; padding: 4px 8px; }
.btn.danger:hover:not(:disabled) { background: rgba(255, 100, 100, 0.1); }

.row-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.row-buttons .btn { flex: 1 0 calc(50% - 3px); min-width: 0; }

/* Select & inputs */
select, input[type="text"], input[type="color"], textarea {
  width: 100%;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none;
}
input[type="color"] { padding: 2px; height: 30px; cursor: pointer; }
textarea { font-family: var(--mono); resize: vertical; min-height: 60px; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.tiny-input {
  width: 52px !important;
  padding: 4px 6px !important;
  font-size: 11px !important;
}

/* File list */
.file-list { list-style: none; margin: 0; padding: 0; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-list li .ext {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-4);
  color: var(--text-3);
  text-transform: uppercase;
  font-family: inherit;
  font-weight: 600;
  flex-shrink: 0;
}
.file-list li .ext.html { background: #5b8dff33; color: #8fb3ff; }
.file-list li .ext.css { background: #c78a4233; color: #e8b878; }
.file-list li .ext.js { background: #42c78a33; color: #7ed9a6; }
.file-list li .ext.img { background: #c26bff33; color: #d99aff; }
.file-list li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; }

.layer-list { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.layer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 3px 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
}
.layer-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}
.layer-main:hover { background: var(--bg-3); color: var(--text); }
.layer-row.active .layer-main { background: var(--bg-4); color: var(--accent-2); }
.layer-row.hidden-layer .layer-name { opacity: 0.45; text-decoration: line-through; }
.layer-row.locked-layer .layer-name::after { content: " lock"; color: var(--text-3); font-size: 9px; }
.layer-indent { width: calc(var(--depth, 0) * 12px); flex-shrink: 0; }
.layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-action {
  width: 24px;
  min-width: 24px;
  padding: 4px 0;
  background: transparent;
  border-color: transparent;
  color: var(--text-3);
}
.layer-action:hover:not(:disabled) { background: var(--bg-3); color: var(--text); }
.block-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* Preview */
.preview {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  min-width: 0;
}
.preview-toolbar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-2);
  min-height: 44px;
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
}
.toolbar-group:last-of-type { border-right: 0; }
.viewport-group .vp:not(.active) { background: transparent; border-color: transparent; color: var(--text-3); }
.viewport-scope {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--border);
  color: var(--text-2);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.viewport-scope input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
.viewport-scope.active { color: var(--accent-2); }

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-family: var(--mono);
  font-size: 11px;
}
.breadcrumbs .crumb {
  color: var(--text-3);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.breadcrumbs .crumb:hover { background: var(--bg-3); color: var(--text); }
.breadcrumbs .crumb.active { color: var(--accent-2); background: var(--bg-3); }
.breadcrumbs .sep { color: var(--text-3); opacity: 0.5; font-size: 10px; }

.selection-label {
  font-size: 11px;
  color: var(--text-3);
  font-family: var(--mono);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-label,
.autosave-label {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}
.autosave-label { color: var(--success); }
.spacer { flex: 1; }

.preview-frame {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #2a2d34;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: stretch;
}
.preview-viewport {
  flex: 1;
  display: flex;
  background: #fff;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
  transition: max-width 0.2s;
  position: relative;
}
.preview-frame.viewport-mobile .preview-viewport { max-width: 375px; margin: 20px auto; }
.preview-frame.viewport-tablet .preview-viewport { max-width: 768px; margin: 20px auto; }
.preview-frame.viewport-desktop .preview-viewport { max-width: none; }

#preview-iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-3);
  background: var(--bg);
  pointer-events: none;
}
.empty-state h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; color: var(--text-2); }
.empty-state p { margin: 4px 0; font-size: 12px; line-height: 1.6; }
.empty-state code { background: var(--bg-3); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* Right panel: tabs */
.tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--bg-2); }
.tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-3);
  padding: 10px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-family: inherit;
}
.tab:hover { color: var(--text-2); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab-panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.tab-panel.hidden { display: none; }

.empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.6;
}

.hidden { display: none !important; }

/* Element editor */
.selector-chip {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-3);
  color: var(--accent-2);
  font-family: var(--mono);
  font-size: 11px;
  border-radius: 4px;
  word-break: break-all;
  max-width: 100%;
}

.attrs { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.attr-row { display: grid; grid-template-columns: 80px 1fr auto; gap: 6px; align-items: center; }
.attr-row label { font-family: var(--mono); font-size: 11px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }

.style-grid { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.style-row { display: grid; grid-template-columns: 110px 1fr auto auto; gap: 4px; align-items: center; }
.style-row label { font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.style-row .color-pick { width: 30px; padding: 0; height: 28px; }

.inline-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: center; }

.image-picker { display: grid; grid-template-columns: 80px 1fr; gap: 10px; align-items: start; }
.image-thumb {
  width: 80px;
  height: 80px;
  background: var(--bg-3) center/contain no-repeat;
  background-image:
    linear-gradient(45deg, #2a2f38 25%, transparent 25%),
    linear-gradient(-45deg, #2a2f38 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2f38 75%),
    linear-gradient(-45deg, transparent 75%, #2a2f38 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.image-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.image-controls { display: flex; flex-direction: column; gap: 6px; }
.image-controls .btn { width: 100%; }

.hint { font-size: 11px; color: var(--text-3); margin: 6px 0 0; line-height: 1.5; }
.hint code { font-family: var(--mono); background: var(--bg-3); padding: 1px 4px; border-radius: 3px; }

/* Rules list */
.rules-list { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.rule-card {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  overflow: hidden;
}
.rule-card header { padding: 8px 10px; display: flex; gap: 8px; align-items: center; background: var(--bg-4); font-family: var(--mono); font-size: 11px; }
.rule-card header .selector { flex: 1; color: var(--accent-2); word-break: break-all; }
.rule-card header .source { color: var(--text-3); font-size: 10px; }
.rule-card textarea { border: 0; border-radius: 0; background: var(--bg-3); font-family: var(--mono); font-size: 11px; resize: vertical; min-height: 80px; }
.rule-card .card-actions { display: flex; gap: 6px; padding: 6px 10px; background: var(--bg-4); border-top: 1px solid var(--border); }
.rule-card .card-actions .saved { font-size: 11px; color: var(--success); margin-left: auto; align-self: center; opacity: 0; transition: opacity 0.2s; }
.rule-card .card-actions .saved.show { opacity: 1; }

/* CSS file editor */
.tab-panel[data-tab-panel="css"] #css-editor {
  flex: 1;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  min-height: 200px;
  resize: none;
  font-size: 11px;
}

/* Drop overlay */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(91, 141, 255, 0.15);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  pointer-events: none;
  border: 4px dashed var(--accent);
}
.drop-overlay.show { display: flex; }
.drop-overlay .drop-msg {
  background: var(--bg-2);
  padding: 24px 40px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-2);
}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #414958; }
