:root {
  --bg: #0e1012;
  --panel: #14171a;
  --line: #2a2f35;
  --fg: #ffffff;
  --dim: #8b949e;
  --pink: #f394be;
  --red: #ee4445;
  --orange: #f4802a;
  --yellow: #fdbd2e;
  --blue: #77cee0;
  --green: #bdd869;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-family: var(--mono); font-size: 13px; }
body { overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

header {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.brand { font-weight: 700; letter-spacing: 0.12em; margin-right: auto; white-space: nowrap; }
.brand span { color: var(--pink); }
.brand .tag { font-size: 10px; font-weight: 400; letter-spacing: .08em; color: var(--dim); border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px; margin-left: 6px; vertical-align: middle; }
a.btn { text-decoration: none; }
footer { padding: 4px 14px 6px; color: var(--dim); font-size: 11px; border-top: 1px solid var(--line); }
footer a { color: var(--blue); }
.brand.big { font-size: 22px; margin: 0 0 12px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--dim); }
select, .btn {
  background: var(--panel); color: var(--fg); border: 1px solid var(--line);
  font: inherit; padding: 6px 10px; border-radius: 4px; cursor: pointer;
}
select { max-width: 52vw; }
#engine-select { max-width: 300px; }
header { row-gap: 6px; }
header .btn, header select { padding: 5px 8px; }
.btn:hover, select:hover { border-color: var(--pink); }
.btn.primary { background: var(--pink); color: #111; border-color: var(--pink); font-weight: 700; padding: 10px 22px; font-size: 15px; }
.btn.primary:disabled { opacity: .5; cursor: default; }

#layout {
  flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px;
  grid-template-columns: minmax(230px, 1fr) minmax(0, 2.2fr) minmax(250px, 1.1fr);
}
section { display: flex; flex-direction: column; gap: 8px; min-height: 0; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px; position: relative; min-width: 0; }
.panel-title { color: var(--dim); font-size: 11px; letter-spacing: .14em; margin-bottom: 8px; }
.engine-name { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--fg); }
.specs { color: var(--dim); line-height: 1.6; }
.log { margin-top: 8px; color: var(--yellow); min-height: 1.4em; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 9em; overflow: auto; }
.log.error { color: var(--red); }

#left { overflow-y: auto; }
.ctrl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.ctl {
  background: #1b1f23; color: var(--fg); border: 1px solid var(--line); border-radius: 4px;
  font: inherit; padding: 9px 6px; cursor: pointer; text-align: left; user-select: none; touch-action: none;
}
.ctl b { display: inline-block; min-width: 2.2em; color: var(--dim); font-weight: 700; }
.ctl.on { border-color: var(--green); color: var(--green); }
.ctl.on b { color: var(--green); }
.ctl.warn { border-color: var(--orange); color: var(--orange); }
.ctl.wide { grid-column: span 2; }
.slider { display: block; margin: 8px 0; color: var(--dim); }
.slider span { display: flex; justify-content: space-between; margin-bottom: 4px; }
.slider em { font-style: normal; color: var(--fg); }
input[type=range] { width: 100%; accent-color: var(--pink); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.kv div:nth-child(odd) { color: var(--dim); }
.kv div:nth-child(even) { text-align: right; }

#center { min-height: 0; }
.view-panel { flex: 2.2; min-height: 0; padding: 0; overflow: hidden; }
.scope-panel { flex: 1; min-height: 140px; display: flex; flex-direction: column; padding: 6px 8px 8px; }
canvas { display: block; width: 100%; height: 100%; }
#scope { flex: 1; min-height: 0; }
#view-hint { position: absolute; left: 10px; bottom: 8px; color: var(--dim); font-size: 11px; pointer-events: none; }
.scope-tabs { display: flex; gap: 4px; margin-bottom: 4px; }
.tab { background: none; border: 1px solid transparent; color: var(--dim); font: inherit; font-size: 11px; padding: 3px 8px; cursor: pointer; border-radius: 3px; }
.tab.active { color: var(--fg); border-color: var(--line); }
.gauge-panel { flex: 1; min-height: 0; padding: 4px; }

#start-overlay {
  position: fixed; inset: 0; background: rgba(14, 16, 18, .92); display: flex;
  align-items: center; justify-content: center; z-index: 10; padding: 16px;
}
.start-card { max-width: 460px; text-align: center; line-height: 1.6; }
.start-card .small { color: var(--dim); font-size: 12px; }
.start-card a { color: var(--blue); }
#help { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 11; padding: 16px; }
#help[hidden] { display: none; }
.help-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 18px; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; }
.help-card table { border-collapse: collapse; width: 100%; margin-bottom: 14px; }
.help-card td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-card td:first-child { color: var(--pink); white-space: nowrap; }

@media (max-width: 980px) {
  body { overflow: auto; }
  #app { height: auto; min-height: 100vh; }
  #layout { display: flex; flex-direction: column; }
  section { display: contents; }
  .view-panel { order: 1; height: 62vw; min-height: 240px; max-height: 60vh; flex: none; }
  #control-panel { order: 2; }
  .gauge-panel { order: 3; height: 560px; flex: none; }
  .scope-panel { order: 4; height: 190px; flex: none; }
  #info-panel { order: 5; }
  #perf-panel { order: 6; }
  .brand { width: 100%; }
  select, #engine-select { max-width: calc(100vw - 110px); }
  #view-hint { display: none; }
  footer { padding-bottom: 16px; }
}
