:root {
  --bg: #111318;
  --panel: #181b22;
  --fg: #e6e8ee;
  --muted: #9aa1b0;
  --accent: #4f8cff;
  --border: #2a2f3a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas:
    "panel canvas"
    "activity activity";
  height: 100vh;
}

#panel {
  grid-area: panel;
  padding: 20px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#canvas {
  grid-area: canvas;
  position: relative;
  min-width: 0;
}

#canvas canvas { display: block; }

/* The two readouts the view carries: which consolidation the session runs, and
   what it produced. They sit stacked in the top-left corner of the canvas,
   where the eye already is — the mode is fixed when the session starts, and the
   boxes alone do not reveal it (the same shell is a fine grid under canonical
   and a few slabs under merge adjacent). */
#readout {
  position: absolute;
  left: 12px;
  top: 10px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
  max-width: calc(100% - 24px);
}

/* A readout without anything to report yet is not drawn, so the corner holds
   no empty pills while the session is still coming up. */
#readout > :empty { display: none; }

#mode,
#stats {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgb(17 19 24 / 70%);
  color: var(--muted);
  font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace;
}

/* A session that consolidates is doing something to the boxes, so it is called
   out; canonical keeps them as they come, and is the neutral default. */
#mode:not([data-mode="canonical"]),
.compaction:not([data-mode="canonical"]) {
  border-color: var(--accent);
  color: var(--fg);
}

/* The engine works in a worker, so the page can say so while it does. The
   overlay sits over the canvas rather than in the sidebar, because that is
   where the eye is while a 3D session recomputes. */
#busy {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  pointer-events: none;
  background: rgb(17 19 24 / 45%);
  color: var(--fg);
  font-size: 13px;
}

#busy[hidden] { display: none; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(1turn); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
}

#activity {
  grid-area: activity;
  max-height: 180px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 20px;
}

#presence {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--accent);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

#log {
  list-style: none;
  margin: 0;
  padding: 0;
  font: 12px/1.6 ui-monospace, Menlo, Consolas, monospace;
  color: var(--muted);
}

#log li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#log li.add { color: #8fd3a4; }
#log li.remove { color: #ff9b9b; }
#log li.clear { color: var(--muted); }
#log li.me::before { content: '▸ '; color: var(--accent); }

h1 { margin: 0 0 4px; font-size: 20px; }

.lede { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.hint { margin: 8px 0 0; font-size: 12px; line-height: 1.45; color: var(--muted); }

.hint strong { color: var(--fg); font-weight: 600; }

.compaction {
  margin: 0 0 14px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0e1015;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}


.field { margin-bottom: 14px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  color: var(--muted);
}

.field label.inline { display: inline; margin-left: 8px; color: var(--fg); }

select, textarea { width: 100%; }

select {
  background: #0e1015;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
}

textarea {
  min-height: 120px;
  resize: vertical;
  background: #0e1015;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace;
}

#result { min-height: 80px; }

.row { display: flex; gap: 8px; margin-bottom: 14px; }

.session-actions { display: flex; gap: 8px; }

.session-actions #newSession { flex: 1; }

.session-actions #helpTourBtn {
  flex: 0 0 auto;
  width: auto;
  height: auto;
  min-width: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
}

.session-actions #helpTourBtn:hover { background: rgb(255 255 255 / 6%); }

.dims-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.dims-row label { margin: 0; flex-shrink: 0; }

.dims-row select { flex: 1; min-width: 0; }

.dims-row button { flex: 0 0 auto; white-space: nowrap; }

button {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #222734;
  color: var(--fg);
  cursor: pointer;
}

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }

button:hover { filter: brightness(1.12); }

button .icon {
  width: 15px;
  height: 15px;
  margin-right: 6px;
  vertical-align: -3px;
}

#status {
  font-size: 12px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

#reconnectBanner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 16px;
  background: #2b1c1c;
  border-bottom: 1px solid #7a3030;
  color: #ffb3b3;
  font-size: 13px;
}

#reconnectBanner[hidden] { display: none; }

#reconnectBanner button {
  flex: 0 0 auto;
  background: #7a3030;
  border-color: #a04040;
  color: #fff;
}

body.disconnected #canvas {
  pointer-events: none;
  opacity: 0.55;
  filter: grayscale(0.4);
}

button:disabled,
button:disabled:hover {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

code {
  background: #0e1015;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

details summary { cursor: pointer; margin-bottom: 8px; color: var(--muted); }

@media (max-width: 820px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto;
    grid-template-areas:
      "panel"
      "canvas"
      "activity";
    height: auto;
    min-height: 100vh;
  }
  #panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: visible;
  }
  #canvas { min-height: 320px; }
  #activity { max-height: 160px; }
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}

.modal[hidden] { display: none; }

.modal-box {
  width: min(360px, calc(100vw - 40px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.modal-box h2 { margin: 0 0 14px; font-size: 16px; }

/* GitHub badge in the sidebar. */
.gh {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.gh a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
}

.gh a:hover {
  color: var(--fg);
}

.gh-mark {
  width: 16px;
  height: 16px;
}
