* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1200px 800px at 60% 40%, var(--bg1), var(--bg0));
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
}

:root {
  --bg0: #05070d;
  --bg1: #0a0f1c;
  --ink: #e8f0ff;
  --dim: #7f8aa8;
  --panel-bg: rgba(10, 16, 30, 0.55);
  --panel-border: rgba(120, 150, 220, 0.18);
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  z-index: 1;
  touch-action: none;
}

.panel {
  position: fixed;
  z-index: 10;
  backdrop-filter: blur(6px);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  padding: 10px 12px;
}

#hud {
  top: 18px;
  left: 18px;
  max-width: min(46vw, 560px);
}

#hud h1 {
  margin: 0 0 1px;
  font-size: 15px;
  letter-spacing: 0.3px;
  font-weight: 700;
}

#hud .sub {
  color: var(--dim);
  font-size: 11.5px;
  margin-bottom: 8px;
}

#step {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 3px;
}

#field {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.2px;
  line-height: 1.1;
  margin-bottom: 6px;
}

#chain {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #cdd9f5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-word;
}

#inspector {
  top: 18px;
  right: 18px;
  width: 240px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

/* Custom scrollbar for inspector panel */
#inspector::-webkit-scrollbar {
  width: 6px;
}

#inspector::-webkit-scrollbar-track {
  background: rgba(10, 16, 30, 0.3);
  border-radius: 3px;
}

#inspector::-webkit-scrollbar-thumb {
  background: rgba(120, 180, 255, 0.25);
  border-radius: 3px;
}

#inspector::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 180, 255, 0.4);
}

/* Custom scrollbar for tree panel to match inspector */
#tree-panel::-webkit-scrollbar,
#tree-list::-webkit-scrollbar {
  width: 6px;
}

#tree-panel::-webkit-scrollbar-track,
#tree-list::-webkit-scrollbar-track {
  background: rgba(10, 16, 30, 0.3);
  border-radius: 3px;
}

#tree-panel::-webkit-scrollbar-thumb,
#tree-list::-webkit-scrollbar-thumb {
  background: rgba(120, 180, 255, 0.25);
  border-radius: 3px;
}

#tree-panel::-webkit-scrollbar-thumb:hover,
#tree-list::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 180, 255, 0.4);
}

/* Custom scrollbar for Edit Connections panel and its scrollable lists */
#connection-panel::-webkit-scrollbar,
#connection-panel *::-webkit-scrollbar {
  width: 6px;
}

#connection-panel::-webkit-scrollbar-track,
#connection-panel *::-webkit-scrollbar-track {
  background: rgba(10, 16, 30, 0.3);
  border-radius: 3px;
}

#connection-panel::-webkit-scrollbar-thumb,
#connection-panel *::-webkit-scrollbar-thumb {
  background: rgba(120, 180, 255, 0.25);
  border-radius: 3px;
}

#connection-panel::-webkit-scrollbar-thumb:hover,
#connection-panel *::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 180, 255, 0.4);
}

#inspector label {
  display: block;
  font-size: 11px;
  color: var(--dim);
  margin: 6px 0 3px;
}

#inspector input,
#inspector select,
#inspector textarea {
  width: 100%;
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 170, 230, 0.25);
  border-radius: 6px;
  padding: 5px 7px;
  color: var(--ink);
  font-size: 12px;
}

#inspector select option {
  background: #0a0f1c;
  color: var(--ink);
}

#inspector textarea,
#tree-panel textarea,
#connection-panel textarea {
  min-height: 60px;
  resize: vertical;
}

#inspector button {
  margin-top: 6px;
  margin-right: 4px;
}

#inspector .danger,
#controls .danger,
#tree-panel .danger,
#connection-panel .danger,
#welcome-modal .danger {
  background: linear-gradient(
    135deg,
    rgba(40, 10, 10, 0.9) 0%,
    rgba(60, 20, 20, 0.9) 100%
  );
  border-color: rgba(255, 77, 77, 0.5);
  color: #ff6b6b;
}

#controls .danger:hover,
#inspector .danger:hover,
#tree-panel .danger:hover,
#connection-panel .danger:hover,
#welcome-modal .danger:hover {
  background: linear-gradient(
    135deg,
    rgba(60, 20, 20, 0.9) 0%,
    rgba(80, 30, 30, 0.9) 100%
  );
  border-color: rgba(255, 77, 77, 0.7);
  color: #ff8787;
  box-shadow:
    0 4px 12px rgba(255, 77, 77, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#controls .danger:active,
#inspector .danger:active,
#tree-panel .danger:active,
#connection-panel .danger:active,
#welcome-modal .danger:active {
  background: linear-gradient(
    135deg,
    rgba(40, 10, 10, 0.9) 0%,
    rgba(60, 20, 20, 0.9) 100%
  );
  border-color: rgba(255, 77, 77, 0.5);
  color: #ff6b6b;
}

/* Primary button style for main actions */
#tree-panel .primary,
#controls .primary,
#inspector .primary,
#connection-panel .primary,
#welcome-modal .primary {
  background: linear-gradient(
    135deg,
    rgba(77, 214, 255, 0.2) 0%,
    rgba(100, 180, 255, 0.15) 100%
  );
  border-color: rgba(77, 214, 255, 0.5);
  color: #4dd6ff;
  font-weight: 700;
}

#tree-panel .primary:hover,
#controls .primary:hover,
#inspector .primary:hover,
#connection-panel .primary:hover,
#welcome-modal .primary:hover {
  background: linear-gradient(
    135deg,
    rgba(77, 214, 255, 0.3) 0%,
    rgba(120, 200, 255, 0.25) 100%
  );
  border-color: rgba(77, 214, 255, 0.7);
  color: #7dd6ff;
  box-shadow:
    0 4px 16px rgba(77, 214, 255, 0.4),
    0 0 20px rgba(77, 214, 255, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#tree-panel .primary:active,
#controls .primary:active,
#inspector .primary:active,
#connection-panel .primary:active,
#welcome-modal .primary:active {
  background: linear-gradient(
    135deg,
    rgba(77, 214, 255, 0.25) 0%,
    rgba(100, 180, 255, 0.2) 100%
  );
  border-color: rgba(77, 214, 255, 0.6);
  color: #4dd6ff;
}

#controls {
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

#controls button,
#inspector button,
#tree-panel button,
#connection-panel button,
#welcome-modal button {
  appearance: none;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(
    135deg,
    rgba(10, 16, 30, 0.9) 0%,
    rgba(20, 30, 50, 0.9) 100%
  );
  border: 1px solid rgba(140, 170, 230, 0.3);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

#controls button:hover,
#inspector button:hover,
#tree-panel button:hover,
#connection-panel button:hover,
#welcome-modal button:hover {
  background: linear-gradient(
    135deg,
    rgba(30, 50, 80, 0.9) 0%,
    rgba(40, 70, 120, 0.9) 100%
  );
  border-color: rgba(140, 170, 230, 0.5);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

#controls button:active,
#inspector button:active,
#tree-panel button:active,
#connection-panel button:active,
#welcome-modal button:active {
  background: linear-gradient(
    135deg,
    rgba(20, 30, 50, 0.9) 0%,
    rgba(30, 50, 80, 0.9) 100%
  );
  border-color: rgba(140, 170, 230, 0.4);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transform: translateY(0);
}

#controls button:focus,
#inspector button:focus,
#tree-panel button:focus,
#connection-panel button:focus,
#welcome-modal button:focus {
  outline: none;
  border-color: rgba(100, 180, 255, 0.6);
  box-shadow:
    0 0 0 3px rgba(77, 214, 255, 0.2),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

#controls .sp,
#inspector .sp,
#tree-panel .sp,
#connection-panel .sp {
  color: var(--dim);
  font-size: 11px;
  min-width: 40px;
  text-align: center;
  background: linear-gradient(
    135deg,
    rgba(15, 25, 40, 0.9) 0%,
    rgba(25, 40, 60, 0.9) 100%
  );
  border: 1px solid rgba(100, 130, 180, 0.2);
}

#controls select,
#controls input,
#inspector select,
#inspector input,
#tree-panel select,
#tree-panel input,
#connection-panel select,
#connection-panel input {
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 170, 230, 0.25);
  border-radius: 6px;
  padding: 5px 7px;
  color: var(--ink);
  font-size: 11.5px;
}

#controls select option,
#inspector select option,
#tree-panel select option,
#connection-panel select option {
  background: #0a0f1c;
  color: var(--ink);
}

#legend {
  bottom: 18px;
  left: 18px;
  padding: 8px 10px;
  font-size: 11.5px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

#legend .ob-inspector-title {
  grid-column: 1 / -1;
  margin-bottom: 6px;
}

#legend .row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c7d2ee;
}

#legend .dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}

.hint {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--dim);
  font-size: 11px;
  opacity: 0.7;
  z-index: 5;
  pointer-events: none;
}

.ob-modal {
  position: fixed;
  z-index: 100;
  min-width: 240px;
  max-width: 320px;
  backdrop-filter: blur(8px);
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(120, 150, 220, 0.3);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  color: var(--ink);
}

.ob-modal-header {
  border-bottom: 1px solid rgba(120, 150, 220, 0.25);
  padding-bottom: 8px;
  margin-bottom: 8px;
  position: relative;
}

.ob-modal-title {
  font-size: 14px;
  font-weight: 700;
}

.ob-modal-actor {
  font-size: 11px;
  color: var(--dim);
  margin-top: 2px;
}

.ob-modal-content,
.ob-modal-hurdle {
  font-size: 12px;
  line-height: 1.5;
  color: #cdd9f5;
  margin-bottom: 8px;
}

.ob-modal-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--dim);
  margin-top: 10px;
  margin-bottom: 4px;
}

.ob-modal ul {
  margin: 0;
  padding-left: 16px;
  font-size: 12px;
  color: #cdd9f5;
}

.ob-modal li {
  margin-bottom: 3px;
}

.ob-modal-blocker {
  display: inline-block;
  background: rgba(255, 77, 77, 0.18);
  color: #ff9999;
  border: 1px solid rgba(255, 77, 77, 0.35);
  border-radius: 6px;
  padding: 2px 6px;
  margin: 2px 4px 2px 0;
  font-size: 11px;
}

.ob-modal-action {
  display: inline-block;
  background: rgba(120, 180, 255, 0.15);
  color: #a6d1ff;
  border: 1px solid rgba(120, 180, 255, 0.3);
  border-radius: 8px;
  padding: 5px 10px;
  margin: 4px 4px 0 0;
  font-size: 11px;
  text-decoration: none;
}

.ob-modal-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.1) 0%,
    rgba(200, 200, 200, 0.08) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--dim);
  font-size: 16px;
  cursor: pointer;
  z-index: 1000;
  padding: 6px 10px;
  border-radius: 6px;
  pointer-events: auto;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ob-modal-close:hover {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15) 0%,
    rgba(200, 200, 200, 0.12) 100%
  );
  border-color: rgba(255, 255, 255, 0.3);
  color: #b0b8c4;
  transform: scale(1.05);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.ob-modal-close:active {
  transform: scale(0.95);
}

.ob-panel-hint {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.5;
}

.ob-inspector-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
  color: #4dd6ff;
  letter-spacing: 0.3px;
}

#brain-info {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
}

.ob-meta {
  font-size: 10px;
  color: var(--dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
}

.ob-meta-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin: 2px 0 3px;
}

.ob-meta-desc {
  font-size: 11px;
  color: var(--dim);
  line-height: 1.4;
}

#tree-search {
  width: 100%;
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 170, 230, 0.25);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
  font-size: 12px;
  margin-bottom: 8px;
}

#tree-filter-btn {
  margin-bottom: 8px;
}

.ob-inspector-section {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--dim);
  margin-top: 12px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(120, 150, 220, 0.15);
  font-weight: 600;
}

/* Improved form styling for control panel */
#inspector label {
  display: block;
  font-size: 11px;
  color: #a0b8e0;
  margin: 8px 0 4px;
  font-weight: 500;
  letter-spacing: 0.2px;
}

#inspector input,
#inspector textarea,
#inspector select {
  background: linear-gradient(
    135deg,
    rgba(15, 25, 40, 0.9) 0%,
    rgba(25, 40, 60, 0.9) 100%
  );
  border: 1px solid rgba(140, 170, 230, 0.3);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 12px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
}

#inspector input:focus,
#inspector textarea:focus,
#inspector select:focus {
  outline: none;
  border-color: rgba(100, 180, 255, 0.6);
  box-shadow: 0 0 0 3px rgba(77, 214, 255, 0.15);
}

#inspector input::placeholder,
#inspector textarea::placeholder {
  color: rgba(127, 138, 168, 0.6);
}

#inspector textarea {
  resize: vertical;
  min-height: 60px;
}

.ob-inspector-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  margin: 4px 0;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 4px;
  border: 1px solid rgba(120, 150, 220, 0.1);
}

.ob-inspector-child:hover {
  background: rgba(255, 255, 255, 0.05);
}

/* Checkbox styling */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #a0b8e0;
  margin: 8px 0;
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4dd6ff;
  cursor: pointer;
  margin: 0;
}

.checkbox-label:hover {
  color: #c0d8f0;
}

/* Inline label for backwards compatibility */
label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #a0b8e0;
  margin: 8px 0;
  font-weight: 500;
}

label.inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4dd6ff;
  cursor: pointer;
  margin: 0;
}

.child-remove {
  background: transparent;
  border: none;
  color: #ff6b6b;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

.child-remove:hover {
  background: rgba(255, 107, 107, 0.15);
  color: #ff8787;
}

.ob-modal-stack {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
}

.ob-modal-stack .ob-modal {
  pointer-events: auto;
}

/* Custom scrollbar for all scrollable elements */
.ob-modal-stack::-webkit-scrollbar,
.ob-modal::-webkit-scrollbar {
  width: 6px;
}

.ob-modal-stack::-webkit-scrollbar-track,
.ob-modal::-webkit-scrollbar-track {
  background: rgba(10, 16, 30, 0.3);
  border-radius: 3px;
}

.ob-modal-stack::-webkit-scrollbar-thumb,
.ob-modal::-webkit-scrollbar-thumb {
  background: rgba(120, 180, 255, 0.25);
  border-radius: 3px;
}

.ob-modal-stack::-webkit-scrollbar-thumb:hover,
.ob-modal::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 180, 255, 0.4);
}

/* Additional select styling for consistency */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23cdd9f5%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 10px;
  padding-right: 24px;
}

select option {
  background: #0a0f1c;
  color: var(--ink);
}

/* Ensure input elements also have consistent dark background */
input {
  background: rgba(10, 16, 30, 0.85);
}

input::placeholder {
  color: var(--dim);
}

/* Tree selection panel styling */
.tree-item {
  transition:
    background-color 0.15s,
    border-color 0.15s;
}

.tree-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.tree-check {
  accent-color: #4dd6ff;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* Modern button variations for tree panel */
#tree-panel button {
  font-size: 11px;
  padding: 6px 12px;
}

#tree-panel #tree-select-all-btn,
#tree-panel #tree-deselect-all-btn {
  background: linear-gradient(
    135deg,
    rgba(60, 80, 120, 0.8) 0%,
    rgba(80, 100, 140, 0.8) 100%
  );
  border-color: rgba(120, 150, 220, 0.3);
  color: #a0b8e0;
}

#tree-panel #tree-select-all-btn:hover,
#tree-panel #tree-deselect-all-btn:hover {
  background: linear-gradient(
    135deg,
    rgba(80, 100, 140, 0.9) 0%,
    rgba(100, 120, 160, 0.9) 100%
  );
  border-color: rgba(120, 150, 220, 0.5);
  color: #c0d0f0;
}

/* Canvas wizard UI */
#top-toolbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(10, 16, 30, 0.7);
  border-bottom: 1px solid rgba(120, 150, 220, 0.18);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#top-toolbar .toolbar-group {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0 6px;
  border-right: 1px solid rgba(120, 150, 220, 0.15);
}

#top-toolbar .toolbar-group:last-of-type {
  border-right: none;
}

#top-toolbar button,
#top-toolbar select {
  appearance: none;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(
    135deg,
    rgba(10, 16, 30, 0.9) 0%,
    rgba(20, 30, 50, 0.9) 100%
  );
  border: 1px solid rgba(140, 170, 230, 0.3);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#top-toolbar button:hover,
#top-toolbar select:hover {
  background: linear-gradient(
    135deg,
    rgba(30, 50, 80, 0.9) 0%,
    rgba(40, 70, 120, 0.9) 100%
  );
  border-color: rgba(140, 170, 230, 0.5);
}

#top-toolbar button.primary {
  background: linear-gradient(
    135deg,
    rgba(77, 214, 255, 0.2) 0%,
    rgba(100, 180, 255, 0.15) 100%
  );
  border-color: rgba(77, 214, 255, 0.5);
  color: #4dd6ff;
}

#left-palette {
  position: fixed;
  top: 50px;
  bottom: 160px;
  left: 8px;
  width: 52px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 4px;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(10, 16, 30, 0.7);
  border: 1px solid rgba(120, 150, 220, 0.18);
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.45);
  overflow-y: auto;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 42px;
  padding: 5px 2px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: rgba(120, 150, 220, 0.15);
  border-color: rgba(120, 150, 220, 0.3);
}

.tool-btn.active {
  background: rgba(77, 214, 255, 0.18);
  border-color: rgba(77, 214, 255, 0.5);
  box-shadow: 0 0 8px rgba(77, 214, 255, 0.25);
}

.tool-icon {
  font-size: 14px;
  line-height: 1;
}

.tool-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.tool-label {
  font-size: 8px;
  color: var(--dim);
  text-transform: capitalize;
}

#bottom-timeline {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 150px;
  display: flex;
  gap: 12px;
  align-items: stretch;
  padding: 10px 12px;
  z-index: 100;
  backdrop-filter: blur(8px);
  background: rgba(10, 16, 30, 0.75);
  border-top: 1px solid rgba(120, 150, 220, 0.18);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

#bottom-timeline #hud {
  position: static;
  transform: none;
  flex: 0 0 260px;
  max-width: 320px;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  z-index: auto;
}

#bottom-timeline .timeline-controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  justify-content: center;
}

#bottom-timeline .timeline-controls button {
  appearance: none;
  cursor: pointer;
  color: var(--ink);
  background: linear-gradient(
    135deg,
    rgba(10, 16, 30, 0.9) 0%,
    rgba(20, 30, 50, 0.9) 100%
  );
  border: 1px solid rgba(140, 170, 230, 0.3);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s ease;
}

#bottom-timeline .timeline-controls button:hover {
  background: linear-gradient(
    135deg,
    rgba(30, 50, 80, 0.9) 0%,
    rgba(40, 70, 120, 0.9) 100%
  );
  border-color: rgba(140, 170, 230, 0.5);
}

#bottom-timeline .progress-bar {
  flex: 1;
  height: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  overflow: hidden;
  margin: auto 0;
  border: 1px solid rgba(120, 150, 220, 0.15);
}

#bottom-timeline .progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(
    90deg,
    rgba(77, 214, 255, 0.8),
    rgba(139, 92, 246, 0.8)
  );
  border-radius: 4px;
  transition: width 0.2s ease;
}

#bottom-timeline .animation-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  max-height: 130px;
  padding-left: 4px;
}

#bottom-timeline .animation-step {
  font-size: 10px;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  color: var(--dim);
}

#bottom-timeline .animation-step:hover {
  background: rgba(120, 150, 220, 0.15);
}

#bottom-timeline .animation-step.active {
  background: rgba(77, 214, 255, 0.2);
  color: #4dd6ff;
  border: 1px solid rgba(77, 214, 255, 0.4);
}

#start-wizard {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

#start-wizard .wizard-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 20px;
  cursor: pointer;
}

#start-wizard .wizard-tabs {
  display: flex;
  border-bottom: 1px solid rgba(120, 150, 220, 0.18);
}

#start-wizard .wizard-tab {
  flex: 1;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: none;
  color: var(--dim);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

#start-wizard .wizard-tab.active {
  background: rgba(77, 214, 255, 0.12);
  color: #4dd6ff;
  border-bottom: 2px solid #4dd6ff;
}

#start-wizard .wizard-body {
  padding: 14px;
  overflow-y: auto;
  max-height: 60vh;
}

#start-wizard .wizard-pane {
  display: none;
}

#start-wizard .wizard-pane.active {
  display: block;
}

#start-wizard label {
  display: block;
  font-size: 11px;
  color: var(--dim);
  margin: 8px 0 3px;
}

#start-wizard input,
#start-wizard select,
#start-wizard textarea {
  width: 100%;
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 170, 230, 0.25);
  border-radius: 6px;
  padding: 5px 7px;
  color: var(--ink);
  font-size: 12px;
}

#start-wizard .wizard-section-title {
  font-size: 12px;
  font-weight: 700;
  color: #4dd6ff;
  margin-bottom: 6px;
}

#start-wizard .wizard-list {
  font-size: 11px;
  max-height: 160px;
  overflow-y: auto;
}

#start-wizard .wizard-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 4px;
  cursor: pointer;
}

#start-wizard .wizard-list-item:hover {
  background: rgba(120, 150, 220, 0.15);
}

#start-wizard .wizard-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#start-wizard .wizard-chip {
  padding: 5px 10px;
  border-radius: 14px;
  background: rgba(77, 214, 255, 0.15);
  border: 1px solid rgba(77, 214, 255, 0.4);
  color: #4dd6ff;
  cursor: pointer;
  font-size: 11px;
}

#context-menu {
  min-width: 140px;
  padding: 4px 0;
  border-radius: 8px;
  background: rgba(10, 16, 30, 0.92);
}

#context-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

#context-menu li {
  padding: 7px 14px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ink);
}

#context-menu li:hover {
  background: rgba(120, 150, 220, 0.15);
}

#search-overlay,
#help-overlay {
  flex-direction: column;
}

#search-overlay .wizard-list,
#search-results .wizard-list-item {
  padding: 6px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  margin-bottom: 4px;
  cursor: pointer;
}

#search-results .wizard-list-item:hover {
  background: rgba(120, 150, 220, 0.15);
}

#search-input {
  width: 100%;
  background: rgba(10, 16, 30, 0.85);
  border: 1px solid rgba(140, 170, 230, 0.25);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--ink);
  font-size: 12px;
}

#inspector {
  top: 50px;
  right: 8px;
  width: 260px;
  max-height: calc(100vh - 170px);
  overflow-y: auto;
}

#inspector .inspector-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0;
}

#inspector .inspector-actions button {
  flex: 1;
  font-size: 10px;
  padding: 4px 6px;
}

#inspector .inspector-section {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
  margin: 10px 0 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid rgba(120, 150, 220, 0.15);
}

#inspector .inspector-advanced {
  display: none;
}

#inspector.advanced .inspector-advanced {
  display: block;
}

#inspector-toggle {
  margin-top: 6px;
  font-size: 10px;
}

#brain-info {
  margin-bottom: 8px;
}

#brain-info .brain-title {
  font-size: 14px;
  font-weight: 700;
  color: #4dd6ff;
}

#brain-info .brain-desc {
  font-size: 11px;
  color: var(--dim);
  margin: 2px 0 6px;
}

#brain-info .brain-meta {
  font-size: 10px;
  color: var(--dim);
  margin-bottom: 6px;
}

#top-toolbar select option {
  background: #0a0f1c;
  color: var(--ink);
}

#top-toolbar #brain-select {
  min-width: 140px;
}

#controls {
  display: none !important;
}

.hint {
  display: none !important;
}

#inspector button,
#start-wizard button,
#bottom-timeline button {
  margin-top: 0;
}

#inspector input,
#inspector select,
#inspector textarea {
  margin-bottom: 4px;
}

/* Mobile workspace navigation. Desktop controls remain the default above. */
#mobile-app-bar,
#mobile-navigation,
.mobile-sheet-header,
#mobile-scrim {
  display: none;
}

@media (max-width: 1024px) {
  :root {
    --mobile-top: calc(58px + env(safe-area-inset-top));
    --mobile-bottom: calc(70px + env(safe-area-inset-bottom));
  }

  body {
    overscroll-behavior: none;
  }

  button,
  [role="button"],
  select,
  input,
  textarea {
    min-width: 44px;
    min-height: 44px;
    font-size: 16px;
  }

  .wizard-list-item,
  .wizard-chip,
  .tree-item,
  #context-menu li,
  .animation-step {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  input[type="checkbox"],
  input[type="radio"] {
    min-width: 24px;
    min-height: 24px;
  }

  #mobile-app-bar {
    position: fixed;
    inset: 0 0 auto;
    z-index: 300;
    height: var(--mobile-top);
    padding: env(safe-area-inset-top) calc(10px + env(safe-area-inset-right)) 0
      calc(10px + env(safe-area-inset-left));
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    background: rgba(8, 14, 27, 0.94);
    border-bottom: 1px solid rgba(120, 150, 220, 0.24);
    backdrop-filter: blur(16px);
  }

  #mobile-app-bar button {
    min-width: 44px;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 18px;
  }

  #mobile-app-bar .mobile-text-btn {
    min-width: auto;
    padding: 0 10px;
    color: #4dd6ff;
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-app-title {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .mobile-app-title strong {
    overflow: hidden;
    font-size: 14px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-app-title span {
    color: var(--dim);
    font-size: 10px;
  }

  #mobile-navigation {
    position: fixed;
    inset: auto 0 0;
    z-index: 300;
    height: var(--mobile-bottom);
    padding: 6px 5px env(safe-area-inset-bottom);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: rgba(8, 14, 27, 0.96);
    border-top: 1px solid rgba(120, 150, 220, 0.24);
    backdrop-filter: blur(16px);
  }

  #mobile-navigation button {
    min-width: 0;
    min-height: 54px;
    padding: 3px;
    border: 0;
    border-radius: 10px;
    color: var(--dim);
    background: transparent;
    font-size: 9px;
    font-weight: 700;
  }

  #mobile-navigation button span {
    display: block;
    margin-bottom: 2px;
    color: var(--ink);
    font-size: 21px;
    line-height: 26px;
  }

  #mobile-navigation .mobile-play span {
    width: 42px;
    height: 42px;
    margin: -10px auto 1px;
    padding: 8px 0 0 3px;
    border-radius: 50%;
    color: #08101d;
    background: #4dd6ff;
    box-shadow: 0 4px 18px rgba(77, 214, 255, 0.35);
  }

  #mobile-scrim {
    position: fixed;
    inset: var(--mobile-top) 0 var(--mobile-bottom);
    z-index: 180;
    width: 100%;
    border: 0;
    background: rgba(0, 0, 0, 0.48);
  }

  #mobile-scrim:not([hidden]) {
    display: block;
  }

  .mobile-sheet-header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 42px;
    padding: 0 4px 8px;
    font-size: 14px;
  }

  .mobile-sheet-header button {
    width: 44px;
    height: 44px;
    border: 0;
    color: var(--dim);
    background: transparent;
    font-size: 24px;
  }

  #top-toolbar,
  #left-palette,
  #inspector {
    z-index: 200;
    visibility: hidden;
    pointer-events: none;
    transition: transform 180ms ease;
  }

  #top-toolbar {
    top: var(--mobile-top);
    bottom: var(--mobile-bottom);
    left: 0;
    right: auto;
    width: min(86vw, 340px);
    height: auto;
    padding: 14px;
    align-content: flex-start;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    background: rgba(8, 14, 27, 0.98);
    transform: translateX(-105%);
  }

  #top-toolbar .toolbar-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 0 0 10px;
    border: 0;
    border-bottom: 1px solid rgba(120, 150, 220, 0.14);
  }

  #top-toolbar button,
  #top-toolbar select {
    min-height: 44px;
    padding: 8px;
    font-size: 13px;
  }

  #top-toolbar #brain-select {
    width: 100%;
    min-width: 0;
  }

  body[data-mobile-panel="menu"] #top-toolbar,
  body[data-mobile-panel="tools"] #left-palette,
  body[data-mobile-panel="details"] #inspector {
    visibility: visible;
    pointer-events: auto;
    transform: translate(0);
  }

  #left-palette,
  #inspector {
    top: auto;
    bottom: var(--mobile-bottom);
    left: 0;
    right: 0;
    width: 100%;
    max-height: min(62vh, 520px);
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
    background: rgba(8, 14, 27, 0.98);
    transform: translateY(105%);
  }

  #left-palette {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    height: auto;
    padding: 10px 12px 14px;
    overflow-y: auto;
  }

  #left-palette .tool-btn {
    width: 100%;
    min-height: 58px;
    padding: 7px 2px;
  }

  #left-palette .tool-icon,
  #left-palette .tool-swatch {
    font-size: 18px;
  }

  #left-palette .tool-label {
    font-size: 10px;
  }

  #inspector {
    padding: 12px 16px 18px;
    overflow-y: auto;
  }

  #inspector input,
  #inspector select,
  #inspector textarea,
  #inspector button {
    min-height: 44px;
    font-size: 16px;
  }

  #bottom-timeline {
    top: var(--mobile-top);
    right: 10px;
    bottom: auto;
    left: 10px;
    height: auto;
    min-height: 64px;
    padding: 9px 12px;
    border: 1px solid rgba(120, 150, 220, 0.18);
    border-radius: 0 0 14px 14px;
    background: rgba(10, 16, 30, 0.82);
  }

  #bottom-timeline #hud {
    flex: 1;
    max-width: none;
  }

  #bottom-timeline #hud h1 {
    max-width: 72vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  #bottom-timeline #brain-desc,
  #bottom-timeline #chain,
  #bottom-timeline #zoom-level,
  #bottom-timeline .timeline-controls,
  #bottom-timeline .animation-list {
    display: none;
  }

  #bottom-timeline #field {
    margin: 2px 0 5px;
    overflow: hidden;
    font-size: 14px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  #bottom-timeline #step {
    margin: 0;
    font-size: 10px;
  }

  #bottom-timeline .progress-bar {
    position: absolute;
    inset: auto 12px 7px;
    width: auto;
    height: 4px;
    margin: 0;
  }

  #start-wizard {
    top: var(--mobile-top) !important;
    bottom: var(--mobile-bottom);
    left: 0 !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none;
    border: 0;
    border-radius: 0;
    transform: none !important;
  }

  #start-wizard .wizard-tabs {
    overflow-x: auto;
  }

  #start-wizard .wizard-tab {
    min-width: 80px;
    min-height: 48px;
  }

  #start-wizard .wizard-body {
    flex: 1;
    max-height: none;
    padding: 18px;
  }

  #start-wizard input,
  #start-wizard select,
  #start-wizard textarea,
  #start-wizard button {
    min-height: 46px;
    font-size: 16px;
  }

  #connection-panel,
  #tree-panel {
    top: var(--mobile-top) !important;
    bottom: var(--mobile-bottom);
    left: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    max-height: none !important;
    border-radius: 0;
    transform: none !important;
  }

  #node-modal-card,
  #edge-modal-card,
  #search-card,
  #help-card {
    width: calc(100% - 20px) !important;
    max-height: calc(100dvh - var(--mobile-top) - 20px) !important;
    padding: 16px !important;
  }
}

@media (min-width: 761px) and (max-width: 1024px) {
  #top-toolbar {
    width: min(52vw, 440px);
  }

  #left-palette {
    right: auto;
    left: 50%;
    width: min(680px, calc(100% - 48px));
    grid-template-columns: repeat(6, minmax(0, 1fr));
    border: 1px solid rgba(120, 150, 220, 0.18);
    border-bottom: 0;
    transform: translate(-50%, 105%);
  }

  body[data-mobile-panel="tools"] #left-palette {
    transform: translate(-50%, 0);
  }

  #inspector {
    right: 24px;
    left: auto;
    width: min(440px, calc(100% - 48px));
    border: 1px solid rgba(120, 150, 220, 0.18);
    border-bottom: 0;
  }

  #bottom-timeline {
    right: 24px;
    left: 24px;
  }

  #start-wizard {
    top: 50% !important;
    bottom: auto;
    left: 50% !important;
    width: min(680px, calc(100% - 48px)) !important;
    max-height: calc(100dvh - var(--mobile-top) - var(--mobile-bottom) - 32px);
    border: 1px solid rgba(120, 150, 220, 0.2);
    border-radius: 16px;
    transform: translate(-50%, -50%) !important;
  }
}

@media (max-width: 1024px) and (orientation: landscape) {
  :root {
    --mobile-bottom: calc(58px + env(safe-area-inset-bottom));
  }

  #bottom-timeline {
    right: auto;
    width: min(48vw, 420px);
  }

  #left-palette,
  #inspector {
    max-height: calc(100dvh - var(--mobile-top) - var(--mobile-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  #top-toolbar,
  #left-palette,
  #inspector {
    transition: none;
  }
}
