:root {
  --bg: #0b1410;
  --panel: #121e18;
  --panel-edge: #1d2c25;
  --ink: #d8e8df;
  --ink-dim: #708876;
  --accent: #6dd29a;
  --warn: #d2966d;
}

* { box-sizing: border-box; }

/* The HTML `hidden` attr has spec (0,0,1,0) which loses to most of our
   selectors (id/class with `display:flex`). Force it to always win. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  overflow: hidden;
}

#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--panel-edge);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#sidebar header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
#sidebar header .subtitle {
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.build-id {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: none;
  font-size: 10px;
  margin-left: 6px;
  opacity: 0.7;
}

section {
  border-top: 1px solid var(--panel-edge);
  padding-top: 12px;
}
section:first-of-type { border-top: none; padding-top: 0; }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input[type="text"] {
  width: 100%;
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  padding: 6px 8px;
  font: inherit;
  border-radius: 3px;
}

.tunable {
  margin-bottom: 10px;
}
.tunable .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
}
.tunable .name {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  color: var(--ink);
}
.tunable .val {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  color: var(--accent);
}
.tunable input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
button {
  background: var(--panel-edge);
  color: var(--ink);
  border: 1px solid var(--panel-edge);
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  border-radius: 3px;
}
button:hover { filter: brightness(1.2); }
button.primary {
  background: var(--accent);
  color: #052b17;
  border-color: var(--accent);
  font-weight: 600;
}
.auto {
  margin: 0;
  text-transform: none;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.auto input { margin: 0; }

button.refetch {
  margin-top: 6px;
  width: 100%;
  padding: 6px 8px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--panel-edge);
  color: var(--ink-dim);
}
button.refetch:hover { color: var(--accent); border-color: var(--accent); }
button.refetch:disabled { opacity: 0.5; cursor: wait; }

.picker-count {
  font-family: ui-monospace, monospace;
  color: var(--accent);
  font-size: 10px;
  margin-left: 6px;
  text-transform: none;
}
.picker-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 6px;
}
.picker-actions button {
  padding: 4px 8px;
  font-size: 11px;
}
.neighbor-list {
  max-height: 220px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  padding: 4px;
}
.neighbor-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border-radius: 2px;
  cursor: pointer;
}
.neighbor-row:hover { background: rgba(109, 210, 154, 0.08); }
.neighbor-row input { margin: 0; cursor: pointer; }
.neighbor-row .handle { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.neighbor-row .eng {
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.neighbor-row .eng-in  { color: var(--accent); opacity: 0.85; }
.neighbor-row .eng-out { color: #b59dd6;       opacity: 0.85; }
.neighbor-row .eng-tot { color: var(--ink);    opacity: 0.95; font-weight: 600; }
.neighbor-row.neighbor-header {
  cursor: default;
  color: var(--ink-dim);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--panel-edge);
  margin-bottom: 2px;
}
.neighbor-row.neighbor-header:hover { background: transparent; }
.neighbor-row.neighbor-header .hdr-spacer { width: 13px; flex: 0 0 13px; }
.neighbor-row.neighbor-header .handle { color: var(--ink-dim); }
.neighbor-row.neighbor-header .eng { color: var(--ink-dim); opacity: 1; font-weight: 400; }

.playback {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.play-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.play-row button {
  padding: 6px 14px;
  font-size: 14px;
}
.play-row select {
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  padding: 5px 6px;
  font: inherit;
  border-radius: 3px;
  flex: 1;
}
#scrub {
  width: 100%;
  accent-color: var(--accent);
}
.scrub-info {
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  color: var(--ink-dim);
}

.stats {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
}
.stats div {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}
.stats .k { color: var(--ink-dim); }

.hover-info {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 11px;
  min-height: 60px;
}
.hover-info .hint { color: var(--ink-dim); font-style: italic; }
.hover-info .row { display: flex; justify-content: space-between; padding: 1px 0; }
.hover-info .row .k { color: var(--ink-dim); }

/* ---- floating post-detail panel (right side of stage) ---- */
#post-detail.post-detail {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  background: rgba(18, 30, 24, 0.96);
  border: 1px solid var(--panel-edge);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(109,210,154,0.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
  padding: 0;
  pointer-events: auto;
}
.post-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px 6px 12px;
  border-bottom: 1px solid var(--panel-edge);
}
.post-detail-title {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.post-detail-close {
  background: transparent;
  border: none;
  color: var(--ink-dim);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  border-radius: 3px;
}
.post-detail-close:hover { color: var(--accent); background: rgba(109,210,154,0.10); }
.post-detail .post-detail-body {
  font-size: 12px;
  line-height: 1.5;
  overflow-y: auto;
  padding: 10px 12px 12px;
  flex: 1;
}
.post-detail .hint { color: var(--ink-dim); font-style: italic; }
.post-detail .post-card {
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.post-detail .post-card.parent {
  border-left: 2px solid var(--ink-dim);
  opacity: 0.85;
}
.post-detail .post-meta {
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  margin-bottom: 4px;
}
.post-detail .post-meta .author { color: var(--accent); font-weight: 600; }
.post-detail .post-meta .ts { color: var(--ink-dim); }
.post-detail .post-text {
  color: var(--ink);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.post-detail .post-label {
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 4px;
}
.post-detail .post-repost-banner {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(109, 210, 154, 0.08);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  padding: 4px 8px;
  margin-bottom: 6px;
}
.post-detail .post-loading {
  color: var(--ink-dim);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 6px;
}
.post-detail .post-error {
  color: var(--warn);
  font-family: ui-monospace, monospace;
  font-size: 10px;
}
.post-detail .post-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  color: var(--accent);
  text-decoration: none;
  font-family: ui-monospace, monospace;
  letter-spacing: 0.04em;
}
.post-detail .post-link:hover { text-decoration: underline; }

footer .hint {
  color: var(--ink-dim);
  font-size: 10px;
  text-align: center;
}

#stage {
  position: relative;
  overflow: hidden;
  background: radial-gradient(ellipse at center, #142621 0%, #0b1410 70%);
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
#canvas:active { cursor: grabbing; }
/* Hover highlight lives on a sibling canvas stacked on top of #canvas so
   mousemove can repaint just the outline without touching the tile layer. */
#canvas-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(109,210,154,0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- big stage panels (idle hint + progress) ---- */
#stage-hint,
#stage-progress {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  gap: 14px;
  pointer-events: none;
}

/* During simulating, once snapshots are streaming to the canvas, shrink
   the progress panel to a slim top-bar overlay so the viz isn't covered.
   Before snapshots start (e.g. mid neighbor-fetch), the default big-center
   panel still shows. The `sim-live` class is toggled by app.js. */
body.sim-live[data-state="simulating"] #stage-progress {
  inset: 0 0 auto 0;
  flex-direction: row;
  justify-content: center;
  gap: 14px;
  padding: 8px 16px;
  background: rgba(11, 20, 16, 0.82);
  border-bottom: 1px solid var(--panel-edge);
  text-align: left;
}
body.sim-live[data-state="simulating"] .stage-progress-title { font-size: 11px; }
body.sim-live[data-state="simulating"] .stage-progress-body  { font-size: 11px; }
body.sim-live[data-state="simulating"] .stage-progress-bar   { width: 220px; height: 6px; }
.stage-hint-icon {
  font-size: 56px;
  opacity: 0.7;
}
.stage-hint-title {
  font-size: 18px;
  color: var(--ink);
  letter-spacing: 0.02em;
}
.stage-hint-title em {
  color: var(--accent);
  font-style: normal;
  font-weight: 600;
}
.stage-hint-body {
  font-size: 13px;
  color: var(--ink-dim);
  max-width: 460px;
  line-height: 1.5;
}

/* Inline handle entry on the idle stage. */
.stage-hint-handle {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 8px;
  pointer-events: auto;
}
.stage-handle-wrap {
  position: relative;
}
.stage-hint-handle input[type="text"] {
  width: 280px;
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  color: var(--ink);
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  border-radius: 3px;
}
.stage-hint-handle input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}
.stage-hint-handle button {
  padding: 10px 18px;
  font-size: 14px;
}

/* "Just Go" CTA on the configuring stage. */
.stage-hint-just-go {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  pointer-events: auto;
}
.stage-hint-just-go .cta-big {
  width: auto;
  padding: 12px 28px !important;
}
.stage-hint-sub {
  font-size: 11px;
  color: var(--ink-dim);
  font-style: italic;
}
.stage-progress-title {
  font-size: 15px;
  color: var(--accent);
  font-family: ui-monospace, monospace;
  letter-spacing: 0.04em;
}
.stage-progress-body {
  font-size: 12px;
  color: var(--ink-dim);
  font-family: ui-monospace, monospace;
  max-width: 520px;
  line-height: 1.6;
}

/* Per-neighbor progress list during multi-neighbor lazy fetch. */
.stage-progress-list {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.5;
  text-align: left;
  background: rgba(11, 20, 16, 0.55);
  border: 1px solid var(--panel-edge);
  border-radius: 4px;
  padding: 8px 10px;
  max-width: 520px;
  width: 100%;
  max-height: 520px;
  overflow-y: auto;
}
.stage-progress-list .row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 1px 0;
}
.stage-progress-list .icon {
  flex: 0 0 14px;
  text-align: center;
  font-size: 10px;
  color: var(--ink-dim);
}
.stage-progress-list .row.is-started .icon,
.stage-progress-list .row.is-progress .icon {
  color: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.stage-progress-list .row.is-done   .icon { color: var(--accent); }
.stage-progress-list .row.is-cancelled .icon,
.stage-progress-list .row.is-failed   .icon { color: var(--warn); }
.stage-progress-list .handle {
  flex: 0 0 auto;
  color: var(--ink);
  min-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-progress-list .msg {
  flex: 1;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-progress-list .row.is-done .msg { color: var(--ink-dim); opacity: 0.65; }
.stage-progress-list .row.is-cancelled .msg,
.stage-progress-list .row.is-failed .msg { color: var(--warn); opacity: 0.85; }

.stage-progress-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.stage-progress-actions button {
  font-size: 11px;
  padding: 6px 12px;
}
.stage-progress-bar {
  position: relative;
  width: 360px;
  max-width: 80vw;
  height: 10px;
  background: rgba(109,210,154,0.10);
  border: 1px solid var(--panel-edge);
  border-radius: 5px;
  overflow: hidden;
}
.stage-progress-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--accent);
  transition: width 0.18s ease-out;
  box-shadow: 0 0 8px rgba(109,210,154,0.6);
}
/* Indeterminate sweep: shown when stage-progress-bar has [data-indeterminate].
   Fill bar is hidden and a thin stripe slides across instead. */
.stage-progress-bar-stripe {
  position: absolute;
  top: 0; bottom: 0;
  left: -30%;
  width: 30%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(109,210,154,0.7) 50%,
    transparent 100%
  );
  display: none;
}
.stage-progress-bar[data-indeterminate] .stage-progress-bar-fill { display: none; }
.stage-progress-bar[data-indeterminate] .stage-progress-bar-stripe {
  display: block;
  animation: stripe-sweep 1.2s linear infinite;
}
@keyframes stripe-sweep {
  from { transform: translateX(0); }
  to   { transform: translateX(430%); }
}

/* ---- big CTA ---- */
.cta-section { text-align: center; padding-top: 24px !important; }
.cta-big {
  width: 100%;
  padding: 14px 18px !important;
  font-size: 14px !important;
  letter-spacing: 0.03em;
}
.cta-hint {
  color: var(--ink-dim);
  font-size: 11px;
  line-height: 1.5;
  margin: 10px 0 0 0;
  text-transform: none;
  letter-spacing: 0.02em;
}

/* ---- handle picker (extended) ---- */
.handle-input-wrap {
  position: relative;
}
.handle-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 30;
  margin-top: 2px;
  background: #0b1612;
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  max-height: 280px;
  overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
}
.typeahead-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 8px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}
.typeahead-row:hover,
.typeahead-row.is-active {
  background: rgba(109, 210, 154, 0.10);
}
.typeahead-row .ta-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex: 0 0 24px;
  object-fit: cover;
  background: var(--panel-edge);
}
.typeahead-row .ta-noavatar {
  display: inline-block;
}
.typeahead-row .ta-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  line-height: 1.2;
}
.typeahead-row .ta-name {
  color: var(--ink);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.typeahead-row .ta-handle {
  color: var(--ink-dim);
  font-family: ui-monospace, monospace;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.picker-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.picker-row button { flex: 1; }
button.ghost {
  background: transparent;
  color: var(--ink-dim);
  border: 1px solid var(--panel-edge);
}
button.ghost:hover { color: var(--accent); border-color: var(--accent); }

/* ---- change-user banner ---- */
.change-user {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.change-user .current-user {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: ui-monospace, monospace;
}
.change-user .current-user .k {
  color: var(--ink-dim);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.change-user .current-user strong {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-left: 8px;
}
.change-user button {
  width: 100%;
  padding: 6px 8px;
  font-size: 11px;
}

/* ---- disabled state polish ---- */
#sidebar input:disabled,
#sidebar button:disabled,
#sidebar select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.neighbor-row.is-disabled { opacity: 0.45; pointer-events: none; }

details.collapsible {
  border-top: 1px solid var(--panel-edge);
  padding-top: 8px;
  margin: 0;
}
details.collapsible[open] { padding-bottom: 4px; }
details.collapsible > summary {
  cursor: pointer;
  list-style: none;
  color: var(--ink);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  user-select: none;
  padding: 6px 10px;
  background: rgba(109, 210, 154, 0.06);
  border: 1px solid var(--panel-edge);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
details.collapsible > summary:hover {
  background: rgba(109, 210, 154, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}
details.collapsible[open] > summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}
details.collapsible > summary::after {
  content: "▸";
  display: inline-block;
  transition: transform 0.12s;
  font-size: 11px;
  color: var(--accent);
  margin-left: auto;
}
details.collapsible[open] > summary::after { transform: rotate(90deg); }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > #tunables {
  padding: 8px 10px 4px;
  border: 1px solid var(--panel-edge);
  border-top: none;
  border-radius: 0 0 3px 3px;
  background: rgba(11, 22, 18, 0.45);
}
