:root {
  --bg-start: #fff6df;
  --bg-end: #dff8ff;
  --surface: #ffffff;
  --surface-alt: #f5f7ff;
  --ink: #1e2430;
  --muted: #5a6578;
  --line: #d8dfeb;

  --brand: #0b7a75;
  --brand-strong: #075e59;
  --accent: #ff9e2c;
  --danger: #d62839;
  --ok: #2eaf58;

  --movement: #8e44ad;
  --flow: #d4ac0d;
  --logic: #2471a3;
  --pose: #1f9d55;
  --advanced: #d97706;

  --radius: 14px;
  --shadow: 0 10px 28px rgba(7, 24, 51, 0.12);

  --transition-fast: 120ms ease;
  --transition-medium: 200ms ease;
  --glow-brand: 0 0 0 4px rgba(11, 122, 117, 0.12);
  --glow-ok: 0 0 0 4px rgba(46, 175, 88, 0.12);
  --glow-danger: 0 0 0 4px rgba(214, 40, 57, 0.12);
  --glow-accent: 0 0 0 4px rgba(255, 158, 44, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(150deg, var(--bg-start), var(--bg-end));
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 14px;
}

/* ---- Icon defaults ---- */
.btn svg,
.panel-label svg,
.modal__title svg,
.bottombar__status-icon svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.topbar__logo svg {
  width: 28px;
  height: 28px;
}

.btn--stop-big svg {
  width: 20px;
  height: 20px;
}

/* ---- Shared panel surfaces ---- */
.topbar,
.bottombar,
.sidebar-card,
.workspace__editor {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar__logo {
  color: var(--brand);
  display: flex;
}

.topbar__title {
  margin: 0;
  font-family: "Orbitron", sans-serif;
  font-size: 1.08rem;
  letter-spacing: 0.02em;
}

.topbar__subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 0.9rem;
}

/* ---- Connection status dot ---- */
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9aa4b8;
  transition: background 300ms ease, box-shadow 300ms ease;
}

.status-dot.is-connected {
  background: var(--ok);
  box-shadow: 0 0 0 5px rgba(46, 175, 88, 0.15);
  animation: pulse-connected 2s ease-in-out infinite;
}

.status-dot.is-connecting {
  background: var(--accent);
  animation: breathe-connecting 1.2s ease-in-out infinite;
}

@keyframes pulse-connected {
  0%, 100% { box-shadow: 0 0 0 4px rgba(46, 175, 88, 0.15); }
  50%      { box-shadow: 0 0 0 8px rgba(46, 175, 88, 0.08); }
}

@keyframes breathe-connecting {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.5; transform: scale(0.85); }
}

/* ---- Buttons ---- */
.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), filter var(--transition-fast), box-shadow var(--transition-medium);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.btn:active {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  filter: none;
}

.btn--connect,
.btn--home,
.btn--save,
.btn--load,
.btn--clear,
.btn--run,
.btn--stop {
  background: var(--surface-alt);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn--connect {
  background: rgba(11, 122, 117, 0.12);
  border-color: rgba(11, 122, 117, 0.3);
  color: var(--brand-strong);
}

.btn--connect:hover {
  box-shadow: var(--glow-brand);
  border-color: rgba(11, 122, 117, 0.5);
}

.btn--home:hover {
  box-shadow: var(--glow-accent);
}

.btn--stop-big {
  background: var(--danger);
  color: #fff;
  min-width: 100px;
  padding: 10px 18px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  border: 2px solid rgba(214, 40, 57, 0.4);
  box-shadow: 0 0 0 3px rgba(214, 40, 57, 0.12);
  margin-left: 4px;
}

.btn--stop-big:hover {
  box-shadow: 0 0 0 5px rgba(214, 40, 57, 0.2);
  transform: translateY(-1px) scale(1.03);
}

.btn--stop-big:active {
  transform: scale(0.97);
}

.btn--run {
  background: rgba(46, 175, 88, 0.16);
  border-color: rgba(46, 175, 88, 0.35);
  color: #136d2f;
}

.btn--run:hover {
  box-shadow: var(--glow-ok);
  border-color: rgba(46, 175, 88, 0.5);
}

.btn--stop {
  background: rgba(214, 40, 57, 0.12);
  border-color: rgba(214, 40, 57, 0.3);
  color: #8f1220;
}

.btn--stop:hover {
  box-shadow: var(--glow-danger);
  border-color: rgba(214, 40, 57, 0.5);
}

.btn--clear:hover svg {
  color: var(--danger);
  transition: color var(--transition-fast);
}

/* ---- Workspace layout ---- */
.workspace {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.workspace-tabs {
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.workspace-tab svg {
  width: 15px;
  height: 15px;
}

.workspace-tab:hover {
  background: var(--surface-alt);
  color: var(--ink);
}

.workspace-tab.is-active {
  background: rgba(11, 122, 117, 0.12);
  border-color: rgba(11, 122, 117, 0.3);
  color: var(--brand-strong);
}

.workspace-tab:focus-visible {
  outline: none;
  box-shadow: var(--glow-brand);
}

.workspace-panel {
  min-height: 0;
}

.workspace-panel.is-hidden {
  display: none;
}

.workspace-panel--block .workspace__editor,
.workspace-panel--manual .workspace__sidebar {
  height: 100%;
}

.workspace__editor {
  min-height: 0;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.workspace__editor--block {
  height: 100%;
  grid-template-columns: minmax(0, 1fr) clamp(220px, 24vw, 300px);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "heading heading"
    "canvas sidebar";
  align-items: stretch;
}

.workspace__editor--block .workspace__editor-title {
  grid-area: heading;
}

.workspace__editor--block #blocklyDiv {
  grid-area: canvas;
  min-height: clamp(460px, 62vh, 900px);
  height: 100%;
}

.workspace__editor--block .blockly-controls {
  grid-area: sidebar;
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  align-content: start;
}

/* ---- Panel labels ---- */
.panel-label {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.panel-label svg {
  width: 15px;
  height: 15px;
  opacity: 0.7;
}

.blockly-controls {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-alt);
  padding: 8px 10px;
  display: grid;
  gap: 8px;
}

.blockly-controls__header {
  display: grid;
  gap: 4px;
}

.blockly-controls__hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.blockly-controls__status {
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--muted);
  background: #f8fbff;
}

.blockly-controls__status[data-tone="ready"] {
  border-color: rgba(11, 122, 117, 0.2);
  color: #2f4f6f;
  background: rgba(11, 122, 117, 0.06);
}

.blockly-controls__status[data-tone="active"] {
  border-color: rgba(46, 175, 88, 0.35);
  color: #136d2f;
  background: rgba(46, 175, 88, 0.12);
}

.blockly-controls__status[data-tone="warning"] {
  border-color: rgba(245, 158, 11, 0.4);
  color: #8a5200;
  background: rgba(245, 158, 11, 0.12);
}

.blockly-controls__status[data-tone="error"] {
  border-color: rgba(214, 40, 57, 0.35);
  color: #8f1220;
  background: rgba(214, 40, 57, 0.1);
}

.blockly-controls__actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.blockly-controls--sidebar .blockly-controls__actions {
  display: grid;
  gap: 6px;
}

.blockly-controls--sidebar .blockly-controls__actions--primary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.blockly-controls--sidebar .blockly-controls__actions--secondary {
  grid-template-columns: 1fr;
}

.blockly-controls--sidebar .btn {
  width: 100%;
  justify-content: center;
}

.blockly-controls__actions .bottombar__divider {
  height: 20px;
  margin: 0 2px;
}

/* ---- Blockly editor ---- */
#blocklyDiv {
  min-height: 0;
  height: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

/* ---- Blockly overrides ---- */

/* Toolbox sidebar */
.blocklyToolboxDiv {
  background: var(--surface) !important;
  border-right: 1px solid var(--line) !important;
  padding: 8px 0 !important;
}

/* Category rows */
.blocklyTreeRow {
  padding: 10px 12px !important;
  margin: 2px 6px !important;
  border-radius: 8px !important;
  transition: background 120ms ease !important;
  line-height: 1.3 !important;
}

.blocklyTreeRow:not(.blocklyTreeSelected):hover {
  background: var(--surface-alt) !important;
}

.blocklyTreeSelected {
  background: var(--surface-alt) !important;
}

/* Category color swatch → small circle */
.blocklyTreeIcon {
  width: 8px !important;
  height: 8px !important;
  border-radius: 50% !important;
  margin-right: 6px !important;
}

/* Category label */
.blocklyTreeLabel {
  font-family: "DM Sans", sans-serif !important;
  font-size: 0.85rem !important;
  font-weight: 600 !important;
  color: var(--ink) !important;
}

/* Flyout background */
.blocklyFlyoutBackground {
  fill-opacity: 0.97 !important;
}

/* Flyout scrollbar */
.blocklyFlyout .blocklyScrollbarHandle {
  rx: 4;
  fill: #c4cdd9 !important;
  fill-opacity: 0.5 !important;
}

.blocklyFlyout .blocklyScrollbarHandle:hover {
  fill-opacity: 0.8 !important;
}

/* Workspace scrollbars */
.blocklyMainWorkspaceScrollbar .blocklyScrollbarHandle {
  rx: 4;
  fill: #b8c2d0 !important;
  fill-opacity: 0.4 !important;
}

.blocklyMainWorkspaceScrollbar .blocklyScrollbarHandle:hover {
  fill-opacity: 0.7 !important;
}

/* Zoom controls */
.blocklyZoom > image {
  opacity: 0.55;
  transition: opacity 150ms ease;
}

.blocklyZoom > image:hover {
  opacity: 0.85;
}

/* Trashcan */
.blocklyTrash image {
  opacity: 0.45;
  transition: opacity 200ms ease;
}

.blocklyTrash:hover image {
  opacity: 0.75;
}

/* Block text */
.blocklyText {
  font-family: "DM Sans", sans-serif !important;
}

.blocklyDropdownText {
  font-family: "DM Sans", sans-serif !important;
}

/* Inline input fields */
.blocklyHtmlInput {
  font-family: "DM Sans", sans-serif !important;
  border-radius: 6px !important;
  border: 1.5px solid var(--line) !important;
}

.blocklyHtmlInput:focus {
  border-color: var(--brand) !important;
  box-shadow: 0 0 0 3px rgba(11, 122, 117, 0.12) !important;
  outline: none !important;
}

/* Dropdown menu */
.blocklyDropDownDiv {
  border-radius: 10px !important;
  border: 1px solid var(--line) !important;
}

/* Context menu */
.blocklyContextMenu {
  border-radius: 10px !important;
  font-family: "DM Sans", sans-serif !important;
}

.blocklyMenuItem {
  font-family: "DM Sans", sans-serif !important;
}

/* ---- Sidebar ---- */
.workspace__sidebar {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(180px, 0.55fr) minmax(180px, 0.45fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "console preview controls";
  gap: 14px;
}

.sidebar-card {
  min-height: 0;
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

.sidebar__controls {
  grid-area: controls;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  min-height: 320px;
  height: 100%;
}

.manual-controls__hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.manual-controls__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
}

.btn--reset-default {
  width: 30px;
  min-width: 30px;
  height: 24px;
  padding: 4px;
  border-radius: 7px;
}

.btn--reset-default span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.btn--reset-default svg {
  width: 12px;
  height: 12px;
}

.btn--icon-only {
  width: 30px;
  min-width: 30px;
  height: 24px;
  padding: 4px;
  border-radius: 7px;
}

.btn--icon-only span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.btn--icon-only svg {
  width: 12px;
  height: 12px;
}

.teach-controls {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-alt);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.teach-controls:not(.is-active) {
  padding: 6px 8px;
}

.teach-controls:not(.is-active) .teach-controls__actions,
.teach-controls:not(.is-active) .teach-controls__status {
  display: none;
}

.teach-controls__toggle {
  min-height: 28px;
}

.teach-controls__actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 2px;
}

.teach-controls__actions .btn {
  flex: 1 1 0;
  min-width: 88px;
  justify-content: center;
  padding: 6px 8px;
  font-size: 0.74rem;
  white-space: nowrap;
}

.teach-controls__status {
  margin: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  background: #f8fbff;
}

.teach-controls__status[data-tone="ready"] {
  border-color: rgba(11, 122, 117, 0.2);
  color: #2f4f6f;
  background: rgba(11, 122, 117, 0.06);
}

.teach-controls__status[data-tone="active"] {
  border-color: rgba(46, 175, 88, 0.35);
  color: #136d2f;
  background: rgba(46, 175, 88, 0.12);
}

.teach-controls__status[data-tone="warning"] {
  border-color: rgba(245, 158, 11, 0.4);
  color: #8a5200;
  background: rgba(245, 158, 11, 0.12);
}

.teach-controls__status[data-tone="error"] {
  border-color: rgba(214, 40, 57, 0.35);
  color: #8f1220;
  background: rgba(214, 40, 57, 0.1);
}

.sidebar__controls.is-locked {
  opacity: 0.78;
}

.sidebar__controls.is-locked .servo-channel,
.sidebar__controls.is-locked .motors-toggle,
.sidebar__controls.is-locked .teach-controls {
  filter: saturate(0.72);
}

.sidebar__controls.is-locked .manual-controls__bar .btn {
  filter: saturate(0.72);
}

.sidebar__controls.is-locked .motors-toggle,
.sidebar__controls.is-locked .teach-controls .btn,
.sidebar__controls.is-locked .servo-slider {
  cursor: not-allowed;
}

.sidebar__console {
  grid-area: console;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 200px;
  overflow: hidden;
}

.sidebar__preview {
  grid-area: preview;
  overflow: hidden;
}

.sidebar__preview .arm-preview-container {
  min-height: 170px;
  overflow: hidden;
}

/* ---- Arm preview ---- */
.arm-preview-container {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #f9fbff 0%, #eef4ff 60%, #e4ecfa 100%);
  min-height: 0;
  height: 100%;
  padding: 4px;
  overflow: hidden;
}

#armSvg {
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: block;
  overflow: hidden;
  user-select: none;
  touch-action: none;
}

#armSvg.is-interactive-disabled .arm-handle,
#armSvg.is-interactive-disabled .arm-track {
  pointer-events: none;
  cursor: default;
}

#armSvg .arm-handle {
  cursor: grab;
  transition: opacity 150ms ease, stroke-opacity 150ms ease;
}

#armSvg .arm-joint-handle:hover {
  stroke-opacity: 1 !important;
  fill: rgba(255, 255, 255, 0.3);
}

#armSvg .arm-handle.is-active {
  cursor: grabbing;
  stroke-opacity: 1 !important;
  fill: rgba(255, 255, 255, 0.35);
  filter: url(#handleGlow);
}

#armSvg .arm-track {
  cursor: ew-resize;
}

#armSvg .arm-track-handle:hover {
  filter: url(#handleGlow);
}

#armSvg.is-dragging .arm-handle {
  filter: none;
}

#armSvg.is-dragging .arm-handle.is-active {
  filter: url(#handleGlow);
}

.arm-preview-container.is-dragging {
  box-shadow: inset 0 0 0 2px rgba(82, 113, 255, 0.18);
}

/* ---- Servo sliders ---- */
.servo-sliders {
  display: grid;
  height: 100%;
  align-content: stretch;
  gap: 3px;
  overflow: visible;
  max-height: none;
}

.motors-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  justify-self: start;
  align-self: start;
  gap: 8px;
  width: auto;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
}

.motors-toggle input[type="checkbox"] {
  inline-size: 16px;
  block-size: 16px;
  accent-color: var(--brand);
  cursor: pointer;
}

.motors-toggle input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.motors-toggle--block {
  width: 100%;
  justify-self: stretch;
}

.servo-channel {
  display: grid;
  grid-template-columns: minmax(72px, 90px) 1fr minmax(52px, 72px);
  align-items: center;
  gap: 6px;
  background: transparent;
  border-radius: 8px;
  padding: 5px 6px;
  transition: background var(--transition-fast);
}

.servo-channel:hover {
  background: var(--surface-alt);
}

.servo-channel:focus-within {
  background: rgba(11, 122, 117, 0.08);
  box-shadow: inset 0 0 0 1px rgba(11, 122, 117, 0.25);
}

.servo-channel__label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 0.82rem;
}

.servo-channel__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #8d97ab;
  flex-shrink: 0;
}

.servo-channel__value {
  text-align: right;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

/* ---- Dot colors per joint ---- */
.servo-channel--base .servo-channel__dot { background: #5271ff; }
.servo-channel--shoulder .servo-channel__dot { background: #f59e0b; }
.servo-channel--elbow .servo-channel__dot { background: #8e44ad; }
.servo-channel--wrist-rot .servo-channel__dot { background: #16a34a; }
.servo-channel--wrist-tilt .servo-channel__dot { background: #0ea5e9; }
.servo-channel--gripper .servo-channel__dot { background: #ef4444; }

/* ---- Custom range sliders ---- */
.servo-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 3px;
  background: #e2e8f0;
  outline: none;
  cursor: pointer;
  --fill-pct: 50%;
}

.servo-slider:focus-visible {
  outline: 2px solid rgba(11, 122, 117, 0.55);
  outline-offset: 3px;
}

/* Webkit thumb */
.servo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  background: #8d97ab;
  cursor: grab;
  margin-top: -5.5px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.servo-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.servo-slider::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.1);
}

/* Firefox track */
.servo-slider::-moz-range-track {
  height: 5px;
  border-radius: 3px;
  background: #e2e8f0;
  border: none;
}

/* Firefox thumb */
.servo-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  background: #8d97ab;
  cursor: grab;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.servo-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Per-joint thumb colors */
.servo-channel--base .servo-slider::-webkit-slider-thumb { background: #5271ff; }
.servo-channel--base .servo-slider::-moz-range-thumb     { background: #5271ff; }

.servo-channel--shoulder .servo-slider::-webkit-slider-thumb { background: #f59e0b; }
.servo-channel--shoulder .servo-slider::-moz-range-thumb     { background: #f59e0b; }

.servo-channel--elbow .servo-slider::-webkit-slider-thumb { background: #8e44ad; }
.servo-channel--elbow .servo-slider::-moz-range-thumb     { background: #8e44ad; }

.servo-channel--wrist-rot .servo-slider::-webkit-slider-thumb { background: #16a34a; }
.servo-channel--wrist-rot .servo-slider::-moz-range-thumb     { background: #16a34a; }

.servo-channel--wrist-tilt .servo-slider::-webkit-slider-thumb { background: #0ea5e9; }
.servo-channel--wrist-tilt .servo-slider::-moz-range-thumb     { background: #0ea5e9; }

.servo-channel--gripper .servo-slider::-webkit-slider-thumb { background: #ef4444; }
.servo-channel--gripper .servo-slider::-moz-range-thumb     { background: #ef4444; }

/* Filled track gradient (driven by --fill-pct via JS) */
.servo-channel--base .servo-slider {
  background: linear-gradient(to right, #5271ff var(--fill-pct), #e2e8f0 var(--fill-pct));
}
.servo-channel--shoulder .servo-slider {
  background: linear-gradient(to right, #f59e0b var(--fill-pct), #e2e8f0 var(--fill-pct));
}
.servo-channel--elbow .servo-slider {
  background: linear-gradient(to right, #8e44ad var(--fill-pct), #e2e8f0 var(--fill-pct));
}
.servo-channel--wrist-rot .servo-slider {
  background: linear-gradient(to right, #16a34a var(--fill-pct), #e2e8f0 var(--fill-pct));
}
.servo-channel--wrist-tilt .servo-slider {
  background: linear-gradient(to right, #0ea5e9 var(--fill-pct), #e2e8f0 var(--fill-pct));
}
.servo-channel--gripper .servo-slider {
  background: linear-gradient(to right, #ef4444 var(--fill-pct), #e2e8f0 var(--fill-pct));
}

/* ---- Bottom bar ---- */
.bottombar {
  padding: 6px 14px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  box-shadow: none;
  background: rgba(255, 255, 255, 0.7);
  border-color: rgba(216, 223, 235, 0.6);
}

.bottombar__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.bottombar__divider {
  width: 1px;
  height: 24px;
  background: var(--line);
  margin: 0 4px;
}

.bottombar__status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  color: var(--muted);
  font-size: 0.82rem;
}

.bottombar__status-icon {
  display: inline-flex;
  color: var(--ok);
}

.bottombar__status-icon svg {
  width: 16px;
  height: 16px;
}

.bottombar__status-icon.is-running svg {
  animation: spin-status 1s linear infinite;
}

.bottombar__status-icon.is-error {
  color: var(--danger);
}

.bottombar__status-icon.is-warning {
  color: #b76b00;
}

@keyframes spin-status {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ---- Modals ---- */
.modal {
  border: 0;
  border-radius: 16px;
  padding: 0;
  max-width: 500px;
  width: min(92vw, 500px);
  box-shadow: 0 20px 60px rgba(7, 24, 51, 0.2), 0 0 0 1px rgba(0, 0, 0, 0.05);
  animation: modal-enter 200ms ease-out;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal::backdrop {
  background: rgba(20, 28, 48, 0.45);
  animation: backdrop-fade 200ms ease-out;
}

@keyframes backdrop-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal__content {
  background: #fff;
  padding: 20px;
  border-radius: 16px;
}

.modal__title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal__title svg {
  width: 20px;
  height: 20px;
  color: var(--brand);
}

.modal__input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.modal__input:focus {
  border-color: var(--brand);
  box-shadow: var(--glow-brand);
  outline: none;
}

.modal__content--script {
  width: min(760px, 88vw);
}

.modal__subtitle {
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal__textarea {
  width: 100%;
  min-height: 260px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #f8fbff;
  font: 0.82rem/1.45 "Consolas", "Courier New", monospace;
  resize: vertical;
}

.modal__textarea:focus {
  border-color: var(--brand);
  box-shadow: var(--glow-brand);
  outline: none;
}

.modal__actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal__list {
  display: grid;
  gap: 8px;
  max-height: 300px;
  overflow: auto;
}

/* ---- Program list rows ---- */
.program-row {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-alt);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.program-row:hover {
  border-color: rgba(11, 122, 117, 0.3);
  box-shadow: 0 2px 8px rgba(7, 24, 51, 0.06);
}

.program-row__icon {
  display: inline-flex;
  color: var(--muted);
  flex-shrink: 0;
}

.program-row__icon svg {
  width: 16px;
  height: 16px;
}

.program-row__meta {
  min-width: 0;
  flex: 1;
}

.program-row__name {
  font-weight: 700;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.program-row__time {
  color: var(--muted);
  font-size: 0.8rem;
}

.program-row__actions {
  display: inline-flex;
  gap: 6px;
}

.program-pill {
  font-size: 0.72rem;
  border-radius: 999px;
  background: rgba(36, 113, 163, 0.12);
  border: 1px solid rgba(36, 113, 163, 0.2);
  color: #1b4f72;
  padding: 2px 7px;
  margin-left: 6px;
}

.serial-console {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fbff;
  padding: 8px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.75rem;
  line-height: 1.35;
  overflow: auto;
  white-space: pre-wrap;
  min-height: 0;
}

.serial-console__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.console-split {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  overflow: hidden;
  align-items: stretch;
}

.console-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  overflow: hidden;
}

.console-pane--debug {
  grid-template-rows: auto auto minmax(0, 1fr) minmax(0, 1fr) auto;
}

.console-pane__title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.01em;
  text-transform: none;
}

.serial-console--debug {
  background: #f6f8fd;
  border-style: dashed;
}


.console-debug__chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 6px;
}

.debug-chip {
  min-width: 0;
  border: 1px solid rgba(100, 122, 160, 0.3);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.9);
  padding: 3px 5px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px;
  align-items: center;
}

.debug-chip__label {
  font-size: 0.63rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #5a6f92;
  white-space: nowrap;
}

.debug-chip__value {
  min-width: 0;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.71rem;
  font-weight: 700;
  color: #253a5a;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.console-debug__toggle {
  width: 100%;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: #3a4d6e;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.console-debug__toggle i {
  width: 14px;
  height: 14px;
  transition: transform 0.14s ease;
}

.console-debug__toggle[aria-expanded="true"] i {
  transform: rotate(180deg);
}

.console-debug__details {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #f7f9fd 0%, #f4f8ff 100%);
  padding: 6px;
  display: grid;
  gap: 4px;
  min-height: 0;
  overflow-y: auto;
}

.console-debug__details[hidden] {
  display: none;
}

.debug-detail-row {
  min-width: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.debug-detail__label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #607089;
  white-space: nowrap;
}

.debug-detail__value {
  min-width: 0;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.69rem;
  color: #2f425f;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Responsive ---- */
@media (max-width: 1100px) {
  body {
    height: auto;
    min-height: 100%;
  }

  .workspace {
    grid-template-rows: auto minmax(420px, 1fr);
  }

  .workspace__sidebar {
    grid-template-columns: minmax(160px, 0.5fr) minmax(160px, 0.5fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "console preview controls";
  }

  .sidebar__controls {
    min-height: 300px;
  }

  .servo-sliders {
    grid-template-columns: 1fr;
    gap: 3px;
  }
}

@media (max-width: 680px) {
  body {
    padding: 10px;
    gap: 10px;
  }

  .workspace-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    overflow: visible;
  }

  .workspace-tab {
    justify-content: center;
    min-height: 42px;
    padding: 8px 10px;
    white-space: normal;
    text-align: center;
  }

  .workspace-tab span {
    line-height: 1.2;
  }

  .workspace__sidebar {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "preview"
      "controls"
      "console";
  }

  .sidebar__preview .arm-preview-container {
    max-height: 280px;
  }

  .servo-sliders {
    grid-template-columns: 1fr 1fr;
    gap: 2px 10px;
  }

  .teach-controls__actions .btn {
    min-width: 92px;
  }

  .manual-controls__bar {
    flex-wrap: wrap;
  }

  .manual-controls__bar .motors-toggle {
    flex: 1 1 170px;
  }

  .blockly-controls--sidebar .blockly-controls__actions--primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .blockly-controls--sidebar #btnStop {
    grid-column: 1 / -1;
  }

  .console-split {
    grid-template-columns: 1fr;
  }

  .console-debug__chips {
    grid-template-columns: 1fr;
  }

  .debug-detail-row {
    grid-template-columns: 1fr;
    gap: 1px;
  }

  .debug-detail__value {
    text-align: left;
  }

  .blockly-controls__actions .bottombar__divider {
    display: none;
  }

  .servo-channel {
    grid-template-columns: auto 1fr;
    gap: 4px;
  }

  .servo-channel__value {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 0.75rem;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar__controls {
    width: 100%;
    justify-content: flex-start;
  }

  .topbar__status {
    width: 100%;
    justify-content: center;
  }

  .topbar__controls .btn {
    flex: 1 1 calc(50% - 8px);
    justify-content: center;
  }

  .topbar__controls .btn--stop-big {
    flex-basis: 100%;
  }
}

@media (max-width: 767px) {
  .workspace__editor--block {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(300px, 1fr) auto;
    grid-template-areas:
      "heading"
      "canvas"
      "sidebar";
  }

  .workspace__editor--block #blocklyDiv {
    min-height: clamp(340px, 58vh, 760px);
  }

  .workspace__editor--block .blockly-controls {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 480px) {
  .servo-sliders {
    grid-template-columns: 1fr;
  }

  .blockly-controls--sidebar .blockly-controls__actions--primary {
    grid-template-columns: 1fr;
  }

  .blockly-controls--sidebar #btnStop {
    grid-column: auto;
  }
}
