:root {
  --panel-w: clamp(300px, 26vw, 360px);
  --radius: 10px;
  --radius-ctl: 8px;
  --radius-dock: 14px;
  --radius-key: 4px;
  --radius-swatch: 50%;
  --radius-sheet: 18px;
  --glass: 0px;
  --display-weight: 600;
  --display-track: 0;
  --fs-label: 13px;
  --track-h: 3px;
  --thumb: 14px;
  --thumb-r: 50%;
  --thumb-bg: #fff;
  --bg: #111;
  --stage-bg: #000;
  --surface: #1a1a1a;
  --surface-2: #222;
  --ink: #eee;
  --ink-2: #aaa;
  --rule: #444;
  --accent: #e2b96a;
  --on-accent: #111;
  --icon-bg: transparent;
  --dock-bg: rgba(20, 20, 20, 0.9);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  --font: system-ui, sans-serif;
  --font-display: var(--font);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--panel-w) minmax(0, 1fr);
}

.app:not(.panel-open) {
  grid-template-columns: 0 minmax(0, 1fr);
}

.app:not(.panel-open) .panel {
  display: none;
}

.panel {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--rule);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--display-weight);
  font-size: 21px;
  letter-spacing: var(--display-track);
  line-height: 1.1;
  color: var(--ink);
}

.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px 0 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.sec {
  padding: 0 18px;
  border-bottom: 1px solid var(--rule);
}

.sec > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  cursor: pointer;
  list-style: none;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: var(--display-track);
  color: var(--ink);
}

.sec > summary::-webkit-details-marker {
  display: none;
}

.sec > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  flex: none;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.2s ease;
}

.sec[open] > summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.sec[open] > summary {
  padding-bottom: 12px;
}

.sec > :not(summary) {
  margin-bottom: 14px;
}

.sec > :last-child {
  margin-bottom: 18px;
}

.field {
  display: grid;
  gap: 6px;
  margin: 0 0 14px;
}

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.field label,
.field-label {
  font-size: var(--fs-label);
  color: var(--ink);
}

.field-label {
  display: block;
  margin-bottom: 2px;
}

.field output {
  font-size: 12.5px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.pair .field {
  margin-bottom: 14px;
}

.field input[type="number"] {
  width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-ctl);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: var(--track-h);
  border-radius: var(--track-h);
  background: linear-gradient(90deg, var(--accent) var(--fill), var(--rule) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc((var(--track-h) - var(--thumb)) / 2);
  border: 2px solid var(--accent);
  border-radius: var(--thumb-r);
  background: var(--thumb-bg);
}

input[type="range"]::-moz-range-track {
  height: var(--track-h);
  border-radius: var(--track-h);
  background: var(--rule);
}

input[type="range"]::-moz-range-progress {
  height: var(--track-h);
  border-radius: var(--track-h);
  background: var(--accent);
}

input[type="range"]::-moz-range-thumb {
  width: var(--thumb);
  height: var(--thumb);
  border: 2px solid var(--accent);
  border-radius: var(--thumb-r);
  background: var(--thumb-bg);
}

.btn,
.toggle {
  min-height: 34px;
  padding: 6px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-ctl);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover,
.toggle:hover {
  border-color: var(--accent);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.toggle {
  color: var(--ink-2);
}

.toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
}

.btn-row > * {
  flex: 1 1 auto;
}

.chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin: 0 0 14px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 10px;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-ctl);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.chip:hover {
  border-color: var(--accent);
}

.chip[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
}

.chip-name {
  font-size: 13px;
  line-height: 1.2;
}

.key {
  flex: none;
  display: inline-grid;
  place-items: center;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  font-size: 11px;
  color: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: var(--radius-key);
}

.palettes {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.pal {
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  padding: 6px;
}

.pal-bar {
  height: 16px;
  border-radius: var(--radius-key);
  background: var(--grad);
}

.pal .chip-name {
  font-size: 12px;
  text-align: left;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: var(--radius-ctl);
}

.seg button {
  flex: 1 1 auto;
  min-height: 32px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 0;
  border-right: 1px solid var(--rule);
  cursor: pointer;
}

.seg button:last-child {
  border-right: 0;
}

.seg button:hover {
  color: var(--ink);
}

.seg button[aria-pressed="true"] {
  color: var(--on-accent);
  background: var(--accent);
}

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

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--sw-bg);
  border-radius: var(--radius-swatch);
  background: var(--sw);
  box-shadow: 0 0 0 1px var(--sw);
  cursor: pointer;
}

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--sw);
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--stage-bg);
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
  outline: none;
}

#view:active {
  cursor: grabbing;
}

.topbar {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 3;
  display: flex;
  gap: 8px;
}

.dock {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 3;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  max-width: calc(100% - 24px);
  padding: 6px;
  background: var(--dock-bg);
  border: 1px solid var(--rule);
  border-radius: var(--radius-dock);
  box-shadow: var(--shadow);
  backdrop-filter: blur(var(--glass));
  -webkit-backdrop-filter: blur(var(--glass));
}

.dock-name {
  min-width: 112px;
  padding: 0 8px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 15px;
  letter-spacing: var(--display-track);
  white-space: nowrap;
  color: var(--ink);
}

.dock-sep {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--rule);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  color: var(--ink);
  background: var(--icon-bg);
  border: 1px solid transparent;
  border-radius: var(--radius-ctl);
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--accent);
}

.icon-btn svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar .icon-btn {
  background: var(--dock-bg);
  border-color: var(--rule);
  backdrop-filter: blur(var(--glass));
  -webkit-backdrop-filter: blur(var(--glass));
}

.sheet-toggle {
  display: none;
}

#btnPlay .ico-play {
  display: none;
}

#btnPlay[data-paused="true"] .ico-play {
  display: block;
}

#btnPlay[data-paused="true"] .ico-pause {
  display: none;
}

.notice {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 32px));
  padding: 16px 18px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .app,
  .app:not(.panel-open) {
    grid-template-columns: minmax(0, 1fr);
  }

  .app:not(.panel-open) .panel,
  .panel {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    height: min(64dvh, 600px);
    border-right: 0;
    border-top: 1px solid var(--rule);
    border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
    box-shadow: var(--shadow);
    transform: translateY(105%);
    transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  }

  .app.panel-open .panel {
    transform: none;
  }

  .app.panel-open .dock {
    bottom: calc(min(64dvh, 600px) + 12px);
  }

  .topbar #btnPanel {
    display: none;
  }

  .sheet-toggle {
    display: inline-grid;
  }

  .dock {
    bottom: 12px;
    width: calc(100% - 20px);
  }

  .dock-name {
    min-width: 0;
    flex: 1 1 110px;
    font-size: 14px;
  }

  .chips {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .palettes {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .panel-body {
    padding-bottom: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .sec > summary::after,
  .btn,
  .toggle,
  .chip {
    transition: none;
  }
}
