:root {
  color-scheme: dark;
  --bg: #05070f;
  --panel: #0d1122;
  --panel-2: #161c34;
  --surface: #0f1530;
  --surface-2: #0b1022;
  --surface-3: #101936;
  --surface-4: #141f3f;
  --surface-5: #24325e;
  --surface-6: #1b2747;
  --canvas-bg: #030512;
  --canvas-top: #050a18;
  --line: #35447a;
  --text: #f2fbff;
  --muted: #b4c3ff;
  --amp: #ffd84d;
  --pd: #37ffd1;
  --graph-amp: #ff5bd1;
  --graph-pd: #34f5ff;
  --graph-amp-point: #ffb3ec;
  --graph-pd-point: #b5fcff;
  --accent: #ff49c7;
  --blue: #72a6ff;
  --hint-bg: linear-gradient(180deg, rgba(255, 73, 199, 0.12), rgba(55, 255, 209, 0.08));
  --legend-bg: linear-gradient(180deg, rgba(20, 31, 63, 0.96) 0%, rgba(13, 17, 34, 0.96) 100%);
  --toggle-bg: linear-gradient(180deg, rgba(36, 50, 94, 0.9) 0%, rgba(15, 21, 48, 0.95) 100%);
  --switch-bg: linear-gradient(180deg, rgba(20, 31, 63, 0.95) 0%, rgba(13, 17, 34, 0.95) 100%);
  --switch-active-bg: linear-gradient(180deg, rgba(255, 216, 77, 0.95) 0%, rgba(255, 73, 199, 0.75) 100%);
  --panel-glow: radial-gradient(circle at top right, rgba(55, 255, 209, 0.08), transparent 36%);
  --panel-gradient: linear-gradient(180deg, var(--surface-3) 0%, var(--bg) 100%);
  --control-bg: linear-gradient(180deg, rgba(255, 216, 77, 0.24) 0%, rgba(255, 73, 199, 0.16) 100%);
  --performance-bg: linear-gradient(180deg, rgba(20, 31, 63, 0.98) 0%, rgba(13, 17, 34, 0.98) 100%);
  --code-bg: rgba(4, 8, 20, 0.88);
  --code-text: #f8e7bb;
}

body.theme-light {
  color-scheme: light;
  --bg: #f7f0df;
  --panel: #fff7e8;
  --panel-2: #f0e0c4;
  --surface: #fff3d8;
  --surface-2: #fffaf0;
  --surface-3: #f5e9cf;
  --surface-4: #eadab9;
  --surface-5: #d8c29a;
  --surface-6: #d5ccb7;
  --canvas-bg: #fff8ea;
  --canvas-top: #fffdf6;
  --line: #bfa783;
  --text: #2b241a;
  --muted: #6e5d48;
  --amp: #d97706;
  --pd: #0a9382;
  --graph-amp: #c46a00;
  --graph-pd: #007d6f;
  --graph-amp-point: #ffcf7a;
  --graph-pd-point: #78dacc;
  --accent: #d24f2e;
  --blue: #3a63c9;
  --hint-bg: linear-gradient(180deg, rgba(210, 79, 46, 0.12), rgba(204, 122, 0, 0.08));
  --legend-bg: linear-gradient(180deg, #fff7e7 0%, #f1e3c5 100%);
  --toggle-bg: linear-gradient(180deg, #f0dfb8 0%, #e2ca9c 100%);
  --switch-bg: linear-gradient(180deg, #f7ebca 0%, #ebd8ad 100%);
  --switch-active-bg: linear-gradient(180deg, #ffd778 0%, #f0b94d 100%);
  --panel-glow: radial-gradient(circle at top right, rgba(0, 0, 0, 0.02), transparent 36%);
  --panel-gradient: linear-gradient(180deg, var(--surface-2) 0%, var(--bg) 100%);
  --control-bg: linear-gradient(180deg, rgba(255, 216, 77, 0.24) 0%, rgba(255, 73, 199, 0.16) 100%);
  --performance-bg: linear-gradient(180deg, #fff7e4 0%, #efddbd 100%);
  --code-bg: rgba(255, 248, 230, 0.95);
  --code-text: #3a2f1f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}

button:hover,
button.is-active {
  border-color: var(--accent);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(circle at top left, rgba(255, 73, 199, 0.18), transparent 40%),
    radial-gradient(circle at top right, rgba(55, 255, 209, 0.16), transparent 34%),
    linear-gradient(180deg, var(--surface) 0%, var(--panel) 100%);
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.transport {
  display: flex;
  gap: 8px;
}

.transport-link {
  display: inline-flex;
  align-items: center;
  min-width: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  text-decoration: none;
}

.transport-link:hover,
.transport-link.is-active {
  border-color: var(--accent);
}

.transport button {
  min-width: 44px;
  padding: 0 12px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 280px minmax(520px, 1fr) clamp(360px, 22vw, 420px);
}

.preset-list,
.output-panel {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.output-panel {
  border-right: 0;
  border-left: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto auto auto auto auto;
  align-content: start;
  gap: 8px;
  padding: 12px;
}

.list-head,
.output-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
}

.list-head {
  justify-content: space-between;
}

.list-head button {
  width: 36px;
}

.preset-buttons {
  display: grid;
  gap: 2px;
}

.preset-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 2px;
}

.preset-button {
  min-width: 0;
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  background: transparent;
  text-align: left;
  overflow: hidden;
}

.preset-remove {
  position: relative;
  z-index: 1;
  min-width: 36px;
  min-height: 42px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.preset-remove:hover {
  color: var(--accent);
}

.preset-button.is-active {
  background: linear-gradient(180deg, rgba(255, 216, 77, 0.34) 0%, rgba(255, 73, 199, 0.22) 100%);
  border-left: 4px solid var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255, 216, 77, 0.18);
}

.preset-name {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.preset-meta {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 10px;
  white-space: nowrap;
}

.preset-state {
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.preset-state.is-local {
  color: var(--muted);
}

.preset-state.is-saved {
  color: var(--pd);
}

.preset-state.is-changed {
  color: var(--accent);
}

.editor {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    radial-gradient(circle at top, rgba(255, 73, 199, 0.08), transparent 34%),
    var(--panel-gradient);
}

.editor-head {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 120px 160px 130px;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.editor-hint {
  margin: 14px 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--hint-bg);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.editor-legend {
  display: grid;
  gap: 6px;
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--legend-bg);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.editor-legend strong {
  color: var(--text);
}

.developer-toggle {
  margin: 0 16px 12px;
  width: calc(100% - 32px);
  min-height: 34px;
  border-color: var(--line);
  background: var(--toggle-bg);
  color: var(--muted);
}

.developer-toggle.is-active {
  border-color: rgba(119, 168, 255, 0.55);
  color: var(--text);
}

.lane-switcher {
  display: inline-flex;
  gap: 6px;
  margin: 12px 16px 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--switch-bg);
}

.lane-switcher button {
  min-height: 32px;
  min-width: 140px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.lane-switcher button.is-active {
  background: var(--switch-active-bg);
  color: var(--text);
  box-shadow: 0 0 16px rgba(255, 73, 199, 0.22);
}

.lane-switcher button:last-child {
  min-width: 110px;
}

.lane-switcher button:not(.is-active) {
  opacity: 0.9;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

.curve-panel {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-glow), var(--panel-gradient);
}

canvas {
  width: 100%;
  height: min(36vh, 360px);
  min-height: 220px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 10%, rgba(55, 255, 209, 0.08), transparent 30%),
    linear-gradient(180deg, var(--canvas-top) 0%, var(--canvas-bg) 100%);
  cursor: crosshair;
  touch-action: none;
  box-shadow: 0 0 0 1px rgba(255, 73, 199, 0.08), 0 0 32px rgba(55, 255, 209, 0.06);
}

.tables {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
}

.stage-panel,
.developer-panel {
  margin: 0 16px 16px;
}

.stage-panel.is-hidden,
.developer-panel.is-hidden,
.stage-grid.is-hidden {
  display: none;
}

.stage-head {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lane-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.lane-title span {
  color: var(--muted);
  font-size: 12px;
}

.stage-grid {
  display: grid;
  gap: 8px;
}

.stage-row input {
  min-width: 0;
}

.stage-row {
  display: grid;
  grid-template-columns: 28px 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.stage-row strong {
  color: var(--muted);
  font-size: 12px;
}

.stage-row input {
  height: 34px;
}

.editor-actions,
.developer-actions {
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.editor-actions {
  margin: 0 16px 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.developer-actions {
  margin-bottom: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.editor-actions button:nth-child(1),
.editor-actions button:nth-child(2),
.editor-actions button:nth-child(3) {
  background: var(--control-bg);
}

.developer-actions button:nth-child(1),
.developer-actions button:nth-child(2) {
  background: var(--control-bg);
}

.editor-actions button:nth-child(5),
.editor-actions button:nth-child(6) {
  border-color: rgba(255, 204, 102, 0.35);
}

.editor-actions button:nth-child(4) {
  border-color: rgba(255, 115, 92, 0.5);
}

.volatility-warning {
  margin: 0 16px 14px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 204, 102, 0.5);
  border-left: 4px solid var(--amp);
  border-radius: 6px;
  background: var(--legend-bg);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.volatility-warning strong {
  color: var(--text);
}

.output-actions button {
  min-height: 32px;
  padding: 0 6px;
  font-size: 12px;
}

textarea {
  min-height: 320px;
  resize: none;
  padding: 12px;
  color: var(--code-text);
  line-height: 1.35;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  tab-size: 4;
  white-space: pre;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
}

.developer-log-panel {
  margin-top: 10px;
}

.developer-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.developer-log-head h3 {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.developer-log {
  min-height: 140px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.performance-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--performance-bg);
}

.performance-title {
  grid-column: 1 / -1;
}

.performance-panel label {
  gap: 4px;
}

.performance-panel input,
.performance-panel select {
  height: 32px;
}

.performance-panel input[type="range"] {
  padding: 0;
}

.detune-control {
  position: relative;
  display: grid;
  gap: 1px;
}

.performance-panel .detune-control input {
  width: 100%;
  height: 18px;
  margin: 0;
  appearance: none;
  background: transparent;
}

.detune-control::after {
  position: absolute;
  top: 2px;
  left: 50%;
  width: 2px;
  height: 14px;
  background: var(--text);
  box-shadow: 0 0 5px var(--text);
  content: "";
  pointer-events: none;
  transform: translateX(-1px);
}

.detune-control input::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: linear-gradient(90deg, var(--accent) 0%, var(--panel-2) 47%, var(--panel-2) 53%, var(--pd) 100%);
}

.detune-control input::-webkit-slider-thumb {
  width: 14px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid var(--text);
  border-radius: 2px;
  appearance: none;
  background: var(--surface);
  box-shadow: 0 0 7px var(--accent);
}

.detune-control input::-moz-range-track {
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: linear-gradient(90deg, var(--accent) 0%, var(--panel-2) 47%, var(--panel-2) 53%, var(--pd) 100%);
}

.detune-control input::-moz-range-thumb {
  width: 12px;
  height: 16px;
  border: 2px solid var(--text);
  border-radius: 2px;
  background: var(--surface);
  box-shadow: 0 0 7px var(--accent);
}

.detune-scale {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
}

.detune-scale span:last-child {
  text-align: right;
}

.detune-scale strong {
  color: var(--text);
  font-size: 8px;
  letter-spacing: 0.08em;
}

.performance-panel label:has(input[type="checkbox"]) {
  grid-template-columns: 18px 1fr;
  grid-column: span 2;
  align-items: center;
  gap: 8px;
}

.performance-panel label:has(input[type="checkbox"]) input {
  width: 18px;
  height: 18px;
}

.status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

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

  .preset-list,
  .output-panel {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .preset-buttons {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .editor-head,
  .tables {
    grid-template-columns: 1fr;
  }
}
