:root {
  --bg: #0c0f14;
  --panel: #141922;
  --panel2: #1b212d;
  --line: #232b39;
  --text: #d7dee8;
  --muted: #8a93a3;
  --accent: #2ec9c0;
  --accent2: #4fb0ff;
  --primary: #1f9d57;
  --primary-h: #25b566;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------------- Top bar ---------------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: linear-gradient(180deg, #161c27, #11151d);
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 28px; color: var(--accent); width: 40px; height: 40px;
  display: grid; place-items: center; background: #0e1620;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.brand h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: .2px; }
.brand .accent { color: var(--accent); }
.subtitle { color: var(--muted); font-size: 11px; }
.run-controls { display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 11px; color: var(--accent); background: #0e1f1e;
  border: 1px solid #1d3a38; padding: 4px 9px; border-radius: 20px; font-weight: 600;
}
.perf { color: var(--muted); font: 11px ui-monospace, Menlo, Consolas, monospace; min-width: 78px; text-align: right; }

.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 550;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #232c3a; border-color: #34405440; }
.btn.primary { background: var(--primary); border-color: #2bbf6e; color: #fff; }
.btn.primary:hover { background: var(--primary-h); }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn:active { transform: translateY(1px); }

/* ---------------- Layout ---------------- */
#layout {
  flex: 1 1 auto; display: grid;
  grid-template-columns: 300px minmax(0,1fr) 330px;
  min-height: 0;
}
.panel { background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 12px 14px 40px; }
#monitors { border-right: none; border-left: 1px solid var(--line); }
.panel h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin: 4px 0 12px; }
.panel section { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: none; }
.panel h3 { font-size: 12.5px; margin: 0 0 9px; color: var(--accent2); font-weight: 600; }

label { display: block; margin: 9px 0; color: var(--muted); font-size: 12px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { accent-color: var(--accent); }
select, input[type="text"] {
  width: 100%; margin-top: 4px; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 12.5px;
}
input[type="range"] { width: 100%; margin-top: 6px; accent-color: var(--accent); }
.val { color: var(--text); float: right; font: 11px ui-monospace, Menlo, Consolas, monospace; }
.numin {
  width: 50px; margin: 0; padding: 1px 4px; text-align: right; vertical-align: baseline;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; font: 11px ui-monospace, Menlo, Consolas, monospace;
}
.numin.wide { width: 62px; }
.numin:focus { outline: none; border-color: var(--accent); }
.hint { color: var(--muted); font-size: 11px; margin-top: 6px; line-height: 1.4; }
.filelabel {
  display: block; text-align: center; background: var(--panel2); border: 1px dashed #38465c;
  border-radius: 6px; padding: 10px; cursor: pointer; color: var(--accent2);
}
.filelabel input { display: none; }
.row { margin-top: 6px; }
.hidden { display: none !important; }

/* ---------------- Viewport ---------------- */
#viewport { display: flex; flex-direction: column; min-width: 0; background: #0a0d12; }
#viewToolbar {
  display: flex; align-items: center; gap: 14px; padding: 8px 14px;
  border-bottom: 1px solid var(--line); background: #0e131b; flex: 0 0 auto;
}
#fieldLabel { font-weight: 600; font-size: 13px; }
#colorbar { display: flex; align-items: center; gap: 6px; margin-left: auto; }
#colorbar span { font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); }
#cbar { border: 1px solid var(--line); border-radius: 3px; display: block; }
#canvasWrap {
  position: relative; flex: 1 1 auto; display: grid; place-items: center;
  padding: 14px; min-height: 0; overflow: hidden;
}
#view, #overlay {
  max-width: 100%; max-height: 100%; aspect-ratio: 2 / 1;
  border-radius: 6px; box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
#view { background: #0a0d12; }
#overlay { position: absolute; pointer-events: none; }
#gpuError {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
  background: rgba(10,13,18,.96); padding: 40px; gap: 6px;
}
#gpuError h3 { color: #ff7a6b; margin: 0; }
#statusbar {
  padding: 6px 14px; border-top: 1px solid var(--line); background: #0e131b;
  font: 11px ui-monospace, Menlo, Consolas, monospace; color: var(--muted); flex: 0 0 auto;
}

/* ---------------- Monitors ---------------- */
.coefgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.coefgrid > div {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; display: flex; justify-content: space-between; align-items: baseline;
}
.coeflabel { color: var(--muted); font-size: 12px; }
.coefval { font: 15px ui-monospace, Menlo, Consolas, monospace; color: var(--accent); font-weight: 600; }
canvas.plot { width: 100%; height: 120px; background: #0c1016; border: 1px solid var(--line); border-radius: 6px; display: block; }
canvas.plot.tall { height: 150px; }
table.info { width: 100%; border-collapse: collapse; }
table.info td { padding: 3px 0; font-size: 12px; }
table.info td:first-child { color: var(--muted); }
table.info td:last-child { text-align: right; font: 11.5px ui-monospace, Menlo, Consolas, monospace; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #283242; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  #layout { grid-template-columns: 270px minmax(0,1fr); }
  #monitors { grid-column: 1 / -1; border-left: none; border-top: 1px solid var(--line);
    display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 18px; }
}
@media (max-width: 760px) {
  #layout { grid-template-columns: 1fr; }
  #setup { border-right: none; border-bottom: 1px solid var(--line); }
  #view, #overlay { aspect-ratio: 2 / 1; width: 100%; }
}
