:root {
  --accent: #00f5d4;
  --panel-bg: rgba(9, 13, 21, 0.78);
  --panel-line: rgba(255, 255, 255, 0.09);
  --ink: rgba(235, 240, 250, 0.92);
  --ink-dim: rgba(235, 240, 250, 0.55);
  --ink-faint: rgba(235, 240, 250, 0.35);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #070a12;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#view {
  position: fixed;
  inset: 0;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

#vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.38));
}

/* ---------------------------------------------------------------- panel */

#panel {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 272px;
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel-bg);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transform: translateX(0);
  opacity: 1;
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  z-index: 10;
  scrollbar-width: thin;
}
body:not(.panel-open) #panel {
  transform: translateX(calc(-100% - 22px));
  opacity: 0;
  pointer-events: none;
}

#panel header h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--accent), #fff 130%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
#panel .sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

#panel section { display: flex; flex-direction: column; gap: 8px; }

.lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* segmented control */
.seg {
  display: flex;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-dim);
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--ink); }
.seg button.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

select, input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  outline: none;
  appearance: none;
}
select { cursor: pointer; }
select:focus, input[type="text"]:focus { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
select option { background: #0d1220; color: #e8edf7; }

#rule-input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.row { display: flex; gap: 6px; align-items: center; }
.grow { flex: 1; }

button.mini {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #05070c;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
button.mini:hover { filter: brightness(1.12); }

#rule-error { font-size: 11px; color: #ff7b8a; min-height: 0; }
#rule-error:empty { display: none; }
#rule-desc { font-size: 11.5px; line-height: 1.45; color: var(--ink-dim); }

button.wide {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 9px 0;
  font-size: 12.5px;
  font-weight: 700;
  color: #05070c;
  background: linear-gradient(120deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #ffffff));
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
}
button.wide:hover { filter: brightness(1.1); }
button.wide:active { transform: scale(0.98); }
button.wide svg { width: 15px; height: 15px; stroke: #05070c; }
button.wide .dot { fill: #05070c; stroke: none; }

button.wide.ghost {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  color: var(--ink-dim);
}
button.wide.ghost svg { stroke: currentColor; }
button.wide.ghost:hover { color: var(--ink); }

/* palettes */
#palettes {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active {
  box-shadow: 0 0 0 2px #0a0e16, 0 0 0 4px var(--accent);
}

/* sliders */
.slider-row { gap: 8px; }
.slbl { font-size: 11px; color: var(--ink-dim); white-space: nowrap; min-width: 52px; }
.sval { font-size: 11px; color: var(--ink-dim); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }

input[type="range"] {
  flex: 1;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0e16;
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0a0e16;
}

.hints { font-size: 10.5px; line-height: 1.6; color: var(--ink-faint); }
.hints b { color: var(--ink-dim); }

/* dimension-conditional UI */
body.dim1 .only-2d { display: none !important; }
body:not(.dim1) .only-1d { display: none !important; }
body.dim1:not(.seed-random) #density-row { display: none; }

/* ------------------------------------------------------------- toggle */

#panel-toggle {
  position: fixed;
  top: 14px;
  left: 14px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-line);
  border-radius: 12px;
  cursor: pointer;
  z-index: 11;
  transition: left 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), top 0.28s;
}
body.panel-open #panel-toggle { left: 244px; top: 22px; border-color: transparent; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
#panel-toggle svg { width: 18px; height: 18px; stroke: var(--ink-dim); }
#panel-toggle:hover svg { stroke: var(--ink); }
#panel-toggle .icon-close { display: none; }
body.panel-open #panel-toggle .icon-menu { display: none; }
body.panel-open #panel-toggle .icon-close { display: block; }

/* ----------------------------------------------------------- transport */

#transport {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  z-index: 10;
}
#transport button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}
#transport button:hover { background: rgba(255, 255, 255, 0.09); }
#transport svg { width: 17px; height: 17px; stroke: var(--ink); }
#transport svg .fill { fill: var(--ink); stroke: none; }
#transport svg .dot { fill: var(--ink); stroke: none; }
#transport input[type="range"] { width: 104px; margin-left: 8px; }
#speed-val {
  font-size: 11px;
  color: var(--ink-dim);
  min-width: 42px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  margin-right: 2px;
}

/* --------------------------------------------------------------- hud */

#hud {
  position: fixed;
  right: 14px;
  bottom: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--ink-faint);
  background: rgba(9, 13, 21, 0.55);
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  pointer-events: none;
  z-index: 9;
}

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

#toast {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -60px);
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s;
  z-index: 20;
  pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ------------------------------------------------------- syntax modal */

.lbl-row { justify-content: space-between; }

#syntax-help {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
#syntax-help:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

#syntax-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 4, 9, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 30;
}
#syntax-modal[hidden] { display: none; }

#syntax-modal .sheet {
  width: min(600px, 100%);
  max-height: min(84dvh, 720px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: rgba(12, 17, 27, 0.92);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid var(--panel-line);
  border-radius: 20px;
  padding: 22px 24px 20px;
  scrollbar-width: thin;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sheet-head h2 {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
}
#syntax-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  cursor: pointer;
}
#syntax-close svg { width: 14px; height: 14px; stroke: var(--ink-dim); }
#syntax-close:hover svg { stroke: var(--ink); }

#syntax-modal .intro,
#syntax-modal .fineprint {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}
#syntax-modal .fineprint { margin-top: 14px; font-size: 11.5px; color: var(--ink-faint); }

#syntax-modal h3 {
  margin: 18px 0 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-top: 1px solid var(--panel-line);
  padding-top: 14px;
}

#syntax-modal dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
#syntax-modal dt { justify-self: start; }
#syntax-modal dd { font-size: 12.5px; line-height: 1.55; color: var(--ink-dim); }
#syntax-modal dd b { color: var(--ink); font-weight: 700; }
#syntax-modal code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  padding: 1px 6px;
  border-radius: 6px;
  white-space: nowrap;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.chip:hover { background: color-mix(in srgb, var(--accent) 28%, transparent); }
.chip:active { transform: scale(0.95); }

@media (max-width: 520px) {
  #syntax-modal dl { grid-template-columns: 1fr; gap: 2px; }
  #syntax-modal dd { margin-bottom: 8px; }
}

/* SVG defaults */
svg { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* --------------------------------------------------------------- mobile */

@media (max-width: 720px) {
  #panel {
    width: calc(100vw - 24px);
    max-width: 340px;
    top: 12px;
    left: 12px;
    max-height: calc(100dvh - 96px);
  }
  body.panel-open #panel-toggle { left: unset; right: 14px; top: 14px; background: var(--panel-bg); border-color: var(--panel-line); }
  #transport { bottom: 12px; padding: 6px 10px; }
  #transport input[type="range"] { width: 70px; }
  #hud { display: none; }
}
