:root {
  --ink: #171b1e;
  --muted: #65706f;
  --paper: #f4f6f5;
  --bench: #e4e9e7;
  --line: #cbd3d0;
  --panel: #fbfcfb;
  --graphite: #242a2c;
  --copper: #b85e32;
  --copper-dark: #7c321d;
  --red: #8a222b;
  --blue: #244f91;
  --yellow: #c99728;
  --success: #2f7c62;
  --display: "STKaiti", "KaiTi", "Songti SC", serif;
  --body: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --utility: "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { width: 100%; min-width: 320px; height: 100%; }
body {
  width: 100%;
  min-width: 320px;
  /* Older classroom Chromium browsers do not understand dvh. */
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--body);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-x: none;
}
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:focus-visible, input:focus-visible, canvas:focus-visible, a:focus-visible {
  outline: 3px solid rgba(184, 94, 50, .34);
  outline-offset: 3px;
}

.app-shell {
  width: calc(100% - 28px);
  max-width: 1540px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 10px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.topbar {
  min-height: 54px;
  display: flex;
  align-items: center;
  padding: 0 3px 11px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}
.brand strong {
  display: block;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .08em;
  white-space: nowrap;
}
.brand-mark {
  position: relative;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border: 1px solid rgba(124, 50, 29, .72);
  border-radius: 50%;
  background: rgba(255, 255, 255, .62);
  box-shadow: inset -8px -2px 0 rgba(184, 94, 50, .09);
}
.brand-mark i {
  position: absolute;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--copper);
}
.brand-mark i:nth-child(1) { left: 10px; top: 9px; }
.brand-mark i:nth-child(2) { left: 16px; top: 16px; }
.brand-mark i:nth-child(3) { left: 22px; top: 20px; }

.lab-layout {
  grid-row: 2; /* 页头被工作台隐藏时（display:none），防止主体掉进第一行按内容收缩 */
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(330px, 390px);
  gap: 10px;
  padding-top: 10px;
}
.motor-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #c3cdca;
  background:
    linear-gradient(rgba(77, 91, 88, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(77, 91, 88, .035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, .97), rgba(222, 228, 226, .94));
  background-size: 32px 32px, 32px 32px, 100% 100%;
  box-shadow: 0 18px 42px rgba(37, 48, 45, .08);
  isolation: isolate;
  touch-action: none;
}
.motor-stage::after {
  position: absolute;
  left: 9%;
  right: 9%;
  bottom: 7%;
  height: 1px;
  z-index: -1;
  content: "";
  background: linear-gradient(90deg, transparent, #9eaaa6 18%, #9eaaa6 82%, transparent);
}
.stage-heading {
  position: absolute;
  z-index: 4;
  top: 18px;
  left: 18px;
  pointer-events: none;
}
.stage-heading h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: .06em;
}
.stage-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .02em;
}
#motorCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.motor-stage.part-ready #motorCanvas { cursor: pointer; }
.motor-stage.part-dragging #motorCanvas { cursor: grabbing; }

.axis-guide {
  position: absolute;
  z-index: 1;
  left: 11%;
  right: 11%;
  top: 54%;
  height: 42px;
  color: rgba(124, 50, 29, .45);
  pointer-events: none;
}
.axis-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 17px;
  height: 1px;
  background: repeating-linear-gradient(90deg, rgba(184, 94, 50, .28) 0 7px, transparent 7px 13px);
}
.axis-line::before, .axis-line::after {
  position: absolute;
  top: -3px;
  width: 7px;
  height: 7px;
  border-top: 1px solid currentColor;
  border-right: 1px solid currentColor;
  content: "";
}
.axis-line::before { left: 0; transform: rotate(-135deg); }
.axis-line::after { right: 0; transform: rotate(45deg); }
.axis-origin {
  position: absolute;
  left: 50%;
  top: 12px;
  width: 11px;
  height: 11px;
  border: 1px solid rgba(124, 50, 29, .55);
  border-radius: 50%;
  transform: translateX(-50%);
}
.axis-origin::after {
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--copper);
  content: "";
}
.axis-guide small {
  position: absolute;
  top: 27px;
  left: 50%;
  padding: 1px 5px;
  background: rgba(235, 239, 238, .72);
  font-family: var(--utility);
  font-size: 8px;
  letter-spacing: .09em;
  transform: translateX(-50%);
}

.selection-badge {
  position: absolute;
  z-index: 5;
  left: 18px;
  bottom: 18px;
  min-width: 154px;
  padding: 9px 12px 10px;
  border-left: 3px solid var(--copper);
  color: #f4f6f5;
  background: rgba(30, 35, 37, .88);
  box-shadow: 0 9px 24px rgba(27, 32, 33, .16);
  backdrop-filter: blur(8px);
}
.selection-badge span, .selection-badge strong { display: block; }
.selection-badge span {
  margin-bottom: 2px;
  color: #b9c1be;
  font-size: 9px;
  letter-spacing: .12em;
}
.selection-badge strong { font-size: 13px; }

.view-actions {
  position: absolute;
  z-index: 5;
  right: 16px;
  top: 16px;
  display: flex;
  gap: 6px;
}
.view-actions button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(88, 103, 99, .28);
  background: rgba(250, 252, 251, .82);
  box-shadow: 0 5px 16px rgba(45, 56, 53, .06);
  font-size: 11px;
  font-weight: 700;
  backdrop-filter: blur(8px);
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.view-actions button:hover { border-color: var(--copper); transform: translateY(-1px); }
.view-actions button[aria-pressed="true"] { color: #fff; border-color: var(--graphite); background: var(--graphite); }
.view-actions span { margin-right: 5px; color: var(--copper); font-size: 15px; }

.gesture-hint {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid rgba(82, 96, 92, .18);
  color: #495450;
  background: rgba(248, 250, 249, .76);
  font-size: 10px;
  transform: translateX(-50%);
  backdrop-filter: blur(7px);
  transition: opacity .45s ease;
}
.gesture-hint.is-hidden { opacity: 0; pointer-events: none; }
.gesture-orbit {
  width: 18px;
  height: 12px;
  border: 1px solid var(--copper);
  border-radius: 50%;
  transform: rotate(-14deg);
}
.gesture-orbit::after {
  display: block;
  width: 4px;
  height: 4px;
  margin: 3px auto;
  border-radius: 50%;
  background: var(--copper);
  content: "";
}

.loading-panel {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 7px;
  color: #26322f;
  background: rgba(238, 242, 240, .9);
  backdrop-filter: blur(7px);
  transition: opacity .35s ease, visibility .35s ease;
}
.loading-panel.ready { opacity: 0; visibility: hidden; pointer-events: none; }
.loading-panel strong { font-family: var(--display); font-size: 17px; letter-spacing: .06em; }
.loading-panel > span:last-child { color: var(--muted); font-size: 11px; }
.loading-rotor {
  position: relative;
  width: 52px;
  height: 52px;
  margin-bottom: 9px;
  border: 1px solid rgba(184, 94, 50, .34);
  border-radius: 50%;
  animation: rotor-loading 1.35s linear infinite;
}
.loading-rotor i {
  position: absolute;
  left: 23px;
  top: 7px;
  width: 6px;
  height: 18px;
  border-radius: 6px;
  background: var(--copper);
  transform-origin: 3px 19px;
}
.loading-rotor i:nth-child(2) { transform: rotate(120deg); }
.loading-rotor i:nth-child(3) { transform: rotate(240deg); }
@keyframes rotor-loading { to { transform: rotate(360deg); } }

.workbench {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: minmax(0, .86fr) minmax(0, 1.14fr);
  gap: 9px;
}
.desk-module {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 10px 26px rgba(42, 55, 51, .045);
}
.module-heading {
  min-width: 0;
  flex: 0 0 auto;
  min-height: 57px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #dde3e1;
}
.module-heading.compact { min-height: 48px; grid-template-columns: 44px minmax(0, 1fr); }
.module-heading > span:nth-child(2), .module-heading > span:nth-child(2) b, .module-heading > span:nth-child(2) small { display: block; }
.module-heading > span:nth-child(2) { min-width: 0; }
.module-heading > span:nth-child(2) b { font-size: 13px; }
.module-heading > span:nth-child(2) small {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.module-heading output {
  min-width: 42px;
  color: var(--copper-dark);
  font-family: var(--utility);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}
.module-index {
  display: grid !important;
  width: 44px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(184, 94, 50, .42);
  color: var(--copper-dark);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
}

.structure-module {
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.structure-module .module-heading {
  grid-template-columns: 44px minmax(0, 1fr) minmax(112px, auto);
  gap: 8px;
}
.structure-restore-button {
  min-width: 112px;
  min-height: 38px;
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  color: #f8f9f8;
  border: 1px solid #3b4543;
  background: linear-gradient(135deg, #313a38 0%, #202625 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 5px 12px rgba(31, 40, 38, .1);
  text-align: left;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease, opacity .16s ease;
}
.structure-restore-button:not(:disabled):hover {
  border-color: #c77448;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1), 0 7px 16px rgba(83, 50, 32, .18);
  transform: translateY(-1px);
}
.structure-restore-button:not(:disabled):active { transform: translateY(0); }
.structure-restore-button:focus-visible { outline: 2px solid #d68353; outline-offset: 2px; }
.structure-restore-button:disabled { cursor: default; opacity: .48; }
.restore-symbol {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  color: #e4a47c;
  border: 1px solid rgba(223, 164, 125, .32);
  border-radius: 50%;
  background: rgba(10, 14, 13, .28);
  font-family: var(--utility);
  font-size: 14px;
}
.structure-restore-button > span:last-child,
.structure-restore-button strong,
.structure-restore-button small { min-width: 0; display: block; }
.structure-restore-button strong { font-family: var(--display); font-size: 10px; letter-spacing: .04em; white-space: nowrap; }
.structure-restore-button small { margin-top: 2px; color: #b7c0bd; font-size: 6px; white-space: nowrap; }
.structure-restore-button small output,
.structure-restore-button small i { color: inherit; font: inherit; font-style: normal; }
.structure-restore-button small output { min-width: 0; display: inline; margin-right: 4px; text-align: inherit; }
.structure-restore-button.is-assembling { opacity: 1; }
.structure-restore-button.is-assembling .restore-symbol { animation: restore-spin .8s linear infinite; }
@keyframes restore-spin { to { transform: rotate(-360deg); } }
@keyframes assemble-pulse {
  from { transform: scaleX(.72); opacity: .56; }
  to { transform: scaleX(1); opacity: 1; }
}

.motor-control-module {
  --instrument: #202625;
  --instrument-line: #485350;
  --instrument-copy: #e9edeb;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.motor-control-module .module-heading { flex: 0 0 auto; }
.motor-control-module .module-heading > span:nth-child(2) b { font-size: 14px; }
.motor-control-module .module-heading > span:nth-child(2) small { font-size: 10px; }
.motor-control-module .module-heading output {
  min-width: 50px;
  padding: 3px 5px;
  color: #7b8582;
  border: 1px solid #cbd2d0;
  background: #eef1f0;
  font-size: 9px;
  text-align: center;
}
.motor-control-module.powered .module-heading output {
  color: #227055;
  border-color: rgba(47, 124, 98, .42);
  background: rgba(47, 124, 98, .08);
}
.motor-dashboard {
  min-width: 0;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(120px, .82fr) minmax(140px, 1.18fr);
  gap: 8px;
  padding: 9px 10px 8px;
}
.motor-power-button {
  min-width: 0;
  min-height: 82px;
  display: grid;
  grid-template-columns: 37px minmax(0, 1fr) 8px;
  align-items: center;
  gap: 8px;
  padding: 10px 9px;
  color: var(--instrument-copy);
  border: 1px solid var(--instrument-line);
  background: linear-gradient(145deg, #303836, var(--instrument));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 7px 17px rgba(31, 39, 37, .12);
  text-align: left;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
.motor-power-button:hover {
  border-color: #bf7046;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1), 0 9px 20px rgba(82, 49, 32, .16);
  transform: translateY(-1px);
}
.motor-power-button:active { transform: translateY(0); }
.motor-power-button > span:nth-child(2), .motor-power-button strong, .motor-power-button small { min-width: 0; display: block; }
.motor-power-button strong { font-family: var(--display); font-size: 14px; letter-spacing: .05em; }
.motor-power-button small { margin-top: 3px; color: #aeb7b4; font-size: 8px; line-height: 1.35; }
.power-symbol {
  position: relative;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(229, 163, 121, .42);
  border-radius: 50%;
  background: rgba(8, 12, 11, .28);
}
.power-symbol::before {
  position: absolute;
  left: 16px;
  top: 8px;
  width: 2px;
  height: 11px;
  border-radius: 2px;
  background: #e3a17a;
  content: "";
}
.power-symbol i {
  position: absolute;
  left: 9px;
  top: 10px;
  width: 16px;
  height: 16px;
  border: 2px solid #e3a17a;
  border-top-color: transparent;
  border-radius: 50%;
}
.power-lamp {
  width: 8px;
  height: 8px;
  border: 1px solid #69736f;
  border-radius: 50%;
  background: #4f5855;
  transition: background .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.motor-control-module.powered .motor-power-button { border-color: #459575; }
.motor-control-module.powered .power-symbol { border-color: rgba(143, 221, 188, .48); }
.motor-control-module.powered .power-symbol::before { background: #a8e0c8; }
.motor-control-module.powered .power-symbol i { border-right-color: #a8e0c8; border-bottom-color: #a8e0c8; border-left-color: #a8e0c8; }
.motor-control-module.powered .power-lamp {
  border-color: #b7e5d2;
  background: #4eb188;
  box-shadow: 0 0 0 3px rgba(78, 177, 136, .14), 0 0 11px rgba(78, 177, 136, .7);
}
.motor-control-module.requires-assembly .motor-power-button { border-style: dashed; }
.motor-control-module.power-blocked .motor-power-button { animation: power-blocked .32s ease 2 alternate; }
@keyframes power-blocked {
  from { transform: translateX(0); border-color: var(--instrument-line); }
  to { transform: translateX(4px); border-color: #b34f3d; }
}
.speed-readout {
  min-width: 0;
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-content: center;
  column-gap: 6px;
  padding: 9px 10px 8px;
  color: var(--instrument-copy);
  border: 1px solid var(--instrument-line);
  background:
    repeating-linear-gradient(90deg, transparent 0 17px, rgba(255, 255, 255, .022) 17px 18px),
    var(--instrument);
}
.speed-label { color: #aeb8b4; font-size: 8px; letter-spacing: .1em; }
.speed-value { grid-column: 1; display: flex; align-items: baseline; gap: 5px; line-height: 1; }
.speed-value output {
  min-width: 0;
  color: #f0a778;
  font-family: var(--utility);
  font-size: 24px;
  font-size: clamp(20px, 2vw, 27px);
  font-weight: 700;
  letter-spacing: -.08em;
}
.speed-value small { color: #939d99; font-family: var(--utility); font-size: 8px; letter-spacing: .1em; }
.target-speed {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: end;
  padding-bottom: 3px;
  color: #aeb7b4;
  font-family: var(--utility);
  font-size: 8px;
  white-space: nowrap;
}
.target-speed output { color: #d9dfdc; }
.speed-track {
  position: relative;
  grid-column: 1 / -1;
  height: 6px;
  margin-top: 6px;
  overflow: hidden;
  background: #3b4542;
}
.speed-track em {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #884025, #e68c54 72%, #f2bf6d);
  box-shadow: 0 0 8px rgba(230, 140, 84, .35);
  transition: width .1s linear;
}
.speed-scale {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  color: #77827e;
  font-family: var(--utility);
  font-size: 7px;
}
.speed-scale i { font-style: normal; }
.variable-controls {
  min-width: 0;
  /* Keep each row's intrinsic height; the panel scrolls when space runs out. */
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  padding: 0 12px 8px;
}
.variable-row {
  min-width: 0;
  min-height: 55px;
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: minmax(92px, .7fr) minmax(0, 2.3fr);
  align-items: stretch;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid #e0e5e3;
}
.variable-label {
  min-width: 0;
  align-self: center;
}
.variable-label strong, .variable-label small { display: block; }
.variable-label strong { font-size: 14px; font-weight: 700; line-height: 1.15; }
.variable-label small { margin-top: 4px; color: var(--muted); font-family: var(--utility); font-size: 9px; }
.variable-buttons { width: 100%; min-width: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-self: stretch; gap: 6px; }
.variable-buttons button {
  min-width: 0;
  min-height: 42px;
  padding: 5px 3px;
  border: 1px solid #d1d8d5;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  touch-action: manipulation;
  transition: border-color .15s ease, color .15s ease, background .15s ease, transform .15s ease;
}
.variable-buttons button:hover { border-color: var(--copper); transform: translateY(-1px); }
.variable-buttons button.active {
  color: #fff;
  border-color: var(--copper-dark);
  background: var(--copper-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1);
}
.motor-theory {
  flex: 0 0 auto;
  display: grid;
  gap: 2px;
  margin: 0 10px 9px;
  padding: 7px 9px;
  border-left: 2px solid var(--copper);
  background: #eef1f0;
}
.motor-theory span { color: var(--copper-dark); font-size: 8px; letter-spacing: .09em; }
.motor-theory strong { font-family: var(--utility); font-size: 9px; font-weight: 600; }
.motor-theory output { color: #5d6864; font-size: 9px; line-height: 1.4; }
.motor-control-module.powered .motor-theory output { color: var(--success); font-weight: 700; }

.part-grid {
  min-width: 0;
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(48px, 1fr));
  gap: 8px;
  padding: 10px 12px 12px;
}
.part-grid button {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #d9dfdd;
  background: #fff;
  text-align: left;
  transition: border-color .15s ease, background .15s ease;
}
.part-grid button:hover, .part-grid button.active { border-color: var(--copper); background: #fbf3ef; }
.part-grid button.detached { border-style: dashed; background: #f7f4f1; }
.part-grid button.detached small { color: var(--copper-dark); }
.part-grid button.rotor-detail { border-left: 3px solid #aa765a; background: #fbfaf8; }
.part-grid button.rotor-detail:hover, .part-grid button.rotor-detail.active { border-left-color: var(--copper-dark); background: #f8eee8; }
.part-grid button.snapped { animation: part-snapped .5s ease; }
@keyframes part-snapped {
  0% { box-shadow: 0 0 0 0 rgba(47, 124, 98, .45); }
  100% { box-shadow: 0 0 0 10px rgba(47, 124, 98, 0); }
}
.part-grid button > span, .part-grid b, .part-grid small { min-width: 0; display: block; }
.part-grid b { overflow: hidden; font-size: 13px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.part-grid small { margin-top: 4px; overflow: hidden; color: var(--muted); font-size: 8.5px; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.swatch {
  width: 16px;
  height: 30px;
  flex: 0 0 16px;
  border: 1px solid rgba(20, 28, 27, .14);
  background: #626a68;
}
.swatch.housing { background: #25292a; }
.swatch.magnets { background: linear-gradient(#8a222b 0 50%, #244f91 50%); }
.swatch.magnet-red { background: #8a222b; }
.swatch.magnet-blue { background: #244f91; }
.swatch.rotor { background: #737b79; box-shadow: inset 4px 0 0 #9c4b28; }
.swatch.commutator { background: #b85e32; }
.swatch.core { background: repeating-linear-gradient(90deg, #606967 0 2px, #929a97 2px 3px); }
.swatch.coil { background: repeating-linear-gradient(0deg, #71301d 0 2px, #b65b31 2px 4px); }
.swatch.brush { background: #a8aaa5; box-shadow: inset 4px 0 0 #292c2d; }
.swatch.front { background: #83242b; }

/* Browser chrome, a site's iframe and Windows scaling all reduce CSS height. */
@media (min-width: 761px) and (max-height: 820px) {
  .workbench { grid-template-rows: minmax(170px, .65fr) minmax(0, 1.35fr); }
  .module-heading { min-height: 48px; padding: 6px 10px; }
  .motor-dashboard { padding: 6px 8px; }
  .motor-power-button, .speed-readout { min-height: 70px; }
  .variable-row { min-height: 49px; padding: 3px 0; }
}

@media (max-width: 760px) {
  body { height: auto; min-height: 100vh; min-height: 100dvh; overflow-x: hidden; overflow-y: auto; }
  .app-shell { width: calc(100% - 18px); max-width: 760px; height: auto; min-height: 100vh; min-height: 100dvh; }
  .lab-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(330px, 62vh) 300px;
    grid-template-rows: minmax(330px, 62vh) clamp(250px, 38vh, 320px);
    grid-template-rows: minmax(330px, 62dvh) clamp(250px, 38dvh, 320px);
    gap: 8px;
    padding-top: 8px;
  }
  .workbench {
    min-width: 0;
    min-height: 0;
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    flex-direction: row;
    gap: 0;
    padding: 0 28px 4px 0;
    scroll-snap-type: x mandatory;
    scroll-padding-inline: 0;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .workbench > .desk-module {
    min-width: 0;
    height: 100%;
    flex: 0 0 calc(100% - 28px);
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
  .workbench > .desk-module + .desk-module { margin-left: 10px; }
  .structure-module, .motor-control-module { overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .module-heading { min-height: 48px; padding: 7px 9px; }
  .part-grid { gap: 6px; padding: 8px; }
  .part-grid b { font-size: 12px; }
  .part-grid small { margin-top: 3px; font-size: 8px; }
  .swatch { width: 14px; height: 26px; flex-basis: 14px; }
  .motor-dashboard { gap: 6px; padding: 6px 8px; }
  .motor-power-button {
    min-height: 64px;
    grid-template-columns: 31px minmax(0, 1fr) 7px;
    gap: 6px;
    padding: 6px 7px;
  }
  .motor-power-button strong { font-size: 12px; }
  .motor-power-button small { margin-top: 2px; font-size: 7px; }
  .power-symbol { width: 30px; height: 30px; }
  .power-symbol::before { left: 13px; top: 6px; height: 10px; }
  .power-symbol i { left: 7px; top: 8px; width: 14px; height: 14px; }
  .speed-readout { min-height: 64px; padding: 6px 8px; }
  .speed-value output { font-size: 20px; }
  .variable-controls { padding: 0 8px 3px; }
  .variable-row { min-height: 37px; grid-template-columns: minmax(80px, .72fr) minmax(0, 2.28fr); gap: 6px; padding: 2px 0; }
  .variable-label strong { font-size: 12px; }
  .variable-label small { margin-top: 2px; font-size: 7px; }
  .variable-buttons { gap: 4px; }
  .variable-buttons button { min-height: 32px; padding: 2px; font-size: 10px; }
  .motor-theory { gap: 1px; margin: 0 8px 6px; padding: 4px 7px; }
  .motor-theory span { display: none; }
  .motor-theory strong, .motor-theory output { font-size: 8px; line-height: 1.25; }
}

@media (max-width: 620px) {
  .app-shell { width: 100%; padding: 7px 8px 12px; }
  .topbar { min-height: 48px; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .brand strong { font-size: 14px; }
  .stage-heading { top: 14px; left: 14px; }
  .stage-heading h1 { font-size: 16px; }
  .stage-heading p { max-width: 210px; font-size: 9px; }
  .view-actions { top: auto; right: 12px; bottom: 12px; }
  .view-actions button { width: 38px; min-height: 36px; overflow: hidden; padding: 0; white-space: nowrap; text-indent: -999px; }
  .view-actions span { display: grid; width: 100%; height: 100%; place-items: center; margin: 0; text-indent: 0; }
  .selection-badge { left: 12px; bottom: 12px; min-width: 130px; padding: 7px 9px; }
  .selection-badge strong { font-size: 11px; }
  .gesture-hint { bottom: 58px; white-space: nowrap; }
  .structure-module .module-heading { grid-template-columns: 36px minmax(0, 1fr) minmax(104px, auto); gap: 6px; padding: 6px; }
  .module-index { width: 36px; height: 28px; font-size: 10px; }
  .structure-restore-button { min-width: 104px; min-height: 34px; padding: 4px 5px; }
  .structure-restore-button strong { font-size: 9px; }
  .structure-restore-button small { font-size: 5.5px; }
  .motor-dashboard { grid-template-columns: minmax(96px, .82fr) minmax(116px, 1.18fr); gap: 5px; padding-left: 6px; padding-right: 6px; }
  .part-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(40px, 1fr)); gap: 5px; padding: 6px; }
  .part-grid button { gap: 5px; padding: 5px; }
  .part-grid b { font-size: 11px; }
  .part-grid small { font-size: 7px; }
  .swatch { width: 12px; height: 24px; flex-basis: 12px; }
  .axis-guide { left: 5%; right: 5%; }
}

@media (max-width: 760px) and (max-height: 680px) {
  .lab-layout { grid-template-rows: minmax(300px, 56vh) 240px; grid-template-rows: minmax(300px, 56dvh) 240px; }
  .module-heading { min-height: 44px; padding: 5px 7px; }
  .motor-dashboard { padding-top: 4px; padding-bottom: 4px; }
  .motor-power-button, .speed-readout { min-height: 56px; }
  .variable-row { min-height: 31px; padding: 1px 0; }
  .variable-buttons button { min-height: 28px; }
  .motor-theory { margin-bottom: 4px; padding: 3px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
