:root {
  --bg: #05070f;
  --panel: #0b1020;
  --panel-hi: #11182f;
  --border: rgba(167, 139, 250, 0.22);
  --border-hi: rgba(56, 189, 248, 0.42);
  --text: #eef2ff;
  --muted: #94a3b8;
  --violet: #a78bfa;
  --cyan: #38bdf8;
  --emerald: #34d399;
  --amber: #fbbf24;
  --rose: #f472b6;
  --radius: 10px;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 20% 0%, #101630 0%, var(--bg) 58%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

/* Header: single-row crisp 1024px fit */
.topbar {
  height: 52px;
  min-height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(8, 12, 24, 0.92);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.brand-badge {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
  color: #05070f;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.45);
  letter-spacing: -0.02em;
}

.brand-title {
  font-size: 13px;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.1;
  white-space: nowrap;
}

.brand-sub {
  font-size: 9.5px;
  color: var(--violet);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

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

.tab-btn {
  background: rgba(17, 24, 47, 0.72);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s ease;
}

.tab-btn:hover {
  border-color: var(--cyan);
  color: #fff;
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.32), rgba(56, 189, 248, 0.28));
  border-color: var(--cyan);
  color: #fff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.28);
}

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

.pill-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.14s ease;
}

.atlas-pill {
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fde68a;
}

.atlas-pill:hover {
  background: rgba(251, 191, 36, 0.26);
  color: #fff;
}

.sibling-pill {
  background: rgba(167, 139, 250, 0.15);
  border: 1px solid rgba(167, 139, 250, 0.42);
  color: #ddd6fe;
}

.sibling-pill:hover {
  background: rgba(167, 139, 250, 0.28);
  color: #fff;
}

.proofs-btn {
  background: rgba(52, 211, 153, 0.16);
  border: 1px solid rgba(52, 211, 153, 0.45);
  color: #a7f3d0;
}

.proofs-btn:hover {
  background: rgba(52, 211, 153, 0.30);
  color: #fff;
}

/* Main workspace */
.workspace {
  flex: 1;
  min-height: 0;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 316px;
  gap: 8px;
}

.stage-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.card {
  background: rgba(11, 16, 32, 0.90);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.main-card {
  flex: 1.55;
}

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

.sub-card {
  min-height: 0;
}

.card-head {
  height: 28px;
  min-height: 28px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: rgba(17, 24, 47, 0.85);
  border-bottom: 1px solid rgba(167, 139, 250, 0.16);
  flex-shrink: 0;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-badge {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.30);
  padding: 1px 6px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}

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

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

.canvas-caption {
  position: absolute;
  left: 8px;
  bottom: 6px;
  right: 8px;
  font-size: 10px;
  color: #cbd5e1;
  background: rgba(5, 7, 15, 0.78);
  border: 1px solid rgba(167, 139, 250, 0.22);
  border-radius: 6px;
  padding: 3px 8px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

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

.stat-card {
  background: rgba(11, 16, 32, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 0;
}

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

.stat-val {
  margin-top: 2px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctrl-card {
  flex: 1;
  min-height: 0;
}

.ctrl-body {
  padding: 8px 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  min-height: 0;
}

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

.ctrl-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10.5px;
  color: #cbd5e1;
  font-weight: 600;
}

.ctrl-val {
  color: var(--amber);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.btn-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.btn-row-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.btn-row-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}

.ctrl-btn {
  background: rgba(17, 24, 47, 0.85);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 6px;
  padding: 4px 5px;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.12s ease;
}

.ctrl-btn:hover {
  border-color: var(--cyan);
  color: #fff;
}

.ctrl-btn.active {
  background: rgba(139, 92, 246, 0.30);
  border-color: var(--violet);
  color: #fff;
  box-shadow: 0 0 8px rgba(139, 92, 246, 0.30);
}

.ctrl-btn.accent {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.45);
  color: #a7f3d0;
}

.ctrl-btn.accent:hover {
  background: rgba(52, 211, 153, 0.28);
  color: #fff;
}

.ctrl-btn.warn {
  background: rgba(244, 114, 182, 0.16);
  border-color: rgba(244, 114, 182, 0.45);
  color: #fbcfe8;
}

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

.mini-note {
  font-size: 9.8px;
  line-height: 1.35;
  color: #94a3b8;
  background: rgba(5, 7, 15, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 6px;
  padding: 5px 7px;
}

.theorem-card {
  flex-shrink: 0;
  padding: 7px 9px;
  background: linear-gradient(180deg, rgba(17, 24, 47, 0.95), rgba(11, 16, 32, 0.95));
  border-color: rgba(56, 189, 248, 0.28);
}

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

.theorem-body {
  font-size: 10.2px;
  line-height: 1.38;
  color: #cbd5e1;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 5, 12, 0.78);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 99;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  width: min(760px, 95vw);
  max-height: 88vh;
  background: #0b1020;
  border: 1px solid var(--border-hi);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
}

.modal-head {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #11182f;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.modal-sub {
  font-size: 11px;
  color: var(--violet);
  margin-top: 2px;
}

.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(148, 163, 184, 0.14);
  border: 1px solid rgba(148, 163, 184, 0.30);
  color: #e2e8f0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.modal-close:hover {
  border-color: var(--rose);
  color: #fff;
}

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

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

.cli-box {
  flex-shrink: 0;
  background: #04060d;
  border: 1px solid rgba(52, 211, 153, 0.42);
  border-radius: 8px;
  padding: 9px 11px;
}

.cli-label {
  font-size: 9.5px;
  font-weight: 800;
  color: var(--emerald);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.cli-box code {
  display: block;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 11px;
  color: #f8fafc;
  word-break: break-all;
}

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

.proof-item {
  background: rgba(17, 24, 47, 0.72);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

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

.proof-h {
  font-size: 11px;
  font-weight: 700;
  color: var(--cyan);
  margin-bottom: 3px;
}

.proof-p {
  font-size: 10.5px;
  line-height: 1.4;
  color: #cbd5e1;
}
