/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
iconify-icon {
  display: block;
}

:root {
  --bg: #0d0d0d;
  --surface: #111111;
  --panel: #161616;
  --border: #2a2a2a;
  --border2: #1f1f1f;
  --text: #e0e0e0;
  --text-dim: #777;
  --text-xs: #555;
  --accent: #7c3aed;
  --accent-h: #9055ff;
  --accent-d: #5b21b6;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --radius: 6px;
  --radius-lg: 10px;
  --trans: 120ms ease;
  --left-w: 280px;
  --right-w: 240px;
  --editor-h: 280px;
  --ui-scale: 1;
}

/* ── Light theme ───────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --panel: #f0f0f0;
  --border: #d0d0d0;
  --border2: #e0e0e0;
  --text: #1a1a1a;
  --text-dim: #555;
  --text-xs: #888;
}

html {
  height: 100%;
  overflow: hidden;
  zoom: var(--ui-scale);
}

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-rows: 44px 1fr var(--editor-h);
  grid-template-columns: 1fr;
  height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────────────────────── */
#topbar {
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#logo {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  flex-shrink: 0;
  text-decoration: none;
  cursor: pointer;
}

#logo span {
  color: var(--text-dim);
  font-weight: 400;
}

#status-bar {
  flex: 1;
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  position: relative;
}

@keyframes status-shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

#status-bar.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent 0%, var(--text-dim) 50%, transparent 100%);
  opacity: 0.35;
  animation: status-shimmer 1.4s ease-in-out infinite;
  pointer-events: none;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 4px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  transition: color var(--trans), background var(--trans);
}

.nav-link:hover {
  color: var(--text);
  background: var(--border2);
}
.nav-link--active {
  color: var(--text);
  background: var(--border2);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#bmc-btn img {
  height: 28px;
  display: block;
}

#save-indicator {
  font-size: 11px;
  color: var(--green);
  opacity: 0;
  transition: opacity 200ms ease;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Main 3-column grid ────────────────────────────────────────────────────── */
#main {
  grid-row: 2;
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  grid-template-rows: 1fr;
  overflow: hidden;
}

/* ── Left panel — Prompt ────────────────────────────────────────────────────── */
#left-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

#left-scroll {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* Left panel resize handle (right edge) */
#left-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
  z-index: 5;
  background: transparent;
  transition: background var(--trans);
}

#left-resize-handle:hover,
#left-resize-handle.dragging {
  background: var(--accent);
}

.panel-header {
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

/* ── Add parameter button ───────────────────────────────────────────────────── */
.param-add-wrap {
  margin-left: auto;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-add-param {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 14px;
  line-height: 0;
  cursor: pointer;
  transition:
    background var(--trans),
    color var(--trans),
    border-color var(--trans);
  padding: 0;
}

.btn-add-param:hover {
  background: var(--border2);
  color: var(--text);
  border-color: var(--text-dim);
}
.btn-add-param.open {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.param-add-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  z-index: 50;
  width: 210px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.param-add-dropdown[hidden] {
  display: none !important;
}

.param-add-dropdown input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  width: 100%;
  transition: border-color var(--trans);
}

.param-add-dropdown input[type="text"]:focus {
  border-color: var(--accent);
}
.param-add-dropdown input[type="text"]::placeholder {
  color: var(--text-xs);
}

#param-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.param-row input[type="text"] {
  flex: 1;
  min-width: 0;
  width: auto;
}

.param-row-remove {
  flex-shrink: 0;
  width: 22px;
  height: 28px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition:
    background var(--trans),
    color var(--trans),
    border-color var(--trans);
}
.param-row-remove:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border-color: var(--red);
}

.param-add-row-btn {
  background: transparent;
  border: none;
  color: var(--text-xs);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-align: left;
  transition: color var(--trans);
}
.param-add-row-btn:hover {
  color: var(--accent);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 11px;
}

#prompt-wrap {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#prompt-input-wrap {
  position: relative;
}

#prompt-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  padding: 10px 12px 24px;
  resize: vertical;
  height: 100px;
  min-height: 60px;
  max-height: 300px;
  transition: border-color var(--trans);
  width: 100%;
}

#prompt-input:focus {
  outline: none;
  border-color: var(--accent);
}

#prompt-input::placeholder {
  color: var(--text-xs);
}

#prompt-char-count {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 10px;
  color: var(--text-xs);
  pointer-events: none;
  transition: color 0.15s;
}

#prompt-char-count.near-limit {
  color: var(--warning, #f59e0b);
}

#prompt-char-count.at-limit {
  color: var(--error, #ef4444);
}

/* ── Image preview ─────────────────────────────────────────────────────────── */
#image-preview-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

#image-preview-inner {
  position: relative;
  display: inline-flex;
  width: 100%;
}

#image-preview-thumb {
  width: 100%;
  max-height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

#image-remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  padding: 0;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#image-remove-btn:hover {
  background: rgba(239, 68, 68, 0.8);
}

.generate-row {
  display: flex;
  gap: 8px;
}

#generate-btn {
  flex: 1;
}

.btn-icon {
  padding: 6px 10px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.spin {
  animation: spin 0.8s linear infinite;
}

/* ── Sweeteners ─────────────────────────────────────────────────────────────── */
#sweeteners-section {
  display: flex;
  flex-direction: column;
}

#sweeteners-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border2);
}

#sweeteners-panel[hidden] {
  display: none;
}

.sweeteners-group-label {
  font-size: 10px;
  color: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}

.sweeteners-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.sweetener-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--sans);
  padding: 3px 9px;
  cursor: pointer;
  transition:
    background var(--trans),
    border-color var(--trans),
    color var(--trans);
  white-space: nowrap;
}

.sweetener-pill:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--border);
}

.sweetener-pill.applied {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Stream terminal ────────────────────────────────────────────────────────── */
/* ── Thinking panel ─────────────────────────────────────────────────────────── */
#thinking-panel {
  margin: 0 12px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.thinking-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  text-align: left;
  transition: color var(--trans);
}

.thinking-header:hover {
  color: var(--text);
}

.thinking-header iconify-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.thinking-spinner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  border-top-color: transparent;
  animation: thinking-spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes thinking-spin {
  to { transform: rotate(360deg); }
}

#thinking-content {
  padding: 8px 12px 10px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.6;
  color: var(--text-xs);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  border-top: 1px solid var(--border2);
}

#thinking-content[hidden] {
  display: none;
}

#stream-preview {
  display: none;
  margin: 0 12px 8px;
  border-radius: var(--radius);
  border: 1px solid #2d3748;
  overflow: hidden;
  background: #0d1117;
}

.terminal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #161b22;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.terminal-dots {
  display: flex;
  gap: 5px;
}

.tdot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tdot-r {
  background: #ff5f56;
}
.tdot-y {
  background: #ffbd2e;
}
.tdot-g {
  background: #27c93f;
}

.terminal-filename {
  font-family: var(--mono);
  font-size: 10px;
  color: #8b949e;
  flex: 1;
  letter-spacing: 0.02em;
}

.terminal-badge {
  font-family: var(--mono);
  font-size: 10px;
  color: #27c93f;
  animation: pulse-badge 1.4s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.terminal-body {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  padding: 10px 12px;
  max-height: 160px;
  overflow-y: auto;
  color: #c9d1d9;
  white-space: pre-wrap;
  word-break: break-all;
}

/* GLSL token colors */
.t-keyword {
  color: #ff7b72;
}
.t-type {
  color: #79c0ff;
}
.t-builtin {
  color: #d2a8ff;
}
.t-comment {
  color: #6e7681;
  font-style: italic;
}
.t-number {
  color: #ffa657;
}
.t-preprocessor {
  color: #7ee787;
}
.t-operator {
  color: #c9d1d9;
}

/* Blinking block cursor */
.t-cursor {
  display: inline-block;
  width: 7px;
  height: 1.1em;
  background: #58a6ff;
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: t-blink 1s step-end infinite;
}

@keyframes t-blink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

#description-section {
  display: flex;
  flex-direction: column;
}

#description-section[hidden] {
  display: none;
}

#explanation {
  padding: 10px 14px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.6;
  border-bottom: 1px solid var(--border2);
}

#history-section {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

#history-list {
  list-style: none;
  padding: 6px;
  max-height: 220px;
  overflow-y: auto;
}

/* Prompt section vertically collapsed */
#left-panel.prompt-collapsed #left-scroll {
  display: none;
}

#left-panel.prompt-collapsed #history-section {
  flex: 1;
  flex-shrink: 1;
  border-top: none;
}

#left-panel.prompt-collapsed #history-list {
  max-height: none;
  flex: 1;
}

#prompt-section-toggle iconify-icon {
  transition: transform 0.15s ease;
  display: block;
}

#left-panel.prompt-collapsed #prompt-section-toggle iconify-icon {
  transform: rotate(180deg);
}

/* ── Collapsible section headers ─────────────────────────────────────────────── */
.collapsible-header {
  cursor: pointer;
  width: 100%;
  background: none;
  border: none;
  font-family: var(--sans);
  text-align: left;
  color: var(--text-dim);
  user-select: none;
}

.collapsible-header:hover {
  color: var(--text);
}

#history-count {
  color: var(--text-xs);
  font-weight: 400;
}

.collapse-arrow {
  margin-left: auto;
  transition: transform var(--trans);
  display: inline-flex;
  align-items: center;
  line-height: 1;
  color: var(--text-xs);
}

.collapse-arrow.open {
  transform: rotate(90deg);
}

/* ── History controls (search + filter) ─────────────────────────────────── */
#history-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border2);
}

#history-search {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  padding: 4px 8px;
  outline: none;
  transition: border-color var(--trans);
}

#history-search:focus {
  border-color: var(--accent);
}

#history-sort-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  padding: 0;
  transition: border-color var(--trans), color var(--trans), background var(--trans);
}

#history-sort-btn:hover {
  border-color: var(--text-xs);
  color: var(--text);
}

#history-sort-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

#history-tag-filter-wrap {
  position: relative;
  flex-shrink: 0;
}

#history-tag-filter-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color var(--trans), color var(--trans);
}

#history-tag-filter-btn:hover {
  border-color: var(--text-xs);
  color: var(--text);
}

#history-filter-badge {
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 5px;
  line-height: 1.4;
}

#history-tag-filter-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#history-tag-filter-menu[hidden] {
  display: none;
}

.tag-filter-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background var(--trans);
}

.tag-filter-row:hover {
  background: var(--border2);
  color: var(--text);
}

.tag-filter-row input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
}

.tag-filter-empty {
  font-size: 11px;
  color: var(--text-xs);
  padding: 4px 6px;
  text-align: center;
}

.tag-filter-clear {
  margin-top: 4px;
  padding: 4px 6px;
  width: 100%;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 10px;
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
}

.tag-filter-clear:hover {
  background: var(--border2);
  color: var(--text);
}

/* ── History list items ───────────────────────────────────────────────────── */
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  transition: background var(--trans), color var(--trans);
}

.history-item:hover {
  background: var(--border);
  color: var(--text);
}

.history-item.active {
  background: var(--border2);
}

.history-item-name {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  grid-column: 1;
}

.history-item-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px;
  grid-column: 1 / -1;
}

.history-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete-btn {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  background: transparent;
  border: none;
  color: var(--text-xs);
  cursor: pointer;
  padding: 0;
  transition: background var(--trans), color var(--trans);
}

.history-item:hover .history-delete-btn {
  display: flex;
}

.history-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

.history-tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--border2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px 1px 7px;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: default;
}

.history-tag-chip-del {
  display: none;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-xs);
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  margin-left: 1px;
}

.history-item:hover .history-tag-chip-del {
  display: flex;
}

.history-tag-chip-del:hover {
  color: var(--red);
}

.history-tag-add {
  display: none;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-xs);
  font-size: 12px;
  line-height: 0;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: border-color var(--trans), color var(--trans);
}

.history-item:hover .history-tag-add {
  display: flex;
}

.history-tag-add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.history-tag-input {
  width: 70px;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 10px;
  padding: 1px 7px;
  outline: none;
}

.history-rename-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  padding: 1px 5px;
  outline: none;
}

/* ── Center panel — Canvas ────────────────────────────────────────────────── */
#center-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #000;
  position: relative;
}

#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

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

#canvas-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#undo-redo-group {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

#error-banner {
  display: none;
  align-items: flex-start;
  gap: 10px;
  background: rgba(239, 68, 68, 0.12);
  border-top: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 14px;
  max-height: 80px;
  overflow: auto;
}

#error-banner .error-msg {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
}

#error-banner .error-fix-btn {
  flex-shrink: 0;
  align-self: flex-start;
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: var(--radius);
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  cursor: pointer;
  transition: background var(--trans), border-color var(--trans);
}

#error-banner .error-fix-btn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.32);
  border-color: rgba(239, 68, 68, 0.75);
}

#error-banner .error-fix-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Right panel — Parameters ────────────────────────────────────────────── */
#right-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

/* Right panel resize handle (left edge) */
#right-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  cursor: col-resize;
  z-index: 5;
  background: transparent;
  transition: background var(--trans);
}

#right-resize-handle:hover,
#right-resize-handle.dragging {
  background: var(--accent);
}

#params-panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#system-params {
  padding: 10px 12px 0;
  flex-shrink: 0;
}

#user-params {
  padding: 0 12px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.control-row--system {
  padding-bottom: 12px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--border2);
}

.control-row--system .control-label::after {
  content: " ↓";
  font-size: 9px;
  color: var(--text-xs);
  font-weight: 400;
}

.no-params {
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.7;
  padding: 8px 0;
  text-align: center;
}

.no-params code {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: capitalize;
  cursor: text;
}

.control-label-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  outline: none;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.slider-group input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: background var(--trans);
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
  background: var(--accent-h);
}

.param-play-btn {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition:
    background var(--trans),
    color var(--trans),
    border-color var(--trans);
}
.param-play-btn:hover {
  background: var(--border);
  color: var(--text);
}
.param-play-btn.playing {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.param-play-btn.playing:hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

.param-speed-input {
  width: 44px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 4px;
  text-align: right;
}
.param-speed-input:focus {
  outline: none;
  border-color: var(--accent);
  color: var(--text);
}

.num-input {
  width: 72px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 10px 3px 6px;
  text-align: right;
}

.num-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Segmented button group */
.seg-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
}

.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--border2); color: var(--text); }
.seg-btn--active { background: var(--accent); color: white; }
.seg-btn--active:hover { background: var(--accent-h); }

/* Toggle */
.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  width: 36px;
  height: 20px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  width: 36px;
  height: 20px;
  background: var(--border);
  border-radius: 10px;
  transition: background var(--trans);
  position: relative;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform var(--trans), background var(--trans);
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
}
.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
  background: white;
}

/* Color */
.color-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-swatch {
  width: 36px;
  height: 24px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: transparent;
}

.color-hex {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

/* Vec */
.vec-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.vec-sub {
  display: flex;
  align-items: center;
  gap: 6px;
}

.vec-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text-xs);
  width: 14px;
  flex-shrink: 0;
}

.vec-sub input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.vec-sub input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.reset-btn {
  margin-top: 4px;
}

/* ── Params edit mode ───────────────────────────────────────────────────────── */
#params-edit-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}

#params-edit-bar[hidden] {
  display: none !important;
}

#params-edit-count {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}

#user-params.edit-mode .control-row[data-uniform-name] {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--trans), border-color var(--trans);
}

#user-params.edit-mode .control-row[data-uniform-name]:hover {
  background: var(--border2);
}

#user-params.edit-mode .control-row[data-uniform-name].marked {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.3);
}

#user-params.edit-mode .control-row[data-uniform-name].marked .control-label {
  color: #fca5a5;
  text-decoration: line-through;
}

.param-edit-check {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  accent-color: var(--red);
  cursor: pointer;
  margin-top: 2px;
}

#user-params.edit-mode .slider-group input,
#user-params.edit-mode .vec-sub input,
#user-params.edit-mode .toggle,
#user-params.edit-mode .color-swatch,
#user-params.edit-mode .num-input,
#user-params.edit-mode .param-play-btn,
#user-params.edit-mode .param-speed-input {
  pointer-events: none;
  opacity: 0.4;
}

.btn-add-param.edit-active {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
}

/* ── Presets bar ────────────────────────────────────────────────────────────── */
#presets-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border2);
  flex-shrink: 0;
  min-height: 34px;
}

#presets-bar[hidden] {
  display: none !important;
}

#presets-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  transition: background var(--trans), border-color var(--trans), color var(--trans);
  user-select: none;
}

.preset-chip:hover {
  background: var(--border2);
  color: var(--text);
}

.preset-chip--active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.preset-chip--active:hover {
  background: var(--accent-h);
  border-color: var(--accent-h);
}

.preset-chip__label {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-chip__del {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 1px;
  opacity: 0.55;
  flex-shrink: 0;
}

.preset-chip__del:hover {
  opacity: 1;
}

.preset-chip--renaming {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--text);
}

.preset-chip--renaming:hover {
  background: var(--bg);
}

.preset-chip--renaming .preset-chip__label {
  display: none;
}

.preset-chip--renaming input {
  width: 80px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 11px;
  font-family: var(--sans);
  min-width: 0;
}

.preset-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--trans), color var(--trans);
  padding: 0;
}

.preset-add-btn:hover {
  background: var(--border2);
  color: var(--text);
}

/* ── Bottom — GLSL Editor ──────────────────────────────────────────────────── */
#bottom-panel {
  grid-row: 3;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--border);
  position: relative;
}

/* Editor resize handle (top edge of bottom panel) */
#editor-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  cursor: row-resize;
  z-index: 5;
  background: transparent;
  transition: background var(--trans);
  flex-shrink: 0;
}

#editor-resize-handle:hover,
#editor-resize-handle.dragging {
  background: var(--accent);
}

#editor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border2);
  flex-shrink: 0;
}

#editor-header .editor-action-group {
  margin-left: auto;
}

.editor-mode-wrap {
  display: flex;
  align-items: center;
  gap: 3px;
  width: 100px;
}

.editor-mode-select {
  appearance: none;
  background: none;
  border: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  font-family: var(--sans);
  cursor: pointer;
  padding: 0;
  min-width: 0;
  flex: 1;
  outline: none;
}

.editor-mode-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-xs);
  flex-shrink: 0;
  pointer-events: none;
}
.editor-mode-arrow iconify-icon:first-child {
  margin-bottom: -3px;
}
.editor-mode-arrow iconify-icon:last-child {
  margin-top: -3px;
}

.editor-mode-select:hover {
  color: var(--text);
}

.editor-mode-select option {
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}

#glsl-editor {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#compiler-logs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 11px;
  background: var(--bg);
}

#compiler-logs[hidden] {
  display: none;
}

#log-list {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.log-entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-entry:hover {
  background: var(--surface);
}

.log-icon {
  flex-shrink: 0;
  width: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.log-time {
  flex-shrink: 0;
  color: var(--text-xs);
  font-size: 10px;
  width: 54px;
}

.log-msg {
  flex: 1;
}

.log-entry--success .log-icon {
  color: var(--green);
}
.log-entry--success .log-msg {
  color: var(--text-dim);
}

.log-entry--error .log-icon {
  color: var(--red);
}
.log-entry--error .log-msg {
  color: var(--red);
}

.log-entry--info .log-icon {
  color: var(--text-xs);
}
.log-entry--info .log-msg {
  color: var(--text-xs);
}

.log-empty {
  padding: 20px 14px;
  color: var(--text-xs);
  font-family: var(--sans);
  font-size: 11px;
}

/* Dirty state */
#compile-btn.dirty {
  border-color: var(--yellow);
  color: var(--yellow);
}

.editor-action-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition:
    background var(--trans),
    color var(--trans),
    border-color var(--trans),
    opacity var(--trans);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
}
.btn-primary:active:not(:disabled) {
  background: var(--accent-d);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: transparent;
  font-size: 11px;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--border2);
}

/* ── Export dropdown ────────────────────────────────────────────────────────── */
.dropdown {
  position: relative;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
  min-width: 170px;
  z-index: 100;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.dropdown-menu.open {
  display: block;
}

.dropdown-menu.open-up {
  top: auto;
  bottom: calc(100% + 6px);
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: background var(--trans);
}

.dropdown-item:hover {
  background: var(--border);
}

.dropdown-item .item-icon {
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.8;
}

.dropdown-item .item-label {
  flex: 1;
}
.dropdown-item .item-ext {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-xs);
}

.dropdown-sep {
  height: 1px;
  background: var(--border2);
  margin: 4px 0;
}

/* ── Export modal ────────────────────────────────────────────────────────────── */
#export-modal {
  display: flex;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#export-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 780px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  transform: scale(0.95) translateY(10px);
  opacity: 0;
  transition: transform 200ms ease, opacity 200ms ease;
}

#export-modal.open .modal-box {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.modal-body {
  flex: 1;
  overflow: auto;
  position: relative;
}

.modal-body pre {
  margin: 0;
  padding: 16px 20px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: #a8b5d6;
  background: transparent;
  white-space: pre;
  overflow: auto;
}

/* ── Scrollbars ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #3a3a3a;
}

/* ── Prism overrides ────────────────────────────────────────────────────────── */
code[class*="language-"], pre[class*="language-"] {
  background: transparent !important;
  font-family: var(--mono) !important;
  font-size: 12px !important;
}

/* ── Drag active state (body-level) ─────────────────────────────────────────── */
body.resizing-h {
  cursor: col-resize !important;
  user-select: none;
}
body.resizing-v {
  cursor: row-resize !important;
  user-select: none;
}

/* ── Rich tooltip ────────────────────────────────────────────────────────────── */
/* ── Enhance-shader popover ─────────────────────────────────────────────────── */
.enhance-shader-wrap {
  position: relative;
  display: inline-flex;
}

.enhance-shader-popover {
  position: absolute;
  bottom: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px;
  z-index: 200;
  width: 250px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.enhance-shader-popover[hidden] {
  display: none !important;
}

.enhance-shader-popover input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color var(--trans);
}

.enhance-shader-popover input[type="text"]:focus {
  border-color: var(--accent);
}

.enhance-shader-popover input[type="text"]::placeholder {
  color: var(--text-xs);
}

.tooltip-anchor {
  position: relative;
  display: inline-flex;
}

.rich-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) scale(0.94) translateY(6px);
  width: 290px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  opacity: 0;
  transition: opacity 150ms ease, transform 150ms ease;
  z-index: 300;
}

/* arrow */
.rich-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--border);
}
.rich-tooltip::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-1px);
  border: 6px solid transparent;
  border-top-color: var(--surface);
  z-index: 1;
}

.tooltip-anchor:hover .rich-tooltip {
  opacity: 1;
  transform: translateX(-50%) scale(1) translateY(0);
  pointer-events: none;
}

.rt-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
}

.rt-body {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.55;
  margin-bottom: 9px;
}

.rt-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 9px;
}

.rt-list li {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.45;
  padding-left: 12px;
  position: relative;
}

.rt-list li::before {
  content: "→";
  position: absolute;
  left: 0;
  color: var(--accent);
  font-size: 10px;
}

.rt-list code {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 0 3px;
  color: var(--text);
}

.rt-tip {
  font-size: 10px;
  color: var(--text-xs);
  border-top: 1px solid var(--border2);
  padding-top: 8px;
  line-height: 1.45;
}

/* ── Settings modal ──────────────────────────────────────────────────────────── */
#settings-modal {
  display: flex;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

#settings-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 660px;
  max-height: 80vh;
  display: flex;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
  transform: scale(0.95) translateY(10px);
  opacity: 0;
  transition: transform 200ms ease, opacity 200ms ease;
}

#settings-modal.open .settings-box {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.settings-sidebar {
  width: 160px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  gap: 4px;
}

.settings-brand {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--border2);
  margin-bottom: 6px;
}

.settings-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-tab {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
  font-family: var(--sans);
}

.settings-tab:hover {
  background: var(--border2);
  color: var(--text);
}
.settings-tab--active {
  background: var(--border);
  color: var(--text);
  font-weight: 600;
}

.settings-main {
  flex: 1;
  overflow-y: auto;
  position: relative;
  min-height: 0;
}

.settings-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
}

.settings-pane {
  padding: 24px 24px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.settings-pane--hidden {
  display: none;
}

.settings-pane-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 4px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border2);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.settings-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-xs);
  padding: 8px 14px 6px;
  background: var(--panel);
  border-bottom: 1px solid var(--border2);
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border2);
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row--indent {
  padding-left: 28px;
  background: var(--bg);
  opacity: 0.5;
  transition: opacity var(--trans);
}
.settings-row--indent.enabled {
  opacity: 1;
}

.settings-row--col {
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.settings-row-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.settings-row-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.settings-row-desc {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.45;
}

.settings-inline-input {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.settings-inline-input input[type="range"] {
  width: 100px;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.settings-inline-input input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.settings-value-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-dim);
  min-width: 46px;
  text-align: right;
}

/* Accent color swatches */
.accent-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.accent-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 80ms ease, border-color var(--trans);
  outline: none;
}

.accent-swatch:hover {
  transform: scale(1.15);
}
.accent-swatch.active {
  border-color: var(--text);
}

.accent-custom-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.accent-color-input {
  width: 36px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
  background: transparent;
}

/* API Key settings field */
.settings-api-key-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.settings-text-input {
  width: 200px;
  height: 30px;
  padding: 0 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: var(--mono);
  outline: none;
  transition: border-color var(--trans);
}
.settings-text-input::placeholder {
  color: var(--text-xs);
}
.settings-text-input:focus {
  border-color: var(--accent);
}

/* Settings provider select */
.settings-select {
  height: 30px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  font-family: var(--sans);
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color var(--trans);
}
.settings-select:focus {
  border-color: var(--accent);
}

/* Keep indent rows visible when shown (override the disabled opacity) */
.settings-row--enabled {
  opacity: 1 !important;
}

/* ── Provider switcher ──────────────────────────────────────────────────────── */
#provider-switcher {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--border2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.provider-btn {
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-xs);
  cursor: pointer;
  transition: background var(--trans), color var(--trans);
  white-space: nowrap;
}

.provider-btn:hover {
  color: var(--text-dim);
  background: var(--border);
}


.provider-btn--active {
  background: var(--accent) !important;
  color: #fff !important;
}

/* ── Help modal ──────────────────────────────────────────────────────────────── */
#help-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#help-modal.open {
  display: flex;
}

.help-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.6);
}

.help-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.help-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

.help-body {
  overflow-y: auto;
  padding: 8px 0;
}

.help-section {
  display: flex;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border2);
}

.help-section:last-child {
  border-bottom: none;
}

.help-section-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--border2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-top: 1px;
}

.help-section-content {
  flex: 1;
  min-width: 0;
}

.help-section-content h3 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.help-tag {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-xs);
  background: var(--border2);
  border-radius: 4px;
  padding: 1px 5px;
}

.help-section-content p {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.55;
  margin-bottom: 7px;
}

.help-section-content ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.help-section-content li {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
  padding-left: 10px;
  position: relative;
}

.help-section-content li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--text-xs);
}

.help-section-content code {
  font-family: var(--mono);
  font-size: 10px;
  background: var(--border2);
  border-radius: 3px;
  padding: 1px 4px;
  color: var(--accent-h);
}

/* ── Left panel collapse ────────────────────────────────────────────────────── */
#left-collapse-btn {
  padding: 4px;
  flex-shrink: 0;
}

#left-collapse-btn iconify-icon {
  transition: transform 0.15s ease;
  display: block;
}

#main.left-collapsed {
  grid-template-columns: 28px 1fr var(--right-w);
}

#main.left-collapsed #left-scroll,
#main.left-collapsed #history-section {
  display: none;
}

#main.left-collapsed #prompt-header {
  justify-content: center;
  padding: 10px 4px;
}

#main.left-collapsed #prompt-header .panel-header-text,
#main.left-collapsed #prompt-header #new-session-btn,
#main.left-collapsed #prompt-header #prompt-section-toggle {
  display: none;
}

#main.left-collapsed #left-collapse-btn iconify-icon {
  transform: rotate(180deg);
}

#main.left-collapsed #left-resize-handle {
  display: none;
}
