:root {
  --bg: #050811;
  --panel: #0b1121;
  --panel-hi: #101930;
  --border: rgba(94, 234, 212, 0.16);
  --border-hi: rgba(56, 232, 255, 0.38);
  --text: #e6f0ff;
  --muted: #8ea3c5;
  --cyan: #38e8ff;
  --magenta: #f472b6;
  --gold: #fbbf24;
  --emerald: #34d399;
  --violet: #a78bfa;
  --rose: #fb7185;
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 18% 12%, #0e1933 0%, #050811 58%, #03050c 100%);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Single-row compact topbar (strictly <= 1024px safe) */
.topbar {
  height: 46px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(7, 11, 23, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

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

.brand-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, rgba(56, 232, 255, 0.22), rgba(251, 191, 36, 0.25));
  border: 1px solid rgba(56, 232, 255, 0.5);
  color: var(--gold);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: -0.02em;
  box-shadow: 0 0 12px rgba(56, 232, 255, 0.22);
}

.brand-title {
  font-weight: 700;
  font-size: 13.5px;
  letter-spacing: 0.01em;
  background: linear-gradient(90deg, #e6f0ff, #38e8ff 65%, #fbbf24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.tab {
  background: rgba(15, 23, 42, 0.72);
  color: var(--muted);
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  border-color: rgba(56, 232, 255, 0.35);
}

.tab.active {
  color: #04101f;
  background: linear-gradient(135deg, #38e8ff, #60a5fa);
  border-color: #7dd3fc;
  box-shadow: 0 0 14px rgba(56, 232, 255, 0.32);
}

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

.nav-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.2);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

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

.atlas-pill {
  color: var(--gold);
  border-color: rgba(251, 191, 36, 0.38);
  background: rgba(251, 191, 36, 0.08);
}

.atlas-pill:hover {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.72);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.22);
}

.proofs-btn {
  color: var(--emerald);
  border-color: rgba(52, 211, 153, 0.42);
  background: rgba(52, 211, 153, 0.1);
}

.proofs-btn:hover {
  color: #a7f3d0;
  border-color: rgba(52, 211, 153, 0.78);
}

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

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

.canvas-card {
  background: linear-gradient(180deg, rgba(14, 22, 42, 0.94), rgba(8, 13, 27, 0.96));
  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 24px rgba(0, 0, 0, 0.35);
}

.main-card {
  flex: 1.48;
}

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

.card-head {
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(6, 10, 21, 0.55);
  flex-shrink: 0;
}

.card-title-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.chamber-tag {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--cyan);
  background: rgba(56, 232, 255, 0.11);
  border: 1px solid rgba(56, 232, 255, 0.3);
  border-radius: 4px;
  padding: 2px 5px;
  flex-shrink: 0;
}

.card-head h1 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-head h2 {
  font-size: 11.5px;
  font-weight: 700;
  color: #cfe0ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.canvas-hint {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sub-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}

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

.canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* 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: linear-gradient(180deg, rgba(16, 25, 48, 0.92), rgba(9, 15, 31, 0.94));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 0;
}

.stat-label {
  font-family: var(--font-mono);
  font-size: 9.2px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel {
  background: linear-gradient(180deg, rgba(14, 22, 42, 0.94), rgba(8, 13, 27, 0.96));
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 9px;
  min-width: 0;
}

.controls-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow-y: auto;
  min-height: 0;
}

.controls-panel::-webkit-scrollbar {
  width: 5px;
}

.controls-panel::-webkit-scrollbar-thumb {
  background: rgba(56, 232, 255, 0.25);
  border-radius: 4px;
}

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

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

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

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

.btn-grid.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ctrl-btn {
  background: rgba(15, 23, 42, 0.88);
  color: #b7c9e8;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 10.8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.14s ease;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctrl-btn:hover {
  color: var(--text);
  border-color: rgba(56, 232, 255, 0.45);
}

.ctrl-btn.active {
  color: #031120;
  background: linear-gradient(135deg, #38e8ff, #34d399);
  border-color: #67e8f9;
  font-weight: 700;
}

.ctrl-btn.accent-btn {
  color: #161003;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-color: #fde68a;
  font-weight: 700;
}

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

.ctrl-note {
  font-size: 10.5px;
  line-height: 1.38;
  color: var(--muted);
  background: rgba(5, 10, 22, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 6px;
  padding: 5px 7px;
}

.theorem-panel {
  flex-shrink: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 5px;
}

.theorem-kicker {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold);
}

.verify-pill {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
  color: var(--emerald);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.36);
  border-radius: 4px;
  padding: 1px 5px;
}

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

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 15, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 999;
}

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

.modal {
  width: min(880px, 96vw);
  max-height: 90vh;
  background: #091022;
  border: 1px solid rgba(56, 232, 255, 0.36);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
}

.modal-head {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(6, 10, 21, 0.85);
  flex-shrink: 0;
}

.modal-kicker {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--emerald);
  margin-bottom: 2px;
}

.modal-head h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.close-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.close-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

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

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

.modal-intro {
  font-size: 12.2px;
  line-height: 1.48;
  color: #c8d8f4;
}

.cli-box {
  flex-shrink: 0;
  background: #040812;
  border: 1px solid rgba(56, 232, 255, 0.35);
  border-radius: 8px;
  padding: 9px 12px;
}

.cli-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  color: var(--gold);
  margin-bottom: 4px;
}

.cli-box pre {
  margin: 0;
  overflow-x: auto;
  white-space: pre;
}

.cli-box code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--cyan);
}

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

.proof-card {
  background: rgba(13, 21, 41, 0.88);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 8px;
  padding: 9px 11px;
}

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

.proof-card h3 {
  font-size: 11.8px;
  font-weight: 700;
  color: var(--cyan);
  margin-bottom: 5px;
}

.proof-card ul {
  padding-left: 15px;
  display: flex;
  flex-direction: column;
  gap: 3.5px;
}

.proof-card li {
  font-size: 11px;
  line-height: 1.38;
  color: #c8d8f4;
}

.proof-card strong {
  color: var(--gold);
}
