:root {
  --bg: #0a0d11; --panel: #10151b; --line: #1d252e; --text: #c3ccd3; --dim: #75828c;
  --bright: #e8eef2; --ok: #4fae6d; --warn: #d6a54a; --bad: #e05555; --accent: #8cc4d8;
  --k0: #4d93a6; --k1: #bfaa6e; --k2: #b04a68;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 13px; }
button, select, input { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  padding: 5px 11px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--dim); color: var(--bright); }
button:disabled { opacity: .45; cursor: default; }
button.primary { border-color: var(--accent); color: var(--bright); }
button.quiet { background: none; border-color: transparent; color: var(--dim); }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 4px 6px; }
input[type=number] { width: 70px; }
a { color: var(--accent); }
h2 { font-size: 15px; font-weight: 600; color: var(--bright); margin: 0 0 10px; letter-spacing: .04em; }
h3 { font-size: 11px; font-weight: 600; color: var(--dim); margin: 18px 0 8px; letter-spacing: .14em; text-transform: uppercase; }
.dim { color: var(--dim); }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ header */
header {
  height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  border-bottom: 1px solid var(--line); overflow: hidden; white-space: nowrap;
}
.brand { font-weight: 700; letter-spacing: .2em; color: var(--bright); }
nav { display: flex; gap: 2px; margin-left: 10px; }
nav button { border-color: transparent; background: none; color: var(--dim); }
nav button.on { color: var(--bright); border-bottom: 2px solid var(--accent); border-radius: 0; }
.status { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--dim); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); margin-right: 5px; vertical-align: 0; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }

main { height: calc(100% - 48px); }
section { height: 100%; }

/* --------------------------------------------------------------- live */
#view-live { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr) auto; }
.stage { position: relative; min-height: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay { position: absolute; pointer-events: none; line-height: 1.75; text-shadow: 0 1px 3px #000; }
.overlay.tl { top: 16px; left: 18px; }
.overlay.bl { bottom: 14px; left: 18px; pointer-events: auto; display: flex; gap: 6px; align-items: center; }
#clock { font-size: 17px; color: var(--bright); letter-spacing: .03em; }
.bar { width: 170px; height: 4px; background: var(--line); border-radius: 2px; margin-top: 3px; }
.bar > div { height: 100%; background: var(--text); border-radius: 2px; transition: width .6s; }
.banner {
  position: absolute; top: 14px; right: 16px; pointer-events: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; padding: 7px 10px; color: var(--dim);
}
.legend { position: absolute; bottom: 14px; right: 16px; color: var(--dim); font-size: 11px; text-align: right; line-height: 1.9; }
.sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-left: 6px; vertical-align: -1px; }

aside { border-left: 1px solid var(--line); padding: 0 16px 16px; overflow-y: auto; }
.room-row { display: grid; grid-template-columns: 104px minmax(0, 1fr) 76px; align-items: center; gap: 6px; height: 30px; }
.room-row .val { color: var(--bright); text-align: right; }
.room-row canvas { width: 100%; min-width: 0; height: 22px; display: block; }
.sim { font-size: 10px; color: var(--warn); margin-left: 4px; }
.algos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.algo { border: 1px solid var(--line); border-radius: 4px; padding: 4px 4px 6px; cursor: pointer; text-align: center; background: none; }
.algo canvas { width: 100%; aspect-ratio: 1; display: block; }
.algo span { display: block; font-size: 11px; color: var(--dim); margin-top: 2px; }
.algo.on { border-color: var(--accent); }
.algo.on span { color: var(--bright); }
.drives { font-size: 11px; color: var(--dim); margin-top: 6px; }

footer.history {
  grid-column: 1 / 3; border-top: 1px solid var(--line); padding: 9px 18px;
  display: flex; align-items: center; gap: 12px;
}
footer.history input[type=range] { flex: 1; accent-color: var(--accent); }
#histLabel { min-width: 230px; color: var(--bright); }
footer.history input[type=range] { min-width: 80px; }

/* ------------------------------------------------- setup, boards pages */
.page { max-width: 880px; margin: 0 auto; padding: 26px 22px 60px; overflow-y: auto; height: 100%; }
.steps { counter-reset: s; padding: 0; list-style: none; }
.steps li { counter-increment: s; position: relative; padding: 2px 0 12px 34px; line-height: 1.6; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 1px; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--accent); color: var(--accent); text-align: center; line-height: 21px; font-size: 11px;
}
.steps b { color: var(--bright); font-weight: 600; }
.diagram { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); margin: 6px 0 20px; }
.card { border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 14px 16px; margin: 12px 0; }
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.roles button { padding: 10px; text-align: left; line-height: 1.5; }
.roles button.current { border-color: var(--accent); }
.roles small { display: block; color: var(--dim); }
.progress { height: 4px; background: var(--line); border-radius: 2px; margin: 10px 0; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: 2px; }
pre.log { max-height: 160px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 8px; color: var(--dim); font-size: 11px; white-space: pre-wrap; }
table.servos { border-collapse: collapse; margin: 6px 0 10px; }
table.servos td, table.servos th { padding: 3px 8px 3px 0; text-align: left; font-weight: normal; color: var(--dim); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }

/* ------------------------------------------------------------- dialogs */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 20px 22px; min-width: 360px; max-width: 520px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog .choices { display: grid; gap: 8px; margin: 10px 0 14px; }
dialog .choices button { text-align: left; padding: 10px 12px; line-height: 1.5; }
dialog .choices small { display: block; color: var(--dim); }
dialog label { display: grid; grid-template-columns: 150px 1fr; align-items: center; margin: 8px 0; }
.toast {
  position: fixed; bottom: 60px; left: 50%; transform: translateX(-50%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 4px; padding: 8px 14px; color: var(--bright);
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
.toast.on { opacity: 1; }

@media (max-width: 860px) {
  header { gap: 8px; padding: 0 10px; }
  .brand { letter-spacing: .08em; }
  nav { margin-left: 0; }
  #nodes, #settingsBtn { display: none; }
  .overlay.tl { font-size: 12px; }
  #view-live { grid-template-columns: minmax(0, 1fr); grid-template-rows: 60vh auto auto; height: auto; }
  footer.history { flex-wrap: wrap; }
  #histLabel { min-width: 0; }
  .legend { display: none; }
  aside { border-left: none; border-top: 1px solid var(--line); }
  footer.history { grid-column: 1; }
  .roles { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  #status { display: none; }
  .brand { font-size: 11px; }
}

.algo.off { opacity: .5; }
#teachSliders label { display: grid; grid-template-columns: 70px 1fr 36px; align-items: center; gap: 6px; height: 24px; }
#teachSliders input { accent-color: var(--accent); min-width: 0; }
#teachList .ex { display: flex; justify-content: space-between; align-items: center; }
#teachList button { padding: 0 6px; }
