/* ===========================================================
   Better Spike — clean light theme
   Cream/white surfaces, yellow accent, a lot of breathing room.
   =========================================================== */

:root {
  --bg:        #f6f4ee;
  --surface:   #ffffff;
  --surface-2: #faf8f2;
  --surface-3: #f1ede2;
  --border:    #ebe7db;
  --border-2:  #d9d4c5;
  --text:      #1d1d1d;
  --text-dim:  #6c6c6c;
  --text-mute: #9a948a;
  --brand:     #ffd500;
  --brand-deep:#f5c500;
  --brand-ink: #2b1f00;
  --accent:    #ff7a00;
  --accent-2:  #2080d8;
  --good:      #2ec46b;
  --bad:       #e0353a;
  --warn:      #ff9b1f;

  --shadow-1: 0 1px 0 rgba(20,15,5,.04), 0 4px 16px rgba(20,15,5,.04);
  --shadow-2: 0 8px 28px rgba(20,15,5,.10);
  --shadow-pop: 0 1px 2px rgba(0,0,0,.05), 0 12px 36px rgba(0,0,0,.12);

  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;

  --rail-w: 80px;
  --inspector-w: 240px;
  --console-h: 0px;

  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  display: grid;
  grid-template-rows: 56px 1fr 32px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }

/* ====================================================================
   TOPBAR
   ==================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  z-index: 5;
}
.topbar-left, .topbar-right {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.topbar-right { gap: 10px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--brand);
  position: relative;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.06);
}
.brand-mark::before {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px; border-radius: 50%;
  background: #1a1300;
  box-shadow: inset 2px 2px 0 rgba(255,255,255,.18);
}
.brand-name {
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .1px;
}

.topbar-divider {
  width: 1px; height: 22px; background: var(--border);
}

.project-field {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: text;
  transition: background .15s, border-color .15s;
}
.project-field:hover { background: var(--surface-2); }
.project-field:focus-within { background: var(--surface-2); border-color: var(--border-2); }
.project-pencil {
  width: 14px; height: 14px;
  fill: none; stroke: var(--text-mute);
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
  transition: stroke .15s;
}
.project-field:hover .project-pencil { stroke: var(--text-dim); }
.project-name {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 14px;
  padding: 2px 4px;
  color: var(--text);
  outline: none;
  width: 200px;
  border-bottom: 1px dashed transparent;
  transition: border-color .15s;
}
.project-field:hover .project-name { border-bottom-color: var(--border-2); }
.project-field:focus-within .project-name { border-bottom-color: transparent; }
.save-indicator {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px;
  color: var(--text-mute);
  margin-left: 4px;
  opacity: 0;
  transition: opacity .2s;
}
.save-indicator.is-visible { opacity: 1; }
.save-indicator.is-saving { color: var(--text-mute); }
.save-indicator.is-saved  { color: var(--good); }
.save-ico { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.save-indicator.is-saving .save-ico { display: none; }

/* Hub status pill */
.hub-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-dim);
}
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot-off { background: var(--text-mute); }
.dot-on  { background: var(--good); box-shadow: 0 0 0 4px rgba(46,196,107,.18); }
.dot-warn { background: var(--warn); }

/* Slot picker */
.slot-picker {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12.5px;
}
.slot-picker label { color: var(--text-dim); }
.slot-picker select {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 4px 22px 4px 6px;
  cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%236c6c6c' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 4px center;
}

/* Run / icon buttons */
.run-group {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn .ico { width: 16px; height: 16px; }

.run-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 10px 7px 12px;
  border: 0; border-radius: 9px;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 700; font-size: 13px;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
  transition: filter .15s, transform .05s, opacity .15s;
}
.run-btn:hover { filter: brightness(1.04); }
.run-btn:active { transform: translateY(1px); }
.run-btn:disabled, .icon-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.run-btn:disabled:hover { filter: none; }
.run-btn .ico { width: 12px; height: 12px; }
.run-kbd {
  font-family: var(--mono);
  font-size: 10.5px;
  background: rgba(0,0,0,.12);
  color: rgba(43,31,0,.8);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 2px;
}
.info-ico {
  width: 13px; height: 13px;
  fill: none; stroke: currentColor;
  stroke-width: 1.75;
  opacity: .55;
  margin-left: 2px;
}
.py-toggle:hover .info-ico { opacity: .85; }

.ico {
  width: 18px; height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ====================================================================
   LAYOUT
   ==================================================================== */
.layout {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr var(--inspector-w);
  min-height: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  transition: grid-template-columns .25s ease;
}
body.inspector-collapsed { --inspector-w: 0px; }
body.inspector-collapsed .inspector-toggle svg { transform: rotate(180deg); }

/* Rail */
.rail {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.rail-tab {
  background: transparent;
  border: 0;
  padding: 10px 6px;
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: background .15s, color .15s;
}
.rail-tab .rail-ico {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor;
  stroke-width: 1.75;
  stroke-linejoin: round;
}
.rail-tab:hover { background: var(--surface-2); color: var(--text); }
.rail-tab-active {
  color: var(--brand-ink);
  background: var(--surface-3);
}
.rail-tab-active::before {
  content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.rail-num {
  position: absolute;
  top: 6px; right: 8px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-mute);
  background: var(--surface-3);
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1;
}
.rail-tab-active .rail-num {
  color: var(--brand-ink);
  background: var(--brand);
}

/* Canvas */
.canvas {
  min-width: 0; min-height: 0;
  position: relative;
  background: var(--bg);
  padding-bottom: var(--console-h);
  transition: padding-bottom .2s ease;
}
body.console-open { --console-h: 200px; }

.panel { display: none; height: 100%; min-height: 0; }
.panel-active { display: block; }
/* Scrollable tab contents — guard against the docked console covering rows. */
.fw-shell, .docs-shell, .card-grid { padding-bottom: 16px; }

/* ====================================================================
   BLOCKS PANEL
   ==================================================================== */
[data-panel="blocks"] { padding: 0; position: relative; }
#blocklyDiv { width: 100%; height: 100%; background: #fbfaf4; }

.empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  text-align: center;
  pointer-events: none;
  color: var(--text-mute);
  background: linear-gradient(180deg, transparent 0%, rgba(251,250,244,.4) 100%);
}
.empty-state[hidden] { display: none; }
.empty-state svg {
  width: 44px; height: 44px;
  fill: none; stroke: currentColor;
  stroke-width: 1.5; stroke-linejoin: round;
  opacity: .5;
}
.empty-state h4 { margin: 0; font-size: 15px; color: var(--text-dim); font-weight: 600; }
.empty-state p { margin: 0; max-width: 320px; font-size: 13px; }
.empty-state em { font-style: normal; background: rgba(255,213,0,.22); padding: 1px 6px; border-radius: 4px; color: var(--text); }

/* ====================================================================
   TOAST
   ==================================================================== */
.toast-wrap {
  position: fixed;
  top: 70px; right: 24px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-pop);
  pointer-events: auto;
  max-width: 320px;
  display: flex; align-items: center; gap: 10px;
  animation: toast-in .2s ease;
}
.toast-warn { background: #6b3a00; }
.toast-err  { background: #7a1f22; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Blockly chrome — light skin */
.blocklyToolboxDiv {
  background: var(--surface) !important;
  border-right: 1px solid var(--border) !important;
  padding: 8px 6px !important;
}
.blocklyTreeRow {
  border-radius: 8px !important;
  margin: 2px 0 !important;
  padding: 6px 8px 6px 14px !important;
  height: auto !important;
  line-height: 1.2 !important;
  border-left-style: solid !important;
  border-left-width: 5px !important;
  /* border-left-color is set inline by Blockly per category */
}
.blocklyTreeRow:not(.blocklyTreeSelected):hover {
  background-color: var(--surface-2) !important;
}
.blocklyTreeSelected, .blocklyTreeRowSelected {
  background-color: var(--surface-3) !important;
}
.blocklyTreeLabel {
  color: var(--text) !important;
  font-family: var(--sans) !important;
  font-size: 13px !important;
  font-weight: 500 !important;
}
.blocklyMainBackground { fill: #fbfaf4 !important; stroke: none !important; }
.blocklyFlyoutBackground {
  fill: var(--surface) !important;
  fill-opacity: 1 !important;
}
.blocklyFlyout { filter: drop-shadow(2px 0 6px rgba(0,0,0,.04)); }
.blocklyScrollbarHandle { fill: rgba(0,0,0,.18) !important; }

/* ====================================================================
   PYTHON PANEL
   ==================================================================== */
.py-shell { height: 100%; display: flex; flex-direction: column; background: var(--surface); }
.py-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.py-tabs { display: flex; gap: 4px; }
.py-tab {
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.py-tab-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}
.py-actions { display: flex; align-items: center; gap: 14px; }
.py-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.py-toggle input { accent-color: var(--brand); }

#pythonEditor {
  flex: 1; min-height: 0;
  resize: none; border: 0; outline: 0;
  font-family: var(--mono);
  font-size: 13px;
  padding: 18px 22px;
  line-height: 1.65;
  tab-size: 4;
  background: var(--surface);
  color: var(--text);
}
#pythonEditor:read-only { background: var(--surface-2); color: #555; }

/* ====================================================================
   CONNECT / FIRMWARE / DOCS
   ==================================================================== */
.card-grid {
  height: 100%; padding: 28px;
  overflow: auto;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  align-content: start;
}
.fw-shell {
  height: 100%; padding: 28px;
  overflow: auto;
  display: flex; flex-direction: column; gap: 16px;
  max-width: 760px;
}
.docs-shell {
  height: 100%; padding: 28px 36px;
  overflow: auto;
  max-width: 920px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: var(--shadow-1);
}
.card-pad { padding: 22px; }
.card-head {
  display: flex; gap: 14px; align-items: flex-start;
}
.card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-icon svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.card-icon-yellow { background: rgba(255,213,0,.18); color: #8a6800; }
.card-icon-blue   { background: rgba(32,128,216,.14); color: #155da3; }
.card-icon-mint   { background: rgba(46,196,107,.14); color: #1e7e44; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 0; color: var(--text-dim); font-size: 13px; }
.card-status {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.card-actions { display: flex; gap: 8px; }

.primary-btn {
  border: 0;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 700;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 9px;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
  transition: filter .15s;
}
.primary-btn:hover { filter: brightness(1.04); }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s;
}
.ghost-btn:hover { background: var(--surface-2); }
.ghost-btn:disabled { opacity: .5; cursor: not-allowed; }

.text-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 12.5px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.text-btn:hover { background: var(--surface-3); }
.text-btn-mute { color: var(--text-dim); }

.callout {
  display: flex; gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  border: 1px solid;
}
.callout-warn {
  background: #fff7e6;
  border-color: #ffd9a0;
  color: #74471a;
}
.callout-ico {
  width: 22px; height: 22px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round;
}

.form-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
}
.form-row label { color: var(--text-dim); min-width: 80px; }
.form-row select {
  font-family: inherit; font-size: 13px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.fw-progress { display: flex; flex-direction: column; gap: 6px; }
.fw-progress-bar {
  height: 8px; border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
  border: 1px solid var(--border);
}
.fw-progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .25s ease;
}
.fw-progress-label {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-dim);
}

/* Docs */
.docs-shell h2 { margin: 0 0 16px; font-size: 22px; }
.docs-shell h3 {
  margin: 28px 0 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-mute);
  font-weight: 700;
}
.docs-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.docs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.docs-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: #a14400;     /* darker than --accent (#ff7a00) for WCAG-AA on white */
  font-weight: 700;
}
.docs-card p { margin: 0; color: var(--text-dim); font-size: 13px; }
.docs-card em {
  font-style: normal;
  background: rgba(255,213,0,.22);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--text);
}
.cat-legend {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 8px;
}
.cat-chip {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text);
}
.cat-chip svg {
  width: 20px; height: 20px;
  fill: none;
  stroke: var(--c, var(--accent));
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
.cat-chip::before {
  content: ""; width: 4px; height: 18px; border-radius: 2px;
  background: var(--c, var(--accent));
  margin-left: -4px;
}

.kbd-grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.kbd-grid > div {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-dim);
}
.kbd-grid span { margin-left: auto; }
kbd {
  display: inline-block;
  padding: 2px 7px;
  font-family: var(--mono); font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  color: var(--text);
}

/* ====================================================================
   INSPECTOR (right pane)
   ==================================================================== */
.inspector {
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px 16px calc(18px + var(--console-h)) 16px;
  display: flex; flex-direction: column; gap: 22px;
  overflow: hidden auto;
  min-width: 0;
  transition: padding-bottom .2s ease;
}
.inspector-toggle {
  position: absolute;
  top: 50%;
  right: var(--inspector-w);
  transform: translate(50%, -50%);
  width: 22px; height: 56px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-mute);
  display: flex; align-items: center; justify-content: center;
  z-index: 4;
  box-shadow: var(--shadow-1);
  transition: right .25s ease;
}
.inspector-toggle:hover { color: var(--text); }
.inspector-toggle svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.75; transition: transform .25s; }
body.inspector-collapsed .inspector-toggle { transform: translate(0, -50%); }

.ins-section {}
.ins-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.ins-head h4 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-mute);
  font-weight: 700;
}
.ins-dot { width: 8px; height: 8px; border-radius: 50%; }
.ins-hint { font-size: 12px; color: var(--text-mute); margin: 0 0 10px; }
.ins-hint em { font-style: normal; color: var(--text); }

.kv {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px 12px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; color: var(--text); text-align: right; }
.kv-sensors dd { color: var(--accent-2); }

.key-map { display: flex; flex-direction: column; gap: 6px; }
.key-map .empty { color: var(--text-mute); font-style: italic; font-size: 12px; }
.rp-bind {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 12px;
}
.rp-bind .rp-bind-label {
  color: var(--text-dim);
  font-size: 11px;
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rp-bind.is-active {
  border-color: var(--brand);
  background: #fff8d6;
  box-shadow: 0 0 0 3px rgba(255,213,0,.18);
}

/* ====================================================================
   STATUS BAR + CONSOLE
   ==================================================================== */
.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  gap: 12px;
}
.status-cluster {
  display: inline-flex; align-items: center; gap: 8px;
}
.status-cluster-mute { color: var(--text-mute); }
.status-cluster strong { color: var(--text); font-weight: 600; }
.status-led {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-mute);
}
body.is-connected .status-led { background: var(--good); }
.status-sep { width: 1px; height: 12px; background: var(--border); }

.console-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: transparent;
  border: 0; border-radius: 6px;
  font: inherit;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.console-toggle svg {
  width: 12px; height: 12px;
  fill: none; stroke: currentColor;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
  transition: transform .2s;
}
.console-toggle:hover { background: var(--surface-2); color: var(--text); }
body.console-open .console-toggle svg { transform: rotate(180deg); }

.console {
  position: fixed;
  left: var(--rail-w); right: 0; bottom: 32px;
  height: 200px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
  z-index: 6;
}
.console[hidden] { display: none; }
.console-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface-2);
}
.console-head > div { display: flex; gap: 4px; }
#consoleOut {
  flex: 1; min-height: 0;
  margin: 0; padding: 12px 16px;
  overflow: auto;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  color: var(--text);
  background: var(--surface);
  white-space: pre-wrap; word-break: break-word;
}
#consoleOut .log-info { color: var(--text); }
#consoleOut .log-ok   { color: var(--good); }
#consoleOut .log-warn { color: #b07300; }
#consoleOut .log-err  { color: var(--bad); }
#consoleOut .log-tx   { color: var(--accent); }
#consoleOut .log-rx   { color: var(--accent-2); }
#consoleOut .log-time { color: var(--text-mute); margin-right: 10px; font-variant-numeric: tabular-nums; }

/* ====================================================================
   MODAL
   ==================================================================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(20,15,5,.42);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;     /* above Blockly's flyout (which uses ~70) */
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(880px, 92vw);
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-close {
  background: transparent; border: 0;
  width: 30px; height: 30px;
  border-radius: 8px;
  font-size: 20px; line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body {
  margin: 0; padding: 18px 22px;
  overflow: auto;
  font-family: var(--mono); font-size: 12.5px;
  color: var(--text);
  background: var(--surface-2);
  white-space: pre;
  tab-size: 4;
}

/* ====================================================================
   TEST BUTTON (topbar)
   ==================================================================== */
.test-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.test-btn:hover {
  background: var(--surface);
  border-color: var(--accent-2);
}
.test-btn .ico { width: 14px; height: 14px; color: var(--accent-2); }

/* ====================================================================
   LOCAL SIMULATOR
   ==================================================================== */
.sim-card {
  width: min(960px, 96vw);
  max-height: 92vh;
  background: var(--surface);
  display: flex; flex-direction: column;
}
.sim-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  gap: 14px;
}
.sim-head-left { display: flex; align-items: center; gap: 12px; }
.sim-head-left h3 { margin: 0; font-size: 16px; }
.sim-tag {
  font-size: 11px;
  background: var(--surface-3);
  color: var(--text-dim);
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: .2px;
}
.sim-head-actions { display: flex; align-items: center; gap: 8px; }
.sim-run-btn, .sim-stop-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 0; border-radius: 8px;
  font: inherit; font-weight: 700; font-size: 13px;
  cursor: pointer;
  transition: filter .15s, opacity .15s;
}
.sim-run-btn { background: var(--brand); color: var(--brand-ink); box-shadow: inset 0 -2px 0 rgba(0,0,0,.08); }
.sim-run-btn:hover { filter: brightness(1.04); }
.sim-stop-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 7px 10px; }
.sim-run-btn:disabled, .sim-stop-btn:disabled { opacity: .45; cursor: not-allowed; }
.sim-run-btn .ico { width: 11px; height: 11px; }
.sim-stop-btn .ico { width: 11px; height: 11px; }

.sim-body {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 16px;
  padding: 18px 20px;
  flex: 1; min-height: 0;
}

/* Hub illustration */
.sim-stage {
  background: linear-gradient(180deg, #f8f6ee 0%, #efece1 100%);
  border-radius: 14px;
  padding: 24px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
  border: 1px solid var(--border);
  position: relative;
}
.sim-hub {
  background: #ffd500;
  border-radius: 22px;
  padding: 18px 16px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  position: relative;
  box-shadow: 0 12px 32px rgba(0,0,0,.18), inset 0 -4px 0 rgba(0,0,0,.08);
}
.sim-hub-tab {
  position: absolute;
  top: -6px; left: 50%; transform: translateX(-50%);
  width: 60px; height: 12px;
  background: #2b1f00;
  border-radius: 4px 4px 0 0;
  opacity: .15;
}
.sim-hub-screen {
  background: #1a1a1a;
  border-radius: 14px;
  padding: 16px 14px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  position: relative;
}
.sim-status-pixel {
  position: absolute;
  top: 6px; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #2a2a2a;
  transition: background .2s, box-shadow .2s;
}
.sim-status-pixel.is-on {
  /* color set inline */
  box-shadow: 0 0 6px currentColor;
}
.sim-matrix {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.sim-led {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(255, 200, 0, 0.08);
  transition: background .12s, box-shadow .12s;
}
.sim-led.is-on {
  background: #ffd500;
  box-shadow: 0 0 8px rgba(255, 213, 0, .8);
}
.sim-buttons {
  display: flex; gap: 70px;
  margin-top: 4px;
}
.sim-hub-btn {
  width: 22px; height: 14px;
  background: #444;
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, transform .05s;
}
.sim-hub-btn:hover { background: #666; }
.sim-hub-btn:active, .sim-hub-btn.is-down { background: var(--brand); transform: translateY(1px); }

.sim-hub-foot {
  display: grid; grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
}
.sim-hub-port {
  background: #2b1f00;
  color: #ffd500;
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  text-align: center;
  padding: 4px 0;
  border-radius: 4px;
  opacity: .55;
  transition: opacity .15s, box-shadow .15s, background .15s;
}
.sim-hub-port.is-active {
  opacity: 1;
  background: #2080d8;
  color: #fff;
  box-shadow: 0 0 0 2px rgba(32,128,216,.25);
}

.sim-axes {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px;
  width: 100%; max-width: 320px;
}
.sim-axis {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}
.sim-axis label { color: var(--text-dim); }
.sim-axis span {
  font-family: var(--mono); font-size: 12px;
  color: var(--accent-2); font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  outline: none;
  min-width: 44px;
  text-align: right;
}
.sim-axis span.sim-axis-editable {
  cursor: text;
  border: 1px dashed transparent;
}
.sim-axis span.sim-axis-editable:hover {
  border-color: var(--border-2);
  background: var(--surface-2);
}
.sim-axis span.sim-axis-editable:focus {
  border-style: solid;
  border-color: var(--brand);
  background: var(--surface-2);
}
/* Timer is computed from real time — clearly mark as read-only */
.sim-axis #simTimer {
  cursor: default;
  color: var(--text-mute);
  font-style: italic;
}

/* Side panel: motors + sensors */
.sim-side {
  display: flex; flex-direction: column; gap: 16px;
  overflow: auto; min-height: 0;
}
.sim-section h4 {
  margin: 0 0 10px;
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-mute); font-weight: 700;
}
.sim-motors {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.sim-motor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  opacity: .4;
  transition: opacity .15s, border-color .15s, box-shadow .15s;
  position: relative;
}
.sim-motor.is-discovered { opacity: .9; }
.sim-motor.is-running {
  opacity: 1;
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(255,213,0,.2);
}
.sim-motor-port {
  font-weight: 700; font-size: 13px; color: var(--text-dim);
}
.sim-motor.is-running .sim-motor-port { color: var(--text); }
.sim-motor-gear {
  width: 36px; height: 36px;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, transparent 9px, var(--text-dim) 9.5px, var(--text-dim) 11px, transparent 11.5px),
    conic-gradient(var(--text-dim) 0 12.5%, transparent 12.5% 25%,
                   var(--text-dim) 25% 37.5%, transparent 37.5% 50%,
                   var(--text-dim) 50% 62.5%, transparent 62.5% 75%,
                   var(--text-dim) 75% 87.5%, transparent 87.5% 100%);
  position: relative;
  --gear-spin-dur: 0s;
  --gear-spin-dir: normal;
}
.sim-motor.is-running .sim-motor-gear {
  background:
    radial-gradient(circle at center, transparent 9px, var(--brand-deep) 9.5px, var(--brand-deep) 11px, transparent 11.5px),
    conic-gradient(var(--brand-deep) 0 12.5%, transparent 12.5% 25%,
                   var(--brand-deep) 25% 37.5%, transparent 37.5% 50%,
                   var(--brand-deep) 50% 62.5%, transparent 62.5% 75%,
                   var(--brand-deep) 75% 87.5%, transparent 87.5% 100%);
  animation: sim-gear-spin var(--gear-spin-dur) linear infinite;
  animation-direction: var(--gear-spin-dir);
}
@keyframes sim-gear-spin {
  to { transform: rotate(360deg); }
}
.sim-motor-speed {
  font-family: var(--mono); font-size: 11px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.sim-motor.is-running .sim-motor-speed { color: var(--text); }

.sim-sensors {
  display: grid; gap: 6px;
}
.sim-empty { color: var(--text-mute); font-size: 12px; font-style: italic; }
.sim-sensor {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}
.sim-sensor label { color: var(--text-dim); }
.sim-sensor input[type=range] {
  width: 100px;
  accent-color: var(--brand);
}
.sim-sensor-val {
  font-family: var(--mono); font-size: 12px;
  color: var(--accent-2); font-weight: 600;
  min-width: 56px; text-align: right;
}
.sim-sensor-color { display: flex; gap: 4px; }
.sim-sensor-color button {
  width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  cursor: pointer; padding: 0;
}
.sim-sensor-color button.is-on { box-shadow: 0 0 0 2px var(--brand); }

/* Trace log */
.sim-foot {
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex; flex-direction: column;
  max-height: 160px;
  min-height: 60px;
}
.sim-foot-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  font-size: 11px; color: var(--text-mute);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 700;
}
.sim-log {
  margin: 0;
  padding: 0 16px 12px;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.55;
  color: var(--text);
  overflow: auto;
  white-space: pre-wrap;
  flex: 1;
}
.sim-log .sim-log-time { color: var(--text-mute); margin-right: 8px; }
.sim-log .sim-log-warn { color: #b07300; }
.sim-log .sim-log-err  { color: var(--bad); }

/* Squeeze on narrow */
@media (max-width: 760px) {
  .sim-body { grid-template-columns: 1fr; }
  .sim-axes { grid-template-columns: repeat(4, 1fr); max-width: none; }
}

/* ====================================================================
   MAKE A BLOCK — Scratch-style custom procedure modal
   ==================================================================== */
.mb-card {
  width: min(720px, 92vw);
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-pop);
}
.mb-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 10px;
  border-bottom: 0;
}
.mb-head h3 {
  margin: 0; font-size: 15px; font-weight: 500;
  color: var(--text-dim);
}
.mb-head .modal-close {
  font-size: 22px;
  color: var(--text-mute);
}

.mb-body {
  padding: 0 22px 16px;
  position: relative;
}
.mb-trash {
  display: block;
  margin: 0 auto 6px;
  background: transparent; border: 0;
  color: var(--text-mute);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.mb-trash:hover { background: var(--surface-2); color: var(--bad); }

.mb-preview-row {
  display: flex; align-items: center; justify-content: center;
  padding: 28px 0;
  min-height: 120px;
}
.mb-block {
  display: inline-flex; align-items: center; gap: 8px;
  background: #ec5e85;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 0 0 4px rgba(236,94,133,.32);
  position: relative;
  flex-wrap: wrap;
  max-width: 80%;
}
.mb-block::after {
  content: "";
  position: absolute;
  right: -12px; top: 50%; transform: translateY(-50%);
  width: 0; height: 0;
  border-style: solid;
  border-width: 8px 0 8px 12px;
  border-color: transparent transparent transparent #ec5e85;
}
.mb-name, .mb-part-input {
  background: #fff;
  color: #1d1d1d;
  border: 0;
  padding: 4px 10px;
  border-radius: 4px;
  font: inherit;
  font-size: 14px;
  outline: 2px solid #5a8be8;
  width: 130px;
}
.mb-part {
  display: inline-flex; align-items: center; gap: 6px;
  position: relative;
}
.mb-part-num .mb-part-input,
.mb-part-bool .mb-part-input {
  border-radius: 14px;
  outline: 2px solid #fff;
  background: rgba(255,255,255,.92);
  color: #c44867;
  font-weight: 600;
  width: 90px;
  text-align: center;
}
.mb-part-bool .mb-part-input {
  border-radius: 4px;
  transform: skewX(-12deg);
  width: 80px;
}
.mb-part-bool .mb-part-input::placeholder { transform: skewX(12deg); }
.mb-part-label .mb-part-input {
  background: transparent;
  outline: 0;
  color: #fff;
  width: auto;
  min-width: 50px;
  padding: 4px 4px;
  border-bottom: 1px dashed rgba(255,255,255,.5);
  border-radius: 0;
}
.mb-part-del {
  position: absolute; top: -8px; right: -8px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  color: #c44867;
  border: 1px solid rgba(0,0,0,.08);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center; justify-content: center;
  padding: 0;
}
.mb-part:hover .mb-part-del { display: inline-flex; }

.mb-divider {
  height: 4px;
  width: min(440px, 80%);
  margin: 8px auto 24px;
  background: #d4d4d4;
  border-radius: 2px;
}

.mb-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  padding: 0 16px 8px;
}
.mb-add {
  background: transparent;
  border: 0;
  padding: 12px 8px 8px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  border-radius: 12px;
  transition: background .15s;
  font-family: inherit;
}
.mb-add:hover { background: var(--surface-2); }
.mb-add:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.mb-add-shape {
  width: 64px; height: 64px;
  background: #ec5e85;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.mb-add-shape-num {
  width: 36px; height: 22px;
  background: #d24c75;
  border-radius: 999px;
}
.mb-add-shape-bool {
  width: 28px; height: 28px;
  background: #d24c75;
  transform: rotate(45deg);
  border-radius: 4px;
}
.mb-add-shape-text {
  color: #fff;
  font-size: 14px;
  font-weight: 400;
  font-style: italic;
}

.mb-add-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}
.mb-add-sub {
  font-size: 12px;
  color: var(--text-dim);
  min-height: 1em;
}

.mb-foot {
  display: flex;
  border-top: 1px solid var(--border);
  margin: 12px 0 0;
}
.mb-foot-btn {
  flex: 1;
  padding: 18px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: #2080d8;
  letter-spacing: 1px;
  font-family: inherit;
  transition: background .15s;
}
.mb-foot-btn:hover { background: var(--surface-2); }
.mb-foot-save { border-left: 1px solid var(--border); }

/* ====================================================================
   RESPONSIVE
   ==================================================================== */
@media (max-width: 1100px) {
  :root { --inspector-w: 0px; }
  .inspector { display: none; }
  .inspector-toggle { display: none; }
}
@media (max-width: 720px) {
  :root { --rail-w: 56px; }
  .project-name, .topbar-divider, .slot-picker label { display: none; }
  .rail-tab span { display: none; }
  .console { left: var(--rail-w); }
  .brand-name { display: none; }
}
