/* CPAL-1.0 License. See chaosaccelerator.com/license.html */

/* The scene builder (editor view of chaos.html): theme variables, panel, canvas, controls. */
:root {
  --bg: #14161c;
  --bg-panel: #1b1e27;
  --bg-input: #0f1116;
  --border: #2c3040;
  --text: #e6e8ef;
  --text-dim: #9399ad;
  --accent: #5b8cff;
  --accent-hover: #75a0ff;
  --danger: #ff5f56;
  --danger-hover: #ff7a72;
  --panel-width: 320px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

.status-ok, .status-playing {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-ok { background: #21273a; color: #9db0e8; }
.status-playing { background: #163a25; color: #7ee0a0; }
.status-error { background: #3a1418; color: #ff9a9a; }

/* ---- Panel head: all the chrome there is (#editor-view only; the grid view keeps its own menu column) ---- */
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
/* Errors only: a compile failure or an unreadable scene. */
#status:not(.status-error) {
  display: none;
}
#status.status-error {
  flex: 1;
  min-width: 0;
}

#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#panel {
  width: var(--panel-width);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel-section h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 10px 0;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
button.secondary:hover { background: var(--bg-input); }
button.danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
button.danger:hover { background: var(--danger); color: white; }

.tool-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
}
.tool-btn:hover { background: #171a22; }
.tool-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
/* + Portals: green and spent while the pair is placed. */
.tool-btn.portals-placed,
.tool-btn.portals-placed:hover { background: #1f7a4f; border-color: #36d399; }
.tool-btn.portals-placed:disabled { opacity: 1; }

/* Native <details>/<summary>, collapsed by default. Open, a dashed fieldset-style box
   with the summary as legend: pulled out of flow, background-matched to erase the line. */
.collapsible {
  margin-top: 12px;
}
.collapsible > summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.collapsible > summary::-webkit-details-marker { display: none; }
.collapsible > summary::before {
  content: "\25b8";
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.15s ease;
}
.collapsible[open] > summary::before {
  transform: rotate(90deg);
}
.collapsible > summary:hover { color: var(--text); }
.collapsible[open] {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 10px;
}
.collapsible[open] > summary {
  position: absolute;
  top: -9px;
  left: 8px;
  padding: 0 6px;
  background: var(--bg-panel);
}
.collapsible-body {
  margin-top: 4px;
}
.collapsible-body .field:last-child { margin-bottom: 0; }

.field {
  display: block;
  font-size: 13px;
  margin-bottom: 10px;
}
.field span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  color: var(--text-dim);
}
.field span b { color: var(--text); font-weight: 600; }
/* Simulation Duration readout, typed into: reads like the bold number until focused. 16px or iOS zooms. */
.steps-number {
  width: 5.2em;
  padding: 1px 4px;
  font: inherit;
  font-weight: 600;
  text-align: right;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.steps-number:focus { outline: none; border-color: var(--accent, #5b8cff); }
html.input-coarse .steps-number { font-size: 16px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
input[type="range"]:disabled { opacity: 0.5; }

select {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
}
select:disabled { opacity: 0.5; }

/* A select that is the whole field (Edge Handling): full width, not its longest option. */
.field select {
  width: 100%;
}

.dual-select {
  display: flex;
  gap: 8px;
}
.dual-select select {
  flex: 1;
  min-width: 0;
}
/* An author display beats the UA's [hidden] rule, so el.hidden needs this. */
.dual-select[hidden] {
  display: none;
}
/* Same guarantee for the Spring section (refreshSpringPanel). */
#spring-section[hidden] {
  display: none;
}

.editor-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
/* Clear All sized like a tool button. */
#samples-section .editor-actions { display: grid; grid-template-columns: 1fr 1fr; }

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
/* Simulation's Advanced box sits right above the playback controls: 4px reads cramped after a bordered box. */
.collapsible + .field-row,
.collapsible + .playback-controls {
  margin-top: 18px;
}
.field-row button { flex: 1; }

.readout {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  margin: 8px 0 0 0;
}
.readout:empty { display: none; }

#canvas-area {
  flex: 1;
  position: relative;
  min-width: 0;
  background: #0c0d11;
  /* Centers #physics-canvas, which resizeCanvas() sizes in JS (not 100%/100%). */
  display: flex;
  align-items: center;
  justify-content: center;
}
/* A shared scene of another shape: black bars around its frame (resizeCanvas). */
#canvas-area.letterboxed {
  background: #000;
}

/* Floats over the scene, positioned against #canvas-area so it stays centered in both
   layouts. pointer-events none on the wrapper, auto on children: the empty space must not block the canvas. */
#fractalize-wrap {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}
#fractalize-wrap > * {
  pointer-events: auto;
}
#fractalize-wrap .readout {
  background: rgba(12, 13, 17, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  max-width: 320px;
  text-align: center;
  margin: 0;
  color: var(--text);
}
/* A genuine error, shown only after a send attempt fails. */
#fractalize-wrap .readout.error {
  border-color: var(--danger);
  color: var(--danger);
}

/* Builder Nerd Stats, top left under the home button. Look shared with #perf-readout. */
#editor-perf-readout {
  display: none;
  left: var(--panel-inset);
  top: calc(var(--panel-inset) + var(--settings-btn-size) + 10px);
  z-index: 9;
}
html:has(#perf-readout-checkbox:checked) #editor-perf-readout {
  display: block;
}

/* The Play transport, floated top-center over the scene. Its own translucent card:
   .playback-controls was designed for #panel's solid background. */
#playback-toolbar {
  position: absolute;
  left: 50%;
  top: var(--panel-inset);
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 14px;
  background: var(--bg-panel-float);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
/* Their margin-top was for #panel's column; meaningless here. */
#playback-toolbar .playback-controls {
  margin-top: 0;
}
#playback-toolbar .readout {
  margin-top: 0;
}
/* Not-ready hint (showNotReadyHint in physics-ui.js): calmer than .error, nothing is broken. */
#fractalize-wrap .readout.hint {
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* Loud on purpose: the one action that leaves the editor. Always this color; .not-ready below is the exception. */
.fractalize-btn {
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  padding: 14px 34px;
  border-radius: 999px;
  border: none;
  color: #200b00;
  background: linear-gradient(135deg, #ffd23f, #ff6b35 55%, #ff2e63);
  box-shadow: 0 4px 18px rgba(255, 107, 53, 0.55);
  cursor: pointer;
  white-space: nowrap;
  animation: fractalizePulse 2.2s ease-in-out infinite;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
/* The gradient again: button:hover above would paint it blue. */
.fractalize-btn:hover {
  background: linear-gradient(135deg, #ffd23f, #ff6b35 55%, #ff2e63);
  transform: translateY(-2px) scale(1.05);
  filter: brightness(1.08);
  box-shadow: 0 6px 26px rgba(255, 46, 99, 0.8);
}
.fractalize-btn:active {
  transform: translateY(0) scale(0.97);
}
/* A class, not :disabled: a disabled button stops firing the hover events this depends on. */
.fractalize-btn.not-ready,
.fractalize-btn.not-ready:hover {
  animation: none;
  cursor: not-allowed;
  color: var(--text-dim);
  background: var(--border);
  box-shadow: none;
  transform: none;
  filter: none;
}
@keyframes fractalizePulse {
  0%, 100% { box-shadow: 0 4px 18px rgba(255, 107, 53, 0.55); }
  50% { box-shadow: 0 4px 30px rgba(255, 46, 99, 0.9); }
}

/* Pulses the button that would move the scene toward ready (gridReadiness's highlight list). */
@keyframes highlightHintPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 53, 0.65); }
  50% { box-shadow: 0 0 0 6px rgba(255, 107, 53, 0); }
}
.tool-btn.highlight-hint {
  border-color: #ff6b35;
  animation: highlightHintPulse 1.1s ease-out infinite;
}

#physics-canvas {
  display: block;
  cursor: default;
  background: #0c0d11;
}
#physics-canvas.tool-select { cursor: default; }
#physics-canvas.tool-circle,
#physics-canvas.tool-line,
#physics-canvas.tool-velocity { cursor: crosshair; }
#physics-canvas.tool-anchor,
#physics-canvas.tool-hinge,
#physics-canvas.tool-input,
#physics-canvas.tool-input-velocity,
#physics-canvas.tool-output { cursor: pointer; }
#physics-canvas.dragging { cursor: grabbing; }

/* Gear button and its close twin in the settings panel: square, icon-only. */
.icon-button {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.icon-button:hover {
  background: var(--bg-input);
}

/* Apple-style toggle: still the same checkbox input, visually hidden, with .toggle-slider styled off :checked/:disabled. */
/* Settings kept for the code and presets only. */
#shared-settings-body .field[hidden],
#shared-settings-body .toggle-field[hidden] {
  display: none;
}

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 10px;
  cursor: pointer;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s ease;
  pointer-events: none;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}
.toggle-switch input:disabled + .toggle-slider {
  opacity: 0.5;
}
.toggle-switch input:disabled {
  cursor: not-allowed;
}

/* ---- The Output's color key, on the scrubber ----
   With Scene Lifespan as the Output the track IS the key (physics-ui.js sets the class
   and --output-key). A native track cannot be painted from outside, so the input gives
   up its native look: gradient background, transparent track, white thumb. */
#playback-progress-slider.output-key {
  -webkit-appearance: none;
  appearance: none;
  height: 10px;
  border-radius: 5px;
  background: var(--output-key);
  outline-offset: 4px;
}
#playback-progress-slider.output-key::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 10px;
  background: transparent;
}
#playback-progress-slider.output-key::-moz-range-track {
  height: 10px;
  background: transparent;
}
#playback-progress-slider.output-key::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -3px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #14161c;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
#playback-progress-slider.output-key::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #14161c;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
/* Disabled before Play, but the key is most use then: full color, only the thumb dims. */
#playback-progress-slider.output-key:disabled {
  opacity: 1;
}
#playback-progress-slider.output-key:disabled::-webkit-slider-thumb {
  background: #9399ad;
}
#playback-progress-slider.output-key:disabled::-moz-range-thumb {
  background: #9399ad;
}

/* ...and on the Set Output button, a swatch of its whole range. background-IMAGE so the
   idle/hover/active colors still apply; armed is a white ring, not the blue fill. */
button.tool-btn.output-key {
  background-image: var(--output-key);
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}
button.tool-btn.output-key.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff;
}

button.tool-btn.input-set {
  background: #1f7a3d;
  border-color: #2fa352;
  color: #fff;
}
button.tool-btn.input-set:hover { background: #25904a; }
button.tool-btn.input-set.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px #fff;
}
