:root {
  --bg: #070912;
  --panel: #0e1324;
  --panel-2: #131a31;
  --border: #233054;
  --border-hi: #3a4f86;
  --text: #e8efff;
  --muted: #93a7cf;
  --cyan: #38e8ff;
  --mint: #3ef2b2;
  --gold: #ffd166;
  --magenta: #ff5ec4;
  --violet: #a78bfa;
  --crimson: #ff5c7a;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at 18% 12%, #111936 0%, var(--bg) 62%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  line-height: 1.38;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Single-row 1024px-safe top header */
.topbar {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  background: rgba(11, 16, 32, 0.94);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

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

.brand-badge {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 15px;
  color: #06101d;
  background: linear-gradient(135deg, var(--cyan), var(--mint));
  box-shadow: 0 0 14px rgba(56, 232, 255, 0.42);
}

.brand-title {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--text);
  white-space: nowrap;
}

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

.tab-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(20, 28, 52, 0.72);
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s ease;
}

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

.tab-btn.active {
  background: linear-gradient(135deg, rgba(56, 232, 255, 0.2), rgba(62, 242, 178, 0.14));
  border-color: var(--cyan);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(56, 232, 255, 0.24);
}

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

.ext-pill, .proofs-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 5px 7px;
  border-radius: 7px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.14s ease;
}

.ext-pill {
  color: var(--gold);
  background: rgba(255, 209, 102, 0.09);
  border: 1px solid rgba(255, 209, 102, 0.34);
}

.ext-pill:hover {
  background: rgba(255, 209, 102, 0.2);
  border-color: var(--gold);
}

.ext-pill.se-link {
  color: var(--violet);
  background: rgba(167, 139, 250, 0.1);
  border-color: rgba(167, 139, 250, 0.38);
}

.ext-pill.se-link:hover {
  background: rgba(167, 139, 250, 0.22);
  border-color: var(--violet);
}

.proofs-btn {
  border: 1px solid rgba(62, 242, 178, 0.45);
  background: rgba(62, 242, 178, 0.12);
  color: var(--mint);
}

.proofs-btn:hover {
  background: rgba(62, 242, 178, 0.24);
  border-color: var(--mint);
}

/* Main workspace */
.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 298px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: linear-gradient(180deg, rgba(16, 22, 42, 0.94), rgba(11, 15, 30, 0.96));
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  overflow-y: auto;
}

.chamber-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--cyan);
}

.chamber-title {
  font-size: 14.5px;
  font-weight: 800;
  color: #ffffff;
  line-height: 1.2;
}

.chamber-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.32;
}

/* 4-card stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.stat-card {
  background: rgba(19, 27, 50, 0.88);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 7px;
  min-width: 0;
}

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

.stat-val {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cyan);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-val.mint { color: var(--mint); }
.stat-val.gold { color: var(--gold); }
.stat-val.magenta { color: var(--magenta); }
.stat-val.crimson { color: var(--crimson); }

/* Controls */
.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-top: 1px;
}

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

.ctrl-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.ctrl-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.ctrl-readout {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
}

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

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

.seg-btn, .act-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(20, 29, 55, 0.85);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
}

.seg-btn:hover, .act-btn:hover {
  border-color: var(--cyan);
  color: var(--text);
}

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

.act-btn.primary {
  background: rgba(62, 242, 178, 0.14);
  border-color: rgba(62, 242, 178, 0.5);
  color: var(--mint);
}

.act-btn.primary:hover {
  background: rgba(62, 242, 178, 0.26);
}

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

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

.toggle-chip input {
  accent-color: var(--mint);
  cursor: pointer;
}

/* Theorem box */
.theorem-box {
  margin-top: auto;
  background: linear-gradient(135deg, rgba(22, 31, 60, 0.9), rgba(14, 21, 42, 0.95));
  border: 1px solid rgba(56, 232, 255, 0.28);
  border-left: 3px solid var(--cyan);
  border-radius: 8px;
  padding: 7px 8px;
}

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

.theorem-body {
  font-size: 10.5px;
  color: #d6e4ff;
  line-height: 1.31;
}

/* Right stage */
.stage-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.canvas-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(13, 19, 36, 0.96), rgba(8, 12, 24, 0.98));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  min-height: 0;
}

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

.sub-row {
  height: 192px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.card-hdr {
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  background: rgba(18, 25, 48, 0.85);
  border-bottom: 1px solid rgba(35, 48, 84, 0.85);
}

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

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

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

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

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

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

.modal-dialog {
  width: min(760px, 100%);
  max-height: 90vh;
  background: #0e1427;
  border: 1px solid var(--border-hi);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-hdr h2 {
  font-size: 14.5px;
  font-weight: 800;
  color: #ffffff;
}

.close-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

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

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

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

.modal-intro {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.cli-box {
  flex-shrink: 0;
  background: #080c19;
  border: 1px solid rgba(56, 232, 255, 0.4);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--mint);
  overflow-x: auto;
  white-space: nowrap;
}

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

.proof-card {
  background: rgba(18, 26, 48, 0.85);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.proof-card h3 {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--cyan);
  margin-bottom: 4px;
}

.proof-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: #d6e4ff;
}

.proof-card li strong {
  color: var(--gold);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px;
}

.modal-footer-note {
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
