:root {
  --bg: #111418;
  --fg: #e8eaed;
  --muted: #8a8f98;
  --panel: #1a1e24;
  --border: #262b33;
  --accent: #6ee7b7;
  --warn: #f5b971;
  --error: #f97373;
  --highlight: #f5b971;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
html { font-size: 16px; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

button, input, select, textarea {
  font-size: 1rem;
}

header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.room {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  min-width: 0;
}
.room code {
  background: var(--panel);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 1rem;
}
.room button {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
}
.room button:hover { border-color: var(--accent); }

.status {
  font-size: 1rem;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.status.connecting { color: var(--warn); }
.status.online     { color: var(--accent); border-color: var(--accent); }
.status.offline    { color: var(--error); border-color: var(--error); }

.muted { color: var(--muted); font-size: 1rem; }

#errors {
  margin: 0.85rem 1.1rem 0;
  background: #3a1d1d;
  border: 1px solid var(--error);
  color: #ffd8d8;
  padding: 0.75rem 0.95rem;
  border-radius: 6px;
  font-size: 1rem;
}
#errors[hidden] { display: none; }

/* --- Alias button --- */
.alias-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  max-width: 16rem;
}
.alias-btn:hover { border-color: var(--accent); }
.alias-btn .alias-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
  flex: none;
}

/* --- Main layout: hub on the left, chat on the right --- */
main.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  padding: 0.85rem 1.1rem 1.1rem;
  min-height: 0;
}
@media (min-width: 960px) {
  main.layout {
    grid-template-columns: 1fr 360px;
  }
}

/* --- Hub --- */
#hub {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  min-width: 0;
}
.hub-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0 0.3rem;
  margin-bottom: 0.6rem;
}
.hub-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 0.8rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}
.hub-status-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.hub-status-icon {
  font-size: 34px;
  line-height: 1;
  color: var(--muted);
  flex: 0 0 auto;
}
.hub-status-row.ok    .hub-status-icon { color: var(--lime, #6ee7b7); }
.hub-status-row.warn  .hub-status-icon { color: var(--warn, #f5b971); }
.hub-status-row.error .hub-status-icon { color: var(--error, #f97373); }
.hub-status-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.hub-status-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.hub-status-detail {
  font-size: 0.95rem;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
}
.alias-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  font-size: 1rem;
}
.alias-row input {
  flex: 1;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 1rem;
}
.device-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 1rem;
}
.device-row select, .device-row button {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 1rem;
}
.device-row select { min-width: 14rem; }
.device-row button[disabled] { opacity: 0.5; cursor: not-allowed; }
.device-row .muted { font-size: 1rem; }

.hub-hint {
  background: rgba(245, 185, 113, 0.12);
  border: 1px solid var(--highlight);
  color: var(--highlight);
  border-radius: 4px;
  padding: 0.55rem 0.8rem;
  font-size: 1rem;
}
.hub-hint[hidden] { display: none; }

.mapping-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.85rem;
  padding: 0.3rem;
  align-items: start;
}
.peer-stack {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
}

.cable-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

/* --- Peer column --- */
.peer-col {
  min-width: 0;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  position: relative;
  z-index: 2;
}
.peer-col.io-inputs  .map-row {
  background: rgba(110, 231, 183, 0.18);
  border: none;
}
.peer-col.io-outputs .map-row {
  background: rgba(255, 90, 110, 0.18);
  border: none;
}
.peer-col.io-inputs  .map-row .row-dir { color: var(--accent); }
.peer-col.io-outputs .map-row .row-dir { color: var(--error); }
.map-row .row-dir {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  user-select: none;
}
.peer-col.io-inputs  .map-row .row-dir { margin-right: 0.4rem; }
.peer-col.io-outputs .map-row .row-dir { margin-left: 0.4rem; }
.map-row.is-clickable { cursor: pointer; }
.map-row.is-clickable:hover { filter: brightness(1.15); }
.peer-col-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.1rem;
}
.peer-col-head .you-tag {
  font-size: 1rem;
  color: var(--accent);
  background: rgba(110,231,183,0.1);
  border: 1px solid rgba(110,231,183,0.4);
  border-radius: 3px;
  padding: 0.05rem 0.45rem;
  margin-left: auto;
  font-weight: 600;
}

.list-section h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.row-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.row-list:empty::before {
  content: "—";
  color: var(--muted);
  font-size: 1rem;
}

.map-row {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.55rem 0.65rem 0.55rem 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  cursor: default;
  user-select: none;
  font-size: 1rem;
}
.map-row .anchor {
  position: absolute;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--muted);
  top: 50%;
  transform: translateY(-50%);
}
.map-row.is-input .anchor { right: -0.4rem; background: var(--accent); }
.map-row.is-output .anchor { left: -0.4rem; background: var(--error); }
.map-row.is-input {
  background: rgba(110, 231, 183, 0.10);
  border-color: rgba(110, 231, 183, 0.45);
}
.map-row.is-output {
  background: rgba(249, 115, 115, 0.10);
  border-color: rgba(249, 115, 115, 0.45);
}
.map-row .row-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  overflow: hidden;
}
.map-row .row-slug {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.map-row .row-detail {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
}
.map-row .gear {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  border-radius: 4px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font: inherit;
  font-size: 2.4rem;
  line-height: 1;
}
.map-row .gear:hover { color: var(--fg); border-color: var(--border); }

.map-row.is-clickable {
  cursor: pointer;
  transition: border-color 100ms, background 100ms;
}
.map-row.is-clickable:hover { border-color: var(--accent); }

.map-row.is-pending {
  border-color: var(--highlight);
  box-shadow: 0 0 0 2px rgba(245, 185, 113, 0.18) inset;
}
.map-row.is-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(110, 231, 183, 0.16) inset;
}
.map-row.is-already-connected {
  border-color: rgba(110, 231, 183, 0.5);
}

.row-conns {
  margin-top: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.conn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 1rem;
  color: var(--muted);
  background: rgba(110, 231, 183, 0.06);
  border: 1px solid rgba(110, 231, 183, 0.2);
  border-radius: 4px;
  padding: 0.15rem 0.45rem;
}
.conn-chip .dot { width: 0.6rem; height: 0.6rem; }

.map-row .row-value {
  --v: 0;
  min-width: 2.6rem;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  background: linear-gradient(
    to right,
    rgba(110, 231, 183, calc(0.25 + var(--v) * 0.45)) 0%,
    rgba(110, 231, 183, calc(0.25 + var(--v) * 0.45)) calc(var(--v) * 100%),
    transparent calc(var(--v) * 100%),
    transparent 100%
  );
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  margin: 0 0.5rem;
  transition: color 100ms;
}
.map-row .row-value.is-live { color: var(--fg); }

.live-value {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.4rem 0 0.6rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
}
.live-value .live-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.live-value .live-number {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 2.6rem;
}
.live-value.is-live .live-number { color: var(--fg); }
.live-value .live-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 3px;
  overflow: hidden;
}
.live-value .live-bar-fill {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 60ms linear;
}

.test-cc {
  margin: 0.4rem 0 0.6rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.test-cc-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
}
.test-cc-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.test-cc-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.test-cc-row input[type="range"] { flex: 1; }
.test-cc-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  min-width: 2.6rem;
  text-align: right;
}
.test-cc-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.test-cc-buttons button {
  flex: 1;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  cursor: pointer;
}
.test-cc-buttons button:hover { background: rgba(255, 255, 255, 0.05); }

.debug-panel {
  position: fixed;
  left: 12px;
  top: 64px;
  bottom: 12px;
  width: min(460px, 42vw);
  background: transparent;
  border: none;
  box-shadow: none;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  text-shadow:
    0 0 2px rgba(0,0,0,0.85),
    0 0 4px rgba(0,0,0,0.65);
}
.debug-panel[hidden] { display: none; }
.debug-panel .debug-placeholder {
  color: var(--muted);
  font-size: 0.75rem;
  padding: 0.3rem 0.4rem;
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  align-self: flex-start;
}
.debug-panel .debug-list {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0;
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.debug-panel .dbg {
  display: grid;
  grid-template-columns: 4.5rem 5rem 1fr 2.6rem;
  gap: 0.4rem;
  align-items: center;
  padding: 0.05rem 0.3rem;
  background: transparent;
  border: none;
  opacity: 0;
  animation: dbg-fade 6s linear forwards;
}
@keyframes dbg-fade {
  0%   { opacity: 1; }
  70%  { opacity: 1; }
  100% { opacity: 0.18; }
}
.debug-panel .dbg-t { color: var(--muted); }
.debug-panel .dbg-k { font-weight: 700; }
.debug-panel .dbg-v {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--fg);
}
.debug-panel .dbg-m {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.debug-panel .dbg-midi-in   .dbg-k { color: #6ee7b7; }
.debug-panel .dbg-midi-out  .dbg-k { color: #f5b971; }
.debug-panel .dbg-net-in    .dbg-k { color: #7aa8ff; }
.debug-panel .dbg-net-out   .dbg-k { color: #ff2bd6; }
.debug-panel .dbg-drop      .dbg-k { color: #f97373; }
.debug-panel .dbg-drop      { background: rgba(249, 115, 115, 0.06); }
.debug-panel .dbg-midi-raw  .dbg-k { color: #c8a45e; }
.debug-panel .dbg-midi-port .dbg-k { color: #9ad0ff; }
.debug-midi-status { margin-left: auto; font-size: 0.75rem; }
.debug-midi-status.warn { color: #f97373; }
.debug-midi-status.ok   { color: #6ee7b7; }
.head-btn.active { background: rgba(110,231,183,0.18); }

.add-row {
  margin-top: 0.3rem;
}
.add-row button {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  width: 100%;
}
.add-row button:hover { color: var(--accent); border-color: var(--accent); }

/* --- Chat panel --- */
#chat-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-height: 20rem;
  overflow: hidden;
}
.panel-head {
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 {
  margin: 0;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.7rem 1rem;
  font-size: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.chat-log .msg .who { font-weight: 600; margin-right: 0.4rem; }
.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--border);
}
.chat-form input, .chat-form button {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  font-size: 1rem;
}
.chat-form input { flex: 1; min-width: 0; }
.chat-form button:hover { border-color: var(--accent); }

/* --- Dialogs (alias + mapping edit) --- */
dialog {
  border: none;
  padding: 0;
  background: transparent;
  color: var(--fg);
  font-size: 1rem;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
dialog#alias-dialog { max-width: min(460px, 96vw); width: 100%; }
dialog#mapping-edit-dialog { max-width: min(600px, 96vw); width: 100%; }

.modal-card {
  background: var(--panel);
  border: none;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: none;
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.close-btn {
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.modal-body {
  padding: 1rem 1.1rem 1.1rem;
  font-size: 1rem;
}

.alias-card .alias-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 1rem;
  color: var(--muted);
}
.alias-card .alias-field input {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 0.7rem;
  font: inherit;
  font-size: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem 0.85rem;
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
}
.form-grid label {
  display: flex;
  flex-direction: column;
  font-size: 1rem;
  color: var(--muted);
  gap: 0.3rem;
}
.form-grid input, .form-grid select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 1rem;
}
.form-error {
  color: var(--error);
  font-size: 1rem;
  margin-top: 0.6rem;
}
.form-error[hidden] { display: none; }
.form-hint {
  color: var(--muted);
  font-size: 1rem;
  margin: 0 0 0.85rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.95rem;
  align-items: center;
}
.form-actions .spacer { flex: 1; }
.form-actions button {
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.form-actions button[data-save] {
  background: var(--accent);
  color: #0c1a14;
  border: none;
  font-weight: 600;
}
.form-actions button.danger {
  border-color: var(--error);
  color: var(--error);
}
.form-actions button.danger:hover { background: rgba(249, 115, 115, 0.1); }
.alias-actions { justify-content: flex-end; }

/* --- Patch text in edit dialog --- */
.patch-block { margin-top: 0.95rem; }
.patch-block[hidden] { display: none; }
.patch-label {
  display: block;
  font-size: 1rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.patch-instructions {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0.65rem;
  border-left: 3px solid var(--warn);
  background: rgba(245, 185, 113, 0.06);
  color: var(--fg);
  font-size: 0.85rem;
  line-height: 1.4;
}
.patch-textarea {
  width: 100%;
  background: #0c0f12;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.7rem 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  line-height: 1.4;
  resize: vertical;
  overflow: hidden;
}
.patch-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ============================================================================
 * Orbit shell — primary canvas overlay
 * ============================================================================ */
body.orbit-body {
  display: block;             /* override the legacy flex column */
  height: 100%;
  margin: 0;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
body.orbit-body #errors {
  position: fixed; left: 50%; bottom: 60px; transform: translateX(-50%);
  z-index: 30; max-width: 80vw;
}
.stage {
  position: fixed; inset: 0;
  z-index: 0;
}
.stage svg.board {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  cursor: grab;
}
.stage svg.board:active { cursor: grabbing; }
.stage svg.board, .stage svg.board * {
  user-select: none; -webkit-user-select: none;
}

/* --- Floating header overlay --- */
.orbit-head {
  position: fixed; left: 0; right: 0; top: 0;
  z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px;
  background: linear-gradient(180deg, rgba(10,4,16,0.75), rgba(10,4,16,0.0));
  border-bottom: none;
}
.orbit-head .wordmark {
  font-family: var(--font-display);
  font-size: 20px; letter-spacing: 0.04em;
  text-shadow: 0 0 12px rgba(255,43,214,.55), 0 0 24px rgba(34,227,255,.18);
  color: var(--fg-1);
}
.orbit-head .wordmark .hy { color: var(--magenta); text-shadow: 0 0 14px var(--magenta-glow); }

.orbit-head .alias-btn,
.orbit-head .head-btn,
.orbit-head .room button,
.orbit-head .status {
  background: rgba(20,9,30,.65);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ink-3);
  color: var(--fg-1);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.orbit-head .alias-btn:hover,
.orbit-head .head-btn:hover,
.orbit-head .room button:hover { border-color: var(--magenta); }
.orbit-head .room { gap: 8px; flex: 0 1 auto; min-width: 0; font-family: var(--font-mono); font-size: 12px; color: var(--fg-3); }
.orbit-head .room .label { color: var(--fg-3); }
.orbit-head .room code {
  background: var(--ink-2); color: var(--fg-1);
  padding: 4px 12px; border-radius: 999px;
  font-family: var(--font-mono); font-size: 12px;
}
.orbit-head .status { font-size: 11px; }
.orbit-head .status.connecting { color: var(--warn); }
.orbit-head .status.online     { color: var(--lime); border-color: var(--lime); }
.orbit-head .status.offline    { color: var(--error); border-color: var(--error); }

.orbit-head .room button.icon-btn,
.orbit-head .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  padding: 0;
  border-radius: 999px;
  background: rgba(20,9,30,.65);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ink-3);
  color: var(--fg-1);
  cursor: pointer;
}
.orbit-head .icon-btn svg { display: block; }
.material-symbols-rounded {
  font-family: "Material Symbols Rounded";
  font-weight: 400;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  font-feature-settings: "liga";
  -webkit-font-smoothing: antialiased;
}
.orbit-head .icon-btn .material-symbols-rounded { font-size: 18px; }
.orbit-head .room button.icon-btn:hover,
.orbit-head .icon-btn:hover { border-color: var(--magenta); color: var(--magenta); }

.corner-controls {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
}
.corner-controls .corner-btn {
  background: rgba(20,9,30,.65);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ink-3);
  color: var(--fg-1);
  border-radius: 999px;
  padding: 6px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.corner-controls .corner-btn:hover { border-color: var(--magenta); }
.corner-controls .corner-btn.active { background: rgba(110,231,183,0.18); border-color: var(--lime); }
.corner-controls .corner-btn.warn {
  color: var(--warn);
  border-color: var(--warn);
  background: rgba(245, 185, 113, 0.08);
}
.corner-controls .corner-btn.warn:hover { background: rgba(245, 185, 113, 0.16); }
.corner-pi {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: 999px;
  background: transparent;
  border: none;
  font-family: var(--font-display, serif);
  font-size: 28px;
  line-height: 1;
  color: var(--fg-1);
  text-shadow: 0 0 12px rgba(255,43,214,.55), 0 0 24px rgba(34,227,255,.18);
  user-select: none;
  cursor: pointer;
  padding: 0;
}
.corner-pi:hover, .corner-pi[aria-expanded="true"] { color: var(--magenta); }
.corner-pi:focus-visible { outline: 1px dashed var(--magenta); outline-offset: 2px; }

/* Center "me" button — replaces the SVG ME label, always clickable */
.me-center {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 8;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 110px;
  height: 110px;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
  border: 1px dotted color-mix(in srgb, var(--me-color, var(--magenta)) 30%, transparent);
  border-radius: 50%;
  color: var(--me-color, var(--magenta));
  opacity: 0.9;
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-shadow: 0 0 12px rgba(255, 43, 214, 0.4);
  transition: border-color 120ms ease, transform 120ms ease, opacity 120ms ease;
}
.me-center:hover {
  transform: translate(-50%, -50%) scale(1.06);
  opacity: 1;
}
.me-center:focus-visible { outline: 1px solid var(--magenta); outline-offset: 3px; }
.me-center-name {
  white-space: nowrap;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-center-badges {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.me-badge {
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  text-shadow: none;
  transition: color 120ms ease;
}
.me-badge.ok    { color: var(--lime, #6ee7b7); }
.me-badge.warn  { color: var(--warn, #f5b971); }
.me-badge.error { color: var(--error, #f97373); text-shadow: 0 0 6px rgba(249, 115, 115, 0.55); }
.me-center.has-error { border-color: var(--error); }
.me-center.has-error .me-center-name { color: var(--error); }

/* Top-right cluster: status badges + share button */
.orbit-head .head-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.orbit-head .me-center-badges {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}
.orbit-head .me-badge {
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: color 120ms ease, transform 120ms ease;
}
.orbit-head .me-badge:hover { color: var(--magenta); transform: scale(1.08); }
.orbit-head .me-badge.ok    { color: var(--lime, #6ee7b7); }
.orbit-head .me-badge.warn  { color: var(--warn, #f5b971); }
.orbit-head .me-badge.error { color: var(--error, #f97373); }
.orbit-head .room { gap: 14px; }
.orbit-head .room button.icon-btn,
.orbit-head .head-right .icon-btn {
  width: auto; height: auto;
  background: transparent;
  backdrop-filter: none;
  border: 0;
  padding: 0;
  color: var(--fg-1);
}
.orbit-head .head-right .icon-btn .material-symbols-rounded { font-size: 22px; }
.orbit-head .head-right .icon-btn:hover { color: var(--magenta); transform: scale(1.08); }

.pi-menu {
  position: relative;
  display: flex;
  align-items: center;
}
.pi-menu-items {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.pi-menu-items[hidden] { display: none; }
.pi-menu-items .corner-btn { text-align: center; }

.orbit-hint {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-sans); font-size: 13px; color: var(--fg-2);
  background: rgba(20,9,30,.65); backdrop-filter: blur(8px);
  border: 1px solid var(--ink-3);
  border-radius: 999px; padding: 8px 18px;
  text-align: center; pointer-events: none;
}
.orbit-hint b { color: var(--magenta); font-weight: 600; }

/* --- Chat panel (floating) --- */
.chat-panel {
  position: fixed; right: 22px; top: 70px; bottom: 70px;
  width: 340px;
  z-index: 15;
  background: transparent;
  backdrop-filter: none;
  border: none;
  border-radius: 0;
  display: flex; flex-direction: column;
  box-shadow: none;
  pointer-events: none; /* let canvas receive events through the log area */
  text-shadow: 0 0 2px rgba(0,0,0,0.85), 0 0 4px rgba(0,0,0,0.65);
}
.chat-panel[hidden], #chat-panel[hidden] { display: none !important; }
.chat-panel .panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 4px;
  border-bottom: none;
  pointer-events: auto;
}
.chat-panel .panel-head h2 {
  font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--fg-2);
}
.chat-panel .chat-disclaimer {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--warn);
  padding: 0 4px 6px;
  letter-spacing: 0.03em;
  pointer-events: none;
}
.chat-panel .chat-log {
  flex: 1; overflow-y: auto; padding: 6px 4px;
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px;
  color: var(--fg-1);
  pointer-events: none;
  scrollbar-width: none;
}
.chat-panel .chat-log::-webkit-scrollbar { display: none; }
.chat-panel .chat-log .msg { line-height: 1.4; }
.chat-panel .chat-log .who { font-weight: 600; }
.chat-panel .chat-form {
  display: flex; gap: 6px; padding: 10px 12px;
  margin-top: 6px;
  border: 1px solid var(--ink-3);
  border-radius: 18px;
  background: rgba(20,9,30,0.88);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-card);
  pointer-events: auto;
}
.chat-panel .chat-form input {
  flex: 1; background: var(--ink-2); border: 1px solid var(--ink-3);
  color: var(--fg-1); border-radius: 999px; padding: 6px 12px;
}
.chat-panel .chat-form button {
  background: var(--magenta); color: var(--ink-0); border: none;
  border-radius: 999px; padding: 6px 14px; font-weight: 600;
}
.chat-panel .close-btn {
  background: none; border: none; color: var(--fg-3); font-size: 20px; cursor: pointer;
  pointer-events: auto;
}

/* --- Hub dialog (mapping CRUD) --- */
.drawer-dialog {
  border: none;
  background: rgba(10,4,16,0.96);
  color: var(--fg-1);
  border-radius: 18px;
  max-width: min(96vw, 1100px);
  width: min(96vw, 1100px);
  padding: 0;
}
.drawer-dialog::backdrop { background: rgba(0,0,0,0.55); backdrop-filter: blur(4px); }
.drawer-dialog .hub-card { padding: 18px 22px; display: flex; flex-direction: column; }
.drawer-dialog .hub-card .modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-dialog #hub { display: flex; flex-direction: column; min-height: 0; }
