/* ============================================================
   ComputeToy — WebGPU Playground
   Theme: CRT terminal × GPU circuit board
   ============================================================ */
:root {
  --bg0: #060810;
  --bg1: #0b0e18;
  --bg2: #111520;
  --bg3: #161b28;
  --bg4: #1c2235;
  --border: #1e2538;
  --border2: #252e44;
  --cyan:   #00f5d4;
  --cyan2:  #00c9ae;
  --green:  #39ff8e;
  --orange: #ff7c2a;
  --red:    #ff3a5c;
  --yellow: #ffe066;
  --purple: #a78bfa;
  --blue:   #4fc3f7;
  --text:   #b8c4d8;
  --text2:  #6e7d9a;
  --text3:  #3d4a62;
  --head:   #dce8f8;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --ui:   'Rajdhani', sans-serif;
  --r: 6px;
}

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

body {
  background: var(--bg0);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  display: flex;
  flex-direction: column;
}

/* ─── Scanline overlay ─── */
body::after {
  content:'';
  position:fixed; inset:0;
  background: repeating-linear-gradient(
    0deg, transparent, transparent 3px,
    rgba(0,245,212,0.008) 3px, rgba(0,245,212,0.008) 4px
  );
  pointer-events:none; z-index:9999;
}

/* ─── TOP BAR ─── */
#topbar {
  height: 42px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 0;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.logo {
  font-family: var(--ui);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--cyan);
  letter-spacing: 0.08em;
  margin-right: 20px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon {
  width: 22px; height: 22px;
  background: conic-gradient(from 0deg, var(--cyan), var(--purple), var(--cyan));
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; color: #000; font-weight: 800;
  animation: logospin 8s linear infinite;
  flex-shrink: 0;
}
@keyframes logospin {
  to { filter: hue-rotate(360deg); }
}

/* Preset tabs */
.preset-tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.preset-tabs::-webkit-scrollbar { display: none; }

.preset-tab {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 5px 13px;
  border-radius: 4px 4px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text2);
  cursor: pointer;
  white-space: nowrap;
  transition: color .2s, background .2s;
  letter-spacing: 0.03em;
}
.preset-tab:hover { color: var(--text); background: var(--bg3); }
.preset-tab.active {
  background: var(--bg2);
  color: var(--cyan);
  border-color: var(--border);
  position: relative;
}
.preset-tab.active::after {
  content:'';
  position:absolute; bottom:-1px; left:0; right:0; height:1px;
  background: var(--bg2);
}

/* Right controls */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.stat-chip {
  font-size: 0.68rem;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
  font-family: var(--mono);
  white-space: nowrap;
}
.stat-chip span { color: var(--cyan); }

.btn {
  font-family: var(--ui);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: var(--r);
  border: none;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all .18s;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn-run {
  background: var(--cyan);
  color: #040810;
}
.btn-run:hover { background: #00ddc0; transform: translateY(-1px); }
.btn-run:active { transform: translateY(0); }
.btn-run.running {
  background: var(--orange);
  color: #fff;
  animation: pulse-run 1s ease-in-out infinite;
}
@keyframes pulse-run {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,124,42,0); }
  50% { box-shadow: 0 0 12px 3px rgba(255,124,42,0.4); }
}
.btn-stop {
  background: var(--bg3);
  color: var(--red);
  border: 1px solid rgba(255,58,92,0.3);
}
.btn-stop:hover { background: rgba(255,58,92,0.12); }

/* ─── MAIN LAYOUT ─── */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ─── EDITOR PANEL ─── */
#editor-panel {
  width: 50%;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg1);
  position: relative;
}

/* Resize handle */
#resize-handle {
  position: absolute;
  top: 0; right: -4px; bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 50;
  background: transparent;
}
#resize-handle:hover, #resize-handle.dragging {
  background: rgba(0,245,212,0.15);
}

/* Editor tabs */
#editor-tabs {
  display: flex;
  align-items: center;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  height: 34px;
  gap: 2px;
  flex-shrink: 0;
}
.editor-tab {
  font-size: 0.7rem;
  padding: 4px 12px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  transition: color .2s, background .2s;
  font-family: var(--mono);
  letter-spacing: 0.03em;
}
.editor-tab.active { background: var(--bg3); color: var(--cyan); }
.editor-tab:hover:not(.active) { color: var(--text); }

/* CodeMirror-like editor */
#editor-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#code-editor {
  width: 100%;
  height: 100%;
  background: transparent;
  color: transparent;
  caret-color: var(--cyan);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  border: none;
  outline: none;
  resize: none;
  padding: 14px 16px 14px 52px;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: auto;
  spellcheck: false;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  -webkit-text-fill-color: transparent;
}

#code-highlight {
  width: 100%;
  height: 100%;
  background: var(--bg1);
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.7;
  margin: 0;
  padding: 14px 16px 14px 52px;
  tab-size: 4;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  overflow-y: auto;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
  overflow: hidden;
}

#code-highlight code {
  display: block;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  background: transparent !important;
  padding: 0;
  white-space: pre;
  word-wrap: normal;
}

/* Line numbers */
#line-numbers {
  position: absolute;
  top: 0; left: 0;
  width: 42px;
  padding: 14px 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  text-align: right;
  color: var(--text3);
  font-size: 12.5px;
  line-height: 1.7;
  pointer-events: none;
  overflow: hidden;
  user-select: none;
  z-index: 3;
}
.ln { padding-right: 8px; display: block; }
.ln.active-line { color: var(--cyan); opacity: 0.7; }

/* ─── CONSOLE ─── */
#console-panel {
  height: 140px;
  min-height: 80px;
  max-height: 300px;
  border-top: 1px solid var(--border);
  background: var(--bg0);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#console-header {
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 26px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}
.console-title {
  font-size: 0.65rem;
  color: var(--text3);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: var(--ui);
  font-weight: 600;
}
#console-clear {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--text3);
  background: none; border: none; cursor: pointer;
  font-family: var(--ui);
  transition: color .2s;
  letter-spacing: 0.05em;
}
#console-clear:hover { color: var(--red); }

#console-output {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 11.5px;
  line-height: 1.7;
}
#console-output::-webkit-scrollbar { width: 4px; }
#console-output::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.log-line { display: flex; gap: 8px; }
.log-time { color: var(--text3); flex-shrink: 0; }
.log-info  { color: var(--text2); }
.log-ok    { color: var(--green); }
.log-warn  { color: var(--yellow); }
.log-error { color: var(--red); }
.log-perf  { color: var(--purple); }
.log-data  { color: var(--blue); }

/* ─── RIGHT PANEL ─── */
#right-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg0);
}

/* Canvas header */
#canvas-header {
  display: flex;
  align-items: center;
  padding: 0 14px;
  height: 34px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.canvas-title {
  font-family: var(--ui);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.canvas-badge {
  font-size: 0.62rem;
  padding: 2px 7px;
  border-radius: 3px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
}
.badge-webgpu { background: rgba(0,245,212,0.12); color: var(--cyan); border: 1px solid rgba(0,245,212,0.2); }
.badge-fallback { background: rgba(255,124,42,0.1); color: var(--orange); border: 1px solid rgba(255,124,42,0.2); }
.badge-error { background: rgba(255,58,92,0.1); color: var(--red); border: 1px solid rgba(255,58,92,0.2); }

.canvas-info { margin-left: auto; font-size: 0.65rem; color: var(--text3); font-family: var(--mono); }

/* Canvas wrapper */
#canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  position: relative;
  overflow: hidden;
}

#gpu-canvas {
  display: block;
  image-rendering: pixelated;
  max-width: 100%;
  max-height: 100%;
}

/* No-WebGPU overlay */
#no-webgpu {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(6,8,16,0.97);
  color: var(--text2);
  display: none;
  padding: 30px;
  text-align: center;
}
.no-webgpu-icon { font-size: 2.4rem; }
.no-webgpu-title { font-family: var(--ui); font-size: 1rem; font-weight: 700; color: var(--orange); letter-spacing: 0.05em; }
.no-webgpu-msg { font-size: 0.8rem; line-height: 1.7; max-width: 360px; }
.no-webgpu-msg code { color: var(--cyan); background: rgba(0,245,212,0.08); padding: 1px 5px; border-radius: 3px; }

/* ─── RIGHT SIDEBAR: Uniforms ─── */
#uniforms-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
#uniforms-panel::-webkit-scrollbar { width: 4px; }
#uniforms-panel::-webkit-scrollbar-thumb { background: var(--border2); }

.up-section {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px 14px;
}
.up-title {
  font-family: var(--ui);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text3);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.uniform-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
}
.uniform-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.uniform-name {
  font-size: 0.72rem;
  color: var(--purple);
}
.uniform-value {
  font-size: 0.68rem;
  color: var(--cyan);
  min-width: 36px;
  text-align: right;
}
.uniform-slider {
  -webkit-appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: var(--bg3);
  outline: none;
  cursor: pointer;
}
.uniform-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--cyan);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(0,245,212,0.5);
}
.uniform-slider::-moz-range-thumb {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--cyan);
  border: none;
  cursor: pointer;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.custom-checkbox {
  width: 14px; height: 14px;
  border: 1px solid var(--border2);
  border-radius: 3px;
  background: var(--bg3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .2s;
}
.checkbox-row input[type=checkbox] { display: none; }
.checkbox-row input[type=checkbox]:checked + .custom-checkbox {
  background: var(--cyan);
  border-color: var(--cyan);
}
.checkbox-row input[type=checkbox]:checked + .custom-checkbox::after {
  content: '✓';
  font-size: 9px;
  color: #040810;
  font-weight: 800;
}
.checkbox-label { font-size: 0.72rem; color: var(--text2); }

/* Buffer preview */
.buf-preview {
  background: var(--bg0);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px;
  font-size: 0.68rem;
  color: var(--text2);
  line-height: 1.8;
  max-height: 120px;
  overflow-y: auto;
  font-family: var(--mono);
}
.buf-preview span { color: var(--green); }

/* FPS graph */
#fps-graph-wrap {
  height: 40px;
  position: relative;
  margin-top: 4px;
}
#fps-canvas {
  width: 100%;
  height: 100%;
  border-radius: 4px;
}
.fps-overlay {
  position: absolute;
  top: 3px; right: 5px;
  font-size: 0.7rem;
  color: var(--green);
  font-family: var(--mono);
  font-weight: 600;
  text-shadow: 0 0 8px rgba(57,255,142,0.6);
}

/* ─── Canvas controls ─── */
#canvas-controls {
  display: flex;
  align-items: center;
  padding: 0 10px;
  height: 30px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}
.ctrl-btn {
  font-size: 0.68rem;
  padding: 3px 9px;
  border-radius: 4px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  cursor: pointer;
  font-family: var(--mono);
  transition: all .18s;
}
.ctrl-btn:hover { color: var(--cyan); border-color: rgba(0,245,212,0.3); }
.ctrl-btn.active { color: var(--cyan); background: rgba(0,245,212,0.07); border-color: rgba(0,245,212,0.3); }

.res-select {
  font-size: 0.68rem;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  cursor: pointer;
  outline: none;
}
.res-select option { background: var(--bg2); }

.ctrl-spacer { flex: 1; }
.ctrl-label { font-size: 0.65rem; color: var(--text3); }

/* ─── Error highlight in editor ─── */
.error-line-bg {
  background: rgba(255,58,92,0.1);
  display: block;
}

/* ─── Tooltip ─── */
.tooltip {
  position: fixed;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: 5px 10px;
  font-size: 0.72rem;
  color: var(--text);
  pointer-events: none;
  z-index: 9998;
  opacity: 0;
  transition: opacity .15s;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.tooltip.show { opacity: 1; }

/* ─── Loading spinner ─── */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(0,245,212,0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: none;
}
.spinner.show { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Resizer console ─── */
#console-resize {
  height: 5px;
  cursor: ns-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
}
#console-resize:hover { background: rgba(0,245,212,0.2); }

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

#editor-wrap { background: var(--bg1); }
