:root {
  color-scheme: dark;
  --bg: #101010;
  --panel: #171717;
  --panel-2: #202020;
  --field: #080909;
  --line: #3d3d3d;
  --line-soft: #292929;
  --text: #c9c9c9;
  --muted: #969696;
  --accent: #8d8d8d;
  --accent-2: #a8a8a8;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  overflow-anchor: none;
  background: var(--bg);
  color: var(--text);
  font-family: "Menlo", "Monaco", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.35;
}

button,
input,
select { font: inherit; }

:where(button, select, input[type="text"], input[type="number"], input[type="color"]) {
  font-size: 11px;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 304px;
  position: fixed;
  inset: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  overflow-anchor: none;
}

.stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 96px 96px auto;
  gap: 10px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: 10px;
}

.topbar,
.statusbar,
.panel section {
  border: 1px solid var(--line);
  background: var(--panel);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
}

h1,
h2,
p { margin: 0; }

h1 {
  font-size: 14px;
  letter-spacing: 0;
}

.topbar p {
  margin-top: 2px;
  color: var(--muted);
}

h2 {
  min-height: 28px;
  margin: -8px -8px 8px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 11px;
  text-transform: uppercase;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.space-header h2 {
  margin: 0;
  min-height: 0;
  padding: 0;
  display: block;
  background: transparent;
  border: 0;
  cursor: default;
}

.space-header h2::after {
  content: none;
}

h2::after {
  content: "-";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--line-soft);
  background: var(--field);
  color: var(--muted);
  font-weight: 400;
}

.panel section.collapsed {
  padding-bottom: 0;
}

.panel section.collapsed h2 {
  margin-bottom: 0;
  border-bottom: 0;
}

.panel section.collapsed h2::after {
  content: "+";
}

.panel section.collapsed > :not(h2) {
  display: none;
}

.transport,
.row {
  display: flex;
  gap: 4px;
}

.row.two > * { flex: 1; }

button,
select,
input[type="text"],
input[type="number"],
input[type="color"] {
  min-height: 21px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--field);
  color: var(--text);
}

select,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 0 6px;
}

button {
  padding: 0 7px;
  cursor: pointer;
}

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

@media (hover: hover) and (pointer: fine) {
  .native-select-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  .custom-select {
    position: relative;
    width: 100%;
    margin-top: 3px;
  }

  .custom-select-button {
    position: relative;
    width: 100%;
    min-height: 21px;
    padding: 0 20px 0 6px;
    border: 1px solid var(--line);
    border-radius: 0;
    background: var(--field);
    color: var(--text);
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    cursor: pointer;
  }

  .custom-select-button::after {
    content: "v";
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-54%);
    color: var(--muted);
    font-size: 9px;
  }

  .custom-select-button:hover,
  .custom-select.open .custom-select-button {
    border-color: var(--accent);
    background: #232323;
    color: #d8d8d2;
  }

  .custom-select-menu {
    position: fixed;
    z-index: 200;
    min-width: 120px;
    max-height: 260px;
    overflow: auto;
    border: 1px solid var(--accent);
    background: #101010;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.48);
  }

  .custom-select-option {
    min-height: 21px;
    padding: 4px 7px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
  }

  .custom-select-option:hover,
  .custom-select-option.active {
    background: #282828;
    color: #d8d8d2;
  }
}

@media (hover: none), (pointer: coarse), (max-width: 780px) {
  select {
    min-height: 30px;
  }
}

#exportJson {
  border-color: #555;
  background: #202020;
}

#field {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  background: #050707;
  touch-action: none;
  overscroll-behavior: contain;
}

#playbar {
  display: block;
  width: 100%;
  height: 96px;
  min-width: 0;
  border: 1px solid var(--line);
  background: #070808;
  cursor: pointer;
  touch-action: none;
  overscroll-behavior: contain;
}

#heatmap {
  display: block;
  width: 100%;
  height: 96px;
  min-width: 0;
  border: 1px solid var(--line);
  background: #070808;
  cursor: pointer;
  touch-action: none;
  overscroll-behavior: contain;
}

.statusbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 14px;
  min-height: 31px;
  padding: 7px 9px;
  color: var(--muted);
  font-size: 11px;
}

.panel {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  overflow-anchor: none;
  padding: 10px 10px 10px 0;
}

.panel section {
  padding: 8px;
  margin-bottom: 8px;
}

label {
  display: grid;
  gap: 4px;
  margin: 7px 0;
  color: var(--muted);
}

label.check {
  display: flex;
  align-items: center;
  gap: 6px;
}

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

@media (hover: hover) and (pointer: fine) {
  input[type="range"] {
    height: 15px;
    margin: 3px 0 0;
    appearance: none;
    -webkit-appearance: none;
    border: 1px solid #4b4b4b;
    border-radius: 0;
    background:
      linear-gradient(90deg, #8d8d8d 0 var(--fill, 50%), #232323 var(--fill, 50%) 100%);
    box-shadow: 0 0 0 1px #080808 inset;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    height: 13px;
    background: transparent;
    border: 0;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 0;
    height: 13px;
    margin-top: 0;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  input[type="range"]::-moz-range-track {
    height: 13px;
    background: transparent;
    border: 0;
  }

  input[type="range"]::-moz-range-thumb {
    width: 0;
    height: 13px;
    background: transparent;
    border: 0;
    border-radius: 0;
  }

  input[type="range"]:hover,
  input[type="range"]:focus-visible {
    border-color: var(--accent);
    background:
      linear-gradient(90deg, #b6b6b6 0 var(--fill, 50%), #2e2e2e var(--fill, 50%) 100%);
  }
}

@media (hover: none), (pointer: coarse), (max-width: 780px) {
  input[type="range"] {
    min-height: 28px;
  }
}

input[type="color"] {
  width: 100%;
  padding: 0;
}

.value-readout {
  float: right;
  color: var(--text);
}

.lane-list,
.section-list {
  display: grid;
  gap: 4px;
  max-height: 250px;
  overflow: auto;
}

.section-list {
  max-height: 120px;
  margin-top: 6px;
}

.lane-button,
.section-button {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 24px;
  padding: 0 6px;
  border: 1px solid var(--line-soft);
  background: var(--field);
  color: var(--muted);
  text-align: left;
}

.section-button {
  grid-template-columns: minmax(0, 1fr) auto;
}

.lane-button.active {
  border-color: var(--accent);
  color: var(--text);
}

.section-button.active {
  border-color: var(--accent-2);
  color: var(--text);
  background: #202020;
}

.lane-swatch {
  width: 10px;
  height: 10px;
  border: 1px solid rgba(255,255,255,0.35);
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 310px; }
  .panel { padding: 0 10px 10px; }
}

.space-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 18px;
  background: rgba(6, 6, 6, 0.78);
}

.space-modal.open {
  display: block;
}

.space-window {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  height: 100%;
  border: 1px solid var(--line);
  background: #101010;
  padding: 10px;
}

.space-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 10px;
}

.space-header p {
  margin-top: 2px;
  color: var(--muted);
}

#spaceView {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  background: #050707;
  cursor: grab;
}

#spaceView:active {
  cursor: grabbing;
}

.space-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 8px 10px;
}

/* Compact toolbox controls; keep the composition canvases at full scale. */
.panel {
  padding: 8px 8px 8px 0;
  font-size: 10px;
}

.panel section {
  padding: 6px;
  margin-bottom: 6px;
}

.panel h2 {
  min-height: 23px;
  margin: -6px -6px 6px;
  padding: 0 6px;
  font-size: 10px;
}

.panel h2::after {
  width: 15px;
  height: 15px;
}

.panel label {
  gap: 3px;
  margin: 5px 0;
  font-size: 10px;
}

.panel button,
.panel select,
.panel input[type="text"],
.panel input[type="number"],
.panel input[type="color"],
.panel .custom-select-button,
.panel .custom-select-option {
  min-height: 18px;
  padding-left: 5px;
  padding-right: 5px;
  font-size: 10px;
}

.panel .custom-select-button {
  padding-right: 18px;
}

.panel .custom-select-option {
  padding-top: 3px;
  padding-bottom: 3px;
}

.panel input[type="range"] {
  height: 13px;
  margin-top: 2px;
}

.panel .row,
.panel .lane-list,
.panel .section-list {
  gap: 3px;
}

.panel .lane-button,
.panel .section-button {
  min-height: 20px;
  padding: 0 5px;
  gap: 5px;
  font-size: 10px;
}

.panel .lane-swatch {
  width: 8px;
  height: 8px;
}

@media (hover: hover) and (pointer: fine) {
  .panel input[type="range"]::-webkit-slider-runnable-track,
  .panel input[type="range"]::-webkit-slider-thumb,
  .panel input[type="range"]::-moz-range-track,
  .panel input[type="range"]::-moz-range-thumb {
    height: 11px;
  }
}

/* s3g-mc browser utility convergence layer */
.topbar,
.statusbar,
.playbar,
.space-header,
.space-controls,
.panel {
  background: var(--panel);
}

.panel {
  padding: 5px;
  border-left-color: var(--line-soft);
  font-size: 10px;
}

.panel section {
  position: relative;
  margin: 5px;
  padding: 6px;
  border: 0;
  background: #141414;
}

.panel section::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: #c9c9c2;
  opacity: 0.58;
  pointer-events: none;
}

.panel h2 {
  min-height: 23px;
  margin: -6px -6px 6px;
  padding: 0 5px 0 6px;
  border-bottom: 0;
  background: #0f0f0f;
  color: #bdbdb8;
  font-size: 10px;
  font-weight: 400;
}

.panel h2::after {
  width: 15px;
  height: 15px;
  margin-left: 6px;
  border-color: var(--line-soft);
  background: var(--field);
}

.panel label {
  margin: 4px 0;
  color: var(--muted);
  font-size: 10px;
}

button,
.custom-select-button {
  background: #0b0b0b;
}

button {
  text-transform: uppercase;
}

button:hover,
button.active,
.custom-select-button:hover,
.custom-select.open .custom-select-button,
.lane-button.active,
.section-button.active {
  border-color: #555;
  background: #111;
  color: #d8d8d2;
}

.panel button,
.panel select,
.panel input[type="text"],
.panel input[type="number"],
.panel input[type="color"],
.panel .custom-select-button,
.panel .custom-select-option {
  min-height: 18px;
  padding-left: 5px;
  padding-right: 5px;
  font-size: 10px;
}

.panel .custom-select-button {
  padding-right: 18px;
}

@media (hover: hover) and (pointer: fine) {
  input[type="range"],
  input[type="range"]:hover,
  input[type="range"]:focus-visible {
    border-color: #4b4b4b;
    background:
      linear-gradient(90deg, #8d8d8d 0 var(--fill, 50%), #232323 var(--fill, 50%) 100%);
  }
}
