:root {
  --bg: #070912;
  --bg2: #0c1020;
  --panel: #10162b;
  --panel2: #141c36;
  --border: #233058;
  --border-hi: #3a518f;
  --text: #e6eeff;
  --muted: #8ea3ce;
  --cyan: #38f6ff;
  --amber: #ffbe3b;
  --magenta: #ff52d9;
  --emerald: #3bf2a5;
  --violet: #a78bfa;
  --coral: #ff6b6b;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', 'DejaVu Sans Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Header: single-row 50px bar tuned cleanly for 1024px */
.topbar {
  height: 50px;
  background: linear-gradient(180deg, #10162c 0%, #0a0e1d 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  gap: 8px;
  white-space: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--text);
  flex-shrink: 0;
}

.brand-sigil {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, rgba(56, 246, 255, 0.22), rgba(255, 190, 59, 0.22));
  border: 1px solid rgba(56, 246, 255, 0.55);
  color: var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(56, 246, 255, 0.25);
}

.brand-title {
  background: linear-gradient(90deg, #ffffff 0%, #7ceeff 60%, #ffbe3b 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.tab-btn {
  background: rgba(18, 25, 48, 0.85);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text);
  border-color: var(--border-hi);
  background: #182346;
}

.tab-btn.active {
  color: #050a14;
  background: linear-gradient(135deg, var(--cyan), #72d6ff);
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(56, 246, 255, 0.35);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.pill-link, .proofs-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
  font-family: var(--font);
}

.pill-link.gold {
  color: #ffd873;
  background: rgba(255, 190, 59, 0.1);
  border-color: rgba(255, 190, 59, 0.42);
}

.pill-link.gold:hover {
  background: rgba(255, 190, 59, 0.22);
  border-color: var(--amber);
}

.pill-link.sibling {
  color: #a8f5ff;
  background: rgba(56, 246, 255, 0.08);
  border-color: rgba(56, 246, 255, 0.32);
}

.pill-link.sibling:hover {
  background: rgba(56, 246, 255, 0.18);
  border-color: var(--cyan);
}

.proofs-btn {
  color: #57ffb9;
  background: rgba(59, 242, 165, 0.12);
  border-color: rgba(59, 242, 165, 0.45);
}

.proofs-btn:hover {
  background: rgba(59, 242, 165, 0.24);
  border-color: var(--emerald);
}

/* Main Workspace */
.workspace {
  height: calc(100vh - 50px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 10px;
  padding: 10px;
}

/* Left Canvas Stage */
.stage-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.canvas-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.canvas-card.main-card {
  flex: 1 1 auto;
}

.sub-row {
  height: 222px;
  flex: 0 0 222px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  min-width: 0;
}

.card-hdr {
  height: 28px;
  flex: 0 0 28px;
  padding: 0 10px;
  background: linear-gradient(180deg, #161f3d 0%, #111830 100%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--cyan);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-hint {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  background: #060913;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Right Control Sidebar */
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.chamber-badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--amber);
}

.chamber-title {
  font-size: 15px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
  margin-top: 1px;
}

.chamber-desc {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.38;
  margin-top: 3px;
}

.stats-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  min-width: 0;
}

.stat-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--cyan);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value.amber { color: var(--amber); }
.stat-value.emerald { color: var(--emerald); }
.stat-value.magenta { color: var(--magenta); }

.controls-box {
  display: flex;
  flex-direction: column;
  gap: 7px;
  flex-shrink: 0;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ctrl-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.ctrl-val {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--cyan);
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
  cursor: pointer;
  height: 4px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pill-btn {
  flex: 1 1 auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
  text-align: center;
  white-space: nowrap;
}

.pill-btn:hover {
  color: var(--text);
  border-color: var(--border-hi);
}

.pill-btn.active {
  background: rgba(56, 246, 255, 0.18);
  border-color: var(--cyan);
  color: #ffffff;
}

.pill-btn.amber.active {
  background: rgba(255, 190, 59, 0.2);
  border-color: var(--amber);
  color: #ffe299;
}

.action-row {
  display: flex;
  gap: 6px;
}

.action-btn {
  flex: 1 1 0;
  padding: 6px 8px;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid rgba(56, 246, 255, 0.5);
  background: rgba(56, 246, 255, 0.14);
  color: var(--cyan);
  transition: all 0.14s ease;
}

.action-btn:hover {
  background: rgba(56, 246, 255, 0.26);
}

.action-btn.secondary {
  border-color: var(--border-hi);
  background: var(--bg2);
  color: var(--text);
}

.action-btn.secondary:hover {
  background: #1a2444;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.toggle-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.toggle-item input {
  accent-color: var(--cyan);
  cursor: pointer;
}

.theorem-box {
  margin-top: auto;
  background: linear-gradient(180deg, rgba(20, 28, 54, 0.9), rgba(10, 15, 30, 0.95));
  border: 1px solid rgba(56, 246, 255, 0.28);
  border-left: 3px solid var(--amber);
  border-radius: 7px;
  padding: 8px 9px;
  flex-shrink: 0;
}

.theorem-title {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--amber);
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}

.theorem-body {
  font-size: 11px;
  line-height: 1.4;
  color: #cfe0ff;
}

.theorem-body .math {
  font-family: var(--mono);
  color: var(--cyan);
  font-size: 10.5px;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 14, 0.82);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 18px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-panel {
  width: 820px;
  max-width: 100%;
  max-height: 88vh;
  background: #0e1428;
  border: 1px solid var(--border-hi);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-hdr {
  padding: 12px 16px;
  background: #141c38;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-title {
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
}

.modal-close {
  background: rgba(255, 107, 107, 0.15);
  border: 1px solid rgba(255, 107, 107, 0.45);
  color: #ff9c9c;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.modal-close:hover {
  background: rgba(255, 107, 107, 0.3);
}

.modal-body {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.modal-body > * {
  flex-shrink: 0;
}

.cli-box {
  background: #070b16;
  border: 1px solid rgba(59, 242, 165, 0.45);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.cli-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: var(--emerald);
}

.cli-box code {
  display: block;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #e6fffa;
  background: #0c1326;
  padding: 7px 9px;
  border-radius: 5px;
  border: 1px solid #1d2d4e;
  overflow-x: auto;
  white-space: nowrap;
}

.copy-btn {
  background: rgba(59, 242, 165, 0.16);
  border: 1px solid rgba(59, 242, 165, 0.5);
  color: var(--emerald);
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
}

.proof-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.proof-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.proof-card.wide {
  grid-column: 1 / -1;
}

.proof-card h4 {
  font-size: 12px;
  font-weight: 800;
  color: var(--cyan);
  margin-bottom: 5px;
}

.proof-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11.2px;
  line-height: 1.42;
  color: #cfe0ff;
}

.proof-card li strong {
  color: var(--amber);
  font-family: var(--mono);
  font-size: 10.8px;
}
