:root {
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-2: #1a1e29;
  --border: #262b38;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #ffb347;
  --accent-ink: #1b1204;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  display: flex;
}

/* ---------- Panel ---------- */
#panel {
  width: 300px;
  flex: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  transition: margin-left 0.2s ease;
  z-index: 2;
}

body.panel-hidden #panel { margin-left: -300px; }

#panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

#togglePanel {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.controls {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field legend, .label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.label { margin-bottom: 0; }
.label em { font-style: normal; color: var(--text); margin-left: 4px; }
.label output { color: var(--text); text-transform: none; letter-spacing: 0; font-weight: 500; }

small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input[type="number"], select {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 14px;
}

input[type="number"]:focus, select:focus, button:focus-visible, .segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

/* Segmented radio control */
.segmented {
  display: flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}

.segmented label {
  flex: 1;
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  text-align: center;
  padding: 6px 4px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  white-space: nowrap;
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.segmented.small span { font-size: 12px; padding: 7px 2px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}

.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.under-check { margin-top: -8px; padding-left: 24px; }

.buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

button {
  font: inherit;
}

.buttons button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 4px;
  font-size: 13px;
  cursor: pointer;
}

.buttons button:hover { border-color: var(--muted); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 12px;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

#status {
  border-top: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

/* ---------- Stage ---------- */
#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#canvas.dragging { cursor: grabbing; }

.hover {
  position: absolute;
  pointer-events: none;
  background: rgba(18, 21, 29, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  transform: translate(14px, 14px);
}

.hover b { color: var(--accent); font-weight: 600; }

.hint {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  opacity: 0.8;
}

.show-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
}

/* ---------- Small screens: panel overlays the canvas ---------- */
@media (max-width: 700px) {
  #panel {
    position: absolute;
    top: 0;
    left: 0;
    width: min(300px, 88vw);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }
  body.panel-hidden #panel { margin-left: calc(-1 * min(300px, 88vw) - 30px); }
  .hint { display: none; }
}
