:root {
  --bg: #000;
  --panel: rgba(16, 18, 26, 0.86);
  --border: rgba(255, 255, 255, 0.12);
  --text: #e6e8ef;
  --muted: #9aa0b0;
  --accent: #5aa9ff;
  --input: rgba(255, 255, 255, 0.07);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

#stage, #view, #overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#overlay {
  cursor: crosshair;
  touch-action: none;
}
#overlay.dragging { cursor: grabbing; }

#panel {
  position: fixed;
  top: 12px;
  left: 12px;
  width: 280px;
  max-height: calc(100% - 60px);
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  transition: transform 0.2s ease, opacity 0.2s ease;
}
body.panel-hidden #panel {
  transform: translateX(calc(-100% - 20px));
  opacity: 0;
  pointer-events: none;
}

/* Switch between the explorers that share this server. */
.apps {
  display: flex;
  gap: 4px;
  margin: -2px 0 10px;
  padding: 3px;
  background: var(--input);
  border-radius: 8px;
}
.apps a {
  flex: 1;
  padding: 4px 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
}
.apps a:hover { color: var(--text); }
.apps a.active { color: var(--text); background: rgba(255, 255, 255, 0.1); }

#panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
h1 { font-size: 16px; margin: 0; font-weight: 600; letter-spacing: 0.02em; }

section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}
label.check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 13px;
}
label output { color: var(--text); margin-left: 4px; }

.row { display: flex; gap: 8px; }
.row label { flex: 1; min-width: 0; }

input[type="number"], input[type="text"], select {
  width: 100%;
  padding: 6px 8px;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
input:disabled { opacity: 0.4; }

button {
  padding: 6px 10px;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.icon { padding: 2px 10px; font-size: 18px; line-height: 1.2; }

.segmented { display: flex; }
.segmented button { flex: 1; border-radius: 0; font-size: 12px; }
.segmented button:first-child { border-radius: 6px 0 0 6px; }
.segmented button:last-child { border-radius: 0 6px 6px 0; border-left: none; }
.segmented button.active { background: var(--accent); color: #001; border-color: var(--accent); }

.buttons { flex-direction: row; flex-wrap: wrap; }
.buttons button { flex: 1 1 40%; }

/* Attractor parameters: name, slider, exact value. */
.param { display: flex; align-items: center; gap: 8px; }
.param b { width: 10px; font: italic 600 14px Georgia, "Times New Roman", serif; color: var(--text); }
.param input[type="range"] { flex: 1; min-width: 0; }
.param input[type="number"] { width: 78px; padding: 4px 6px; font-size: 12px; font-variant-numeric: tabular-nums; }
.param.axis b { color: var(--accent); }
.hint { margin: 0; font-size: 11.5px; line-height: 1.45; color: var(--muted); }
.hint var { font-family: Georgia, "Times New Roman", serif; }
#panel .formula.small { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); white-space: normal; }
#seq { font-family: ui-monospace, monospace; letter-spacing: 0.08em; }

details { padding-top: 10px; }
summary { cursor: pointer; color: var(--muted); }
.help { margin: 8px 0 0; padding-left: 18px; line-height: 1.6; color: var(--muted); font-size: 12px; }
.help b { color: var(--text); font-weight: 500; }

#show-panel {
  position: fixed;
  top: 12px;
  left: 12px;
  display: none;
  background: var(--panel);
}
body.panel-hidden #show-panel { display: block; }

#inset {
  position: fixed;
  right: 12px;
  bottom: 44px;
  margin: 0;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: none;
  cursor: pointer;
}
#inset.visible { display: block; }
#inset canvas { display: block; width: 200px; height: 200px; border-radius: 6px; }
#inset figcaption { margin-top: 4px; font-size: 11px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }

#status {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
  padding: 7px 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
#st-warn { color: #ffb347; }
#status.busy #st-time::after { content: " · rendering…"; color: var(--accent); }

@media (max-width: 600px) {
  #panel { width: calc(100% - 24px); max-height: 55%; }
  #inset canvas { width: 140px; height: 140px; }
}

/* ---- About dialog ---- */
.header-buttons { display: flex; gap: 6px; align-items: center; }
.header-buttons button:not(.icon) { font-size: 12px; padding: 4px 9px; }

#info {
  width: min(780px, calc(100% - 24px));
  max-height: calc(100% - 48px);
  padding: 0;
  color: var(--text);
  background: rgba(14, 16, 23, 0.97);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  overflow-y: auto;
  line-height: 1.55;
}
#info::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }

#info > header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: rgba(14, 16, 23, 0.97);
  border-bottom: 1px solid var(--border);
}
#info h2 { margin: 0; font-size: 18px; font-weight: 600; }
#info h3 { margin: 0 0 8px; font-size: 15px; font-weight: 600; color: #fff; }
#info section {
  display: block;
  padding: 18px 22px;
  scroll-margin-top: 60px;
}
#info p { margin: 0 0 10px; }
#info ul, #info ol { margin: 0 0 10px; padding-left: 20px; }
#info li { margin-bottom: 6px; }
#info a { color: var(--accent); }
#info var { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
#info code { font-size: 12.5px; padding: 1px 4px; background: var(--input); border-radius: 4px; }
#info kbd { font: 12px ui-monospace, monospace; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; }

.toc {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 22px 0;
}
.toc a {
  font-size: 12px;
  padding: 3px 9px;
  color: var(--muted) !important;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.toc a:hover { color: var(--text) !important; border-color: var(--accent); }

.formula {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  white-space: nowrap;
}
p.formula { font-size: 20px; margin: 4px 0 10px; color: #fff; }
.formula.center { text-align: center; }

#info .now {
  margin: 14px 22px 4px;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(90, 169, 255, 0.12), rgba(90, 169, 255, 0.03));
  border: 1px solid rgba(90, 169, 255, 0.35);
  border-radius: 10px;
}
#now-stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 16px;
  margin: 8px 0 0;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
#now-stats dt { color: var(--muted); }
#now-stats dd { margin: 0; overflow-wrap: anywhere; }

#info table { width: 100%; border-collapse: collapse; font-size: 13px; }
#info th, #info td { text-align: left; vertical-align: top; padding: 7px 8px; border-bottom: 1px solid var(--border); }
#info th { color: var(--muted); font-weight: 500; font-size: 12px; }
#info td.formula { font-size: 14px; }

.pipeline {
  list-style: none;
  padding: 0 !important;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  counter-reset: step;
}
.pipeline li {
  position: relative;
  flex: 1 1 110px;
  margin: 0 !important;
  padding: 8px 10px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--muted);
  counter-increment: step;
}
.pipeline li b { display: block; color: var(--text); font-size: 13px; margin-bottom: 2px; }
.pipeline li b::before { content: counter(step) ". "; color: var(--accent); }

@media (max-width: 600px) {
  #info section { padding: 14px 16px; }
  #info .now { margin: 12px 14px 4px; }
  .formula { white-space: normal; }
}
