:root {
  color-scheme: dark;
  --bg: #121313;
  --surface: #f2f4f0;
  --surface-2: #e4e9e2;
  --ink: #171918;
  --muted: #69706b;
  --line: #c8d0c6;
  --steel: #41494d;
  --tower: #8f9a9c;
  --orange: #e2672c;
  --orange-dark: #a94720;
  --teal: #008f8b;
  --green: #5d9d38;
  --red: #c94732;
  --yellow: #e7b53c;
  --white: #fffefa;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--white);
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

.sim-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 78px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: #181a19;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 2px solid var(--orange);
  border-radius: 50%;
  position: relative;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: var(--orange);
}

.brand-mark::before {
  width: 8px;
  height: 21px;
  top: 7px;
  border-radius: 8px 8px 2px 2px;
}

.brand-mark::after {
  width: 18px;
  height: 3px;
  bottom: 7px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  line-height: 1.05;
  font-weight: 760;
  letter-spacing: 0;
}

.brand p,
.panel-heading p,
.metric span,
.range-row span,
.scene-overlay span,
.force-row span,
.toggle-row small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.2;
}

.brand p {
  color: #cdd3cf;
  margin-top: 5px;
}

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

.icon-button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  color: var(--white);
  background: #252927;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition:
    transform 150ms ease,
    background 150ms ease,
    border-color 150ms ease;
}

.icon-button:hover {
  background: #303531;
  border-color: rgba(255, 255, 255, 0.28);
}

.icon-button:active {
  transform: translateY(1px);
}

.icon-button.primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #17120f;
  font-weight: 760;
}

.icon-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.2;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 315px) minmax(380px, 1fr) minmax(270px, 340px);
}

.panel {
  background: var(--surface);
  color: var(--ink);
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.controls {
  border-right: 1px solid var(--line);
}

.telemetry {
  border-left: 1px solid var(--line);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.panel-heading strong {
  font-size: 0.9rem;
  text-align: right;
}

.control-group {
  padding: 15px 0 18px;
  border-bottom: 1px solid var(--line);
}

.control-group:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.control-group h2,
.formula-box h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #3e4641;
  margin-bottom: 12px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  align-items: center;
  margin: 13px 0;
}

.range-row output {
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 760;
  white-space: nowrap;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--orange);
}

.toggle-row {
  min-height: 44px;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.toggle-row span {
  display: grid;
  gap: 3px;
}

.toggle-row strong {
  font-size: 0.9rem;
}

.toggle-row input {
  appearance: none;
  width: 48px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #cbd3cc;
  position: relative;
  cursor: pointer;
  transition: background 150ms ease;
}

.toggle-row input::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  transition: transform 150ms ease;
}

.toggle-row input:checked {
  background: var(--teal);
}

.toggle-row input:checked::before {
  transform: translateX(22px);
}

.manual-only {
  opacity: 0.48;
  pointer-events: none;
}

.manual-enabled {
  opacity: 1;
  pointer-events: auto;
}

.viewport {
  position: relative;
  min-height: calc(100vh - 79px);
  overflow: hidden;
  background: #202322;
}

#sceneCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.scene-overlay {
  position: absolute;
  z-index: 2;
  backdrop-filter: blur(10px);
  background: rgba(18, 19, 19, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: var(--shadow);
}

.top-left {
  top: 16px;
  left: 16px;
  min-height: 38px;
  border-radius: 7px;
  padding: 8px 10px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.status-pill {
  color: #141411;
  border-radius: 999px;
  padding: 5px 9px;
  font-weight: 800;
  background: var(--yellow);
}

.status-pill.ready {
  background: #d8dfd7;
}

.status-pill.running {
  background: var(--green);
}

.status-pill.captured {
  background: var(--teal);
  color: var(--white);
}

.status-pill.failed {
  background: var(--red);
  color: var(--white);
}

.bottom-strip {
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 1px;
  border-radius: 8px;
  overflow: hidden;
}

.bottom-strip div {
  min-width: 0;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.055);
}

.bottom-strip span {
  display: block;
  color: #cbd3cf;
  margin-bottom: 4px;
}

.bottom-strip strong {
  display: block;
  font-size: clamp(0.9rem, 1.8vw, 1.18rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcf8;
}

.metric span,
.metric strong {
  display: block;
}

.metric strong {
  margin-top: 6px;
  font-size: 1.05rem;
}

.force-stack {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.force-row {
  display: grid;
  grid-template-columns: 34px 1fr 74px;
  align-items: center;
  gap: 9px;
}

.force-row > span {
  font-weight: 800;
  color: #3d4540;
}

.force-row > div {
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: #d7ded7;
}

.force-row i {
  display: block;
  height: 100%;
  width: 4%;
  border-radius: inherit;
  transition: width 120ms linear;
}

.force-row strong {
  text-align: right;
  font-size: 0.78rem;
}

.gravity-row i {
  background: var(--red);
}

.drag-row i {
  background: var(--teal);
}

.thrust-row i {
  background: var(--orange);
}

.formula-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 7px;
}

.formula-box p {
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcf8;
  color: #3c4540;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plot-wrap {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
  overflow: hidden;
}

#plotCanvas {
  width: 100%;
  display: block;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: minmax(250px, 310px) minmax(360px, 1fr);
  }

  .telemetry {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: minmax(220px, 0.7fr) 1fr 1fr;
    gap: 18px;
    align-items: start;
  }

  .telemetry .panel-heading {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  .formula-box,
  .plot-wrap,
  .force-stack {
    margin-top: 0;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

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

  .sim-actions {
    width: 100%;
    justify-content: stretch;
  }

  .icon-button {
    flex: 1 1 0;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .panel {
    max-height: none;
  }

  .viewport {
    order: 1;
    min-height: 68vh;
  }

  .controls {
    order: 2;
  }

  .telemetry {
    order: 3;
  }

  .bottom-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .telemetry {
    display: block;
  }

  .force-stack,
  .formula-box,
  .plot-wrap {
    margin-top: 18px;
  }
}
