/* Layout: editor left (Blockly), simulator right (3D view over hub panel). Stacks on narrow screens. */
:root {
  --bg: #F6F7FA;
  --panel: #FFFFFF;
  --line: #DEE3EB;
  --fg: #1E2430;
  --muted: #6B7483;
  --accent: #0A8DFF;
  --run: #2FC25B;
  --stop: #E8232A;
  --hub-yellow: #FFD500;
  --led: #FFD400;
  --radius: 14px;
  --font: "Nunito", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { color-scheme: light; }
/* Blockly's inline number/text editor has no background of its own; pin it light so no host or OS dark theme turns it black. */
.blocklyWidgetDiv { color-scheme: light; }
.blocklyHtmlInput { background: #fff !important; color: var(--fg) !important; color-scheme: light; }   /* the page is light; form controls must not pick up the OS dark theme */
body { font-family: var(--font); font-weight: 600; color: var(--fg); background: var(--bg); display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(10,141,255,.45); outline-offset: 2px; }

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px)); background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; letter-spacing: .01em; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--hub-yellow); color: #1E2430; display: grid; place-items: center; font-weight: 800; }
.project-name { flex: 1 1 160px; min-width: 120px; max-width: 320px; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; font: inherit; font-weight: 700; background: var(--bg); color: var(--fg); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.tb { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 7px 12px; font-weight: 700; font-size: 13px; }
.tb:hover { background: var(--bg); }
.tb.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb.primary:hover { filter: brightness(1.05); }
.menu-wrap { position: relative; }
.popover { position: absolute; right: 0; top: calc(100% + 6px); width: min(340px, 90vw); max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(30,36,48,.16); padding: 8px; z-index: 50; }
.popover h3 { margin: 4px 8px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.proj { display: flex; align-items: stretch; border-radius: 10px; }
.proj.current { background: #EAF4FF; }
.proj .open { flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; border: 0; background: none; padding: 8px 10px; text-align: left; border-radius: 10px; }
.proj .open:hover { background: var(--bg); }
.proj .pn { font-weight: 800; }
.proj .pd { font-size: 11px; color: var(--muted); }
.proj .del { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 0 10px; border-radius: 10px; }
.proj .del:hover { color: var(--stop); background: #FDECEC; }

/* ---- main layout ---- */
.layout { flex: 1; display: flex; min-height: 0; }
.editor { flex: 1 1 60%; min-width: 0; position: relative; }
#blocklyDiv { position: absolute; inset: 0; }
.editor-bar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: space-between; padding: 0 18px 16px 18px; pointer-events: none; z-index: 5; }
.editor-bar > * { pointer-events: auto; }
.ws-tools { display: flex; gap: 6px; }
.wt { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.95); font-size: 18px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(30,36,48,.08); }
.wt:hover { background: #fff; border-color: #B9C0CC; }
.run-controls { display: flex; gap: 10px; }
.round { width: 58px; height: 58px; border-radius: 50%; border: 0; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(30,36,48,.18); transition: transform .12s ease; }
.round:active { transform: scale(.94); }
.round:disabled { opacity: .45; cursor: default; box-shadow: none; }
.round.run { background: var(--run); }
.round.run span { width: 0; height: 0; border-left: 20px solid #fff; border-top: 12px solid transparent; border-bottom: 12px solid transparent; margin-left: 5px; }
.round.stop { background: #fff; }
.round.stop span { width: 20px; height: 20px; background: #1E2430; border-radius: 3px; }
body.running .round.stop span { background: var(--stop); }
.round.step, .round.back { background: #fff; }
.round.back span { width: 22px; height: 22px; background: no-repeat center / contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M19 4L9 12l10 8z' fill='%231E2430'/><rect x='4' y='4' width='3' height='16' rx='1' fill='%231E2430'/></svg>"); }
.round.step span { width: 22px; height: 22px; background: no-repeat center / contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M5 4l10 8-10 8z' fill='%231E2430'/><rect x='17' y='4' width='3' height='16' rx='1' fill='%231E2430'/></svg>"); }
.round.step.active { background: var(--accent); box-shadow: 0 6px 16px rgba(11,95,196,.3); }
.round.step.active span { background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M5 4l10 8-10 8z' fill='white'/><rect x='17' y='4' width='3' height='16' rx='1' fill='white'/></svg>"); }

.splitter { flex: 0 0 8px; cursor: col-resize; background: var(--line); position: relative; touch-action: none; user-select: none; }
.splitter::after { content: ""; position: absolute; left: 2px; top: 50%; width: 4px; height: 36px; margin-top: -18px; border-radius: 2px; background: #AEB5C2; }
.splitter:hover, .splitter.active, .splitter:focus-visible { background: #C9D2E0; outline: none; }
body.resizing { cursor: col-resize; user-select: none; }
body.resizing iframe, body.resizing canvas { pointer-events: none; }
.simpane { flex: 0 0 clamp(320px, min(56%, 100% - 460px), 1200px); min-width: 280px; display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--panel); min-height: 0; }
.view3d-wrap { position: relative; flex: 1 1 55%; min-height: 220px; }
#view3d { position: absolute; inset: 0; }
#view3d canvas { display: block; touch-action: none; }
.view-tools { position: absolute; left: 10px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.vt { border: 1px solid rgba(30,36,48,.12); background: rgba(255,255,255,.92); border-radius: 9px; padding: 5px 9px; font-size: 12px; font-weight: 700; backdrop-filter: blur(4px); }
.vt.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.vt.launch.ending { background: #B3261E; border-color: #B3261E; color: #fff; }
select.vt { cursor: pointer; color: var(--fg); }
.models-panel { position: absolute; left: 10px; top: 52px; z-index: 6; width: 250px; background: rgba(255,255,255,.97); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(30,36,48,.18); padding: 8px 10px; font-size: 12px; backdrop-filter: blur(6px); }
.models-panel h4 { margin: 0 0 6px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.models-panel h4 span { flex: 1; }
.models-panel h4 button { border: 1px solid var(--line); background: #F2F4F8; border-radius: 7px; font: inherit; font-weight: 700; font-size: 11px; padding: 2px 7px; cursor: pointer; }
.models-panel label { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.models-panel label .m { color: var(--muted); font-weight: 800; width: 28px; }
.models-panel label.off { color: var(--muted); }
.models-panel input { accent-color: var(--accent); }
.vt[hidden], .score-chip[hidden] { display: none; }
/* the program to run and the attachment shelf, in the view tools row */
.match-bar { display: contents; }
.match-bar[hidden] { display: none; }
.match-bar label.vt { display: flex; align-items: center; gap: 6px; padding: 2px 4px 2px 9px; }
.match-bar select { font: inherit; font-weight: 700; border: 0; background: transparent; max-width: 200px; color: var(--fg); }
.shelf.vt { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 2px 4px 2px 9px; }
.shelf button { font: inherit; font-weight: 700; font-size: 12px; border: 1px solid rgba(30,36,48,.15); background: #fff; border-radius: 7px; padding: 2px 8px; cursor: pointer; }
.shelf button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.shelf button:disabled, .match-bar select:disabled { opacity: .5; cursor: default; }
.mat-readout { position: absolute; left: 10px; top: 92px; z-index: 4; pointer-events: none; background: rgba(30,36,48,.82); color: #fff; border-radius: 8px; padding: 5px 9px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.35; backdrop-filter: blur(4px); }
.mat-readout small { display: block; font-weight: 600; color: #D6DAE3; }
.mat-readout b { color: #FFD500; }
.cal-readout { position: absolute; right: 10px; top: 52px; z-index: 3; pointer-events: none; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.4; box-shadow: 0 4px 14px rgba(30,36,48,.12); }
.cal-readout small { display: block; font-weight: 600; color: #4B5563; }
a.vt { text-decoration: none; display: inline-flex; align-items: center; }
.view-hint { position: absolute; left: 10px; right: 10px; bottom: 6px; margin: 0; font-size: 11px; color: #4B5563; background: rgba(255,255,255,.75); border-radius: 8px; padding: 4px 8px; pointer-events: none; }

/* ---- hub panel ---- */
/* The hub is a small fixed-size instrument panel over the bottom-left of the 3D view. */
#hubPanel { position: absolute; right: 10px; bottom: 34px; width: 430px; max-width: calc(100% - 20px); background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(30,36,48,.16); backdrop-filter: blur(6px); z-index: 2; }
/* fold the panel down to a tab in the corner */
.hub-toggle { position: absolute; right: 6px; top: 6px; width: 22px; height: 22px; border: 0; border-radius: 6px; background: transparent; color: #6B7280; cursor: pointer; z-index: 1; }
.hub-toggle::before { content: ""; position: absolute; left: 7px; top: 5px; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
.hub-toggle:hover { background: rgba(30,36,48,.08); color: var(--fg); }
#hubPanel.folded { width: auto; }
#hubPanel.folded .hub { display: none; }
#hubPanel.folded .hub-toggle { position: static; display: block; width: auto; height: auto; padding: 6px 12px 6px 28px; font: 700 12px var(--font); color: var(--fg); }
#hubPanel.folded .hub-toggle::after { content: "Hub"; }
#hubPanel.folded .hub-toggle::before { left: 11px; top: 11px; transform: rotate(-135deg); }
.hub { display: flex; gap: 8px; padding: 7px 8px; align-items: stretch; }
.hub-face { flex: 0 0 86px; background: #F4F4F4; border: 2px solid #D6DBE4; border-radius: 12px; padding: 5px 6px 6px; display: flex; flex-direction: column; align-items: center; gap: 5px; box-shadow: inset 0 0 0 3px var(--hub-yellow); }
.hub-top { display: none; }
.hub-dot { width: 8px; height: 8px; border-radius: 50%; background: #2FC25B; }
.hub-matrix { display: grid; grid-template-columns: repeat(5, 8px); gap: 3px; padding: 5px; border-radius: 6px; }
.hub-matrix .px { width: 8px; height: 8px; border-radius: 2px; background: transparent; }
/* white on the hub's white top: a hairline edge shows a lit LED */
.hub-matrix .px.on { background: #fff; box-shadow: inset 0 0 0 1px rgba(30,36,48,.18); }
.hub-buttons { display: flex; gap: 5px; align-items: center; }
.hub-btn { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #C9CED8; background: #F1F3F7; font-size: 9px; color: #4B5563; display: grid; place-items: center; touch-action: none; user-select: none; -webkit-user-select: none; padding: 0; }
.hub-btn.down { background: #C9CED8; transform: scale(.94); }
.hub-btn.hub-center { width: 26px; height: 26px; background: #fff; border-color: #B9C0CC; }
.hub-btn.hub-center.lit { box-shadow: 0 0 10px 2px currentColor; }
.hub-readouts { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; justify-content: center; }
.ro-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
/* the top row stops short of the fold caret in the panel's corner */
#hubPanel .ro-row { margin-right: 26px; }
.ro-row .ro.hide { display: none; }
.ro.match .v { color: #1B7F3B; }
.ro.match.late .v { color: #B7791F; }
.ro.match.over .v { color: var(--stop); }
.vt.launch { background: var(--run); color: #fff; border-color: var(--run); font-weight: 800; }
.ro { background: #F6F7FA; border: 1px solid var(--line); border-radius: 7px; padding: 2px 7px; display: flex; align-items: baseline; gap: 5px; min-width: 0; }
.ro .k { font-size: 9px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ro .v { font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; margin-left: auto; }
.ro .k, .ro .v { white-space: nowrap; }   /* a reading never wraps: tilt's two angles stay on one line */
.ro .v.tight { letter-spacing: -.02em; font-size: 11px; }
.ports { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.port { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font-size: 11px; display: flex; gap: 6px; align-items: center; min-width: 0; }
.port b { font-size: 11px; width: 18px; height: 18px; border-radius: 5px; background: #1E2430; color: #fff; display: grid; place-items: center; flex: none; }
.port .type { color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-size: 8.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.port .v { font-variant-numeric: tabular-nums; white-space: nowrap; display: flex; align-items: center; gap: 4px; flex: none; }
.port .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); }
.port[data-type="color sensor"] b { background: #3DB7E8; }
.hub-source { display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-right: 26px; }
.hub-source[hidden] { display: none; }
.hub-source button { border: 0; background: #fff; font: 700 10px var(--font); padding: 3px 8px; color: var(--muted); cursor: pointer; }
.hub-source button.on { background: #1E2430; color: #fff; }
#hubPanel.real .hub-source button.on { background: #1B7F3B; }
.port.mismatch { border-color: #E3A008; background: #FFF8E6; }
.port.mismatch b { background: #E3A008; }
#hubPanel.real .ro.match .v { color: var(--fg); }
.port[data-type="distance"] b { background: #3DB7E8; }
.port[data-type="force sensor"] b { background: #3DB7E8; }
.port[data-type="left wheel"] b, .port[data-type="right wheel"] b { background: #FF4FA8; }

/* ---- toasts / modal ---- */
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; width: min(520px, calc(100vw - 32px)); }
.toast { background: #1E2430; color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; opacity: 0; transform: translateY(8px); transition: all .25s ease; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { opacity: 1; transform: none; }
.toast.warn { background: #B7791F; }
.toast.error { background: var(--stop); }
.spike-modal-back { position: fixed; inset: 0; background: rgba(30,36,48,.45); display: grid; place-items: center; z-index: 200; padding: 16px; }
.spike-modal { background: #fff; border-radius: 16px; padding: 18px; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 12px; }
.spike-modal h3 { margin: 0; }
.spike-modal .msg { margin: 0; font-size: 15px; }
.spike-modal .hint { margin: 0; font-size: 13px; color: var(--muted); }
.spike-modal .in { border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; font: inherit; font-weight: 700; }
.spike-modal .form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.spike-modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.spike-modal select { font: inherit; font-weight: 700; color: var(--fg); padding: 7px; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.spike-modal .btns { display: flex; justify-content: flex-end; gap: 8px; }
.spike-modal .btns button { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 16px; font-weight: 700; }
.spike-modal .btns .ok { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---- Blockly overrides ---- */
.blocklyToolboxDiv { background: #fff !important; border-right: 1px solid var(--line); padding: 6px 0 !important; }
.blocklyToolboxDiv { display: flex !important; flex-direction: column; }
/* continuous palette: category headers in the flyout, SPIKE-style */
.zelos-renderer.spike-theme .blocklyFlyoutLabel .blocklyFlyoutLabelText { font: 800 26px var(--font); }   /* drawn at the flyout's 0.7 scale; outranks the theme's label rule */
.blocklyFlyoutBackground { fill: #F6F7FA; }
.blocklyToolboxDiv .blocklyTreeRow { padding: 3px 0 !important; }
.blocklyToolboxDiv .blocklyToolboxContents, .blocklyToolboxDiv .blocklyToolboxCategoryGroup { flex: 1 1 auto; }
.toolbox-gh { flex: 0 0 auto; display: flex; justify-content: center; padding: 10px 0 10px; color: var(--muted); text-decoration: none; }
.toolbox-gh:hover { color: var(--fg); }
.blocklyToolboxCategory { margin: 0 !important; }
.blocklyTreeRow { display: flex; flex-direction: column; align-items: center; gap: 4px; height: auto !important; line-height: 1.1 !important; padding: 7px 2px !important; margin: 2px 5px !important; border-radius: 10px; cursor: pointer; border-left: 0 !important; width: 72px; }
.blocklyTreeRow:hover, .blocklyTreeRow.spikeSelected { background: #EEF1F6 !important; }
.blocklyTreeRowContentContainer { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.spikeCatDot { width: 22px; height: 22px; border-radius: 50%; display: block; box-shadow: inset 0 -2px 0 rgba(0,0,0,.15); }
.blocklyTreeLabel { font: 700 9.5px/1.1 var(--font) !important; text-transform: uppercase; letter-spacing: .03em; color: #5B6472 !important; white-space: normal !important; text-align: center; cursor: pointer; }
.blocklyTreeRow.spikeSelected .blocklyTreeLabel { color: var(--fg) !important; }
.blocklyFlyoutButton { cursor: pointer; }
.blocklyFlyoutButton rect, .blocklyFlyoutButton .blocklyFlyoutButtonBackground { fill: #FF6680 !important; stroke: #D03A58 !important; stroke-width: 1.5; rx: 10; ry: 10; }
.blocklyFlyoutButton:hover rect, .blocklyFlyoutButton:hover .blocklyFlyoutButtonBackground { fill: #F04F6C !important; }
.blocklyFlyoutButton .blocklyText { fill: #fff !important; font-weight: 800; }
.blocklyMainBackground { stroke: none; }
.blocklyText { font-family: var(--font) !important; }
.spike-running { filter: drop-shadow(0 0 6px #FFD400) drop-shadow(0 0 2px #FFD400); }
/* the block a running program is on: a white outline with a soft shadow that moves down the stack */
.spike-active > .blocklyPath { stroke: #fff; stroke-width: 4px; paint-order: stroke; filter: drop-shadow(0 0 4px rgba(30,36,48,.55)); }
.spike-matrix-editor { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.spike-matrix-editor .grid { display: grid; grid-template-columns: repeat(5, 30px); gap: 4px; }
.spike-matrix-editor .cell { width: 30px; height: 30px; border-radius: 7px; border: 0; background: rgba(0,0,0,.35); padding: 0; }
.spike-matrix-editor .cell.on { background: var(--led); box-shadow: 0 0 6px rgba(255,212,0,.8); }
.spike-matrix-editor .tools { display: flex; gap: 6px; }
.blocklyDropDownDiv:has(.spike-steer-editor) .blocklyDropDownContent { max-height: 420px; }   /* Blockly caps dropdowns at 300px; the SPIKE dial is taller */
.spike-steer-editor { padding: 12px 14px 10px; display: flex; flex-direction: column; align-items: center; gap: 6px; user-select: none; }
.spike-steer-editor .dial { touch-action: none; cursor: pointer; display: block; }
.spike-steer-editor .bg { fill: #BD1481; }
.spike-steer-editor .wedge { fill: rgba(255,255,255,.2); }
.spike-steer-editor .tick { stroke: rgba(255,255,255,.75); stroke-width: 2.5; stroke-linecap: round; }
.spike-steer-editor .ref, .spike-steer-editor .pointer { stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.spike-steer-editor .wheel-face { fill: #fff; }
.spike-steer-editor .window { fill: #CE4FA1; }
.spike-steer-editor .hub { fill: #CF168D; }
.spike-steer-editor .knob .halo { fill: rgba(255,255,255,.3); }
.spike-steer-editor .knob circle:not(.halo) { fill: #fff; }
.spike-steer-editor .knob .arrow { fill: none; stroke: #A6257C; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.spike-steer-editor .row { display: flex; align-items: center; gap: 10px; width: 100%; justify-content: space-between; }
.spike-steer-editor .row button { width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55); background: transparent; color: rgba(255,255,255,.9); font-size: 24px; font-weight: 500; line-height: 1; padding: 0; cursor: pointer; }
.spike-steer-editor .row button:active { background: rgba(255,255,255,.2); }
.spike-steer-editor .readout { color: #fff; font-weight: 600; font-size: 20px; }
.model-card .note { margin: 4px 0 0; font-size: 11px; color: var(--muted, #667); }
.model-card .nest-setup { display: flex; align-items: center; gap: 6px; margin: 6px 0; font-size: 12px; font-weight: 600; }
.model-card .nest-setup select { flex: 1; min-width: 0; font: inherit; font-weight: 500; }
.spike-matrix-editor .tools button { flex: 1; border: 0; border-radius: 8px; padding: 6px 4px; background: rgba(255,255,255,.9); font-size: 12px; font-weight: 700; }

/* ---- narrow screens: sim on top, blocks below ---- */
@media (max-width: 900px) {
  .layout { flex-direction: column-reverse; }
  .simpane { flex: 0 0 46vh; min-width: 0; border-left: 0; border-bottom: 1px solid var(--line); flex-direction: row; }
  .splitter { flex-basis: 10px; cursor: row-resize; }
  .splitter::after { left: 50%; top: 3px; width: 36px; height: 4px; margin: 0 0 0 -18px; }
  body.resizing { cursor: row-resize; }
  .view3d-wrap { flex: 1 1 55%; min-height: 0; }
  #hubPanel { width: 300px; bottom: 10px; }
  .hub-face { display: none; }
  .view-hint { display: none; }
  .editor { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: reduce) { .toast, .round { transition: none; } }

/* Touch controls, gamepad style: a thumbstick for driving on the left, two arm buttons on the right. Only on touch
   screens, and only while nothing is running. */
.touch-pad { display: none; position: absolute; left: 14px; right: 14px; bottom: 34px; z-index: 3; justify-content: space-between; align-items: flex-end; pointer-events: none; user-select: none; -webkit-user-select: none; }
.touch-pad > * { pointer-events: auto; touch-action: none; }
.stick { position: relative; width: 132px; height: 132px; border-radius: 50%; background: radial-gradient(circle at 50% 45%, rgba(30,36,48,.28), rgba(30,36,48,.5)); box-shadow: inset 0 0 0 3px rgba(255,255,255,.35), 0 8px 20px rgba(30,36,48,.25); backdrop-filter: blur(3px); }
.stick::before { content: ""; position: absolute; inset: 14px; border-radius: 50%; border: 2px dashed rgba(255,255,255,.3); }
.stick-knob { position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #fff, #D6DBE4 70%, #B9C0CC); box-shadow: 0 4px 10px rgba(0,0,0,.35), inset 0 -3px 0 rgba(0,0,0,.08); transition: transform .12s ease; }
.stick.live .stick-knob { transition: none; }
.pad-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; margin-right: 440px; }
.pad-btn { width: 66px; height: 66px; border-radius: 50%; border: 0; display: grid; place-items: center; gap: 0; padding: 0; color: #fff; background: radial-gradient(circle at 40% 35%, #FF7FBF, var(--accent) 70%, #B0206E); box-shadow: 0 5px 0 #8E1A58, 0 10px 18px rgba(30,36,48,.3), inset 0 0 0 3px rgba(255,255,255,.35); font: 800 10px var(--font); letter-spacing: .08em; }
.pad-btn svg { width: 30px; height: 30px; }
.pad-btn span { margin-top: -6px; }
.pad-btn.held { transform: translateY(4px); box-shadow: 0 1px 0 #8E1A58, 0 4px 10px rgba(30,36,48,.3), inset 0 0 0 3px rgba(255,255,255,.35); }
@media (pointer: coarse) { .touch-pad { display: flex; } body.running .touch-pad, body.building .touch-pad { display: none; } }
@media (pointer: coarse) and (max-width: 900px) { .pad-buttons { margin-right: 310px; } }
@media (pointer: coarse) and (max-width: 700px) {
  .touch-pad { bottom: 12px; left: 10px; right: 10px; }
  .stick { width: 110px; height: 110px; }
  .stick-knob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
  .pad-buttons { margin-right: 0; flex-direction: row; }
  .pad-btn { width: 56px; height: 56px; }
  #hubPanel { display: none; }
}

/* ---- hub connection / python ---- */
select.tb.hub-slot { cursor: pointer; padding: 7px 8px; color: var(--fg); }
.tb.hub-btn-connect.connected { border-color: var(--run); color: #1B7F3B; background: #EAF9EF; }
.spike-modal.wide { width: min(720px, 100%); }
.spike-modal .code { width: 100%; height: min(60vh, 480px); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; border: 1px solid var(--line); border-radius: 10px; padding: 10px; resize: vertical; white-space: pre; background: var(--bg); color: var(--fg); }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* ---- Make a Block dialog ---- */
.mb-params { display: flex; flex-direction: column; gap: 6px; }
.mb-param { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.mb-param .kind { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; width: 86px; }
.mb-param input { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; font-weight: 700; min-width: 0; }
.mb-param .del { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.mb-add { display: flex; gap: 6px; flex-wrap: wrap; }
.mb-add button { border: 1px dashed #B9C0CC; background: var(--bg); border-radius: 8px; padding: 6px 10px; font-size: 12px; font-weight: 700; }

body.building #hubPanel { display: none; }


/* ---- score chip + model card (shown when a mission model is clicked) ---- */
.score-chip { margin-left: auto; align-self: center; background: rgba(30,36,48,.88); color: #fff; border: 0; border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; max-width: min(360px, 60%); cursor: pointer; font-family: inherit; }
.score-chip .pts { white-space: nowrap; }
.score-chip .last { font-weight: 600; color: #CFE8D4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.score-chip .last { display: none; }
.score-chip .last.lost { color: #FFC9C9; }
.score-sheet { position: absolute; right: 10px; top: 52px; width: min(340px, calc(100% - 20px)); max-height: calc(100% - 100px); overflow: auto; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(30,36,48,.18); padding: 8px 12px 10px; font-size: 12px; backdrop-filter: blur(6px); z-index: 3; }
.score-sheet h4 { margin: 2px 0 6px; font-size: 13px; display: flex; justify-content: space-between; }
.score-sheet .row { display: flex; gap: 6px; align-items: baseline; padding: 3px 0; border-top: 1px solid #EEF0F4; }
.score-sheet .row .m { color: var(--muted); font-weight: 800; width: 30px; flex: 0 0 auto; }
.score-sheet .row .n { flex: 1; min-width: 0; }
.score-sheet .row .n small { display: block; color: var(--muted); }
.score-sheet .row .p { font-weight: 800; font-variant-numeric: tabular-nums; }
.score-sheet .row.scored .p { color: #1B7F3B; }
.score-sheet .row.zero .p { color: var(--stop); }
.score-sheet .extras { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); color: var(--muted); }
.score-sheet .log { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.score-sheet .log div { padding: 1px 0; }
.score-sheet .log .lost { color: var(--stop); }
.view-tools { right: 10px; }
.model-card { position: absolute; right: 10px; top: 52px; width: min(300px, calc(100% - 20px)); background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px rgba(30,36,48,.18); padding: 10px 12px; font-size: 12px; backdrop-filter: blur(6px); }
.model-card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.model-card .num { background: #E3000B; color: #fff; border-radius: 6px; padding: 2px 6px; font-weight: 800; font-size: 12px; }
.model-card .title { font-weight: 800; font-size: 14px; flex: 1; }
.model-card .close { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1; padding: 2px 6px; }
.model-card .head { padding-right: 22px; }
.model-card .text { margin: 4px 0 6px; color: #3F4653; }
.model-card .task { display: flex; gap: 6px; align-items: baseline; padding: 2px 0; }
.model-card .task .pts { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.model-card .task.done { color: #1B7F3B; }
.model-card .task.lost { color: var(--stop); }
.model-card .how { color: var(--muted); }
.model-card .foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.model-card .foot .total { font-weight: 800; }

/* ---- attachment builder (js/legobuilder.js) ---- */
.lego-builder { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: flex; flex-direction: column; font-family: var(--font); color: var(--fg); }
.lego-builder[hidden] { display: none; }
.lb-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.lb-head h3 { margin: 0; font-size: 16px; }
.lb-tools { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.lb-tools [hidden] { display: none; }
.lb-presets { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.lb-presets > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 800; margin-right: 4px; }
.lb-preset { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 12px; font-weight: 700; color: var(--fg); cursor: pointer; }
.lb-preset:hover { background: var(--bg); }
.lb-preset.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.lb-preset[hidden] { display: none; }
.lb-preset:disabled { opacity: .4; cursor: not-allowed; }
.lb-robots { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.lb-robots > span, .lb-presets > span { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 800; margin-right: 4px; }
.lb-presets > span small { text-transform: none; letter-spacing: 0; font-weight: 700; margin-left: 2px; }
.lb-robot { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 6px 11px; font: inherit; font-size: 12px; font-weight: 700; color: var(--fg); cursor: pointer; }
.lb-robot:hover { background: #E8ECF2; }
.lb-sub { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 7px 14px; background: #FAFBFC; border-bottom: 1px solid var(--line); }
.lb-side { width: 260px; flex: 0 0 auto; overflow: auto; background: var(--panel); border-left: 1px solid var(--line); padding: 10px 12px; font-size: 12px; }
.lb-side h4 { margin: 2px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.lb-port { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 9px; border: 1px solid transparent; }
.lb-port span { flex: 1; min-width: 0; font-weight: 700; }
.lb-port select { font: inherit; font-weight: 800; padding: 3px 4px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--fg); }
.lb-port .fixed { width: 34px; text-align: center; font-weight: 800; color: var(--muted); }
.lb-port.sensor { cursor: pointer; }
.lb-port.sensor:hover { background: var(--bg); }
.lb-port.on { border-color: var(--accent); background: #EAF4FF; }
.lb-port .dev { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.lb-port .dev.motor { background: #FF4FA8; }
.lb-port .dev.color, .lb-port .dev.distance, .lb-port .dev.force { background: #3DB7E8; }
.lb-hint { margin: 8px 0 0; color: var(--muted); line-height: 1.35; }
.lb-palette .lb-hint { margin: 0 2px 4px; font-size: 11px; }
.lb-issues { margin: 8px 0 0; color: var(--stop); font-weight: 700; }
.lb-issues:empty { display: none; }
.lb-sel { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 6px 12px; box-shadow: 0 6px 18px rgba(30,36,48,.14); font-size: 12px; z-index: 2; }
.lb-sel[hidden], .lb-sel [hidden], .lb-motor[hidden], .lb-hand[hidden], .lb-hand [hidden] { display: none; }
.lb-hand { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 6px 12px; box-shadow: 0 6px 18px rgba(30,36,48,.14); font-size: 12px; z-index: 2; white-space: nowrap; }
.lb-hand .tb { padding: 5px 10px; font-size: 12px; }
.lb-colours { display: inline-flex; gap: 4px; align-items: center; padding: 0 2px; }
.lb-colours[hidden] { display: none; }
.lb-colours button { width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(30,36,48,.25); padding: 0; cursor: pointer; }
.lb-colours button.on { border-color: var(--accent); box-shadow: 0 0 0 2px #fff inset; }
.lb-part { position: relative; }
.lb-dots { position: absolute; top: 6px; right: 8px; display: flex; flex-direction: column; gap: 2px; }
.lb-dots b { width: 7px; height: 7px; border-radius: 50%; border: 1px solid rgba(30,36,48,.35); }
.lb-hand-slide { display: inline-flex; align-items: center; gap: 3px; }
.lb-hand-slide small { color: var(--muted); font-weight: 700; }
.lb-hand-slide .tb { padding: 5px 7px; }
.lb-cam { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 2px; background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 10px; padding: 3px; z-index: 2; }
.lb-cam button { border: 0; background: none; font: inherit; font-size: 12px; font-weight: 700; color: var(--fg); padding: 5px 9px; border-radius: 7px; cursor: pointer; min-width: 28px; }
.lb-cam button:hover { background: var(--bg); }
.lb-cam button[data-cam="in"], .lb-cam button[data-cam="out"] { font-size: 15px; line-height: 1; }
.lb-sel label { display: flex; align-items: center; gap: 5px; font-weight: 700; color: var(--muted); }
.lb-sel select { font: inherit; font-weight: 800; padding: 3px 4px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--fg); }
.lb-sel .tb { padding: 5px 10px; font-size: 12px; }
.lb-sel-x { border: 0; background: none; font-size: 18px; line-height: 1; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 6px; }
.lb-sel-x:hover { background: var(--bg); color: var(--fg); }
.lb-body { flex: 1; display: flex; min-height: 0; }
.lb-palette { width: 248px; flex: 0 0 auto; overflow: auto; background: var(--panel); border-right: 1px solid var(--line); padding: 6px 8px 12px; }
.lb-palette details { border-bottom: 1px solid var(--line); padding: 4px 0; }
.lb-palette summary { cursor: pointer; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 800; padding: 6px 2px; }
.lb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 2px 0 6px; }
.lb-part { display: flex; flex-direction: column; align-items: center; gap: 2px; border: 1px solid transparent; background: none; border-radius: 10px; padding: 4px 2px; font: inherit; font-size: 10px; color: var(--fg); cursor: pointer; min-width: 0; }
.lb-part img { width: 56px; height: 56px; object-fit: contain; background: #E3E8EF; border-radius: 8px; }
.lb-part img:not([src]) { visibility: hidden; }
.lb-part span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-part:hover { background: var(--bg); }
.lb-part.on { border-color: var(--accent); background: #EAF4FF; }
.lb-view { flex: 1; position: relative; min-width: 0; }
.lb-view canvas { display: block; width: 100%; height: 100%; }
.lb-keys { position: absolute; left: 10px; top: 10px; right: 10px; font-size: 12px; color: var(--muted); pointer-events: none; }
.lb-keys b { color: var(--fg); }
.lb-msg { position: absolute; left: 10px; bottom: 54px; font-size: 13px; font-weight: 700; background: rgba(255,255,255,.88); border-radius: 8px; padding: 4px 8px; pointer-events: none; }
.lb-msg:empty { display: none; }
.lb-motor { position: absolute; left: 10px; bottom: 10px; display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12px; font-weight: 700; }
.lb-motor label { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.lb-motor small { color: var(--muted); font-weight: 700; }
.lb-motor output { width: 40px; font-variant-numeric: tabular-nums; }
.lb-status { padding: 8px 14px; font-size: 13px; background: var(--panel); border-top: 1px solid var(--line); min-height: 1.2em; }
.lb-status.warn { color: var(--stop); font-weight: 700; }
@media (max-width: 700px) {
  .lb-body { flex-direction: column; }
  .lb-palette { width: auto; max-height: 34%; border-right: 0; border-bottom: 1px solid var(--line); }
  .lb-grid { grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); }
  .lb-keys { display: none; }
  .lb-side { width: auto; max-height: 30%; border-left: 0; border-top: 1px solid var(--line); }
}

/* building instructions */
.ins { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; font-family: var(--font); color: var(--fg); }
.ins[hidden] { display: none; }
.ins-head { display: flex; align-items: center; gap: 14px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.ins-head h3 { margin: 0; font-size: 16px; }
.ins-count { font-weight: 800; color: var(--muted); }
.ins-tools { margin-left: auto; display: flex; gap: 6px; }
.ins-view { flex: 1; position: relative; min-height: 0; }
.ins-view canvas { display: block; width: 100%; height: 100%; }
.ins-callout { position: absolute; left: 14px; top: 14px; display: flex; flex-wrap: wrap; gap: 6px; max-width: min(520px, 70%); background: #fff; border: 2px solid #9fb7d8; border-radius: 12px; padding: 8px; box-shadow: 0 4px 14px rgba(30,36,48,.12); }
.ins-callout[hidden] { display: none; }
.ins-callout.whole { max-width: min(760px, 92%); max-height: 70%; overflow: auto; }
.ins-callout figure { margin: 0; display: flex; flex-direction: column; align-items: center; width: 64px; }
.ins-callout img { width: 60px; height: 60px; object-fit: contain; }
.ins-callout figcaption { font-weight: 800; font-size: 14px; }
.ins-note { position: absolute; left: 14px; bottom: 60px; margin: 0; font-size: 16px; font-weight: 800; }
.ins-note:empty, .ins-status:empty { display: none; }
.ins-status { position: absolute; left: 50%; top: 40%; transform: translateX(-50%); color: var(--muted); font-weight: 700; }
.ins-nav { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; }
.ins-nav .tb { font-size: 15px; padding: 9px 16px; }
.ins-print { display: none; }
@media print {
  body.printing-instructions > *:not(.ins-print) { display: none !important; }
  body.printing-instructions .ins-print { display: block; font-family: var(--font); color: #000; }
  .ins-print h1 { font-size: 22px; margin: 0 0 8px; }
  .ins-print section { page-break-inside: avoid; break-inside: avoid; margin: 0 0 18px; position: relative; }
  .ins-print h2 { font-size: 18px; margin: 0 0 4px; }
  .ins-print img { max-width: 100%; }
  .ins-print .ins-callout { position: static; display: inline-flex; box-shadow: none; max-width: none; }
  .ins-print section > img { display: block; width: 100%; max-height: 60vh; object-fit: contain; }
}
.lb-tools a.tb { text-decoration: none; display: inline-flex; align-items: center; color: var(--fg); }
.lb-hand kbd, .lb-sel kbd { font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 2px 4px; margin-left: 3px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: #fff; color: var(--muted); }
#projectsPanel .add-sample { display: block; width: 100%; margin: 8px 0 2px; }
