:root {
  --bg: #0b0e14;
  --panel: #11151d;
  --panel-2: #171c26;
  --line: rgba(148, 163, 184, 0.15);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #60a5fa;
  --red: #f87171;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* whiteboard palette */
  --wb-text: #0f172a;
  --wb-muted: #64748b;
  --wb-line: #e2e8f0;
  --wb-chip: #f1f5f9;
  --wb-accent: #2563eb;
  --wb-green: #059669;
  --wb-red: #dc2626;
}

* { box-sizing: border-box; }
/* author display rules (flex/grid) would otherwise defeat the hidden attribute */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

header {
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 14px;
}
header h1 { font-size: 18px; margin: 0; letter-spacing: 0.3px; }
header p { margin: 0; color: var(--muted); font-size: 13px; flex: 1; }
header .gh { color: var(--accent); text-decoration: none; font-size: 13px; }
header .gh:hover { text-decoration: underline; }

main {
  flex: 1;
  display: grid;
  grid-template-columns: 330px 1fr;
  min-height: 0;
}

/* ---------- sidebar (dark) ---------- */

.panel {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background: var(--panel);
}
.panel h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 10px;
}
.panel code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
}

.expr-row { display: flex; gap: 8px; }
#expr {
  flex: 1;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 14px;
}
#expr:focus { outline: none; border-color: var(--accent); }
#run {
  background: var(--accent);
  color: #0b0e14;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
#run:hover { filter: brightness(1.1); }
#status { color: var(--red); font-size: 13px; margin-top: 8px; }

.op-list { display: flex; flex-direction: column; gap: 4px; }
.op-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
}
.op-item:hover { background: var(--panel-2); border-color: var(--line); }
.op-item code { color: var(--accent); background: none; padding: 0; white-space: nowrap; }

.object-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
}
.object-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.object-name { font-weight: 700; font-family: var(--mono); color: var(--accent); font-size: 15px; }
.object-dims { color: var(--muted); font-size: 12px; flex: 1; }
.object-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 6px;
}
.object-del:hover { color: var(--red); }
.object-grid { display: grid; gap: 6px; }
.object-grid input {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 4px;
  text-align: center;
  font-family: var(--mono);
  font-size: 13.5px;
}
.object-grid input:focus { outline: none; border-color: var(--accent); }
.object-grid input.invalid { border-color: var(--red); }

.objects-add { display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); }
.add-row { display: flex; align-items: center; gap: 6px; }
.dim-sep { color: var(--muted); }
.objects-add select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  font: inherit;
}
.objects-add button {
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 12px;
  font: inherit;
  cursor: pointer;
  min-width: 92px;
  text-align: left;
}
.objects-add button:hover { border-color: var(--accent); }

details.syntax { border-top: 1px solid var(--line); padding-top: 12px; }
details.syntax summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
details.syntax p { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- whiteboard stage ---------- */

.stage {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: #ffffff;
  color: var(--wb-text);
}

.shelf-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--wb-muted);
  margin-bottom: 8px;
}
#wb-objects {
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--wb-line);
}
#wb-objects .matmul { justify-content: flex-start; gap: 22px; }
#wb-objects table.mat td { padding: 4px 9px; font-size: 13.5px; }
#wb-preview {
  padding: 12px 18px;
  border-bottom: 1px solid var(--wb-line);
  overflow-x: auto;
}
#wb-view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

/* ---------- step view ---------- */

.mv-body { flex: 1; display: flex; min-height: 0; }
.mv-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  overflow: auto;
  padding: 20px;
  min-width: 0;
}
.mv-caption {
  text-align: center;
  font-size: 15px;
  font-family: var(--mono);
  min-height: 24px;
  max-width: 640px;
  color: var(--wb-text);
}
.mv-caption b { color: var(--wb-text); }
.mv-caption code { background: var(--wb-chip); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.mv-legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--wb-muted); font-size: 12.5px; justify-content: center; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.mv-timeline {
  width: 210px;
  border-left: 1px solid var(--wb-line);
  overflow-y: auto;
  padding: 12px;
  flex-shrink: 0;
}
.mv-timeline-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--wb-muted);
  margin-bottom: 8px;
}
.mv-list { list-style: none; margin: 0; padding: 0; }
.mv-list li button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--wb-muted);
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mv-list li button:hover,
.mv-list li.active button { background: var(--wb-chip); color: var(--wb-text); }
.mv-num { color: var(--wb-accent); margin-right: 7px; }

.mv-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  padding: 12px;
  border-top: 1px solid var(--wb-line);
}
.mv-controls button {
  background: #f8fafc;
  color: var(--wb-text);
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 14px;
  cursor: pointer;
}
.mv-controls button:hover { border-color: var(--wb-accent); }
.mv-counter { color: var(--wb-muted); font-size: 13px; font-family: var(--mono); }
.mv-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--wb-muted);
  padding: 24px;
  text-align: center;
  font-size: 14px;
  background: #ffffff;
}
.mv-scalar { font-family: var(--mono); font-size: 22px; padding: 8px 10px; }
.mv-scalar.hl-a-text { color: var(--wb-green); font-weight: 700; }

/* ---------- matrix tables & highlight colors ---------- */

.matmul { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: center; }
.mat-block { text-align: center; }
.mat-name { color: var(--wb-muted); font-size: 12.5px; margin-bottom: 6px; font-family: var(--mono); }
.mat-op { font-size: 20px; color: var(--wb-muted); }
table.mat {
  border-collapse: collapse;
  border-left: 2px solid #334155;
  border-right: 2px solid #334155;
  border-radius: 6px;
}
table.mat td {
  padding: 6px 12px;
  text-align: center;
  font-family: var(--mono);
  font-size: 15px;
  transition: background-color 0.55s ease, color 0.55s ease, box-shadow 0.55s ease;
}

@keyframes mvFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.mv-stage .matmul { animation: mvFade 0.6s ease; }

td.hl-a, .sw.hl-a { background: rgba(16, 185, 129, 0.25); }
td.hl-b, .sw.hl-b { background: rgba(239, 68, 68, 0.20); }
td.hl-c, .sw.hl-c { background: rgba(37, 99, 235, 0.25); }
td.hl-c { font-weight: 700; }
td.hl-target, .sw.hl-target { background: rgba(245, 158, 11, 0.30); }
td.hl-source, .sw.hl-source { background: rgba(37, 99, 235, 0.15); }
td.hl-pivot, .sw.hl-pivot { box-shadow: inset 0 0 0 2px var(--wb-accent); }

.tm-a { color: var(--wb-green); font-style: normal; }
.tm-b { color: var(--wb-red); font-style: normal; }
.tm-c { color: var(--wb-accent); }

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .mv-body { flex-direction: column; }
  .mv-timeline {
    width: auto;
    border-left: 0;
    border-top: 1px solid var(--wb-line);
    max-height: 120px;
  }
  .mv-list { display: flex; overflow-x: auto; gap: 4px; }
  .mv-list li { flex-shrink: 0; }
}
