/* FractalForge — visual language borrowed from macOS/iOS:
   system font stack, translucent materials over content, generous radii,
   restrained colour, and motion that decelerates rather than stopping. */

:root {
  --bg: #000;
  --panel: rgba(30, 30, 32, 0.72);
  --panel-border: rgba(255, 255, 255, 0.12);
  --separator: rgba(255, 255, 255, 0.08);
  --fill: rgba(120, 120, 128, 0.24);
  --fill-hover: rgba(120, 120, 128, 0.36);
  --fill-active: rgba(120, 120, 128, 0.5);
  --label: rgba(255, 255, 255, 0.96);
  --label-2: rgba(235, 235, 245, 0.62);
  --label-3: rgba(235, 235, 245, 0.34);
  --accent: #0a84ff;
  --accent-hi: #409cff;
  --pink: #ff375f;
  --radius-lg: 20px;
  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.48), 0 1px 2px rgba(0, 0, 0, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--label);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI',
        'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { position: relative; width: 100vw; height: 100vh; }

/* ---------- canvas ---------- */

#stage { position: absolute; inset: 0; }

#view {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  image-rendering: auto;
}
#view.dragging { cursor: grabbing; }

/* Selection rectangle for box-zoom */
#marquee {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: rgba(10, 132, 255, 0.16);
  border-radius: 3px;
  pointer-events: none;
  display: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4);
}

/* ---------- floating panels ---------- */

.panel {
  position: absolute;
  background: var(--panel);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border: 0.5px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* Title bar */
#titlebar {
  top: 20px;
  left: 20px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
  user-select: none;
}
#titlebar .mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: conic-gradient(from 210deg, #ff375f, #ff9f0a, #ffd60a, #30d158, #0a84ff, #bf5af2, #ff375f);
  box-shadow: inset 0 0 0 0.5px rgba(255,255,255,0.24);
}
#titlebar h1 {
  font-size: 14px;
  font-weight: 590;
  letter-spacing: -0.01em;
}
#titlebar .sub {
  font-size: 11px;
  color: var(--label-3);
  letter-spacing: 0.02em;
}

/* Side panel */
#controls {
  top: 20px;
  right: 20px;
  width: 268px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 0;
}
#controls::-webkit-scrollbar { width: 0; }

.section {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}
.section:last-child { border-bottom: none; }

.section > .head {
  font-size: 11px;
  font-weight: 590;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--label-3);
  margin-bottom: 10px;
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--fill);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--label);
  font: inherit;
  font-size: 12px;
  font-weight: 510;
  padding: 5px 4px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.22s var(--ease), color 0.22s var(--ease);
  white-space: nowrap;
}
.segmented button:hover:not(.on) { background: rgba(255,255,255,0.06); }
.segmented button.on {
  background: rgba(120,120,128,0.56);
  box-shadow: 0 1px 2px rgba(0,0,0,0.28);
  color: #fff;
}

/* Swatch grid */
.swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.swatch {
  position: relative;
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.24s var(--ease), box-shadow 0.24s var(--ease);
  box-shadow: inset 0 0 0 0.5px rgba(255,255,255,0.14);
}
.swatch:hover { transform: scale(1.06); }
.swatch.on {
  box-shadow: 0 0 0 2px var(--accent), inset 0 0 0 0.5px rgba(255,255,255,0.2);
  transform: scale(1.04);
}
.swatch span {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: 9px;
  font-weight: 590;
  letter-spacing: 0.02em;
  padding: 2px 0 2.5px;
  background: linear-gradient(transparent, rgba(0,0,0,0.72));
  color: rgba(255,255,255,0.94);
  text-align: center;
}

/* Slider */
.slider-row { display: flex; align-items: center; gap: 10px; }
.slider-row .val {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--label-2);
  min-width: 46px;
  text-align: right;
}
input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--fill);
  outline: none;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4), 0 0 0 0.5px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: transform 0.18s var(--ease);
}
input[type=range]::-webkit-slider-thumb:active { transform: scale(1.14); }
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; border: none;
  border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  cursor: pointer;
}

/* Preset list */
.presets { display: flex; flex-direction: column; gap: 1px; }
.preset {
  display: flex;
  align-items: center;
  gap: 9px;
  border: none;
  background: transparent;
  color: var(--label);
  font: inherit;
  font-size: 12px;
  text-align: left;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.18s var(--ease);
}
.preset:hover { background: rgba(255,255,255,0.07); }
.preset.on { background: var(--accent); }
.preset .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--label-3);
  flex-shrink: 0;
  transition: background 0.18s var(--ease);
}
.preset.on .dot { background: #fff; }
.preset .name { flex: 1; }
.preset .z {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--label-3);
}
.preset.on .z { color: rgba(255,255,255,0.72); }

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 3px 0;
}
.toggle-row + .toggle-row { margin-top: 8px; }
.toggle-row .lbl { font-size: 12px; }
.toggle-row .hint { font-size: 10px; color: var(--label-3); margin-top: 1px; }
.switch {
  position: relative;
  width: 42px; height: 25px;
  border-radius: 13px;
  border: none;
  background: var(--fill);
  cursor: pointer;
  transition: background 0.28s var(--ease);
  flex-shrink: 0;
}
.switch.on { background: #30d158; }
.switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  transition: transform 0.28s var(--ease);
}
.switch.on::after { transform: translateX(17px); }

/* ---------- status bar ---------- */

#status {
  left: 20px;
  bottom: 20px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--label-2);
  user-select: text;
}
#status .item { display: flex; align-items: center; gap: 6px; }
#status .k { color: var(--label-3); }
#status .v { color: var(--label); font-weight: 510; }
#status .sep { width: 0.5px; height: 15px; background: var(--separator); }

#warn {
  color: #ff9f0a;
  display: none;
  align-items: center;
  gap: 5px;
}
#warn.show { display: flex; }

/* Busy indicator */
#busy {
  width: 13px; height: 13px;
  border: 1.5px solid rgba(255,255,255,0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  opacity: 0;
  transition: opacity 0.25s var(--ease);
}
#busy.on { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- julia preview ---------- */

#julia {
  right: 20px;
  bottom: 20px;
  width: 188px;
  padding: 10px;
  opacity: 0;
  transform: translateY(8px) scale(0.97);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  pointer-events: none;
}
#julia.show { opacity: 1; transform: none; }
#julia canvas {
  display: block;
  width: 168px; height: 168px;
  border-radius: var(--radius);
  background: #000;
}
#julia .cap {
  margin-top: 7px;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--label-3);
  text-align: center;
}

/* ---------- hint / toast ---------- */

#hint {
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 8px 15px;
  font-size: 11.5px;
  color: var(--label-2);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.45s var(--ease);
  pointer-events: none;
  white-space: nowrap;
}
#hint.show { opacity: 1; }
#hint kbd {
  font: inherit;
  font-weight: 590;
  color: var(--label);
  background: var(--fill);
  border-radius: 4px;
  padding: 1px 5px;
  margin: 0 1px;
}

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  #controls { width: 232px; }
  #julia { display: none; }
  #titlebar .sub { display: none; }
}
@media (max-width: 600px) {
  #controls {
    left: 12px; right: 12px; top: auto; bottom: 12px;
    width: auto; max-height: 44vh;
  }
  #status { display: none; }
  #titlebar { top: 12px; left: 12px; padding: 9px 14px; }
}

