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

:root {
  --bg-primary:   #0a0e17;
  --bg-secondary: #111827;
  --bg-tertiary:  #1a2236;
  --bg-card:      #151d2e;
  --accent-model: #f472b6;
  --accent-view:  #60a5fa;
  --accent-proj:  #34d399;
  --accent-mvp:   #fbbf24;
  --text-primary:   #e2e8f0;
  --text-secondary: #94a3b8;
  --text-dim:       #475569;
  --border: #1e293b;
}

body {
  font-family: sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  display: grid;
  grid-template-columns: clamp(300px, 32%, 420px) 1fr;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  gap: 0;
}

/* ── Header ── */
.header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header h1 {
  font-family: monospace;
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent-model), var(--accent-view), var(--accent-proj));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-info {
  font-size: 11px;
  color: var(--text-dim);
  font-family: monospace;
}

.header-link {
  margin-left: auto;
  font-size: 12px;
  font-family: monospace;
  color: var(--text-dim);
  text-decoration: none;
  letter-spacing: 1px;
  transition: color 0.2s;
}

.header-link:hover {
  color: var(--accent-view);
}

/* ── Viewport ── */
.viewport-area {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

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

.viewport-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  gap: 6px;
}

/* ── Buttons ── */
.prim-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: monospace;
  font-size: 11px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.prim-btn:hover  { border-color: var(--accent-view); color: var(--text-primary); }
.prim-btn.active { border-color: var(--accent-view); color: var(--accent-view); background: rgba(96,165,250,0.1); }

.reset-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: monospace;
  font-size: 10px;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

.reset-btn:hover { border-color: var(--accent-model); color: var(--accent-model); }

/* ── Minimap ── */
.topview-container {
  position: absolute;
  bottom: 12px;
  left: 12px;
  width: 260px;
  height: 260px;
  background: rgba(10, 14, 23, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  backdrop-filter: blur(8px);
}

.topview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  background: rgba(17, 24, 39, 0.8);
  border-bottom: 1px solid var(--border);
  font-family: monospace;
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.topview-header .legend { display: flex; gap: 8px; font-size: 8px; }

.legend-item { display: flex; align-items: center; gap: 3px; }

.legend-dot { width: 6px; height: 6px; border-radius: 50%; }

#topview-canvas { display: block; width: 260px; height: 234px; }

/* ── Right panel ── */
.right-panel {
  grid-column: 1;
  grid-row: 2 / 4;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.right-panel::-webkit-scrollbar { width: 4px; }
.right-panel::-webkit-scrollbar-track { background: transparent; }
.right-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.panel-section { padding: 12px; border-bottom: 1px solid var(--border); }

.section-title {
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ── Controls ── */
.control-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

.control-label {
  font-family: monospace;
  font-size: 10px;
  color: var(--text-dim);
  width: 58px;
  flex-shrink: 0;
}

.slider-wrap { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; }

input[type="range"] {
  flex: 1; -webkit-appearance: none; height: 3px;
  background: var(--bg-tertiary); border-radius: 2px; outline: none; min-width: 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px; border-radius: 50%; cursor: pointer;
}

.model-slider::-webkit-slider-thumb { background: var(--accent-model); }
.view-slider::-webkit-slider-thumb  { background: var(--accent-view); }
.proj-slider::-webkit-slider-thumb  { background: var(--accent-proj); }

.slider-val {
  font-family: monospace;
  font-size: 10px;
  color: var(--text-secondary);
  width: 38px;
  text-align: right;
  flex-shrink: 0;
}

.rot-order-select {
  flex: 1;
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: monospace;
  font-size: 10px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}

.rot-order-select:hover,
.rot-order-select:focus { border-color: var(--accent-model); }

.rot-order-select option { background: var(--bg-secondary); color: var(--text-primary); }

/* ── Matrix grid ── */
.matrix-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px;
  margin-bottom: 8px; background: var(--bg-primary); border-radius: 4px;
  padding: 4px; border: 1px solid var(--border); overflow: hidden;
}

.matrix-cell {
  font-family: monospace; font-size: 9px;
  text-align: center; padding: 4px 1px; border-radius: 2px;
  background: var(--bg-tertiary); color: var(--text-secondary); transition: all 0.3s;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.matrix-cell.highlight { color: var(--text-primary); }

.matrix-label {
  font-family: monospace; font-size: 10px; font-weight: 700;
  margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}

.matrix-label .badge {
  font-size: 8px; padding: 1px 6px; border-radius: 3px; font-weight: 500;
}

/* ── Pipeline bar ── */
.pipeline-bar {
  grid-column: 2; grid-row: 3;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  overflow-x: auto;
}

.pipe-stage { display: flex; align-items: center; flex: 1; min-width: 0; }

.pipe-node {
  padding: 5px 8px; border-radius: 4px;
  font-family: monospace; font-size: 9px;
  white-space: nowrap; border: 1px solid var(--border);
  background: var(--bg-card); color: var(--text-dim);
  cursor: default; transition: all 0.3s; text-align: center; flex-shrink: 0;
}

.pipe-node.active-local  { border-color: var(--text-secondary); color: var(--text-primary); background: rgba(226,232,240,0.05); }
.pipe-node.active-model  { border-color: var(--accent-model); color: var(--accent-model); background: rgba(244,114,182,0.08); box-shadow: 0 0 12px rgba(244,114,182,0.15); }
.pipe-node.active-view   { border-color: var(--accent-view);  color: var(--accent-view);  background: rgba(96,165,250,0.08);  box-shadow: 0 0 12px rgba(96,165,250,0.15); }
.pipe-node.active-proj   { border-color: var(--accent-proj);  color: var(--accent-proj);  background: rgba(52,211,153,0.08);  box-shadow: 0 0 12px rgba(52,211,153,0.15); }
.pipe-node.active-ndc    { border-color: var(--accent-mvp);   color: var(--accent-mvp);   background: rgba(251,191,36,0.08);  box-shadow: 0 0 12px rgba(251,191,36,0.15); }
.pipe-node.active-screen { border-color: #a78bfa; color: #a78bfa; background: rgba(167,139,250,0.08); box-shadow: 0 0 12px rgba(167,139,250,0.15); }

.pipe-arrow { color: var(--text-dim); font-size: 14px; margin: 0 4px; flex-shrink: 0; }

.pipe-transform-label {
  font-family: monospace; font-size: 8px;
  color: var(--text-dim); text-align: center; margin: 0 2px; min-width: 20px;
}

/* ── Vertex trace ── */
.vertex-info {
  margin-top: 8px; padding: 8px; background: var(--bg-primary);
  border-radius: 4px; border: 1px solid var(--border);
}

.vertex-stages { display: flex; flex-direction: column; gap: 3px; }

.vertex-stage-row {
  display: flex; align-items: center; gap: 6px;
  font-family: monospace; font-size: 9px;
}

.vertex-stage-name { width: 50px; flex-shrink: 0; font-weight: 500; }

.info-note {
  font-size: 10px; color: var(--text-dim); line-height: 1.6;
  padding: 8px; background: var(--bg-primary); border-radius: 4px;
  border: 1px solid var(--border); margin-top: 8px;
}
