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

:root {
  --bg:          #0b0b0e;
  --surface:     #131317;
  --surface2:    #1a1a20;
  --border:      #272730;
  --border-hi:   #363645;
  --text:        #c2c2d4;
  --text-dim:    #52526a;
  --text-bright: #e4e4f2;
  --accent:      #7eb8f7;
  --error:       #f76e8a;
  --lh: 1.6;
  --mono: 'Cascadia Code', 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, 'Courier New', monospace;
  --ui: system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
  overflow: hidden;
}

/* ── header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.examples-nav { flex: 1; }

#examples-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--ui);
  cursor: pointer;
  outline: none;
  max-width: 180px;
}

#examples-select:focus { border-color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.btn-sm {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 12px;
  font-family: var(--ui);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
  white-space: nowrap;
}

.btn-sm:hover {
  border-color: var(--border-hi);
  color: var(--text-bright);
}

.btn-sm:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#fps-display {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
  min-width: 52px;
  text-align: right;
}

/* ── layout ─────────────────────────────────────────────────────────────── */

.layout {
  display: flex;
  height: calc(100vh - 44px - 34px);
}

/* ── editor panel ────────────────────────────────────────────────────────── */

.editor-panel {
  display: flex;
  flex-direction: column;
  flex: 0 0 54%;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.code-editor {
  display: flex;
  flex: 1;
  overflow: hidden;
  background: var(--surface);
}

#gutter {
  padding: 12px 8px 12px 10px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: var(--lh);
  color: var(--text-dim);
  text-align: right;
  user-select: none;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  flex-shrink: 0;
  min-width: 42px;
  border-right: 1px solid var(--border);
}

#shader-editor {
  flex: 1;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: var(--lh);
  background: transparent;
  color: var(--text-bright);
  border: none;
  outline: none;
  resize: none;
  overflow-y: scroll;
  overflow-x: auto;
  white-space: pre;
  tab-size: 2;
  caret-color: var(--accent);
  transition: border-bottom 0.15s;
}

#shader-editor.has-errors {
  border-bottom: 2px solid rgba(247, 110, 138, 0.6);
}

#shader-editor::selection {
  background: rgba(126, 184, 247, 0.18);
}

/* ── error console ───────────────────────────────────────────────────────── */

#error-console {
  background: #110a0c;
  border-top: 1px solid rgba(247, 110, 138, 0.35);
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 12px;
  max-height: 130px;
  overflow-y: auto;
  flex-shrink: 0;
}

#error-console.hidden { display: none; }

.error-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
  line-height: 1.5;
}

.err-line {
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: 12px;
  color: rgba(247, 110, 138, 0.65);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
  flex-shrink: 0;
}

.err-line:hover { color: var(--error); }

.err-msg {
  color: var(--text);
  opacity: 0.8;
  word-break: break-word;
}

/* ── preview panel ───────────────────────────────────────────────────────── */

.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #050507;
}

#gl-canvas {
  flex: 1;
  width: 100%;
  display: block;
  min-height: 0;
}

.no-webgl {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-dim);
  padding: 32px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
}

/* ── uniforms panel ──────────────────────────────────────────────────────── */

.uniforms-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  flex-shrink: 0;
  max-height: 176px;
  overflow-y: auto;
}

.uniform-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 0;
  font-size: 12px;
  font-family: var(--mono);
}

.uni-name {
  color: var(--accent);
  min-width: 96px;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.uni-type {
  color: var(--text-dim);
  min-width: 40px;
  flex-shrink: 0;
}

.uni-val {
  color: var(--text-dim);
  min-width: 56px;
  text-align: right;
  flex-shrink: 0;
}

.uni-slider {
  flex: 1;
  accent-color: var(--accent);
  cursor: pointer;
  height: 4px;
  min-width: 40px;
}

#builtin-uniforms {
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 6px;
}

#builtin-uniforms:empty,
#custom-uniforms:empty { display: none; }

#btn-pause {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 9px;
  width: 24px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.12s;
  flex-shrink: 0;
}

#btn-pause:hover { border-color: var(--border-hi); }
#btn-pause:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── footer ──────────────────────────────────────────────────────────────── */

footer {
  height: 34px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  flex-shrink: 0;
}

footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.12s;
}

footer a:hover { color: var(--text); }
footer a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }

.dot { color: var(--border-hi); }

/* ── keyboard hint ───────────────────────────────────────────────────────── */

.kbd-hint {
  margin-left: auto;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
}

kbd {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
  font-size: 10px;
  font-family: var(--ui);
}

/* ── scrollbars ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ── mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 700px) {
  html, body { overflow: auto; }

  .layout {
    flex-direction: column-reverse;
    height: auto;
  }

  .editor-panel {
    flex: none;
    height: 50vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  .preview-panel {
    flex: none;
    height: 45vw;
    min-height: 180px;
  }

  .kbd-hint { display: none; }
  #fps-display { display: none; }
}
