body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

header {
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-inline: contain;
  scrollbar-width: thin;
}
header::-webkit-scrollbar { height: 6px; }
header > button,
header > .brand,
header > .queuePanel,
header > audio,
header > label { flex: 0 0 auto; }
header > .spacer { flex: 1 0 0; }

main {
  height: auto;
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .35rem .75rem;
  padding: .3rem .75rem;
  border-top: 1px solid var(--line);
  background: #0b0e13;
  color: var(--muted);
  font-size: .62rem;
  letter-spacing: .08em;
  text-align: center;
}

footer button,
.presetLegal,
.buttonLink {
  padding: .25rem .45rem;
  font-size: .68rem;
}

.buttonLink {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191e27;
  color: var(--text);
  text-decoration: none;
}

.buttonLink:hover {
  border-color: var(--orange);
}

.presetLegal {
  align-self: flex-start;
}

.presetQuickActions {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}

.presetQuickActions button { padding: .3rem .5rem; font-size: .68rem; }
.presetQuickActions button[aria-pressed="true"] { border-color: var(--orange); color: var(--orange); }

.presetRow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .3rem;
}

.presetRow .preset { min-width: 0; }
.favoritePreset { width: 34px; padding: 0; color: var(--muted); }
.favoritePreset[aria-pressed="true"] { border-color: #9d7920; color: #ffd45c; }

#presetRights {
  scroll-margin-top: 1rem;
}

.editorToolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.autoApplyControl,
.resolutionControl {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  color: var(--muted);
  font-size: .72rem;
  white-space: nowrap;
}

.autoApplyControl {
  padding: .38rem .5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #151a22;
}

.autoApplyControl input {
  margin: 0;
  accent-color: var(--orange);
}

.resolutionControl select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191e27;
  color: var(--text);
  padding: .42rem .35rem;
  font: inherit;
}

.editorToolbar .primary {
  border-color: var(--orange);
}

#editorState {
  min-height: 1.2em;
  color: var(--muted);
  font-size: .72rem;
}

.structure {
  background: #0c1016;
  color: var(--text);
  padding: .45rem;
}

.structure button,
.structure input,
.structure select,
.structure textarea {
  min-width: 0;
  border: 1px solid #343d4b;
  border-radius: 4px;
  background: #171c24;
  color: var(--text);
  font: inherit;
}

.structure input,
.structure select,
.structure textarea {
  padding: .3rem .4rem;
}

.structure textarea {
  min-height: 3.8rem;
  max-height: 11rem;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .75rem;
}

.structure .field {
  display: grid;
  grid-template-columns: minmax(7rem, 38%) minmax(0, 1fr);
  align-items: center;
  gap: .4rem;
  margin: .35rem 0;
  color: #b9c0ca;
  font-size: .76rem;
}

.field > span {
  overflow-wrap: anywhere;
}

.readonlyValue {
  min-height: 1.2em;
  color: var(--muted);
}

.field input:not([type=checkbox]),
.field select,
.field textarea {
  display: block;
  width: 100%;
}

.field input[type=checkbox] {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--orange);
}

.rootSettings,
.component {
  margin: .4rem 0;
  border: 1px solid #2d3541;
  border-radius: 5px;
  background: #11161e;
  padding: .25rem .45rem .45rem;
}

.rootSettings > summary,
.component > summary {
  margin: -.25rem -.45rem 0;
  padding: .45rem;
  cursor: pointer;
  color: #e5e8ed;
  font-weight: 600;
  list-style-position: inside;
}

.rootSettings[open] > summary,
.component[open] > summary {
  margin-bottom: .35rem;
  border-bottom: 1px solid #2d3541;
}

.component > .component {
  margin-left: .55rem;
  background: #0d1219;
}

.componentActions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: .3rem;
  margin: .45rem 0 .1rem;
}

.componentActions select {
  width: 100%;
}

.preset.newPreset {
  border-style: dashed;
  color: var(--mint);
  font-weight: 600;
}

.presetNotice {
  margin: -.15rem 0 0;
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.35;
}

.trackTitle {
  flex: 1 1 8rem;
  min-width: 0;
  max-width: 18rem;
  overflow: hidden;
  color: var(--muted);
  font-size: .72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .structure .field {
    grid-template-columns: 1fr;
    gap: .2rem;
  }
}

body.sidebar-collapsed #sidebar { display: none; }

#sidebar {
  position: relative;
  width: var(--sidebar-width, 360px);
  max-width: min(65vw, 720px);
}

.sidebarResizeHandle {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 0;
  left: -5px;
  width: 10px;
  cursor: col-resize;
  touch-action: none;
}
.sidebarResizeHandle::after {
  content: "";
  position: absolute;
  top: 45%;
  bottom: 45%;
  left: 4px;
  width: 2px;
  min-height: 30px;
  border-radius: 2px;
  background: transparent;
}
.sidebarResizeHandle:hover::after,
.sidebarResizeHandle:focus-visible::after { background: var(--orange); }
body.sidebar-resizing { cursor: col-resize; user-select: none; }

.panelIcon {
  position: relative;
  display: block;
  width: 17px;
  height: 15px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
}
.panelIcon::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 2px;
  width: 4px;
  border-left: 1px solid currentColor;
  background: currentColor;
  opacity: .7;
}
.panelLabel { display: none; }

.queuePanel { position: relative; }
.queuePanel > summary {
  list-style: none;
  cursor: pointer;
  padding: .48rem .68rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191e27;
  color: var(--text);
  white-space: nowrap;
}
.queuePanel > summary::-webkit-details-marker { display: none; }
.queuePanel[open] > summary { border-color: var(--orange); }
.queuePanel summary span { color: var(--muted); font-size: .7rem; }
.queuePopover {
  position: fixed;
  z-index: 40;
  top: calc(100% + .45rem);
  left: 0;
  width: min(360px, calc(100vw - 1rem));
  padding: .45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10151df7;
  box-shadow: 0 14px 45px #000c;
}
.queueToolbar { display: flex; gap: .35rem; margin-bottom: .4rem; }
.queueToolbar button:last-child { margin-left: auto; }
.queueToolbar button[aria-pressed="true"] { border-color: var(--orange); color: var(--orange); }
.queueList {
  position: relative;
  height: 44px;
  max-height: 216px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #2e3744;
  border-radius: 5px;
  background: #090c11;
}
.queueCanvas { position: relative; width: 100%; }
.queueItem {
  position: absolute;
  left: 0;
  right: 0;
  height: 36px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(3, 28px);
  align-items: center;
  gap: .2rem;
  padding: .15rem .25rem;
  border-bottom: 1px solid #202733;
}
.queueItem.dragging { opacity: .45; }
.queueItem.active { background: #241a14; }
.queuePlay { min-width: 0; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.queueItem button { height: 28px; padding: 0 .3rem; font-size: .7rem; }
.queueEmpty { padding: .7rem; color: var(--muted); font-size: .72rem; text-align: center; }

#sidebarToggle[aria-expanded="false"] {
  border-color: var(--orange);
  color: var(--orange);
}

@media (max-width: 760px) {
  main { flex-direction: column; }
  #stage { flex: 1 1 50%; min-height: 0; }
  #sidebar {
    position: static;
    flex: 1 1 50%;
    width: 100%;
    max-width: none;
    min-height: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
    box-shadow: none;
  }

  .sidebarResizeHandle { display: none; }
  .panelIcon { display: none; }
  .panelLabel { display: inline; }
  .panelLabel::before { content: "☰ "; }
  .presetQuickActions button { flex: 1 1 auto; }
}

@media (max-width: 520px) {
  header button { padding-inline: .52rem; }
  .trackTitle { flex-basis: 100%; max-width: none; order: 10; }
  .queuePopover { top: auto !important; right: .5rem !important; bottom: 2.4rem !important; left: .5rem !important; width: auto; }
}

@media (hover: none) and (pointer: coarse) {
  html, body, button, summary, canvas { touch-action: manipulation; }
}
