:root {
  --ink: #18302d;
  --muted: #657570;
  --line: #dce3dc;
  --green: #087e68;
  --bg: #f4f6f0;
  --orange: #c56b27;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  font: 14px/1.5 system-ui, sans-serif;
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
}

button:hover {
  border-color: var(--green);
  background: #edf8f2;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #e0ad46;
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

.primary {
  background: var(--green);
  color: white;
  border-color: var(--green);
}

.primary:hover {
  background: #056653;
  color: white;
}

header {
  padding: 22px 30px;
  background: #143d35;
  color: #fff;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
}

h1 {
  font-size: 25px;
  letter-spacing: -0.6px;
  margin: 0;
}

header p {
  margin: 3px 0 0;
  color: #c0d5cd;
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 2px;
  font-weight: 700;
  text-transform: uppercase;
  color: #a7d6bb;
}

.toolbar {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.app {
  display: grid;
  grid-template-columns: 222px minmax(0, 1fr) 265px;
  gap: 17px;
  padding: 20px;
  max-width: 1800px;
  margin: auto;
}

.panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 17px;
}

.panel h2 {
  font-size: 15px;
  margin: 0 0 12px;
}

.panel h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 21px 0 9px;
  color: var(--muted);
}

.panel p {
  margin: 8px 0;
}

.small {
  font-size: 12px;
  color: var(--muted);
}

/* Component library */

.palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.part {
  padding: 11px 5px;
  text-align: center;
  touch-action: none;
}

.part b {
  display: block;
  font-size: 17px;
}

.part span {
  font-size: 11px;
  color: var(--muted);
}

.part.active {
  border: 2px solid var(--green);
  background: #eaf7ee;
}

.part.wheel {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  align-items: center;
}

.part.wheel b {
  font-size: 14px;
}

.gear-icon {
  color: var(--orange);
}

/* Form controls */

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin: 10px 0 4px;
}

input,
select {
  width: 100%;
  padding: 8px;
  background: white;
  border: 1px solid #ccd6cd;
  border-radius: 7px;
  color: var(--ink);
}

input[type="checkbox"] {
  width: auto;
  vertical-align: middle;
}

.checks label {
  font-weight: 400;
}

/* Layout workspace */

.workspace {
  min-width: 0;
}

.stage {
  background: #fcfdf9;
  border: 1px solid var(--line);
  border-radius: 13px;
  overflow: hidden;
}

.stage-head {
  padding: 13px 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}

.stage-head b {
  font-size: 13px;
}

.badge {
  font-size: 11px;
  background: #e4f1e8;
  color: #246343;
  padding: 4px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

.canvas-scroll {
  overflow: auto;
}

svg {
  display: block;
  width: 100%;
  min-width: 700px;
  touch-action: none;
  user-select: none;
}

svg text {
  font-family: system-ui, sans-serif;
}

svg .object {
  cursor: grab;
}

svg .object:active {
  cursor: grabbing;
}

.hint {
  padding: 11px 17px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  min-height: 43px;
}

.hint.placing {
  background: #e7f4e9;
  color: #195b43;
}

/* Performance cards */

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 13px 0;
}

.metric {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px;
}

.metric span {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}

.metric strong {
  display: block;
  font-size: 23px;
  font-weight: 650;
  margin: 3px 0;
}

.metric small {
  font-size: 11px;
  color: var(--muted);
}

/* Fit checks and dimensions */

.bottom {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 13px;
}

.status {
  font-size: 12px;
  padding: 8px 10px;
  background: #f3f6f0;
  border-radius: 6px;
  margin: 6px 0;
}

.status.ok {
  border-left: 3px solid #239263;
}

.status.warn {
  border-left: 3px solid #df9b2e;
  background: #fff8e9;
}

.status.bad {
  border-left: 3px solid #c55747;
  background: #fff0ec;
}

#issues {
  max-height: 250px;
  overflow: auto;
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 7px 0;
  border-bottom: 1px solid #edf0eb;
}

.readout b {
  text-align: right;
}

/* Selected component and component list */

.component {
  display: flex;
  gap: 4px;
  margin: 5px 0;
}

.component button {
  padding: 6px 8px;
  font-size: 12px;
  flex: 1;
  text-align: left;
}

.component button.active {
  background: #e5f1e8;
  border-color: #309778;
}

.stack {
  display: grid;
  gap: 7px;
}

.danger {
  color: #ae4238;
}

/* Notes and legend */

.footer {
  max-width: 1800px;
  margin: 0 auto;
  padding: 0 25px 25px;
  font-size: 12px;
  color: var(--muted);
}

details {
  margin-top: 14px;
  font-size: 12px;
}

summary {
  cursor: pointer;
  font-weight: 600;
}

.legend {
  display: flex;
  gap: 13px;
  font-size: 11px;
  color: var(--muted);
  flex-wrap: wrap;
}

.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}

.hidden {
  display: none;
}

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #193e34;
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  z-index: 5;
  max-width: 90vw;
  box-shadow: 0 4px 25px #0002;
}

/* Tablet layout */

@media (max-width: 1150px) {
  .app {
    grid-template-columns: 190px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
  }

  .inspector h3 {
    margin-top: 0;
  }

  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Phone layout */

@media (max-width: 700px) {
  header {
    padding: 18px;
    align-items: flex-start;
    flex-direction: column;
  }

  .app {
    padding: 10px;
    grid-template-columns: 1fr;
  }

  .library {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }

  .library h3 {
    margin-top: 0;
  }

  .inspector {
    grid-column: auto;
    display: block;
  }

  .inspector > div {
    margin-bottom: 20px;
  }

  .metrics {
    gap: 5px;
  }

  .metric {
    padding: 9px;
  }

  .metric strong {
    font-size: 19px;
  }

  .bottom {
    grid-template-columns: 1fr;
  }

  .stage-head {
    flex-wrap: wrap;
  }

  .panel {
    padding: 13px;
  }
}

/* =========================================
   SOFT COLOURS FOR DRIVETRAIN LAB
   Add at the bottom of style.css
========================================= */

:root {
  --bg: #f3f5f8;
  --ink: #243449;
  --muted: #59697b;
  --line: #dce3eb;
}

.panel,
.stage,
.metric {
  box-shadow: 0 3px 12px rgba(32, 52, 75, 0.035);
}


/* GEARS — SOFT PEACH */

#gears {
  padding: 10px;
  background: #fff4e8;
  border: 1px solid #efd9bc;
  border-radius: 12px;
}

.library h3:has(+ #gears) {
  color: #835423;
}

#gears .part {
  background: #fffaf3;
  border-color: #e6cba7;
}

#gears .part:hover:not(:disabled) {
  background: #ffebd1;
  border-color: #af7736;
}

#gears .gear-icon {
  color: #996323;
}


/* WHEELS — LIGHT BLUE */

#wheels {
  padding: 10px;
  background: #edf6ff;
  border: 1px solid #cadff1;
  border-radius: 12px;
}

.library h3:has(+ #wheels) {
  color: #285d83;
}

#wheels .part {
  background: #f8fbff;
  border-color: #bfd6eb;
}

#wheels .part:hover:not(:disabled) {
  background: #deeeff;
  border-color: #5285b1;
}


/* C-CHANNEL — COOL GREY */

.library > div:has(#cols) {
  margin-top: 20px;
  padding: 14px;
  background: #edf1f5;
  border: 1px solid #d3dce6;
  border-radius: 12px;
}

.library > div:has(#cols) > h3 {
  margin-top: 0;
  color: #4e6279;
}


/* RIGHT SIDEBAR — SEPARATE CARDS */

.inspector > div {
  padding: 14px;
  border: 1px solid #dde4ec;
  border-radius: 12px;
  margin-bottom: 16px;
  min-width: 0;
}

.inspector > div > h2,
.inspector > div > h3 {
  margin-top: 0;
}

.inspector > div:last-child {
  margin-bottom: 0;
}


/* PREDESIGNED SETUPS — PALE SAND */

.inspector > div:has(#presetMenu) {
  background: #fff8e9;
  border-color: #e9dab6;
}

.inspector > div:has(#presetMenu) > h3 {
  color: #78602b;
}

#loadPreset {
  width: 100%;
  background: #f6e8c8;
  border-color: #d9bf82;
  color: #584519;
}

#loadPreset:hover:not(:disabled) {
  background: #efdcad;
}


/* SELECTED COMPONENT — PALE BLUE */

.inspector > div:has(#selection) {
  background: #f0f6ff;
  border-color: #cbdcf3;
}


/* MOTORS — LAVENDER */

.inspector > div:has(#motor) {
  background: #f4efff;
  border-color: #dcd0ef;
}

.inspector > div:has(#motor) > h3 {
  color: #675087;
}

#setInput,
#setMotor2 {
  background: #efe7fc;
  border-color: #d3c1ed;
  color: #54377b;
}

#setInput:hover:not(:disabled),
#setMotor2:hover:not(:disabled) {
  background: #e3d6f8;
  border-color: #9b7ac5;
}


/* PLACED COMPONENTS */

.inspector > div:has(#components) {
  background: #f8fafc;
}


/* OUTPUT CARDS */

.metric:has(#rpm) {
  background: #edf5ff;
  border-color: #cbdcf0;
}

.metric:has(#speed) {
  background: #eef8fa;
  border-color: #cce3e9;
}

.metric:has(#torque) {
  background: #f5efff;
  border-color: #dfd1ef;
}

#rpm {
  color: #245c91;
}

#speed {
  color: #256672;
}

#torque {
  color: #69468b;
}


/* WORKSPACE AND INPUT FIELDS */

.stage-head {
  background: #f8fafc;
}

.hint:not(.placing) {
  background: #f8fafc;
}

input:not([type="checkbox"]),
select {
  background: #ffffff;
}

input[readonly] {
  background: #edf1f6;
  color: #435469;
}

.part span,
.small {
  color: var(--muted);
}


/* BLUE OUTLINE = SELECTED COMPONENT */

#gears .part.active,
#wheels .part.active,
#components button.active {
  background: #e8f1ff;
  border-color: #356dba;
  box-shadow: inset 0 0 0 1px #356dba;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #356dba;
  outline-offset: 3px;
}


/* FIT CHECK RESULTS */

.status.ok {
  background: #eef8f0;
}

.status.warn {
  background: #fff8e9;
}

.status.bad {
  background: #fff0ec;
}


/* SPEED AND TORQUE TABLE */

section:has(> div > table #speedTorqueRows) {
  padding: 12px;
  background: #f8f5fc;
  border: 1px solid #e3d9ef;
  border-radius: 12px;
}

#speedTorqueRows tr:nth-child(even) {
  background: #eee8f6;
}

#speedTorqueRows tr:hover {
  background: #e3eaf6;
}


/* SMALLER SCREENS */

@media (max-width: 1150px) and (min-width: 701px) {
  .inspector {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .library > div:has(#cols) {
    margin-top: 0;
  }
}