:root {
  color-scheme: light;
  --canvas-bg: #dee3db;
  --surface: #ffffff;
  --button-bg: #ebebeb;
  --button-bg-hover: #e0e0e0;
  --button-bg-soft: rgb(235 235 235 / 0.4);
  --input-bg: #f5f5f5;
  --radius-section: 24px;
  --radius-control: 16px;
  --section-font-size: 13px;
  --section-padding: 10px;
  --section-header-inset: calc(var(--section-padding) * 2);
  --section-stack-gap: 6px;
  --slider-track-pad: 16px;
  --bg: #dee3db;
  --panel: #ffffff;
  --panel-strong: #ffffff;
  --text: #20242b;
  --muted: #69707a;
  --line: #d8d2c4;
  --accent: #126b6f;
  --accent-strong: #0d5659;
  --accent-soft: #d9eeeb;
  --danger: #a64b3d;
  --shadow: 0 18px 45px rgba(35, 39, 47, 0.12);
  --sidebar-left-width: 340px;
  --sidebar-right-width: 320px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--canvas-bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 38px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--button-bg);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  background: var(--button-bg-hover);
}

button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  position: relative;
  min-height: 100vh;
}

.panel-left,
.panel-right {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: var(--sidebar-left-width);
  padding: 40px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-x: none;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background: transparent;
  border: none;
  box-shadow: none;
}

.panel-left {
  left: 0;
}

.panel-right {
  right: 0;
  width: var(--sidebar-right-width);
}

.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar {
  display: none;
}

.app-title {
  position: fixed;
  top: 40px;
  left: 50%;
  z-index: 21;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

.app-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo {
  display: block;
  height: 22px;
  width: auto;
}

.app-title h1 {
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: -1px;
}

.app-title p {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.section-header,
.button-grid {
  display: flex;
  align-items: center;
}

.panel-block {
  display: flex;
  flex-direction: column;
  gap: var(--section-stack-gap);
}

.section-header {
  justify-content: space-between;
  gap: 12px;
  min-height: 24px;
  padding: 0 var(--section-header-inset);
}

.section-hint,
.panel-block > .header-meta {
  margin: 0;
  padding: 0 var(--section-header-inset);
  line-height: 1.35;
}

.section-header button:not(.section-switch) {
  min-height: 0;
  font-size: calc(var(--section-font-size) * 0.8);
  line-height: 1.2;
}

.section-header .text-button {
  padding: 0 8px;
}

.section-header .segmented-control {
  padding: 2px;
  border: 1px solid rgba(62, 68, 77, 0.5);
  border-radius: 999px;
  background: transparent;
}

.section-header .mode-button {
  min-height: 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
}

.section-header .mode-button:hover:not(.active) {
  background: transparent;
}

.section-header .mode-button.active {
  background: var(--text);
  color: #ffffff;
  box-shadow: none;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-meta {
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.05;
}

.hint {
  color: var(--muted);
}

.control-section {
  display: grid;
  gap: 8px;
  flex: 0 0 auto;
  padding: var(--section-padding);
  border: none;
  border-radius: var(--radius-section);
  background: var(--panel-strong);
  font-size: var(--section-font-size);
}

h2 {
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.text-button {
  min-height: 30px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  font-size: inherit;
}

.text-button.section-reset,
#resetInstancesButton {
  color: var(--text);
}

.toggle.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.hint-mini {
  font-size: 11px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

.param-row.is-selected,
.stepper-row.is-selected {
  background: rgba(18, 107, 111, 0.07);
  border-radius: var(--radius-control);
}

.slider-row,
.stepper-row {
  border-radius: var(--radius-control);
  transition: background 0.12s ease;
}

input.num {
  width: 100%;
  min-height: 30px;
  border: none;
  border-radius: var(--radius-control);
  padding: 0 6px;
  background: var(--input-bg);
  color: var(--text);
  text-align: right;
  font-size: inherit;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

input.num::-webkit-outer-spin-button,
input.num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.segmented-control.mini {
  grid-template-columns: 1fr 1fr;
  width: 150px;
}

.source-panel {
  display: grid;
  gap: 8px;
}

.layer-list {
  display: grid;
  gap: 6px;
}

.layer-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 26px 26px;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--button-bg);
  cursor: pointer;
}

.layer-row.active {
  background: var(--accent-soft);
}

.layer-vis,
.layer-del {
  min-height: 24px;
  width: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: inherit;
  line-height: 1;
}

.layer-del:hover {
  color: var(--danger);
}

.layer-name {
  overflow: hidden;
  font-size: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-color {
  width: 26px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--radius-control);
  background: var(--input-bg);
  cursor: pointer;
}

.layer-color::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.layer-color::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

textarea {
  width: 100%;
  min-height: 160px;
  resize: none;
  border: none;
  border-radius: var(--radius-control);
  padding: 12px;
  background: var(--input-bg);
  color: #1f2329;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: inherit;
}

#exportOutput {
  min-height: 200px;
}

.export-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-control);
  overflow: hidden;
  background: #ffffff;
}

.export-preview svg {
  display: block;
  width: 100%;
  height: 100%;
}

.export-preview-zoom {
  position: absolute;
  left: 50%;
  bottom: 8px;
  z-index: 2;
  display: flex;
  gap: 4px;
  transform: translateX(-50%);
}

.export-zoom-button {
  min-width: 36px;
  min-height: 28px;
  padding: 0 8px;
  border-radius: var(--radius-control);
  background: transparent;
  box-shadow: none;
  font-size: 11px;
}

.export-zoom-button:hover:not(.active) {
  background: transparent;
}

.export-zoom-button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.export-code-panel {
  display: grid;
}

.export-code-panel[hidden] {
  display: none;
}

.primary-button {
  border: none;
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.slider-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-control);
  background: var(--button-bg-soft);
  font-size: inherit;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
}

.slider-row > span {
  position: relative;
  z-index: 2;
  color: var(--text);
  font-size: 11px;
  opacity: 1;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

.slider-row > output,
.slider-row > input.num,
.slider-row--select select {
  position: relative;
  z-index: 2;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 20px;
  font-weight: 400;
  font-synthesis: none;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

.slider-row > output,
.slider-row > input.num {
  grid-column: 3;
  min-width: 2.5em;
  text-align: right;
  letter-spacing: -1px;
  opacity: 0.3;
}

.slider-row > output.is-modified,
.slider-row > input.num.is-modified {
  opacity: 1;
}

.slider-row > input.num {
  width: 3.5em;
  -moz-appearance: textfield;
}

.slider-row > input.num::-webkit-outer-spin-button,
.slider-row > input.num::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.slider-row > output:empty {
  display: none;
}

.slider-body {
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  overflow: hidden;
  pointer-events: none;
}

.slider-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--slider-pct, 0%);
  border-radius: var(--radius-control) 0 0 var(--radius-control);
  background: transparent;
  pointer-events: none;
}

.slider-grabber {
  position: absolute;
  left: var(--slider-pct, 0%);
  top: 0;
  bottom: 0;
  width: 1px;
  transform: translateX(-100%);
  border-radius: 0;
  background: var(--text);
  opacity: var(--grabber-opacity, 1);
  pointer-events: none;
}

.slider-body input[type="range"] {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
  pointer-events: auto;
}

.slider-row--select {
  grid-template-columns: auto minmax(0, 1fr);
}

.slider-row--select-only {
  grid-template-columns: 1fr;
}

.slider-row--select select {
  grid-column: 2;
  width: 100%;
  min-height: 40px;
  padding: 0 20px 0 8px;
  letter-spacing: -0.5px;
  opacity: 1;
  text-align: right;
  text-align-last: right;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2369707a' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
}

.slider-row--select #progCurve {
  opacity: 0.3;
}

.slider-row--select #progCurve.is-modified {
  opacity: 1;
}

.slider-row--select-only select {
  grid-column: 1;
  padding-left: 0;
  text-align: left;
  text-align-last: left;
}

output {
  text-align: right;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stepper-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 10px;
}

.stepper-row input,
.path-stepper-label {
  width: 100%;
  min-height: 38px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--input-bg);
  color: var(--text);
  text-align: center;
  font-size: inherit;
  font-variant-numeric: tabular-nums;
}

.path-stepper-label {
  margin: 0;
  line-height: 38px;
}

.path-stepper-total {
  opacity: 0.3;
}

.path-stepper-meta {
  margin-left: 0.2em;
  line-height: 0;
  opacity: 0.3;
  vertical-align: super;
}

.workspace {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.section-header > h2 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-switch {
  flex-shrink: 0;
  width: 34px;
  height: 18px;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.section-switch:hover,
.section-switch:focus-visible {
  background: transparent;
}

.section-switch.active {
  background: transparent;
  color: inherit;
}

.section-switch-track {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  border: 1px solid rgba(62, 68, 77, 0.5);
  box-sizing: border-box;
  background: transparent;
}

.section-switch-thumb {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(62, 68, 77, 0.5);
  background: transparent;
  box-sizing: border-box;
  transform: translateY(-50%);
  transition: left 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.section-switch.active .section-switch-thumb {
  left: calc(100% - 14px);
  background: var(--text);
  border-color: var(--text);
}

/* --- Collapsible panel blocks --- */
.panel-block[data-collapsible] > .section-header {
  cursor: pointer;
}

.panel-block[data-collapsed] > .control-section,
.panel-block[data-collapsed] > .section-hint,
.panel-block[data-collapsed] > .header-meta {
  display: none;
}

/* --- Bottom quick-tools dock --- */
.dock {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dock button {
  min-height: 34px;
  min-width: 38px;
  padding: 0 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1;
}

.dock button:hover {
  background: var(--button-bg);
}

.dock button:disabled {
  background: transparent;
  opacity: 0.38;
}

.dock .toggle {
  font-size: 12px;
  padding: 0 12px;
}

.dock .toggle.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.dock-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
}

#zoomResetButton {
  min-width: 52px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.dock button.dock-round {
  min-width: 34px;
  width: 34px;
  padding: 0;
  font-size: 16px;
}

.dock-mobile,
.mobile-canvas-brand {
  display: none;
}

.segmented-control {
  display: grid;
  padding: 3px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--button-bg);
}

.mode-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  font-size: inherit;
}

.mode-button.active {
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(35, 39, 47, 0.1);
}

.canvas-wrap {
  position: fixed;
  inset: 0;
  z-index: 0;
  min-height: 0;
  padding: 0;
  background: var(--canvas-bg);
}

.canvas-grid {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-repeat: repeat;
  -webkit-mask-image: radial-gradient(
    ellipse 95% 95% at 50% 50%,
    #000 0%,
    #000 28%,
    rgba(0, 0, 0, 0.65) 52%,
    rgba(0, 0, 0, 0.2) 72%,
    transparent 100%
  );
  mask-image: radial-gradient(
    ellipse 95% 95% at 50% 50%,
    #000 0%,
    #000 28%,
    rgba(0, 0, 0, 0.65) 52%,
    rgba(0, 0, 0, 0.2) 72%,
    transparent 100%
  );
}

#canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  display: block;
  border-radius: 0;
  background: transparent;
  cursor: default;
}

.axis-line {
  stroke-width: 1;
}

.logo-instance {
  cursor: move;
}

.instance-shell {
  fill: transparent;
  stroke: transparent;
  pointer-events: none;
}

.selection-box {
  fill: transparent;
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.handle {
  fill: var(--text);
  stroke: none;
  vector-effect: non-scaling-stroke;
  cursor: nwse-resize;
}

.handle.ne,
.handle.sw {
  cursor: nesw-resize;
}

.handle.move {
  cursor: move;
}

.rotate-handle {
  fill: transparent;
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: grab;
}

.rotate-handle:active {
  cursor: grabbing;
}

.marquee-box {
  fill: rgba(32, 36, 43, 0.06);
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.path-anchor {
  fill: transparent;
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: move;
}

.path-anchor.active {
  fill: transparent;
  stroke: var(--text);
}

.path-handle-line {
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.path-handle {
  fill: transparent;
  stroke: var(--text);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: crosshair;
}

.path-segment {
  fill: none;
  stroke: rgba(176, 93, 75, 0);
  stroke-width: 14;
  vector-effect: non-scaling-stroke;
  pointer-events: stroke;
  cursor: copy;
}

.path-segment:hover {
  stroke: rgba(176, 93, 75, 0.18);
}

@media (max-width: 1080px) {
  :root {
    --sidebar-left-width: 310px;
    --sidebar-right-width: 310px;
  }

  .panel-right {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 42vh;
    flex-direction: row;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 12px;
    padding: 12px 16px;
  }

  .panel-right .control-section {
    flex: 1 1 280px;
  }
}

@media (max-width: 760px) {
  :root {
    --sidebar-left-width: 0px;
    --sidebar-right-width: 0px;
  }

  html,
  body {
    min-height: 100%;
  }

  body {
    overflow: auto;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow: visible;
  }

  .app-title {
    display: none;
  }

  .workspace {
    position: sticky;
    top: 0;
    z-index: 10;
    order: -2;
    flex: 0 0 50dvh;
    height: 50dvh;
    min-height: 50dvh;
    padding: 12px;
    overflow: visible;
    background: var(--canvas-bg);
  }

  .mobile-canvas-brand {
    position: absolute;
    inset: 24px 24px 24px 24px;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
  }

  .mobile-canvas-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .mobile-canvas-title-row h1 {
    font-size: 18px;
    line-height: 1.05;
    letter-spacing: -0.5px;
  }

  .mobile-canvas-brand .app-logo {
    height: 18px;
    width: auto;
  }

  .mobile-canvas-brand p {
    max-width: 220px;
    font-size: 10px;
    line-height: 1.25;
    color: var(--muted);
  }

  .canvas-wrap {
    position: absolute;
    inset: 12px;
    min-height: 0;
    overflow: hidden;
    border-radius: var(--radius-section);
    background: var(--panel-strong);
    box-shadow: var(--shadow);
  }

  #canvas {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .panel-left,
  .panel-right {
    position: static;
    z-index: 1;
    width: auto;
    max-height: none;
    flex: 0 0 auto;
    flex-direction: column;
    flex-wrap: nowrap;
    align-content: stretch;
    gap: 12px;
    padding: 12px 16px;
    overflow: visible;
    background: var(--canvas-bg);
  }

  .panel-right .control-section {
    flex: 0 0 auto;
  }

  .panel-left {
    padding-top: 6px;
  }

  .panel-right {
    padding-bottom: 24px;
  }

  .dock-desktop {
    display: none;
  }

  .dock-mobile {
    position: static;
    display: flex;
    order: -1;
    align-self: center;
    flex: 0 0 auto;
    margin: 12px auto 6px;
    top: auto;
    bottom: auto;
    max-width: calc(100vw - 24px);
    overflow-x: auto;
    scrollbar-width: none;
    transform: none;
  }

  .dock-mobile::-webkit-scrollbar {
    display: none;
  }
}
