/* All styling for the Animator app. Its code only attaches class names. */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }

/* ── Layout: two columns ─────────────────────────────────────────────────── */

.app {
  display: flex;
  width: 100vw;
  height: 100vh;
  background: #1a1a2e;
  color: #d4c5a0;
  font-family: system-ui, sans-serif;
  font-size: 14px;
}

/* Left column: the code editor. */
.code-col {
  width: 42%;
  min-width: 320px;
  max-width: 720px;
  flex-shrink: 0;
  display: flex;
  border-right: 1px solid #3a3a5e;
  background: #0f0f1e;
}

/* The code column stays in the DOM when collapsed, so CodeMirror keeps its
   state; hiding it gives the right column the full width. */
.app.code-hidden .code-col { display: none; }

/* A small emoji button (the code pane's collapse toggle, and the playback
   controls once they exist). */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #2a2a4a;
  color: #d4c5a0;
  border: 1px solid #4a4a8a;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 5px 8px;
}
.icon-btn:hover { background: #3a3a5e; }

/* ── Code panel (left column) ───────────────────────────────────────────── */

.code-panel {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #1a1a3e;
  border-bottom: 1px solid #3a3a5e;
}
.code-title {
  color: #e8d8b0;
  font-family: 'Georgia', serif;
  font-size: 16px;
  letter-spacing: 1px;
}

/* Wrapper holding the editor. */
.code-editor-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
}
/* CodeMirror mount node: grows to fill the panel. */
.code-editor {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: #0d0d1a;
}
.code-editor .cm-editor { width: 100%; height: 100%; }

/* Collapsible reference of the built-ins available to draw functions. */
.reference {
  margin: 8px 14px 0;
  border: 1px solid #3a3a5e;
  border-radius: 4px;
  background: #0d0d1a;
  overflow: hidden;
}
.reference-summary {
  padding: 6px 12px;
  cursor: pointer;
  color: #b8a888;
  font-family: monospace;
  font-size: 12px;
  user-select: none;
}
.reference-summary:hover { color: #e8d8b0; }
.reference-body {
  padding: 4px 12px 10px;
  border-top: 1px solid #3a3a5e;
}
.reference-group { margin-top: 8px; }
.reference-group-title {
  color: #8a8aca;
  font-family: monospace;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.reference-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 1px 0;
}
.reference-sig {
  color: #89ddff;
  font-family: monospace;
  font-size: 12px;
  white-space: pre;
}
.reference-desc { color: #6a7a8a; font-size: 11px; }

/* ── Animation area (right column) ──────────────────────────────────────── */

.preview-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.preview-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  padding: 10px 14px;
  background: #1a1a3e;
  border-bottom: 1px solid #3a3a5e;
}

.drawing-control {
  flex: 1 1 170px;
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 4px;
  color: #e8d8b0;
}

.drawing-control select {
  width: 100%;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid #4a4a8a;
  border-radius: 4px;
  background: #0f0f1e;
  color: inherit;
  font: inherit;
}

.slider-control {
  flex: 1 1 140px;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 4px 8px;
  color: #e8d8b0;
}

.slider-value {
  color: #b8cfff;
  font-variant-numeric: tabular-nums;
}

.slider-control input {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  accent-color: #89ddff;
}

.timeline {
  padding: 8px 14px 10px;
  background: #1a1a3e;
  border-top: 1px solid #3a3a5e;
}

.timeline-loop-track {
  height: 4px;
  margin: 3px 8px 10px;
  border-radius: 4px;
  background: #303052;
  position: relative;
}

.timeline-loop-interval {
  position: absolute;
  inset-block: 0;
  border-radius: inherit;
  background: #646e9e;
}

.timeline-loop-track[data-repeating="true"] .timeline-loop-interval {
  background: #89ddff;
}

.timeline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.timeline-button {
  padding: 5px 9px;
  border: 1px solid #4a4a8a;
  border-radius: 4px;
  background: #2a2a4a;
  color: #e8d8b0;
  font: inherit;
  cursor: pointer;
}

.timeline-button:hover:not(:disabled) { background: #3a3a5e; }
.timeline-button[aria-pressed="true"] {
  border-color: #89ddff;
  color: #b8eaff;
  background: #203957;
}
.timeline-button:disabled { opacity: 0.5; cursor: default; }

.timeline-times {
  margin-inline-start: auto;
  color: #b8cfff;
  font-variant-numeric: tabular-nums;
}

.studio {
  padding: 7px 14px;
  background: #111127;
  border-top: 1px solid #3a3a5e;
}

.studio [hidden] { display: none; }
.studio-modes, .studio-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.studio button, .studio input, .studio select, .studio textarea {
  font: inherit;
  color: #ecdcb8;
  background: #232344;
  border: 1px solid #535387;
  border-radius: 4px;
}

.studio button { padding: 4px 8px; cursor: pointer; }
.studio button:hover:not(:disabled) { background: #34345c; }
.studio button:disabled { opacity: 0.5; cursor: default; }
.studio button[aria-pressed="true"] {
  color: #b8eaff;
  border-color: #89ddff;
  background: #203957;
}

.studio-body {
  max-height: min(34vh, 250px);
  overflow: auto;
  padding: 8px 2px 2px;
}

.studio-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
}

.studio-tracks {
  flex: 1 1 190px;
  min-width: 0;
  max-height: 114px;
  overflow: auto;
}

.studio button.studio-track {
  display: grid;
  grid-template-columns: 6em minmax(0, 1fr);
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-bottom: 3px;
  text-align: left;
}

.studio-track-line {
  position: relative;
  height: 7px;
  border-radius: 3px;
  background: #0d1021;
}

.studio-track-line span {
  position: absolute;
  inset-block: 1px;
  min-width: 2px;
  border-radius: 3px;
}

.studio-track-line::after {
  content: "";
  position: absolute;
  inset-block: -2px;
  left: var(--studio-playhead, 0%);
  width: 1px;
  background: #ffd18e;
}

.studio-properties {
  flex: 1 1 230px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: start;
}

.studio-properties label, .studio-actions label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.studio-properties input, .studio-properties select, .studio-actions select { padding: 2px 4px; }
.studio-properties input[type="number"] { width: 5em; }
.studio-properties input[type="color"] { width: 32px; height: 24px; padding: 1px 2px; }
.studio-source { display: grid; gap: 5px; margin-top: 8px; color: #b8cfff; }
.studio-source textarea { width: 100%; resize: vertical; font: 12px ui-monospace, monospace; padding: 6px; }
.studio [role="status"] { margin-top: 6px; color: #b8cfff; }
.studio-legend {
  display: flex;
  justify-content: space-between;
  max-width: 200px;
  padding-top: 4px;
  border-top: 3px solid transparent;
  border-image: linear-gradient(to right, #55ec90, #ffe377, #f25858) 1;
  font-size: 12px;
}

.canvas[data-studio-mode="edit"], .canvas[data-studio-mode="trace"] {
  cursor: crosshair;
  touch-action: none;
}

.canvas-area {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a14;
  container-type: size;
}

/* Keep evaluation errors visible without removing the last valid preview. */
.error-banner {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-height: 40%;
  padding: 12px 16px;
  border: 1px solid #c86b79;
  border-radius: 6px;
  background: #301722;
  color: #ffd0d7;
  overflow: auto;
}
.error-banner p { margin-bottom: 6px; font-weight: 600; }
.error-banner pre {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Button that reveals the code column again when it is hidden. */
.reveal-code {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
}

/* A centred square that fits the (possibly non-square) animation area. Give your
   <canvas> this class, so that drawings aren't stretched. */
.canvas {
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
}

