.ape-editor {
  --ape-bg: #101114;
  --ape-panel: #17191f;
  --ape-panel-2: #1f222b;
  --ape-text: #e8e8ea;
  --ape-muted: #9ca0aa;
  --ape-accent: #8f7cff;
  --ape-hue: #ff5e8a;
  --ape-sat: #60d394;
  --ape-lit: #72a7ff;
  --ape-shadow: rgba(0, 0, 0, .35);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 66px;
  align-items: start;
  column-gap: 12px;
  width: 100%;
  color: var(--ape-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

.ape-editor,
.ape-editor * {
  box-sizing: border-box;
}

.ape-editor > :not(.ape-saved-bar) {
  grid-column: 1;
}

.ape-editor .ape-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.ape-editor .ape-title {
  margin: 0;
  font-size: clamp(23px, 2vw, 30px);
  line-height: 1.1;
  font-weight: 680;
  letter-spacing: -.015em;
}

.ape-editor .ape-subtitle {
  display: block;
  margin: 6px 0 0;
  color: var(--ape-muted);
  font-size: 13px;
}

.ape-editor .ape-top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.ape-editor .ape-button,
.ape-editor .ape-mini-button,
.ape-editor .ape-export-menu button {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--ape-text);
  background: var(--ape-panel-2);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 8px 22px var(--ape-shadow);
}

.ape-editor .ape-button:hover,
.ape-editor .ape-mini-button:hover,
.ape-editor .ape-export-menu button:hover {
  background: #292d39;
}

.ape-editor .ape-button-primary {
  background: rgba(143, 124, 255, .28);
}

.ape-editor button:focus-visible,
.ape-editor input:focus-visible {
  outline: 1px solid var(--ape-accent);
  outline-offset: 2px;
}

.ape-editor .ape-export-wrap {
  position: relative;
}

.ape-editor .ape-export-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  right: 0;
  width: 190px;
  display: grid;
  gap: 3px;
  padding: 7px;
  border-radius: 12px;
  background: #222630;
  box-shadow: 0 18px 42px rgba(0, 0, 0, .46);
}

.ape-editor .ape-export-menu[hidden] {
  display: none;
}

.ape-editor .ape-export-menu button {
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  color: var(--ape-muted);
  background: transparent;
  box-shadow: none;
}

.ape-editor .ape-panel {
  border-radius: 18px;
  background: rgba(23, 25, 31, .92);
  box-shadow: 0 18px 48px var(--ape-shadow);
}

.ape-editor .ape-preview-panel {
  padding: 12px;
}

.ape-editor .ape-gradient-preview {
  position: relative;
  height: 150px;
  overflow: hidden;
  border-radius: 14px;
}

.ape-editor .ape-gradient-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255,255,255,.16), transparent 35%, rgba(0,0,0,.25));
  mix-blend-mode: soft-light;
}

.ape-editor .ape-palette-strip {
  display: grid;
  grid-template-columns: repeat(var(--ape-stop-count), 1fr);
  gap: 6px;
  margin-top: 10px;
}

.ape-editor .ape-swatch {
  position: relative;
  height: 34px;
  overflow: hidden;
  border-radius: 8px;
}

.ape-editor .ape-swatch span {
  position: absolute;
  left: 6px;
  bottom: 4px;
  color: rgba(255,255,255,.85);
  font-size: 10px;
  text-shadow: 0 1px 4px rgba(0,0,0,.75);
}

.ape-editor .ape-control-stage {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr) 108px;
  align-items: stretch;
  gap: 14px;
  margin-top: 18px;
}

.ape-editor .ape-side-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 322px;
  padding: 12px;
}

.ape-editor .ape-panel-title {
  margin-bottom: 8px;
  color: var(--ape-muted);
  font-size: 11px;
  letter-spacing: .12em;
  text-align: center;
  text-transform: uppercase;
}

.ape-editor .ape-align-left {
  text-align: left;
}

.ape-editor .ape-align-right {
  text-align: right;
}

.ape-editor .ape-vertical-controls {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  min-width: 0;
  gap: 4px;
}

.ape-editor .ape-vcontrol {
  display: grid;
  grid-template-rows: 1fr auto auto;
  justify-items: center;
  min-width: 0;
  gap: 8px;
}

.ape-editor .ape-vcontrol input[type="range"] {
  appearance: none;
  writing-mode: vertical-lr;
  direction: rtl;
  width: 18px;
  height: 212px;
  min-width: 0;
  background: transparent;
}

.ape-editor .ape-vlabel {
  font-size: 11px;
  font-weight: 650;
}

.ape-editor .ape-vvalue {
  min-height: 12px;
  color: var(--ape-muted);
  font-size: 10px;
}

.ape-editor .ape-wave-panel {
  min-width: 0;
  padding: 12px;
}

.ape-editor .ape-wave-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.ape-editor .ape-color-pick {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
  color: var(--ape-muted);
  font-size: 12px;
}

.ape-editor input[type="color"] {
  appearance: none;
  width: 42px;
  height: 32px;
  overflow: hidden;
  border: 0;
  border-radius: 9px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.ape-editor input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.ape-editor input[type="color"]::-webkit-color-swatch {
  border: 0;
}

.ape-editor .ape-target-info {
  display: grid;
  gap: 2px;
}

.ape-editor .ape-hex {
  color: var(--ape-text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.ape-editor .ape-target-chip {
  width: 42px;
  height: 32px;
  border-radius: 9px;
  background: #333;
}

.ape-editor .ape-mini-button {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  padding: 0;
  color: var(--ape-muted);
  background: rgba(255,255,255,.045);
  box-shadow: none;
  line-height: 1;
}

.ape-editor .ape-wave-wrap {
  position: relative;
  height: 258px;
  overflow: hidden;
  border-radius: 14px;
  background:
    linear-gradient(to bottom, rgba(255,255,255,.07), transparent),
    linear-gradient(180deg, #202430, #151821);
}

.ape-editor .ape-wave-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.ape-editor .ape-legend {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-top: 10px;
  color: var(--ape-muted);
  font-size: 11px;
}

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

.ape-editor .ape-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.ape-editor .ape-flow-panel {
  margin-top: 14px;
  padding: 14px;
}

.ape-editor .ape-flow-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: start;
  gap: 16px;
}

.ape-editor .ape-control-column {
  display: grid;
  min-width: 0;
  gap: 12px;
}

.ape-editor .ape-control {
  display: grid;
  grid-template-columns: 94px 1fr 46px;
  align-items: center;
  gap: 10px;
}

.ape-editor .ape-control-label {
  color: var(--ape-muted);
  font-size: 12px;
}

.ape-editor .ape-value {
  color: var(--ape-text);
  font-size: 11px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.ape-editor input[type="range"] {
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
}

.ape-editor input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
}

.ape-editor .ape-bipolar input[type="range"]::-webkit-slider-runnable-track {
  background:
    linear-gradient(
      to right,
      transparent calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% + .75px),
      transparent calc(50% + .75px)
    ),
    rgba(255,255,255,.14);
}

.ape-editor input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border: 0;
  border-radius: 50%;
  background: var(--ape-accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}

.ape-editor input[type="range"]::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
}

.ape-editor .ape-bipolar input[type="range"]::-moz-range-track {
  background:
    linear-gradient(
      to right,
      transparent calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% + .75px),
      transparent calc(50% + .75px)
    ),
    rgba(255,255,255,.14);
}

.ape-editor input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--ape-accent);
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}

.ape-editor .ape-vcontrol input[type="range"]::-webkit-slider-runnable-track {
  width: 4px;
  height: 100%;
}

.ape-editor .ape-vcontrol.ape-bipolar input[type="range"]::-webkit-slider-runnable-track {
  background:
    linear-gradient(
      to bottom,
      transparent calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% + .75px),
      transparent calc(50% + .75px)
    ),
    rgba(255,255,255,.14);
}

.ape-editor .ape-vcontrol input[type="range"]::-webkit-slider-thumb {
  margin-top: 0;
  margin-left: -5px;
}

.ape-editor .ape-vcontrol input[type="range"]::-moz-range-track {
  width: 4px;
  height: 100%;
}

.ape-editor .ape-vcontrol.ape-bipolar input[type="range"]::-moz-range-track {
  background:
    linear-gradient(
      to bottom,
      transparent calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% - .75px),
      rgba(255,255,255,.46) calc(50% + .75px),
      transparent calc(50% + .75px)
    ),
    rgba(255,255,255,.14);
}

.ape-editor .ape-select-control {
  display: grid;
  grid-template-columns: 94px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.ape-editor .ape-choice-menu {
  display: flex;
  min-width: 0;
  overflow-x: auto;
  gap: 5px;
  padding: 2px 2px 5px;
  scrollbar-width: thin;
  scrollbar-color: rgba(143,124,255,.45) transparent;
}

.ape-editor .ape-choice-button {
  display: grid;
  flex: 0 0 30px;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  padding: 0;
  color: var(--ape-muted);
  background: rgba(255,255,255,.045);
  box-shadow: none;
  cursor: pointer;
}

.ape-editor .ape-choice-button:hover {
  color: var(--ape-text);
  background: rgba(255,255,255,.09);
}

.ape-editor .ape-choice-button[aria-checked="true"] {
  color: #c9c0ff;
  background: rgba(143,124,255,.24);
  box-shadow: 0 5px 16px rgba(90,70,210,.2);
}

.ape-editor .ape-choice-button svg {
  width: 21px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.ape-editor .ape-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.ape-editor .ape-saved-bar {
  position: sticky;
  top: 12px;
  grid-column: 2;
  grid-row: 1 / span 5;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 150px;
  max-height: min(620px, calc(100vh - 48px));
  padding: 8px 7px;
  border-radius: 14px;
  background: rgba(23, 25, 31, .92);
  box-shadow: 0 18px 48px var(--ape-shadow);
}

.ape-editor .ape-saved-title {
  margin-bottom: 7px;
  color: var(--ape-muted);
  font-size: 9px;
  letter-spacing: .08em;
  text-align: center;
  text-transform: uppercase;
}

.ape-editor .ape-saved-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 7px;
  padding: 1px 2px 3px;
  scrollbar-width: thin;
  scrollbar-color: rgba(143,124,255,.4) transparent;
}

.ape-editor .ape-saved-empty {
  color: rgba(156, 160, 170, .52);
  font-size: 9px;
  line-height: 1.25;
  text-align: center;
  writing-mode: vertical-rl;
}

.ape-editor .ape-saved-thumbnail {
  position: relative;
  flex: 0 0 auto;
  width: 50px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  padding: 0;
  opacity: .68;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .28);
  transition: opacity .15s ease, transform .15s ease, filter .15s ease, box-shadow .15s ease;
}

.ape-editor .ape-saved-thumbnail:hover {
  opacity: .9;
  transform: scale(1.04);
}

.ape-editor .ape-saved-thumbnail[aria-pressed="true"] {
  opacity: 1;
  filter: saturate(1.18) brightness(1.08);
  transform: scale(1.07);
  box-shadow: 0 7px 18px rgba(98, 76, 220, .42);
}

.ape-editor .ape-saved-thumbnail span {
  position: absolute;
  right: 3px;
  bottom: 2px;
  color: rgba(255,255,255,.82);
  font-size: 8px;
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
}

@media (max-width: 1180px) {
  .ape-editor {
    grid-template-columns: 1fr;
    row-gap: 12px;
  }

  .ape-editor > :not(.ape-saved-bar) {
    grid-column: 1;
  }

  .ape-editor .ape-saved-bar {
    position: static;
    grid-column: 1;
    grid-row: auto;
    min-height: 0;
    max-height: none;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto;
    align-items: center;
    gap: 8px;
  }

  .ape-editor .ape-saved-title {
    margin: 0;
  }

  .ape-editor .ape-saved-list {
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .ape-editor .ape-saved-empty {
    writing-mode: horizontal-tb;
  }
}

@media (max-width: 900px) {
  .ape-editor {
    row-gap: 12px;
  }

  .ape-editor .ape-header {
    align-items: start;
    flex-direction: column;
  }

  .ape-editor .ape-control-stage,
  .ape-editor .ape-flow-columns {
    grid-template-columns: 1fr;
  }

  .ape-editor .ape-side-panel {
    min-height: auto;
  }

  .ape-editor .ape-vertical-controls {
    height: 230px;
  }
}

.ape-modal-backdrop {
  position: fixed;
  z-index: 10000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 9, .78);
  backdrop-filter: blur(14px);
}

.ape-modal-shell {
  position: relative;
  width: min(1280px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 22px;
  padding: 24px;
  background: #101114;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .62);
}

.ape-modal-close {
  position: sticky;
  z-index: 2;
  top: 0;
  float: right;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  color: #e8e8ea;
  background: #1f222b;
  font-size: 22px;
  cursor: pointer;
}
