:root {
  --bg-a: #f7efe1;
  --bg-b: #d8e8f2;
  --ink: #16222f;
  --muted: #425b72;
  --panel: rgba(255, 255, 255, 0.9);
  --stroke: rgba(22, 34, 47, 0.2);
  --accent: #e6672e;
  --accent-dark: #c54f1d;
  --safe: #1f8852;
  --warn: #b3443c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  background:
    radial-gradient(circle at 10% 15%, rgba(230, 103, 46, 0.18), transparent 30%),
    radial-gradient(circle at 88% 20%, rgba(31, 136, 82, 0.16), transparent 26%),
    linear-gradient(140deg, var(--bg-a), var(--bg-b));
  min-height: 100vh;
}

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(22, 34, 47, 0.12);
  backdrop-filter: blur(5px);
}

.sim-panel {
  padding: 0.75rem;
}

.sim-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.5rem 0.75rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  letter-spacing: 0.01em;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.sim-config {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.55rem;
  padding: 0.25rem 0.5rem 0.8rem;
}

.cfg-item {
  display: grid;
  gap: 0.26rem;
}

.sim-config label {
  font-size: 0.78rem;
  color: #2f485d;
}

.sim-config input {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0.34rem 0.42rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: #1d2b38;
  background: #fbfdff;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: linear-gradient(180deg, #fefcf8, #e8f0f5);
  cursor: grab;
}

canvas.dragging {
  cursor: grabbing;
}

canvas.draw-mode {
  cursor: crosshair;
}

.side {
  display: grid;
  gap: 1rem;
  align-content: start;
  min-width: 0;
}

.controls,
.code,
.telemetry {
  padding: 0.9rem;
  min-width: 0;
}

.code-inline {
  margin-top: 0.8rem;
  padding: 0.8rem 0.4rem 0.2rem;
  border-top: 1px solid var(--stroke);
}

.section-title {
  margin: 0 0 0.7rem;
  font-size: 1rem;
  font-weight: 700;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.52rem 0.75rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
  transition: transform 120ms ease, background-color 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: var(--accent-dark);
}

button.secondary {
  background: #3b6d90;
}

button.safe {
  background: var(--safe);
}

button.warn {
  background: var(--warn);
}

.wheel-grid {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.45rem 0.5rem;
  align-items: center;
}

.wheel-label {
  font-weight: 600;
  width: 2.1rem;
}

.wheel-value {
  font-family: "IBM Plex Mono", monospace;
  color: var(--muted);
  font-size: 0.9rem;
  min-width: 5ch;
  text-align: right;
}

.small-btn {
  padding: 0.4rem 0.62rem;
  font-size: 0.88rem;
  border-radius: 8px;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  padding: 0.7rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.45;
  background: #f9fbfd;
  color: #1d2b38;
}

.CodeMirror {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  height: 220px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86rem;
  background: #f9fbfd;
}

.status {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  color: #27465f;
  background: rgba(39, 70, 95, 0.08);
  border: 1px dashed rgba(39, 70, 95, 0.25);
  border-radius: 8px;
  padding: 0.5rem 0.6rem;
  min-height: 44px;
  white-space: pre-wrap;
}

.debug-log {
  width: 100%;
  max-width: 100%;
  margin-top: 0.55rem;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: #f4f8fb;
  min-height: 84px;
  max-height: 170px;
  overflow: auto;
  padding: 0.45rem 0.55rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.79rem;
  line-height: 1.38;
  color: #2c3f52;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.api-doc {
  margin-top: 0.55rem;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: #f7fafc;
  padding: 0.35rem 0.5rem;
}

.api-doc summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: #2f485d;
  font-weight: 600;
}

.api-doc pre {
  margin: 0.45rem 0 0;
  white-space: pre-wrap;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.76rem;
  line-height: 1.4;
  color: #2b4257;
}

.memory-view {
  max-height: 160px;
  overflow: auto;
  border-top: 1px dashed var(--stroke);
  padding-top: 0.45rem;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.42rem 0.8rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84rem;
}

.metrics div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: #1d3347;
}

.camera-grid {
  display: grid;
  grid-template-columns: 1fr 1.25fr auto;
  align-items: center;
  gap: 0.42rem 0.6rem;
}

.camera-grid label {
  font-size: 0.84rem;
  color: #2f485d;
}

.camera-grid input[type="range"] {
  width: 100%;
}

.camera-value {
  font-family: "IBM Plex Mono", monospace;
  color: #2f485d;
  font-size: 0.84rem;
  min-width: 5ch;
  text-align: right;
}

.track-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.45rem 0.6rem;
}

.track-grid label,
.mini-label {
  font-size: 0.78rem;
  color: #2f485d;
}

.track-grid input,
.track-grid select {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 0.34rem 0.42rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.78rem;
  color: #1d2b38;
  background: #fbfdff;
}

.small-textarea {
  min-height: 88px;
  margin-top: 0.35rem;
  font-size: 0.78rem;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}
