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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  background: #1a1a2e;
  color: #e0e0e0;
}

/* ---- Version badge ---- */

#version-badge {
  position: fixed;
  top: 4px;
  right: 4px;
  z-index: 900;
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  pointer-events: none;
}

/* ---- Layout ---- */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

#panels {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ---- Panels ---- */

.panel {
  display: none;
  overflow: hidden;
  min-height: 0;
}

.panel--active {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

/* Palette is always-visible strip, doesn't compete for flex space */
#palette-panel {
  flex: 0 0 auto;
}

#palette-panel.panel--active {
  flex: 0 0 auto;
}

/* ---- Command bar ---- */

#command-bar {
  flex-shrink: 0;
  position: relative;
  background: #0a0f1e;
  border-top: 1px solid #0f3460;
  padding: 4px;
  padding-bottom: max(4px, env(safe-area-inset-bottom));
}

#command-row {
  position: relative;
}

#command-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 52px 8px 12px;
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
  color: #e0e0e0;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 16px; /* prevents iOS zoom */
}

#command-input::placeholder {
  color: rgba(255,255,255,0.25);
}

#command-input:focus {
  outline: none;
  border-color: #e94560;
}

#command-go {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: rgba(255,255,255,0.5);
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-appearance: none;
  appearance: none;
  padding: 0;
}

#command-go:active {
  background: rgba(233,69,96,0.3);
  color: #e0e0e0;
}

#autocomplete {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 4px;
  right: 4px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px 8px 0 0;
  overflow: hidden;
  z-index: 20;
}

#autocomplete.visible {
  display: block;
}

.autocomplete-item {
  padding: 10px 12px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 14px;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item--selected, .autocomplete-item:active {
  background: rgba(233,69,96,0.2);
  color: #e0e0e0;
}

.autocomplete-hint {
  color: rgba(255,255,255,0.3);
  font-size: 12px;
  margin-left: 8px;
}

/* ---- Palette ---- */

#palette {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-bottom: 1px solid #0f3460;
}

#palette-items {
  display: flex;
  gap: 10px;
  padding: 6px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  min-height: 44px;
}

#palette-selector {
  display: flex;
  gap: 10px;
  padding: 6px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.palette-item {
  flex-shrink: 0;
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 2px solid transparent;
  font-size: 14px;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Active category's representative block in the selector row */
.palette-item--selected {
  border-color: rgba(255,255,255,0.6);
}

/* ---- Workspace ---- */

#workspace {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
  background: #16213e;
}

#workspace:empty::after {
  content: "Drag blocks here";
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #555;
  font-style: italic;
  pointer-events: none;
}

/* ---- Blocks ---- */

.block {
  border-radius: 8px;
  margin-bottom: 6px;
  border: 2px solid rgba(255,255,255,0.1);
}
.block--highlight {
  border-color: #fff;
  box-shadow: 0 0 12px 2px rgba(255,255,255,0.5);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  min-height: 44px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  border-radius: 6px 6px 0 0;
}

.block__label {
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.block__delete {
  min-width: 32px;
  min-height: 32px;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #e0e0e0;
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.block__delete:hover {
  background: rgba(255,80,80,0.5);
}

.block__promote {
  min-width: 32px;
  min-height: 32px;
  border: none;
  background: rgba(255,255,255,0.10);
  color: rgba(255,255,255,0.8);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  margin-right: 4px;
}

.block__promote:hover:not(:disabled) {
  background: rgba(100,200,255,0.4);
}

.block__promote:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Inline single-param in header (e.g. paint color, fuse k) */
.block__inline-param {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  margin: 0 8px;
  font-size: 13px;
}

.block__inline-param span {
  color: rgba(255,255,255,0.7);
  flex-shrink: 0;
}

.block__inline-param input[type="number"],
.block__inline-param select {
  flex: 1;
  min-height: 32px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.3);
  color: #e0e0e0;
  font-size: 16px; /* prevents iOS zoom */
}

.block__params {
  padding: 6px 10px;
}

.block__params label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 13px;
}

.block__params label span {
  min-width: 50px;
  color: rgba(255,255,255,0.7);
}

.block__params input[type="number"],
.block__params select {
  flex: 1;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.3);
  color: #e0e0e0;
  font-size: 16px; /* prevents iOS zoom */
}

.block__children {
  padding: 4px 4px 4px 16px;
  min-height: 8px;
  border-left: 3px solid rgba(255,255,255,0.1);
  margin: 0 6px 6px 10px;
  border-radius: 0 0 4px 4px;
}

/* ---- Drop zone ---- */

.drop-zone {
  min-height: 40px;
  border: 2px dashed rgba(255,255,255,0.15);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: rgba(255,255,255,0.3);
  margin-bottom: 4px;
}

.drop-zone--gap {
  min-height: 8px;
  border: 2px dashed transparent;
  margin-bottom: 2px;
  transition: min-height 0.1s, border-color 0.1s, background 0.1s;
}

.drop-zone--gap.drop-zone--active {
  min-height: 28px;
  border-color: #e94560;
  background: rgba(233,69,96,0.15);
}

.drop-zone--active {
  border-color: #e94560;
  background: rgba(233,69,96,0.1);
  color: #e94560;
}

.block--wrap-target {
  outline: 2px dashed #e94560;
  outline-offset: 2px;
  box-shadow: 0 0 12px 2px rgba(233,69,96,0.3);
}

/* ---- Block type colors ---- */

.block--cube, .palette-item--cube {
  background: #c45e00;
}
.block--sphere, .palette-item--sphere {
  background: #1a5fb4;
}
.block--cylinder, .palette-item--cylinder {
  background: #26a269;
}
.block--text, .palette-item--text {
  background: #a0522d;
}
.block--translate, .palette-item--translate {
  background: #813d9c;
}
.block--paint, .palette-item--paint {
  background: #c44;
}
.block--recolor, .palette-item--recolor {
  background: #944;
}
.block--union, .palette-item--union {
  background: #555;
}
.block--fuse, .palette-item--fuse {
  background: #cc7700;
}
.block--intersect, .palette-item--intersect {
  background: #3a7;
}
.block--anti, .palette-item--anti {
  background: #c44;
  border-style: dashed;
}
.block--complement, .palette-item--complement {
  background: #668;
}
.block--rotate, .palette-item--rotate {
  background: #a5c;
}
.block--mirror, .palette-item--mirror {
  background: #5a8;
}
.block--twist, .palette-item--twist {
  background: #a68;
}
.block--radial, .palette-item--radial {
  background: #68a;
}
.block--stretch, .palette-item--stretch {
  background: #8a5;
}
.block--tile, .palette-item--tile {
  background: #58a;
}
.block--bend, .palette-item--bend {
  background: #a85;
}
.block--taper, .palette-item--taper {
  background: #85a;
}
/* PL blocks — binding category */
.block--let, .palette-item--let {
  background: #2a6e8f;
}
.block--var, .palette-item--var {
  background: #1a5e7f;
  border-style: dotted;
}
.block--grow, .palette-item--grow {
  background: #2a8f4e;
}
.block--stir, .palette-item--stir {
  background: #8f6a2a;
}
.block--enzyme, .palette-item--enzyme {
  background: #6a5e8f;
}
.block--tag, .palette-item--tag {
  background: #5e8f6a;
}
.block--tags, .palette-item--tags {
  background: #4e7f5a;
}
.block--fractal, .palette-item--fractal {
  background: #5e3a8f;
}
.block--scalar, .palette-item--scalar {
  background: #8f8f2a;
}
/* Expression-capable param slots */
.expr-slot {
  display: inline-block;
  min-width: 48px;
  min-height: 28px;
  border: 2px dashed rgba(255,255,255,0.2);
  border-radius: 6px;
  vertical-align: middle;
}
.expr-slot--active {
  border-color: #4af;
  background: rgba(68, 170, 255, 0.15);
}
.expr-slot__block {
  display: inline-block;
  margin: 0 2px;
  vertical-align: middle;
}
/* Tag rows for enzyme blocks */
.tag-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}
.tag-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tag-row--empty {
  opacity: 0.45;
}
.tag-row--empty:focus-within {
  opacity: 1;
}
.tag-row input.tag-row__tag {
  flex: 1 0 60px;
  min-height: 32px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.2);
  color: #fff;
  font-size: 13px;
}
.tag-row input.tag-row__default {
  width: 100%;
  min-height: 32px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.2);
  color: #fff;
  font-size: 13px;
  text-align: center;
}
.tag-row .expr-slot {
  flex: 3;
  min-width: 48px;
}
/* Slot labels for let/grow blocks */
.block__slot-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 0;
  margin-top: 4px;
}
/* Text inputs in block params */
.block__params input[type="text"],
.block__inline-param input[type="text"] {
  flex: 1;
  min-height: 32px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(0,0,0,0.3);
  color: #e0e0e0;
  font-size: 16px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}
/* ---- Drag ghost ---- */

.drag-ghost {
  position: fixed;
  opacity: 0.85;
  pointer-events: none;
  z-index: 1000;
  transform: scale(1.05);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  color: #e0e0e0;
}

/* ---- Code preview ---- */

#code-panel {
  background: #16213e;
}

#code-output {
  padding: 8px 10px;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.5;
  color: #a0d0a0;
  background: rgba(0,0,0,0.2);
  overflow: auto;
  white-space: pre;
  margin: 0;
  flex: 1;
  min-height: 0;
  border: none;
  resize: none;
  outline: none;
  -webkit-appearance: none;
}

/* ---- Viewport ---- */

#viewport-panel {
  position: relative;
  overflow: hidden;
  background: #f0f0f0;
}

#viewport-panel canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.meshing-indicator {
  display: none;
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(22, 33, 62, 0.85);
  color: #e0e0e0;
  padding: 6px 16px;
  border-radius: 4px;
  font-size: 14px;
  z-index: 10;
  pointer-events: none;
}

.meshing-indicator.visible {
  display: block;
}

.hud {
  display: none;
  position: absolute;
  bottom: 8px;
  right: 8px;
  max-height: 40%;
  overflow-y: auto;
  background: rgba(22, 33, 62, 0.8);
  color: #c0c0c0;
  font-family: monospace;
  font-size: 11px;
  line-height: 1.4;
  padding: 6px 10px;
  border-radius: 4px;
  z-index: 10;
  pointer-events: none;
}

.hud.visible {
  display: block;
}

.hud-entry {
  white-space: nowrap;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 2px 0;
}

.hud-entry:last-child {
  border-bottom: none;
}
