* { margin: 0; padding: 0; box-sizing: border-box; }
:focus-visible { outline: 2px solid #53a8b6; outline-offset: 2px; }
button:focus-visible { outline: 2px solid #53a8b6; outline-offset: 1px; border-radius: 4px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #0f346088; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #0f3460cc; }
body.light ::-webkit-scrollbar-thumb { background: #c0c8d888; }
body.light ::-webkit-scrollbar-thumb:hover { background: #b0b8c8; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Toolbar ============ */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  user-select: none;
}
#toolbar button {
  background: #0f3460;
  color: #c0c0d8;
  border: 1px solid #1a1a5e;
  border-radius: 4px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s;
}
#toolbar button:hover { background: #1a4a8a; color: #fff; }
.tb-icon { font-size: 14px !important; padding: 5px 8px !important; min-width: 28px; text-align: center; }
.tb-ai { background: #1b4332 !important; border-color: #95d5b2 !important; color: #95d5b2 !important; }
.tb-ai:hover { background: #2d6a4f !important; }
#toolbar button:active { background: #0d2d50; }
#toolbar button:disabled { opacity: 0.35; cursor: default; pointer-events: none; }
#toolbar button.replay-active { background: #22c55e33; border-color: #22c55e; color: #22c55e; }
#toolbar button.tb-active { background: #53a8b633; border-color: #53a8b6; color: #53a8b6; }

.sep { width: 1px; height: 22px; background: #0f3460; margin: 0 4px; }

.warning-badge {
  font-size: 11px;
  color: #f59e0b;
  background: #f59e0b18;
  border: 1px solid #f59e0b44;
  border-radius: 10px;
  padding: 2px 8px;
  cursor: pointer;
  margin-left: auto;
  transition: opacity 0.2s;
}
.warning-badge:hover { background: #f59e0b30; }
.warning-badge.hidden { display: none; }

.zoom-level {
  font-size: 11px;
  color: #8888aa;
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  user-select: none;
  min-width: 36px;
  text-align: center;
  transition: background 0.12s, color 0.12s;
}
.zoom-level:hover { background: #0f3460; color: #c0c0d8; }
body.light .zoom-level { color: #666; }
body.light .zoom-level:hover { background: #d0d6e2; color: #333; }

.autosave-indicator {
  font-size: 10px;
  color: #22c55e88;
  opacity: 0;
  transition: opacity 0.3s;
  margin-left: 0;
  pointer-events: none;
}
.autosave-indicator.flash { opacity: 1; }
.autosave-indicator.persistent { opacity: 0.5; }
.autosave-indicator.persistent.flash { opacity: 1; }

#tree-title {
  font-size: 13px;
  color: #8888aa;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 3px;
  transition: background 0.15s;
}
#tree-title:hover { background: #0f346033; }

.title-edit {
  margin-left: auto;
  font-size: 13px;
  color: #e0e0e0;
  background: #1a1a2e;
  border: 1px solid #53a8b6;
  border-radius: 3px;
  padding: 2px 6px;
  outline: none;
  font-family: inherit;
}

/* ============ Tab bar ============ */
#tab-bar {
  display: flex;
  align-items: center;
  background: #0d1b2a;
  border-bottom: 1px solid #0f3460;
  padding: 0 4px;
  gap: 0;
  min-height: 28px;
  overflow-x: auto;
  user-select: none;
  font-size: 11px;
}
#tab-bar::-webkit-scrollbar { height: 0; }
.tab-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  color: #666;
  cursor: pointer;
  border-right: 1px solid #0f346044;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
  max-width: 160px;
}
.tab-item:hover { background: #16213e; color: #aaa; }
.tab-item.active { background: #16213e; color: #53a8b6; border-bottom: 2px solid #53a8b6; }
.tab-item .tab-close {
  opacity: 0;
  font-size: 10px;
  padding: 0 2px;
  cursor: pointer;
  color: #666;
  transition: opacity 0.1s;
}
.tab-item:hover .tab-close { opacity: 0.6; }
.tab-item .tab-close:hover { opacity: 1; color: #ef4444; }
.tab-item .tab-dirty { color: #53a8b6; font-size: 8px; margin-left: -2px; }
.tab-item .tab-count { font-size: 9px; opacity: 0.4; margin-left: 2px; }
.tab-item.tab-dragging { opacity: 0.4; }
.tab-item.tab-dragover { border-left: 2px solid #53a8b6; }
#tab-add {
  background: none;
  border: none;
  color: #555;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
}
#tab-add:hover { color: #53a8b6; }
body.light #tab-bar { background: #dde1e8; border-color: #c0c8d8; }
body.light .tab-item { color: #888; border-color: #c0c8d844; }
body.light .tab-item:hover { background: #e2e6ee; color: #555; }
body.light .tab-item.active { background: #e2e6ee; color: #1a7080; border-bottom-color: #1a7080; }
body.light #tab-add { color: #aaa; }
body.light #tab-add:hover { color: #1a7080; }

/* ============ Breadcrumb ============ */
.breadcrumb {
  background: #12192e;
  border-bottom: 1px solid #0f3460;
  padding: 0 10px;
  font-size: 11px;
  min-height: 0;
  overflow: hidden;
  transition: min-height 0.15s, padding 0.15s;
  display: flex;
  align-items: center;
  gap: 2px;
  user-select: none;
}
.breadcrumb:empty { min-height: 0; padding: 0 10px; }
.breadcrumb:not(:empty) { min-height: 24px; padding: 3px 10px; }
.breadcrumb .bc-seg {
  color: #8888aa;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  transition: background 0.1s;
}
.breadcrumb .bc-seg:hover { background: #0f346066; color: #c0c0d8; }
.breadcrumb .bc-seg.active { color: #e0e0e0; font-weight: 600; }
.breadcrumb .bc-sep { color: #0f3460; margin: 0 1px; }

/* ============ Main layout ============ */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ============ Palette ============ */
#palette {
  width: 170px;
  min-width: 170px;
  flex-shrink: 0;
  background: #16213e;
  border-right: 1px solid #0f3460;
  padding: 12px 10px;
  overflow-y: auto;
  user-select: none;
}
#palette h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  color: #8888aa;
}

.palette-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #555;
  margin: 10px 0 4px 2px;
}
.palette-section:first-of-type { margin-top: 0; }

#palette-filter {
  width: 100%;
  padding: 5px 8px;
  margin-bottom: 10px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
}
#palette-filter:focus { border-color: #53a8b6; }
#palette-filter::placeholder { color: #555; }

.palette-item {
  padding: 7px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  cursor: grab;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.palette-item:hover { border-color: #53a8b6; transform: translateX(2px); }
.palette-item:active { cursor: grabbing; }
.palette-item[data-category="composite"] { background: #1b4332; color: #95d5b2; }
.palette-item[data-category="leaf"] { background: #3c1642; color: #c77dff; }
.palette-item[data-category="decorator"] { background: #4a3728; color: #e09f3e; }

.palette-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}
.palette-key {
  margin-left: auto;
  font-size: 9px;
  font-weight: 600;
  opacity: 0.35;
  background: #ffffff10;
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
}
.type-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  background: #ffffff15;
  flex-shrink: 0;
}
body.light .type-count { background: #00000012; }

/* ============ Panel resizers ============ */
.panel-resizer {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  flex-shrink: 0;
  z-index: 10;
}
.panel-resizer:hover, .panel-resizer.active { background: #53a8b6; }

/* ============ Canvas ============ */
#canvas { flex: 1; min-width: 0; display: block; }

/* ============ Properties ============ */
#properties {
  width: 240px;
  min-width: 240px;
  flex-shrink: 0;
  background: #16213e;
  border-left: 1px solid #0f3460;
  padding: 12px 10px;
  overflow-y: auto;
}
#properties h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  color: #8888aa;
}
.hint { color: #555; font-size: 12px; font-style: italic; }

#properties label {
  display: block;
  font-size: 11px;
  color: #8888aa;
  margin-top: 8px;
}
#properties input, #properties select {
  width: 100%;
  margin-top: 3px;
  padding: 5px 7px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
#properties .prop-textarea {
  width: 100%;
  margin-top: 3px;
  padding: 5px 7px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.bb-key-tag { background: #0f3460; color: #53a8b6; }
#properties input:focus, #properties select:focus, #properties textarea:focus { border-color: #53a8b6; }
#properties input:disabled { color: #555; cursor: default; }
#properties input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
  vertical-align: middle;
}
#properties .param-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-top: 4px;
}
#properties .param-row input { flex: 1; }
#properties .param-row button {
  background: #5c1a1a;
  color: #e0e0e0;
  border: none;
  border-radius: 4px;
  padding: 5px 7px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
#properties .param-row button:hover { background: #8a2a2a; }
#properties button.add-param {
  margin-top: 8px;
  background: #0f3460;
  color: #c0c0d8;
  border: none;
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
#properties button.add-param:hover { background: #1a4a8a; }
.child-order { margin-top: 4px; }
.child-order-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 0;
  border-bottom: 1px solid #0f346022;
}
.child-order-row button {
  background: #0f3460;
  color: #c0c0d8;
  border: 1px solid #1a1a5e;
  border-radius: 3px;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
}
.child-order-row button:hover { background: #1a4a8a; color: #fff; }
.child-order-row button:disabled { opacity: 0.3; pointer-events: none; }

/* ============ Minimap ============ */
#minimap-container {
  position: fixed;
  bottom: 12px;
  right: 254px;
  width: 180px;
  height: 120px;
  background: #0d1b2a;
  border: 1px solid #0f3460;
  border-radius: 6px;
  overflow: hidden;
  opacity: 0.8;
  transition: opacity 0.2s;
}
#minimap-container:hover { opacity: 1; }
#minimap { width: 100%; height: 100%; display: block; }

/* ============ Replay bar ============ */
#replay-bar {
  background: #0d1b2a;
  border-top: 1px solid #0f3460;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
}
#replay-bar.hidden { display: none; }
#replay-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
#replay-controls button {
  background: #0f3460;
  color: #c0c0d8;
  border: 1px solid #1a1a5e;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.12s;
}
#replay-controls button:hover { background: #1a4a8a; color: #fff; }
#replay-slider {
  flex: 1;
  accent-color: #53a8b6;
  cursor: pointer;
}
#replay-tick-label {
  font-size: 12px;
  color: #8888aa;
  min-width: 60px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
#replay-speed {
  background: #0f3460;
  color: #c0c0d8;
  border: 1px solid #1a1a5e;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 11px;
  cursor: pointer;
}
#replay-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #666;
  white-space: nowrap;
}
.legend-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 6px;
}
.legend-dot:first-child { margin-left: 0; }

/* ============ Blackboard panel ============ */
#blackboard-panel {
  position: fixed;
  bottom: 60px;
  left: 182px;
  width: 260px;
  max-height: 250px;
  background: #0d1b2aee;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 10px 12px;
  overflow-y: auto;
  font-size: 12px;
  z-index: 50;
}
#blackboard-panel.hidden { display: none; }
#blackboard-panel h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8888aa;
  margin-bottom: 8px;
}
#blackboard-content {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 10px;
}
/* ============ Status timeline (replay node inspect) ============ */
.status-timeline {
  display: flex;
  gap: 1px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.st-tick {
  width: 8px;
  height: 16px;
  border-radius: 2px;
  cursor: pointer;
  transition: transform 0.1s;
}
.st-tick:hover { transform: scaleY(1.4); }
.st-tick.st-active { outline: 2px solid #fff; outline-offset: 1px; }

.bb-key { color: #53a8b6; font-weight: 500; }
.bb-val { color: #e0e0e0; transition: color 0.2s; }
.bb-changed { color: #f59e0b; font-weight: 600; }

/* ============ Context menu ============ */
.ctx-menu {
  position: fixed;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 4px 0;
  min-width: 160px;
  z-index: 250;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.ctx-menu.hidden { display: none; }
.ctx-item {
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  color: #c0c0d8;
  transition: background 0.1s;
}
.ctx-item:hover { background: #0f3460; color: #fff; }
.ctx-sep { height: 1px; background: #0f3460; margin: 4px 0; }
.ctx-item.danger { color: #ef4444; }
.ctx-item.danger:hover { background: #5c1a1a; }

/* ============ Drop overlay ============ */
#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(83, 168, 182, 0.12);
  border: 3px dashed #53a8b6;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none;
}
#drop-overlay.active { display: flex; }
#drop-overlay span {
  background: #16213eee;
  padding: 16px 32px;
  border-radius: 8px;
  font-size: 16px;
  color: #53a8b6;
  font-weight: 600;
}

/* ============ Toast ============ */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: #1a4a8a;
  color: #e0e0e0;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
  max-width: 80vw;
  text-align: center;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ Dialogs ============ */
.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.dialog.hidden { display: none; }
.dialog-inner {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 24px;
  min-width: 320px;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.dialog-inner h3 { margin-bottom: 14px; font-size: 16px; }
.dialog-inner button {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a1a5e;
  border-radius: 4px;
  padding: 7px 16px;
  cursor: pointer;
  margin-top: 10px;
  margin-right: 6px;
  font-size: 13px;
  transition: background 0.1s;
}
.dialog-inner button:hover { background: #1a4a8a; }
.dialog-buttons { display: flex; gap: 8px; margin-top: 14px; }

#load-list .load-item,
#replay-list .load-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  transition: background 0.1s;
}
#load-list .load-item:hover,
#replay-list .load-item:hover,
#search-results .load-item:hover { background: #0f3460; }

#search-input:focus { border-color: #53a8b6; }
#cmd-input:focus { border-color: #53a8b6; }
.cmd-active { background: #0f3460 !important; color: #fff; }

#save-dialog label { display: block; font-size: 13px; }
#save-dialog input {
  width: 100%;
  margin-top: 6px;
  padding: 7px 10px;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
#save-dialog input:focus { border-color: #53a8b6; }

/* ============ Help dialog ============ */
.help-inner { min-width: 420px; max-height: 80vh; overflow-y: auto; }
.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.help-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #0f346033;
}
.help-table td:first-child { color: #a0a0c0; white-space: nowrap; }
.help-table td:last-child { color: #888; }
.help-table .sep-row {
  height: 6px;
  border: none;
}
.help-table .help-cat {
  color: #53a8b6;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 10px 8px 4px;
  border-bottom: 1px solid #53a8b633;
}
body.light .help-table .help-cat { color: #0f3460; border-color: #0f346033; }
kbd {
  background: #0f3460;
  border: 1px solid #1a1a5e;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  font-family: inherit;
  color: #c0c0d8;
}

/* ============ JSON Preview ============ */
#json-panel {
  position: fixed;
  bottom: 0;
  left: 170px;
  right: 240px;
  height: 220px;
  background: #0d1b2a;
  border-top: 1px solid #0f3460;
  z-index: 60;
  display: flex;
  flex-direction: column;
  transition: height 0.15s;
}
#json-panel.hidden { display: none; }
#json-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  font-size: 11px;
  color: #8888aa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  user-select: none;
}
#json-panel-header button {
  background: none;
  border: none;
  color: #8888aa;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
}
#json-panel-header button:hover { color: #e0e0e0; }
#json-content {
  flex: 1;
  overflow: auto;
  padding: 8px 12px;
  font-family: "SF Mono", "Consolas", "Monaco", monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #a0c0d0;
  margin: 0;
  tab-size: 2;
}

/* ============ Outline panel ============ */
#outline-panel {
  position: fixed;
  top: 42px;
  left: 170px;
  width: 260px;
  max-height: calc(100vh - 80px);
  background: #0d1b2aee;
  border: 1px solid #0f3460;
  border-radius: 0 0 6px 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(8px);
}
#outline-panel.hidden { display: none; }
#outline-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: #16213e; border-bottom: 1px solid #0f3460;
  font-size: 11px; color: #8888aa; text-transform: uppercase; letter-spacing: 0.5px; user-select: none;
}
#outline-header button { background: none; border: none; color: #8888aa; font-size: 14px; cursor: pointer; padding: 0 4px; }
#outline-header button:hover { color: #e0e0e0; }
#outline-filter {
  width: calc(100% - 12px); margin: 4px 6px; padding: 4px 8px; font-size: 11px;
  background: #0d1b2a; color: #e0e0e0; border: 1px solid #0f3460; border-radius: 4px;
  outline: none; font-family: inherit;
}
#outline-filter:focus { border-color: #53a8b6; }
body.light #outline-filter { background: #fff; color: #333; border-color: #c0c8d8; }
.outline-node.ancestor { opacity: 0.6; }
.outline-node.ancestor-path { border-left: 2px solid #53a8b644; }
.outline-node.filter-hidden { display: none; }
#outline-content {
  flex: 1; overflow-y: auto; padding: 6px 0; font-size: 12px;
}
.outline-node {
  padding: 2px 8px 2px 0; cursor: pointer; display: flex; align-items: center; gap: 4px;
  color: #c0c8d8; white-space: nowrap; transition: background 0.1s;
}
.outline-node:hover { background: #0f346044; }
.outline-node.selected { background: #0f3460; color: #fff; }
.outline-node .on-icon { width: 14px; text-align: center; font-size: 10px; flex-shrink: 0; }
.outline-node .on-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.outline-node .on-type { font-size: 9px; color: #555; flex-shrink: 0; }
body.light #outline-panel { background: #f5f7faee; border-color: #c0c8d8; }
body.light #outline-header { background: #e2e6ee; border-color: #c0c8d8; color: #666; }
body.light .outline-node { color: #333; }
body.light .outline-node:hover { background: #d8dce4; }
body.light .outline-node.selected { background: #c0d0e0; color: #111; }

/* ============ History panel ============ */
#history-panel {
  position: fixed;
  top: 42px;
  right: 254px;
  width: 240px;
  max-height: 340px;
  background: #0d1b2aee;
  border: 1px solid #0f3460;
  border-radius: 0 0 6px 6px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(8px);
}
#history-panel.hidden { display: none; }
#history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: #16213e; border-bottom: 1px solid #0f3460;
  font-size: 11px; color: #8888aa; text-transform: uppercase; letter-spacing: 0.5px; user-select: none;
}
#history-header button { background: none; border: none; color: #8888aa; font-size: 14px; cursor: pointer; padding: 0 4px; }
#history-header button:hover { color: #e0e0e0; }
#history-list { flex: 1; overflow-y: auto; padding: 4px 0; font-size: 11px; }
.history-item {
  padding: 4px 10px; cursor: pointer; color: #666; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; transition: background 0.1s;
}
.history-item:hover { background: #0f346044; color: #c0c8d8; }
.history-item.current { background: #0f3460; color: #53a8b6; font-weight: 600; }
.history-item.future { opacity: 0.4; }
body.light #history-panel { background: #f5f7faee; border-color: #c0c8d8; }
body.light #history-header { background: #e2e6ee; border-color: #c0c8d8; color: #666; }
body.light .history-item { color: #888; }
body.light .history-item:hover { background: #d8dce4; color: #333; }
body.light .history-item.current { background: #c0d0e0; color: #1a6070; }

/* ============ Blackboard Key Viewer panel ============ */
#bb-viewer-panel {
  position: fixed;
  top: 42px;
  right: 254px;
  width: 260px;
  max-height: calc(100vh - 80px);
  background: #0d1b2aee;
  border: 1px solid #0f3460;
  border-radius: 0 0 6px 6px;
  z-index: 65;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(8px);
}
#bb-viewer-panel.hidden { display: none; }
#bb-viewer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; background: #16213e; border-bottom: 1px solid #0f3460;
  font-size: 11px; color: #8888aa; text-transform: uppercase; letter-spacing: 0.5px; user-select: none;
}
#bb-viewer-header button { background: none; border: none; color: #8888aa; font-size: 14px; cursor: pointer; padding: 0 4px; }
#bb-viewer-header button:hover { color: #e0e0e0; }
#bb-viewer-content { flex: 1; overflow-y: auto; padding: 6px 0; font-size: 12px; }
.bbv-key-group { padding: 4px 0; }
.bbv-key-name {
  padding: 3px 10px; font-size: 11px; font-weight: 600; color: #53a8b6;
  cursor: pointer; user-select: none; display: flex; align-items: center; gap: 4px;
}
.bbv-key-name:hover { background: #0f346044; }
.bbv-node-row {
  padding: 2px 10px 2px 22px; color: #c0c8d8; display: flex; align-items: center;
  gap: 4px; font-size: 11px; white-space: nowrap; overflow: hidden; cursor: pointer;
}
.bbv-node-row:hover { background: #0f346044; }
.bbv-node-icon { width: 14px; text-align: center; font-size: 10px; flex-shrink: 0; }
.bbv-node-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.bbv-op { font-size: 10px; color: #8888aa; flex-shrink: 0; }
.bbv-empty { padding: 10px; color: #555; font-size: 11px; }
body.light #bb-viewer-panel { background: #f5f7faee; border-color: #c0c8d8; }
body.light #bb-viewer-header { background: #e2e6ee; border-color: #c0c8d8; color: #666; }
body.light .bbv-key-name { color: #1a6070; }
body.light .bbv-key-name:hover { background: #d8dce4; }
body.light .bbv-node-row { color: #333; }
body.light .bbv-node-row:hover { background: #d8dce4; }

/* ============ Warnings panel ============ */
#warnings-panel {
  position: fixed;
  top: 42px;
  right: 254px;
  width: 320px;
  max-height: 300px;
  background: #0d1b2aee;
  border: 1px solid #f59e0b44;
  border-radius: 6px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  backdrop-filter: blur(8px);
}
#warnings-panel.hidden { display: none; }
#warnings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 11px;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #f59e0b22;
  user-select: none;
}
#warnings-header button {
  background: none;
  border: none;
  color: #f59e0b88;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
}
#warnings-header button:hover { color: #f59e0b; }
#warnings-list {
  overflow-y: auto;
  padding: 4px 0;
}
.warning-item {
  padding: 7px 12px;
  font-size: 12px;
  color: #c0c0d8;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
}
.warning-item:hover { background: #0f346066; }
.warning-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f59e0b;
  flex-shrink: 0;
}

/* ============ Light theme ============ */
body.light { background: #f0f2f5; color: #1a1a2e; }
body.light #toolbar { background: #e2e6ee; border-color: #c0c8d8; }
body.light #toolbar button { background: #d0d6e2; color: #333; border-color: #b0b8c8; }
body.light #toolbar button:hover { background: #c0c8d8; color: #000; }
body.light #tree-title { color: #555; }
body.light .breadcrumb { background: #e8ebf0; border-color: #c0c8d8; }
body.light .breadcrumb .bc-seg { color: #666; }
body.light .breadcrumb .bc-seg:hover { background: #d0d6e2; color: #333; }
body.light .breadcrumb .bc-seg.active { color: #1a1a2e; }
body.light .breadcrumb .bc-sep { color: #aaa; }
body.light .sep { background: #c0c8d8; }
body.light #palette { background: #e2e6ee; border-color: #c0c8d8; }
body.light #palette h3 { color: #666; }
body.light .palette-section { color: #888; }
body.light #palette-filter { background: #fff; color: #333; border-color: #c0c8d8; }
body.light #palette-filter::placeholder { color: #999; }
body.light .palette-item[data-category="composite"] { background: #d4edda; color: #155724; }
body.light .palette-item[data-category="leaf"] { background: #e8d5f5; color: #5b2d8e; }
body.light .palette-item[data-category="decorator"] { background: #fce8cd; color: #7a4f1e; }
body.light .palette-item:hover { border-color: #2980b9; }
body.light #properties { background: #e2e6ee; border-color: #c0c8d8; }
body.light #properties h3 { color: #666; }
body.light #properties label { color: #666; }
body.light #properties input, body.light #properties select { background: #fff; color: #333; border-color: #c0c8d8; }
body.light .hint { color: #888; }
body.light #minimap-container { background: #dde1e8; border-color: #c0c8d8; }
body.light .dialog { background: rgba(0,0,0,0.25); }
body.light .dialog-inner { background: #f0f2f5; border-color: #c0c8d8; color: #333; }
body.light .dialog-inner button { background: #d0d6e2; color: #333; border-color: #b0b8c8; }
body.light .dialog-inner button:hover { background: #c0c8d8; }
body.light .ctx-menu { background: #f0f2f5; border-color: #c0c8d8; box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
body.light .ctx-item { color: #333; }
body.light .ctx-item:hover { background: #d0d6e2; color: #000; }
body.light .ctx-sep { background: #c0c8d8; }
body.light #toast { background: #2980b9; color: #fff; }
body.light kbd { background: #d0d6e2; border-color: #b0b8c8; color: #333; }
body.light #replay-bar { background: #e2e6ee; border-color: #c0c8d8; }
body.light #replay-controls button { background: #d0d6e2; color: #333; border-color: #b0b8c8; }
body.light #replay-tick-label { color: #666; }
body.light #blackboard-panel { background: #f0f2f5ee; border-color: #c0c8d8; }
body.light .bb-key { color: #2980b9; }
body.light .bb-val { color: #333; }
body.light .title-edit { background: #fff; color: #333; border-color: #2980b9; }
body.light .autosave-indicator { color: #22c55e; }
body.light .warning-badge { color: #b45309; background: #f59e0b18; border-color: #f59e0b44; }
body.light .warning-badge:hover { background: #f59e0b30; }
body.light #json-panel { background: #f5f7fa; border-color: #c0c8d8; }
body.light #json-panel-header { background: #e2e6ee; border-color: #c0c8d8; color: #666; }
body.light #json-panel-header button { color: #666; }
body.light #json-content { color: #2c3e50; }
body.light #ai-input { background: #fff; color: #333; border-color: #c0c8d8; }
body.light #ai-input::placeholder { color: #999; }
body.light .tb-ai { background: #d4edda !important; border-color: #28a745 !important; color: #155724 !important; }
body.light .tb-ai:hover { background: #c3e6cb !important; }
body.light #properties textarea, body.light #properties .prop-textarea { background: #fff; color: #333; border-color: #c0c8d8; }
body.light .bb-key-tag { background: #d0d6e2; color: #2980b9; }
body.light #properties .param-row button { background: #e8c8c8; color: #a33; }
body.light #properties .param-row button:hover { background: #daa; }
body.light #properties button.add-param { background: #d0d6e2; color: #555; }
body.light #properties button.add-param:hover { background: #c0c8d8; }
body.light .child-order-row button { background: #d0d6e2; color: #555; }
body.light .child-order-row button:hover { background: #c0c8d8; color: #333; }
body.light .template-item { background: #f0f2f5 !important; color: #2980b9 !important; border-color: #2980b944 !important; }
body.light .template-item:hover { border-color: #2980b9 !important; }
body.light #search-input, body.light #cmd-input, body.light #load-filter { background: #fff; color: #333; border-color: #c0c8d8; }
body.light #search-input::placeholder, body.light #cmd-input::placeholder, body.light #load-filter::placeholder { color: #999; }
body.light .cmd-active { background: #d0d6e2 !important; color: #000; }
body.light #properties .color-swatch { border-color: transparent; }
body.light .load-item:hover { background: #d0d6e2 !important; }
body.light #load-list .load-item:hover, body.light #replay-list .load-item:hover { background: #d0d6e2; }
body.light .ctx-item.danger { color: #dc2626; }
body.light .ctx-item.danger:hover { background: #fee2e2; }
body.light #drop-overlay { background: rgba(41, 128, 185, 0.08); border-color: #2980b9; }
body.light #drop-overlay span { background: #f0f2f5ee; color: #2980b9; }
body.light .suggest-param { background: #c0c8d833 !important; color: #2980b9 !important; border-color: #2980b944 !important; }
body.light .suggest-param:hover { background: #c0c8d866 !important; }
body.light #warnings-panel { background: #f0f2f5ee; border-color: #f59e0b44; }
body.light #warnings-header { color: #b45309; border-color: #f59e0b22; }
body.light .warning-item { color: #333; }
body.light .warning-item:hover { background: #d0d6e2; }
body.light #replace-find, body.light #replace-with { background: #fff; color: #333; border-color: #c0c8d8; }

.empty-examples { position: absolute; left: 50%; bottom: 38%; transform: translateX(-50%); text-align: center; pointer-events: auto; z-index: 2; }
.empty-examples.hidden { display: none; }
.empty-hints { display: flex; gap: 16px; justify-content: center; margin-bottom: 14px; font-size: 11px; color: #ffffff20; }
.empty-hints kbd { font-size: 10px; padding: 1px 4px; background: #ffffff10; border-radius: 3px; }
body.light .empty-hints { color: #00000020; }
body.light .empty-hints kbd { background: #00000010; }
.empty-examples-label { font-size: 11px; color: #ffffff18; margin-bottom: 8px; }
.empty-examples-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.empty-ex-btn { background: #ffffff08; border: 1px solid #ffffff15; color: #ffffff30; border-radius: 6px; padding: 6px 14px; font-size: 12px; cursor: pointer; transition: all 0.15s; }
.empty-ex-btn:hover { background: #ffffff15; color: #ffffffaa; border-color: #ffffff40; }
body.light .empty-examples-label { color: #00000018; }
body.light .empty-ex-btn { background: #00000008; border-color: #00000015; color: #00000030; }
body.light .empty-ex-btn:hover { background: #00000015; color: #000000aa; border-color: #00000040; }

/* Selection info bar */
.selection-info {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: #16213eee;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 4px 14px;
  font-size: 11px;
  color: #8888aa;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}
.selection-info.visible { opacity: 1; }
body.light .selection-info { background: #e8ecf0ee; border-color: #c0c8d8; color: #666; }

/* Print styles */
@media print {
  body { background: #fff !important; color: #000 !important; overflow: visible !important; height: auto !important; }
  #toolbar, #tab-bar, #breadcrumb, #palette, #outline-panel, #properties-panel, .panel-resizer,
  .minimap, #toast, .dialog, .selection-info, .empty-hints, .empty-examples,
  #drop-overlay, .warning-badge, .autosave-indicator, .zoom-level { display: none !important; }
  #main { display: block !important; position: static !important; }
  #canvas { width: 100% !important; height: 80vh !important; }
  #minimap { display: none !important; }
}
