/* contrapunctus — design system
   palette is disciplined: one dark base, three replica accents, three states */

:root {
  --bg: #05080f;
  --panel: rgba(15, 22, 36, 0.82);
  --panel-edge: #1a2537;
  --panel-edge-hover: #263550;
  --ink: #e8f0fb;
  --dim: #8fa1bd;
  --faint: #55637d;
  --cyan: #38e1ff;
  --magenta: #ff6bd6;
  --amber: #ffc94d;
  --ok: #3ddc97;
  --warn: #ffc94d;
  --danger: #ff5d73;
  --radius: 14px;
  --font: ui-monospace, "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14.5px/1.55 var(--font);
  padding: 20px clamp(12px, 3vw, 40px) 34px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* fixed ambient backdrop: two glow pools + faint grid + vignette */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(1100px 480px at 78% -12%, rgba(56, 225, 255, 0.08), transparent 60%),
    radial-gradient(900px 460px at 4% 108%, rgba(255, 107, 214, 0.07), transparent 60%),
    radial-gradient(700px 380px at 52% 118%, rgba(255, 201, 77, 0.04), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 39px, rgba(140, 170, 220, 0.028) 39px 40px),
    repeating-linear-gradient(90deg, transparent 0 39px, rgba(140, 170, 220, 0.028) 39px 40px);
}
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(140% 110% at 50% 40%, transparent 60%, rgba(0, 0, 0, 0.42));
}

a {
  color: var(--cyan);
  text-decoration: none;
  border-bottom: 1px solid rgba(56, 225, 255, 0.35);
  transition: border-color 0.15s;
}
a:hover {
  border-bottom-color: var(--cyan);
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin: 2px 2px 18px;
}

.masthead h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 700;
  letter-spacing: 2.5px;
  background: linear-gradient(92deg, #f2f8ff 0%, var(--cyan) 45%, var(--magenta) 80%, var(--amber) 110%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline {
  margin: 3px 0 0;
  color: var(--dim);
  font-size: 13px;
}

.masthead-badges {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-edge);
  font-size: 11.5px;
  letter-spacing: 0.4px;
  white-space: nowrap;
  color: var(--dim);
  transition: color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.badge.version {
  color: var(--faint);
}
.badge.online {
  color: var(--ok);
  border-color: rgba(61, 220, 151, 0.45);
  box-shadow: 0 0 14px rgba(61, 220, 151, 0.18), inset 0 0 8px rgba(61, 220, 151, 0.06);
}
.badge.offline {
  color: var(--danger);
  border-color: rgba(255, 93, 115, 0.45);
}

/* ---------- layout ---------- */

main {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 14px;
  max-width: 1460px;
  margin: 0 auto;
}

.span-all {
  grid-column: 1 / -1;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 15px 18px 17px;
  min-width: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03), 0 8px 28px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(6px);
  transition: border-color 0.2s;
}
.panel:hover {
  border-color: #233450;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel h2 .hint {
  text-transform: none;
  letter-spacing: 0.2px;
  font-weight: 400;
  color: var(--faint);
  font-size: 11px;
}

.mark {
  width: 6px;
  height: 6px;
  border-radius: 2px;
  display: inline-block;
}
.mark.cyan {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
.mark.magenta {
  background: var(--magenta);
  box-shadow: 0 0 8px var(--magenta);
}
.mark.amber {
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
}

/* ---------- replicas ---------- */

.replica-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.replica {
  min-width: 0;
}

.replica-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  margin-bottom: 6px;
}

.rdot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  align-self: center;
  flex: none;
}

.replica h3 {
  margin: 0;
  font-size: 13.5px;
  color: var(--accent);
  letter-spacing: 0.6px;
}

.vv {
  margin-left: auto;
  color: var(--faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.pane {
  min-height: 118px;
  max-height: 190px;
  overflow-y: auto;
  background: rgba(6, 10, 19, 0.85);
  border: 1px solid #1b2840;
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  padding: 9px 12px;
  outline: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
  transition: box-shadow 0.18s, border-color 0.18s, background-color 0.5s;
}
.pane:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, #1b2840);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent),
    0 0 22px color-mix(in srgb, var(--accent) 16%, transparent);
}
.pane::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}
.pane.empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
  pointer-events: none;
}
/* flash when remote ops land on an unfocused pane */
.pane.recv {
  background-color: color-mix(in srgb, var(--accent) 7%, rgba(6, 10, 19, 0.85));
  border-color: color-mix(in srgb, var(--accent) 45%, #1b2840);
}

/* ---------- canvas ---------- */

#flow-panel canvas {
  width: 100%;
  height: 280px;
  display: block;
}

/* ---------- tree ---------- */

.tree {
  max-height: 246px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.8;
  padding-right: 4px;
}
.tnode {
  cursor: pointer;
  white-space: pre;
  border-radius: 4px;
  padding: 0 6px 0 2px;
  transition: background-color 0.12s, color 0.12s;
}
.tnode:hover {
  background: rgba(56, 225, 255, 0.07);
  color: #fff;
}
.tnode .glyph {
  color: #33445f;
}
.tnode.tomb {
  opacity: 0.38;
}
.tnode.tomb .ch {
  text-decoration: line-through;
}
.tnode .ch {
  color: #dbe9ff;
}
.tnode .tid {
  color: #3d4c66;
  font-size: 10px;
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}

select {
  background: #0a0f1a;
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  padding: 2px 8px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
select:hover,
select:focus {
  border-color: var(--cyan);
}

/* ---------- meter ---------- */

.meter {
  font-size: 21px;
  letter-spacing: 4px;
  padding: 12px 16px;
  border-radius: 11px;
  border: 1px solid;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.meter .pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.meter.ok {
  color: var(--ok);
  border-color: rgba(61, 220, 151, 0.4);
  box-shadow: 0 0 22px rgba(61, 220, 151, 0.12), inset 0 0 14px rgba(61, 220, 151, 0.05);
}
.meter.syncing {
  color: var(--warn);
  border-color: rgba(255, 201, 77, 0.35);
}
.meter.syncing .pulse-dot {
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.72); }
}

.chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  justify-content: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--faint);
  border: 1px solid var(--panel-edge);
  border-radius: 999px;
  padding: 2px 10px;
  transition: color 0.3s, border-color 0.3s, box-shadow 0.3s;
}
.chip .rdot-small {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent, #666);
  opacity: 0.35;
  transition: opacity 0.3s, box-shadow 0.3s;
}
.chip.done {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--panel-edge));
}
.chip.done .rdot-small {
  opacity: 1;
  box-shadow: 0 0 8px var(--accent);
}

/* ---------- controls ---------- */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px 20px;
}
.controls label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 12.5px;
  color: var(--dim);
}
.controls input[type="range"] {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--cyan) var(--fill, 20%), #1c2942 var(--fill, 20%));
  outline: none;
  cursor: pointer;
}
.controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #dff5ff;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 8px rgba(56, 225, 255, 0.5);
  transition: transform 0.12s;
}
.controls input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.18);
}
.controls input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #dff5ff;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 8px rgba(56, 225, 255, 0.5);
}
.controls output {
  color: var(--ink);
  min-width: 46px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

.check {
  gap: 9px;
  cursor: pointer;
  user-select: none;
}
.check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch {
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: #16233a;
  border: 1px solid #243450;
  position: relative;
  transition: background-color 0.2s, border-color 0.2s, box-shadow 0.2s;
  flex: none;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #64748f;
  transition: transform 0.2s, background-color 0.2s;
}
.check input:checked + .switch {
  background: color-mix(in srgb, var(--cyan) 22%, #16233a);
  border-color: rgba(56, 225, 255, 0.5);
  box-shadow: 0 0 10px rgba(56, 225, 255, 0.18);
}
.check input:checked + .switch::after {
  transform: translateX(16px);
  background: var(--cyan);
  box-shadow: 0 0 6px rgba(56, 225, 255, 0.6);
}
.check input:focus-visible + .switch {
  outline: 1px solid var(--cyan);
  outline-offset: 2px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 13px;
}
.row.wrap {
  flex-wrap: wrap;
}

button {
  background: rgba(10, 15, 26, 0.9);
  color: var(--ink);
  border: 1px solid #25405f;
  border-radius: 9px;
  font: inherit;
  font-size: 12.5px;
  letter-spacing: 0.3px;
  padding: 7px 15px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.06s, background-color 0.15s;
}
button:hover {
  border-color: var(--cyan);
  box-shadow: 0 0 14px rgba(56, 225, 255, 0.22);
}
button:active {
  transform: translateY(1px) scale(0.985);
}
button:focus-visible {
  outline: 1px solid var(--cyan);
  outline-offset: 2px;
}
.btn-danger:hover {
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(255, 93, 115, 0.22);
}
.btn-ok:hover {
  border-color: var(--ok);
  box-shadow: 0 0 14px rgba(61, 220, 151, 0.22);
}
button.lit {
  border-color: var(--amber);
  box-shadow: 0 0 16px rgba(255, 201, 77, 0.3);
}

.dim {
  color: var(--dim);
}
.small {
  font-size: 11.5px;
  margin: 9px 0 0;
}
.mono-num {
  font-variant-numeric: tabular-nums;
}

/* ---------- footer & misc ---------- */

footer {
  margin: 20px auto 0;
  text-align: center;
  max-width: 1460px;
}

.tree::-webkit-scrollbar,
.pane::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.tree::-webkit-scrollbar-thumb,
.pane::-webkit-scrollbar-thumb {
  background: #1d2b44;
  border-radius: 4px;
}
.tree::-webkit-scrollbar-thumb:hover,
.pane::-webkit-scrollbar-thumb:hover {
  background: #2a3c5e;
}
.tree::-webkit-scrollbar-track,
.pane::-webkit-scrollbar-track {
  background: transparent;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 1080px) {
  main {
    grid-template-columns: 1fr;
  }
  .replica-grid {
    grid-template-columns: 1fr;
  }
}
