/* particletoy — dark editor theme */

:root {
  --bg: #0d0e11;
  --panel: #14161b;
  --panel-2: #191c22;
  --border: #262a33;
  --text: #d7dae0;
  --text-dim: #8b909c;
  --accent: #e8a33d;
  --accent-2: #4d9fff;
  --danger: #e05252;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  --editor-w: 44%;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, "Segoe UI", system-ui, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--text-dim); font-size: 12px; }
.flex-spacer { flex: 1; }

/* ---------------------------------------------------------------- topbar */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 46px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 17px;
  letter-spacing: 0.3px;
  color: var(--text-dim);
  user-select: none;
  margin-right: 4px;
}
.brand b { color: var(--accent); font-weight: 700; }
.topbar-sep { width: 1px; height: 22px; background: var(--border); }
.fx-name { width: 150px; }
#btn-mobile-actions { display: none; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg-btn {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
.seg-btn.active { background: var(--accent-2); color: #fff; }
.seg-btn:not(.active):hover { background: var(--panel-2); }

/* ---------------------------------------------------------------- layout */
#main {
  display: grid;
  grid-template-columns: 1fr 5px var(--editor-w);
  height: calc(100% - 46px);
}
#left { display: flex; flex-direction: column; min-width: 320px; overflow: hidden; }
#viewport {
  position: relative;
  height: 55%;
  min-height: 220px;
  background: #000;
  border-bottom: 1px solid var(--border);
}
#gl { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#gl:active { cursor: grabbing; }
#viewport-overlay {
  position: absolute;
  left: 8px;
  bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
#viewport-overlay .btn { pointer-events: auto; }
#stats {
  font-family: var(--mono);
  font-size: 11px;
  color: #cfd3da;
  background: rgba(10, 11, 14, 0.55);
  padding: 3px 8px;
  border-radius: 5px;
}
#gl-error {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  color: var(--danger);
  font-size: 15px;
  background: var(--bg);
}
#inspector { flex: 1; overflow-y: auto; background: var(--panel); }
#splitter { background: var(--border); cursor: col-resize; }
#splitter:hover { background: var(--accent-2); }
#right {
  display: flex;
  flex-direction: column;
  min-width: 300px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

#mobile-tabs { display: none; }

/* ---------------------------------------------------------------- buttons */
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: #3a4050; background: #1f232b; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1c1405; font-weight: 600; }
.btn-accent:hover { background: #f0b054; border-color: #f0b054; }
.btn-icon { padding: 5px 9px; }
.btn-small { padding: 3px 8px; font-size: 11px; }
.btn-danger { color: var(--danger); }
.btn-row { display: flex; gap: 6px; margin-top: 8px; }
/* Disabled controls: the debug view outside the deferred pipeline, and
   everything that needs a GPU on a browser that hasn't got one. Without this
   they look live and simply refuse to work. */
.btn:disabled, .seg-btn:disabled, .select-in:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); background: var(--panel-2); }

/* ---------------------------------------------------------------- inputs */
.text-in, .num-in, .select-in, .obj-in {
  background: #101216;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 12px;
}
.text-in:focus, .num-in:focus, .select-in:focus, .obj-in:focus {
  outline: none;
  border-color: var(--accent-2);
}
.num-in { width: 68px; font-family: var(--mono); }
.num-in::-webkit-inner-spin-button { opacity: 0.3; }
.color-in {
  width: 34px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}
input[type="range"] { accent-color: var(--accent); flex: 1; min-width: 60px; }
input[type="checkbox"] { accent-color: var(--accent-2); width: 15px; height: 15px; }
.obj-in {
  width: 100%;
  height: 90px;
  font-family: var(--mono);
  font-size: 11px;
  resize: vertical;
  margin: 6px 0;
}

/* ---------------------------------------------------------------- inspector */
.section { border-bottom: 1px solid var(--border); }
.section > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  user-select: none;
  list-style: none;
}
.section > summary::before { content: "▸ "; color: var(--text-dim); }
.section[open] > summary::before { content: "▾ "; }
.section-body { padding: 8px 12px 12px; }
/* The same disclosure inside a dialog, where there is no inspector column to
   sit flush against: it needs its own edges rather than the panel's. */
.dialog-section { border: 1px solid var(--border); border-radius: 7px; margin: 10px 0; }
.dialog-section > summary { border-radius: 6px 6px 0 0; }

.prop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0;
  min-height: 24px;
}
.prop-label {
  width: 96px;
  flex: none;
  color: var(--text-dim);
  font-size: 12px;
}
.prop-controls { display: flex; align-items: center; gap: 6px; flex: 1; flex-wrap: wrap; }
.vec-wrap { display: flex; gap: 4px; align-items: center; }
.range-sep { color: var(--text-dim); }
.slider-wrap { display: flex; gap: 8px; align-items: center; flex: 1; }

.emitter-list { display: flex; flex-direction: column; gap: 2px; }
.emitter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: default;
}
.emitter-item:hover { background: var(--panel-2); }
.emitter-item.selected { background: #1c2532; outline: 1px solid #2c3e57; }
.emitter-name { flex: 1; cursor: pointer; }
.emitter-count { font-family: var(--mono); font-size: 10px; color: var(--text-dim); }

.burst-list { display: flex; flex-direction: column; gap: 4px; }
.burst-row { display: flex; align-items: center; gap: 5px; }
.burst-label { color: var(--text-dim); font-size: 11px; }

.material-box {
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 10px;
  margin: 8px 0;
  background: var(--panel-2);
}
.material-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.material-name { font-weight: 600; }

.curve-holder { flex: 1; min-width: 180px; }
.curve-wrap { position: relative; }
/* touch-action: none stops the page from scrolling/refreshing while a
   point, handle, or pinch gesture is being dragged on the canvas. */
.curve-canvas { width: 100%; height: 116px; display: block; border-radius: 5px; cursor: crosshair; touch-action: none; }
.gradient-canvas { width: 100%; height: 44px; display: block; border-radius: 5px; cursor: pointer; touch-action: none; }

.curve-viewtools {
  position: absolute;
  top: 5px;
  right: 5px;
  display: flex;
  gap: 4px;
}
.curve-viewtools .btn-small {
  padding: 3px 7px;
  background: rgba(20, 22, 27, 0.75);
  backdrop-filter: blur(2px);
}
.curve-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.curve-tools .btn[aria-label^="Nudge"] { min-width: 34px; }
.curve-num-in { width: 56px; }
.curve-hint { font-size: 11px; }

/* Selected-stop controls under the gradient bar. The colour input is a real,
   visible swatch — a hidden zero-size input cannot open the native picker. */
.gradient-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.gradient-color-input {
  width: 34px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
  cursor: pointer;
  flex: none;
}
.gradient-color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.gradient-color-input::-webkit-color-swatch { border: none; border-radius: 2px; }
.gradient-stop-info { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }
.gradient-tools .btn-small { margin-left: auto; }

/* ---------------------------------------------------------------- editor */
#editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.editor-mat-select { max-width: 170px; }
.tab-btn { border-radius: 6px 6px 0 0; }
.tab-btn.active { background: #0f1115; border-color: var(--accent); color: var(--accent); }
.auto-label { display: flex; align-items: center; gap: 4px; color: var(--text-dim); font-size: 12px; }

#editor-host { flex: 1; overflow: hidden; position: relative; }
.ce-wrap { display: flex; height: 100%; background: #0f1115; }
.ce-gutter {
  width: 44px;
  flex: none;
  overflow: hidden;
  padding: 10px 0;
  background: #0c0e12;
  border-right: 1px solid var(--border);
  text-align: right;
  user-select: none;
}
.ce-ln {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: #4a4f5c;
  padding-right: 10px;
}
.ce-ln-err { color: #fff; background: var(--danger); }
.ce-body { position: relative; flex: 1; overflow: hidden; }
.ce-highlight, .ce-input {
  position: absolute;
  inset: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  padding: 10px 12px;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}
.ce-highlight {
  pointer-events: none;
  color: #c9d1e0;
  margin: 0;
}
.ce-highlight code { font: inherit; }
.ce-input {
  background: transparent;
  color: transparent;
  caret-color: #f5f6f8;
  border: none;
  resize: none;
  outline: none;
}
.ce-input::selection { background: rgba(77, 159, 255, 0.3); }

.tok-comment { color: #5d6576; font-style: italic; }
.tok-preproc { color: #b678d6; }
.tok-number { color: #d9945f; }
.tok-keyword { color: #6fa8ff; }
.tok-builtin { color: #56c8b2; }
.tok-api { color: #e8c95d; }

#editor-errors {
  max-height: 130px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  padding: 6px 10px;
  background: #101216;
  font-family: var(--mono);
  font-size: 11.5px;
}
.compile-ok { color: #58c07a; }
.compile-err { color: #ff8a8a; padding: 2px 0; }

/* ---------------------------------------------------------------- modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-box {
  width: 440px;
  max-width: 92vw;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
}
.modal-wide { width: 640px; }
.xm-progress-wrap { margin: 10px 0; display: flex; align-items: center; gap: 10px; }
.xm-progress-bar {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
}
.xm-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s ease;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 600; }
.modal-body { padding: 14px; overflow-y: auto; }
.modal-body p { margin: 6px 0; }
.modal-body a { color: var(--accent-2); }
.share-url { width: 100%; font-family: var(--mono); font-size: 11px; margin: 8px 0; }

.lib-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
.lib-name { flex: 1; }

/* ---------------------------------------------------------------- help */
.help h3 { margin: 14px 0 6px; color: var(--accent); font-size: 13px; }
.help pre {
  background: #0f1115;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  overflow-x: auto;
  margin: 6px 0;
}
.help code {
  background: #0f1115;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 11.5px;
}
.help ul { margin: 6px 0 6px 18px; }
.help li { margin: 3px 0; }

/* ---------------------------------------------------------------- toast */
#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: #23272f;
  border: 1px solid #3a4050;
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ------------------------------------------------------- narrow workspaces
   A three-column editor cannot merely shrink into a phone. Give each task the
   whole screen and keep the desktop split layout untouched above this width. */
@media (max-width: 760px) {
  html, body { height: 100%; height: 100dvh; }
  body { display: flex; flex-direction: column; }

  #topbar {
    width: 100%;
    flex: none;
    overflow: hidden;
    flex-wrap: wrap;
    align-content: center;
    transition: height 0.16s ease;
  }
  #topbar > * { flex: none; }
  #topbar .brand { display: none; }
  #topbar .mobile-secondary { display: none; order: 2; }
  #topbar.mobile-actions-open {
    height: auto;
    max-height: min(70dvh, 420px);
    padding-top: 5px;
    padding-bottom: 7px;
    align-content: flex-start;
    overflow-y: auto;
  }
  #topbar.mobile-actions-open .mobile-secondary { display: revert; }
  #topbar.mobile-actions-open .seg.mobile-secondary { display: flex; }
  #topbar.mobile-actions-open .topbar-sep { display: none; }
  .fx-name { width: auto; min-width: 76px; flex: 1 !important; }
  #btn-mobile-actions { display: block; }

  #main {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: auto;
    grid-template-columns: minmax(0, 1fr);
  }
  #splitter { display: none; }
  #left, #right {
    min-width: 0;
    width: 100%;
    height: 100%;
  }
  #viewport, #inspector { height: 100%; min-height: 0; }
  #right { border-left: 0; }

  body[data-mobile-view="preview"] #inspector,
  body[data-mobile-view="preview"] #right,
  body[data-mobile-view="inspect"] #viewport,
  body[data-mobile-view="inspect"] #right,
  body[data-mobile-view="code"] #left { display: none; }

  #editor-toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  #editor-toolbar::-webkit-scrollbar { display: none; }
  #editor-toolbar > * { flex: none; }
  #editor-toolbar .flex-spacer { min-width: 8px; }

  #mobile-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    flex: none;
    min-height: 48px;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--panel);
    border-top: 1px solid var(--border);
  }
  .mobile-tab {
    min-width: 0;
    min-height: 47px;
    border: 0;
    border-top: 2px solid transparent;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }
  .mobile-tab.active {
    color: var(--accent);
    border-top-color: var(--accent);
    background: var(--panel-2);
  }

  .btn, .seg-btn, .select-in, .text-in { min-height: 36px; }
  #inspector {
    scroll-padding-block: 12px 42vh;
    overscroll-behavior-y: contain;
  }
  #inspector .section > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  #inspector .section-body { padding: 10px 12px 14px; }
  #inspector .emitter-item { min-height: 44px; }
  #inspector .prop-row {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    align-items: center;
    min-height: 42px;
    margin: 7px 0;
  }
  #inspector .prop-controls { min-width: 0; }
  #inspector .vec-wrap,
  #inspector .slider-wrap { min-width: 0; flex-wrap: wrap; }
  #inspector .num-in,
  #inspector .select-in,
  #inspector .text-in,
  #inspector .color-in { min-height: 40px; }
  #inspector .num-in { width: 72px; }
  #inspector input[type="checkbox"] { width: 22px; height: 22px; }
  #inspector input[type="range"] { min-height: 32px; }
  #inspector input,
  #inspector select,
  #inspector textarea { scroll-margin-bottom: 42vh; }
  #inspector .btn { min-height: 40px; }
  #inspector .btn-icon { min-width: 40px; }
  #inspector .material-head { min-height: 40px; gap: 8px; }
  #inspector .curve-holder { min-width: 0; }
  #viewport-overlay { bottom: 10px; }
  #toast { bottom: calc(62px + env(safe-area-inset-bottom)); max-width: 90vw; }

  .modal-overlay {
    align-items: flex-end;
    padding: max(10px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }
  .modal-box,
  .modal-wide {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - max(18px, env(safe-area-inset-top)));
    border-radius: 12px 12px 8px 8px;
  }
  .modal-head {
    position: sticky;
    top: 0;
    z-index: 1;
    min-height: 52px;
    background: var(--panel);
    border-radius: 12px 12px 0 0;
  }
  .modal-head .btn-icon { min-width: 40px; min-height: 40px; }
  .modal-body { padding: 12px; overscroll-behavior-y: contain; }
  .modal-body .prop-row {
    display: grid;
    grid-template-columns: minmax(92px, 0.4fr) minmax(0, 1fr);
    min-height: 42px;
  }
  .modal-body .prop-label { width: auto; }
  .modal-body .prop-controls { min-width: 0; flex-wrap: wrap; }
  .modal-body .text-in,
  .modal-body .select-in,
  .modal-body .obj-in { max-width: 100%; }
  .modal-body .btn-row,
  .lib-row { flex-wrap: wrap; }
  .lib-row .lib-name { min-width: min(180px, 55vw); }
  .share-url { min-height: 44px; }
}

@media (max-width: 760px) and (orientation: landscape) {
  .modal-overlay { align-items: center; }
  .modal-box,
  .modal-wide { max-height: calc(100dvh - 12px); }
}
