:root {
  --bg: #070a0e;
  --panel: #0e141c;
  --panel-2: #141c27;
  --border: #1e2a3a;
  --border-soft: #162030;
  --text: #e8eef6;
  --muted: #8b9bb0;
  --accent: #38bdf8;
  --accent-2: #a78bfa;
  --accent-dim: rgba(56, 189, 248, 0.12);
  --danger: #f87171;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* —— Sidebar —— */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  background:
    radial-gradient(ellipse 80% 40% at 0% 0%, rgba(56, 189, 248, 0.08), transparent 50%),
    radial-gradient(ellipse 60% 30% at 100% 100%, rgba(167, 139, 250, 0.06), transparent 50%),
    var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background:
    linear-gradient(135deg, var(--accent), var(--accent-2));
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.35);
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  background: rgba(7, 10, 14, 0.55);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.panel {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* —— Fractal picker —— */
.fractal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.fractal-card {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.fractal-card:hover {
  border-color: #2a3d55;
  background: #182230;
}

.fractal-card.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.fractal-card .name {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 2px;
}

.fractal-card .kind {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* —— Controls —— */
.params {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.82rem;
  color: var(--text);
}

.control label .val,
.control .val {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}

.control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #67e8f9);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
  cursor: grab;
}

.control input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #67e8f9);
  cursor: grab;
}

.control input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  padding: 4px;
}

.control select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  outline: none;
  cursor: pointer;
}

.control select:focus {
  border-color: var(--accent);
}

.checkbox {
  display: flex !important;
  align-items: center;
  gap: 10px;
  justify-content: flex-start !important;
  cursor: pointer;
  font-size: 0.82rem;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.param-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: -4px;
  line-height: 1.4;
}

/* —— Actions —— */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex: 1 1 auto;
  min-width: 0;
}

.btn:hover {
  background: #1a2636;
  border-color: #2a3d55;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 16px rgba(14, 165, 233, 0.3);
}

.btn.primary:hover {
  filter: brightness(1.08);
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
}

.sidebar-foot {
  padding: 14px 20px 20px;
  margin-top: auto;
}

.sidebar-foot p {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.45;
}

/* —— Stage —— */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #05070a;
  min-width: 0;
  min-height: 0;
}

.stage-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(14, 20, 28, 0.85);
  backdrop-filter: blur(12px);
  z-index: 2;
}

.stage-bar .info strong {
  display: block;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.blurb {
  display: block;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 52ch;
  line-height: 1.45;
}

.stats {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  line-height: 1.6;
}

#canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#canvas.dragging {
  cursor: grabbing;
}

.hud {
  position: absolute;
  bottom: 16px;
  right: 16px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(14, 20, 28, 0.75);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

/* —— Responsive —— */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    max-height: 48vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

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

@media (max-width: 560px) {
  .fractal-grid {
    grid-template-columns: 1fr 1fr;
  }

  .stage-bar {
    flex-direction: column;
  }

  .stats {
    text-align: left;
  }
}
