/**
 * math-visual-v2.css
 * Publication-Grade CAD / TikZ Studio Aesthetic (Prototype v2 Exact Match)
 * Supports Dark CAD Blueprint Theme & Light Paper SGK Theme, 24px Engineering Grid,
 * Single-Bar Executive Header, Scenario Pills, Live Mathematical Inspector,
 * and Flawless Responsive Layout (320px Mobile -> 820px Tablet -> 1440px+ Desktop).
 *
 * Strict adherence to SOLID, KISS, DRY (<= 450 lines).
 * Official branding: AUTOGRADING.
 */

/* --- 1. Theme Tokens --- */
#math-visual-studio-view {
  --mv-bg: #141722;
  --mv-card: #1b1f2d;
  --mv-header: #212534;
  --mv-border: #2e3448;
  --mv-fg: #f8fafc;
  --mv-muted: #94a3b8;
  --mv-secondary: #282e42;
  --mv-secondary-fg: #e2e8f0;
  --mv-primary: #b794f4;
  --mv-primary-hover: #c4b5fd;
  --mv-primary-fg: #141622;
  --mv-grid-line: rgba(148, 163, 184, 0.11);
  gap: 0 !important;
  max-width: 1480px;
  margin: 0 auto;
  background: var(--mv-card);
  color: var(--mv-fg);
  border: 1px solid var(--mv-border);
  border-radius: 16px;
  box-shadow: 0 18px 42px -12px rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

/* Dedicated /tools/math-visual Shell Optimization & Zero Floating-Widget Collision */
html.math-visual-mode .workspace-container,
body.math-visual-mode .workspace-container,
body.unauthenticated.math-visual-mode .workspace-container {
  padding: 0.6rem 1rem !important;
  max-width: 1520px !important;
}

html.math-visual-mode #ag-support-fab,
body.math-visual-mode #ag-support-fab,
body:has(#math-visual-studio-view:not([style*="display: none"])) #ag-support-fab {
  display: none !important;
}

#math-visual-studio-view.mv-theme-light,
[data-theme="light"] #math-visual-studio-view:not(.mv-theme-dark) {
  --mv-bg: #f8fafc;
  --mv-card: #ffffff;
  --mv-header: #f1f5f9;
  --mv-border: #e2e8f0;
  --mv-fg: #0f172a;
  --mv-muted: #64748b;
  --mv-secondary: #eef2ff;
  --mv-secondary-fg: #1e293b;
  --mv-primary: #4f46e5;
  --mv-primary-hover: #4338ca;
  --mv-primary-fg: #ffffff;
  --mv-grid-line: rgba(148, 163, 184, 0.16);
  box-shadow: 0 10px 28px -8px rgba(15, 23, 42, 0.10);
}

/* --- 2. Top Studio Header Bar --- */
#math-visual-studio-view .math-visual-header {
  position: relative; display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 0.55rem 0.85rem;
  padding: 0.65rem 1rem !important; background: var(--mv-header) !important;
  border: none !important; border-bottom: 1px solid var(--mv-border) !important;
  border-radius: 0 !important; box-shadow: none !important;
}
#math-visual-studio-view .math-visual-header-title {
  display: flex; align-items: center; gap: 0.6rem; min-width: 0; flex: 1 1 320px;
}
#math-visual-studio-view .mv-back-btn {
  display: inline-flex !important; align-items: center; gap: 0.28rem;
  padding: 0.34rem 0.62rem !important; min-height: 35px !important; border-radius: 10px !important;
  background: var(--mv-bg) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.76rem !important;
  font-weight: 700 !important; flex-shrink: 0;
}
#math-visual-studio-view .mv-back-btn:hover { border-color: var(--mv-primary) !important; }
#math-visual-studio-view .mv-brand-icon-box {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--mv-primary); color: var(--mv-primary-fg);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem; font-weight: 800; flex-shrink: 0;
}
#math-visual-studio-view .mv-header-text-wrap { min-width: 0; }
#math-visual-studio-view .mv-header-title-row { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; }
#math-visual-studio-view .math-visual-title {
  font-size: 0.94rem !important; font-weight: 800 !important;
  color: var(--mv-fg) !important; margin: 0 !important; line-height: 1.28;
}
#math-visual-studio-view .mv-pill-badge {
  padding: 0.14rem 0.5rem; border-radius: 6px; font-size: 0.71rem; font-weight: 700;
  background: var(--mv-secondary); color: var(--mv-secondary-fg);
  border: 1px solid var(--mv-border); white-space: nowrap;
}
#math-visual-studio-view .badge-autograding-3d { display: none; }
#math-visual-studio-view .math-visual-subtitle {
  font-size: 0.73rem !important; color: var(--mv-muted) !important;
  margin-top: 0.12rem; line-height: 1.32;
}
#math-visual-studio-view .math-visual-actions-group {
  position: relative; display: flex !important; flex-wrap: wrap; align-items: center; gap: 0.4rem !important;
}
#math-visual-studio-view .visual-quota-capsule {
  cursor: pointer; display: inline-flex !important; align-items: center; gap: 0.32rem;
  padding: 0.34rem 0.68rem !important; min-height: 35px; border-radius: 10px !important;
  background: var(--mv-bg) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.74rem !important;
  font-weight: 700 !important; white-space: nowrap;
}
#math-visual-studio-view .mv-hdr-btn {
  min-height: 35px !important; padding: 0.34rem 0.68rem !important; border-radius: 10px !important;
  background: var(--mv-bg) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.75rem !important;
  font-weight: 700 !important; white-space: nowrap;
}
#math-visual-studio-view .mv-hdr-btn:hover { border-color: var(--mv-primary) !important; }
#math-visual-studio-view .mv-hdr-btn-accent {
  border-color: rgba(183, 148, 244, 0.48) !important;
  background: var(--mv-secondary) !important;
  color: var(--mv-secondary-fg) !important;
}
#math-visual-studio-view.mv-theme-light .mv-hdr-btn-accent {
  border-color: rgba(79, 70, 229, 0.38) !important;
  color: #3730a3 !important;
}
#math-visual-studio-view .mv-hdr-btn-violet {
  min-height: 35px !important; padding: 0.34rem 0.78rem !important; border-radius: 10px !important;
  background: var(--mv-primary) !important; color: var(--mv-primary-fg) !important;
  border: 1px solid transparent !important; font-size: 0.75rem !important; font-weight: 800 !important;
  display: inline-flex !important; align-items: center; gap: 0.32rem; white-space: nowrap;
}
#math-visual-studio-view .mv-lib-count-badge {
  background: rgba(20, 22, 34, 0.22); color: inherit;
  font-size: 0.68rem; padding: 0.04rem 0.36rem; border-radius: 999px; font-weight: 800;
}
#math-visual-studio-view .math-visual-mobile-more-btn { display: inline-flex !important; }
#math-visual-studio-view .math-visual-secondary-actions {
  display: none !important; position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  min-width: 220px; padding: 0.55rem; background: var(--mv-card); border: 1px solid var(--mv-border);
  border-radius: 12px; box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45); flex-direction: column; gap: 0.35rem;
}
#math-visual-studio-view .math-visual-secondary-actions.is-open { display: flex !important; }
#math-visual-studio-view .math-visual-secondary-actions .btn,
#math-visual-studio-view .math-visual-secondary-actions .mv-compact-select {
  width: 100%; justify-content: flex-start; min-height: 34px; padding: 0.35rem 0.65rem;
  border-radius: 8px; background: var(--mv-bg) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.78rem; font-weight: 600;
}
#modal-geometry-library .geom-library-sort-select {
  width: auto !important; min-height: 32px !important; padding: 0.24rem 0.6rem !important;
  border-radius: 8px !important; background: #f8fafc !important; color: #0f172a !important;
  border: 1px solid #cbd5e1 !important; font-size: 0.76rem !important; font-weight: 600 !important;
}

/* --- 3. Problem Statement + 3 Benchmark Scenario Pills --- */
#math-visual-studio-view .math-visual-problem-capsule {
  display: flex; flex-direction: column; gap: 0.6rem;
  margin: 0 !important; border-radius: 0 !important; box-shadow: none !important;
  border-top: none !important; border-left: none !important; border-right: none !important;
  padding: 0.75rem 1.1rem !important; background: var(--mv-bg) !important;
  border-bottom: 1px solid var(--mv-border) !important;
}
#math-visual-studio-view .math-visual-problem-summary {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 0.75rem; padding: 0 !important; cursor: pointer; position: static !important;
}
#math-visual-studio-view .math-visual-problem-summary-left {
  display: flex; align-items: flex-start; gap: 0.6rem; min-width: 0; flex: 1;
}
#math-visual-studio-view .math-visual-problem-summary-right {
  position: static !important; flex-shrink: 0;
}
#math-visual-studio-view .math-visual-problem-badge {
  padding: 0.22rem 0.55rem !important; border-radius: 6px !important;
  background: var(--mv-secondary) !important; color: var(--mv-secondary-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.74rem !important;
  font-weight: 700 !important; white-space: nowrap; flex-shrink: 0; margin-top: 0.08rem;
}
#math-visual-studio-view .math-visual-problem-preview {
  font-size: 0.8rem !important; color: var(--mv-fg) !important; line-height: 1.48 !important;
  white-space: normal !important; overflow: visible !important; text-overflow: unset !important; font-weight: 500 !important;
}
#math-visual-studio-view .mv-edit-prompt-btn {
  padding: 0.28rem 0.6rem !important; border-radius: 8px !important;
  background: var(--mv-card) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.74rem !important;
  font-weight: 700 !important; white-space: nowrap;
}
#math-visual-studio-view .mv-scenario-pills-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem;
}
#math-visual-studio-view .mv-scen-label {
  font-size: 0.74rem; font-weight: 700; color: var(--mv-muted); margin-right: 0.1rem; white-space: nowrap;
}
#math-visual-studio-view .mv-scen-btn {
  padding: 0.42rem 0.75rem; min-height: 34px; border-radius: 9px;
  background: var(--mv-card); color: var(--mv-fg); border: 1px solid var(--mv-border);
  font-size: 0.76rem; font-weight: 600; cursor: pointer; transition: all 0.15s ease;
}
#math-visual-studio-view .mv-scen-btn:hover { border-color: var(--mv-primary); }
#math-visual-studio-view .mv-scen-btn.active {
  background: var(--mv-primary); color: var(--mv-primary-fg); border-color: transparent; font-weight: 800;
}

/* --- 4. Split-Studio Grid & Precision Bar --- */
#math-visual-studio-view .math-visual-layout {
  display: grid; grid-template-columns: minmax(0, 7.2fr) minmax(410px, 4.8fr); gap: 0 !important; align-items: stretch;
}
#math-visual-studio-view .math-visual-viewport-wrapper {
  display: flex; flex-direction: column; min-width: 0; width: 100%; max-width: 100%; padding: 0 !important; background: var(--mv-card) !important;
  border: none !important; border-right: 1px solid var(--mv-border) !important;
  border-radius: 0 !important; box-shadow: none !important; overflow: hidden !important; box-sizing: border-box;
}
#math-visual-studio-view .math-visual-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 0.42rem 0.6rem; padding: 0.48rem 0.85rem !important; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box;
  background: var(--mv-card) !important; border-bottom: 1px solid var(--mv-border) !important;
}
#math-visual-studio-view .mv-precision-left {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.38rem; flex: 1 1 auto; min-width: 0;
}
#math-visual-studio-view .mv-precision-right {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.38rem; flex: 0 1 auto;
}
#math-visual-studio-view .math-visual-constraint-badge {
  display: inline-flex; align-items: center; padding: 0.28rem 0.65rem; border-radius: 8px;
  background: var(--mv-secondary); color: var(--mv-secondary-fg);
  border: 1px solid var(--mv-border); font-size: 0.74rem; font-weight: 700; white-space: nowrap; flex-shrink: 0;
}
#math-visual-studio-view .math-visual-constraint-badge[data-status="warning"] {
  background: rgba(245, 158, 11, 0.16); color: #fbbf24; border-color: rgba(245, 158, 11, 0.35);
}
#math-visual-studio-view .mv-hint-pill {
  display: inline-flex; align-items: center; padding: 0.28rem 0.65rem; border-radius: 8px;
  background: var(--mv-bg); color: var(--mv-muted); border: 1px solid var(--mv-border);
  font-size: 0.74rem; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#math-visual-studio-view .mv-cavalier-control {
  display: inline-flex; align-items: center; flex-wrap: nowrap; gap: 0.42rem;
  padding: 0.22rem 0.62rem; border-radius: 8px; background: var(--mv-bg);
  border: 1px solid var(--mv-border); font-size: 0.74rem; font-weight: 700; color: var(--mv-fg); white-space: nowrap;
}
#math-visual-studio-view .mv-cavalier-control label {
  display: inline !important; margin: 0 !important; white-space: nowrap !important; color: var(--mv-fg) !important; font-size: 0.74rem !important;
}
#math-visual-studio-view .mv-cavalier-control input[type="range"] {
  width: 88px !important; min-width: 88px !important; margin: 0 !important; flex-shrink: 0; accent-color: var(--mv-primary);
}
#math-visual-studio-view .mv-tool-chip {
  min-height: 31px; padding: 0.25rem 0.62rem; border-radius: 8px;
  background: var(--mv-bg); color: var(--mv-fg); border: 1px solid var(--mv-border);
  font-size: 0.74rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
#math-visual-studio-view .mv-tool-chip.active { border-color: var(--mv-primary); }

#math-visual-studio-view .mv-theme-mode-segmented {
  display: inline-flex;
  align-items: center;
  background: var(--mv-bg);
  border: 1px solid var(--mv-border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
#math-visual-studio-view .mv-theme-chip {
  min-height: 27px !important;
  padding: 0.2rem 0.55rem !important;
  border: none !important;
  border-radius: 6px !important;
  background: transparent !important;
  color: var(--mv-muted) !important;
  font-size: 0.72rem !important;
  font-weight: 600 !important;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
#math-visual-studio-view .mv-theme-chip:hover {
  color: var(--mv-fg) !important;
  background: rgba(148, 163, 184, 0.12) !important;
}
#math-visual-studio-view .mv-theme-chip.active {
  background: var(--mv-primary) !important;
  color: var(--mv-primary-fg) !important;
  font-weight: 700 !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

/* --- 5. Blueprint Grid Canvas, 3D Toolbar & Interactive CAD Viewport --- */
#math-visual-studio-view .math-visual-interactive-toolbar {
  padding: 0.48rem 0.9rem !important; background: var(--mv-bg) !important;
  border-bottom: 1px solid var(--mv-border) !important; border-radius: 0 !important; margin: 0 !important;
}
#math-visual-studio-view .math-visual-interactive-toolbar .btn {
  min-height: 31px !important; padding: 0.25rem 0.62rem !important; border-radius: 8px !important;
  font-size: 0.74rem !important; font-weight: 700 !important;
  background: var(--mv-card) !important; color: var(--mv-fg) !important; border: 1px solid var(--mv-border) !important;
}
#math-visual-studio-view .math-visual-interactive-toolbar .btn.active,
#math-visual-studio-view .math-visual-interactive-toolbar .btn.btn-primary {
  background: var(--mv-primary) !important; color: var(--mv-primary-fg) !important; border-color: transparent !important;
}
#math-visual-studio-view .mv-canvas-stage {
  position: relative; width: 100%; min-height: 420px; flex: 1 1 auto; background-color: var(--mv-bg);
  display: flex; flex-direction: column; align-items: stretch; justify-content: center; overflow: hidden;
}
#math-visual-studio-view .mv-canvas-stage.blueprint-grid {
  background-image:
    linear-gradient(to right, var(--mv-grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--mv-grid-line) 1px, transparent 1px);
  background-size: 24px 24px;
}
#math-visual-studio-view .math-visual-canvas-box {
  width: 100%; height: 100%; flex: 1 1 auto; min-height: 360px; background: transparent !important;
}
#math-visual-studio-view .math-visual-svg-viewport {
  position: relative; z-index: 4; width: 100%; height: 100%; flex: 1 1 auto; align-self: stretch;
  min-height: 410px; background: transparent;
  display: flex; align-items: center; justify-content: center; padding: 0.65rem 0.85rem 2.65rem;
  cursor: grab; overflow: hidden; touch-action: none;
}
#math-visual-studio-view .math-visual-svg-viewport.is-panning,
#math-visual-studio-view .math-visual-svg-viewport.is-dragging-point { cursor: grabbing; }
#math-visual-studio-view .math-visual-svg-viewport svg {
  width: 100%; height: 100%; max-width: 100%; max-height: 100%;
  overflow: visible; user-select: none; touch-action: none;
  will-change: transform;
}
#math-visual-studio-view .math-visual-svg-viewport .geom-edge-line { transition: stroke-width 0.12s ease; cursor: pointer; }
#math-visual-studio-view .math-visual-svg-viewport .geom-edge-line:hover { stroke-width: 3.1px; }
#math-visual-studio-view .mv-hover-hud {
  position: absolute; top: 10px; left: 12px; z-index: 9; pointer-events: none;
  padding: 0.28rem 0.65rem; border-radius: 8px; background: var(--mv-card); color: var(--mv-fg);
  border: 1px solid var(--mv-primary); font-size: 0.74rem; font-weight: 700; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}
#math-visual-studio-view .mv-cad-hud {
  position: absolute; right: 12px; bottom: 10px; z-index: 9; display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.26rem 0.42rem; border-radius: 10px; background: var(--mv-card); border: 1px solid var(--mv-border);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28); opacity: 0.94;
}
#math-visual-studio-view .mv-cad-hint {
  font-size: 0.69rem; font-weight: 600; color: var(--mv-muted); padding: 0 0.35rem; white-space: nowrap;
}
#math-visual-studio-view .mv-cad-btn {
  min-width: 28px; height: 27px; padding: 0 0.45rem; border-radius: 7px; border: 1px solid var(--mv-border);
  background: var(--mv-bg); color: var(--mv-fg); font-size: 0.76rem; font-weight: 800; cursor: pointer;
}
#math-visual-studio-view .mv-cad-btn:hover { border-color: var(--mv-primary); }
#math-visual-studio-view .mv-cad-btn-reset { min-width: 52px; font-size: 0.71rem; }
@media (max-width: 640px) { #math-visual-studio-view .mv-cad-hint { display: none; } }

/* --- 6. Construction Stepper Bar --- */
#math-visual-studio-view .math-visual-timeline-bar {
  display: flex; flex-direction: column; gap: 0.45rem; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; overflow: hidden;
  padding: 0.75rem 1rem !important; background: var(--mv-card) !important; border-top: 1px solid var(--mv-border) !important;
}
#math-visual-studio-view .mv-stepper-top-row {
  display: flex !important; flex-wrap: wrap !important; align-items: center; justify-content: space-between !important; gap: 0.5rem; width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box;
}
#math-visual-studio-view .mv-stepper-nav-group {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; min-width: 0; max-width: 100%;
}
#math-visual-studio-view .mv-stepper-pills-right {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.45rem; min-width: 0; max-width: 100%; flex: 1 1 auto;
}
#math-visual-studio-view .mv-step-btn-outline {
  min-height: 35px; padding: 0.35rem 0.75rem; border-radius: 9px;
  background: var(--mv-bg); color: var(--mv-fg); border: 1px solid var(--mv-border);
  font-size: 0.76rem; font-weight: 700; cursor: pointer;
}
#math-visual-studio-view .mv-step-btn-violet {
  min-height: 35px; padding: 0.35rem 0.8rem; border-radius: 9px;
  background: var(--mv-primary); color: var(--mv-primary-fg); border: 1px solid transparent;
  font-size: 0.76rem; font-weight: 800; cursor: pointer;
}
#math-visual-studio-view .mv-step-btn-outline:disabled,
#math-visual-studio-view .mv-step-btn-violet:disabled { opacity: 0.5; cursor: not-allowed; }
#math-visual-studio-view .math-visual-step-badge {
  background: transparent !important; color: var(--mv-fg) !important; border: none !important;
  font-size: 0.78rem !important; font-weight: 800 !important; padding: 0 0.25rem !important;
}
#math-visual-studio-view .mv-number-pills,
#math-visual-studio-view #math-visual-stepper-container {
  display: flex !important; flex-wrap: wrap !important; align-items: center !important; justify-content: flex-start !important; gap: 0.3rem !important;
  padding: 0.1rem 0 !important; background: transparent !important; border: none !important; box-shadow: none !important;
  max-width: 100% !important; min-width: 0 !important; flex: 1 1 240px !important; white-space: normal !important; box-sizing: border-box !important;
}
#math-visual-studio-view .math-visual-stepper-dot {
  width: 28px !important; height: 28px !important; min-width: 28px !important; min-height: 28px !important;
  border-radius: 8px !important; background: var(--mv-bg) !important; color: var(--mv-muted) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.75rem !important; font-weight: 800 !important;
  transform: none !important; box-shadow: none !important;
}
#math-visual-studio-view .math-visual-stepper-dot.completed {
  background: var(--mv-secondary) !important; color: var(--mv-fg) !important; border-color: var(--mv-border) !important;
}
#math-visual-studio-view .math-visual-stepper-dot.active {
  background: var(--mv-primary) !important; color: var(--mv-primary-fg) !important; border-color: transparent !important;
}
#math-visual-studio-view .math-visual-speed-select {
  width: auto !important; min-width: 62px; height: 30px !important; padding: 0.15rem 0.45rem !important;
  border-radius: 7px !important; background: var(--mv-bg) !important; color: var(--mv-fg) !important;
  border: 1px solid var(--mv-border) !important; font-size: 0.75rem !important; font-weight: 700 !important;
}
#math-visual-studio-view .math-visual-step-desc {
  font-size: 0.76rem !important; color: var(--mv-muted) !important; font-weight: 500 !important; white-space: normal !important;
}
#math-visual-studio-view .math-visual-slider-row { display: none !important; }

/* --- 7. Right Inspector Column --- */
#math-visual-studio-view .math-visual-sidebar {
  display: flex; flex-direction: column; min-width: 0; gap: 0 !important; max-height: none !important;
  min-height: auto !important; padding: 0 !important; background: var(--mv-card); overflow: visible;
}
#math-visual-studio-view .mv-inspector-section {
  padding: 0.9rem 1.05rem; border-bottom: 1px solid var(--mv-border);
  display: flex; flex-direction: column; gap: 0.6rem;
}
#math-visual-studio-view .mv-inspector-grow { flex: 1; border-bottom: none; justify-content: flex-start; }
#math-visual-studio-view .mv-inspector-heading-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap;
}
#math-visual-studio-view .mv-inspector-grow > .mv-inspector-heading-row {
  position: sticky; top: 0; z-index: 8; background: var(--mv-card);
  margin-top: -0.9rem; padding-top: 0.9rem; padding-bottom: 0.45rem;
}
#math-visual-studio-view .mv-inspector-heading {
  margin: 0; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--mv-muted);
}
#math-visual-studio-view .mv-cas-badge {
  padding: 0.16rem 0.5rem; border-radius: 6px; font-size: 0.7rem; font-weight: 800;
  background: var(--mv-secondary); color: var(--mv-secondary-fg); border: 1px solid var(--mv-border); white-space: nowrap;
}
#math-visual-studio-view .mv-constraint-list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.32rem;
}
#math-visual-studio-view .mv-constraint-item {
  padding: 0.36rem 0.62rem; border-radius: 7px; background: var(--mv-bg);
  border: 1px solid var(--mv-border); color: var(--mv-fg); font-size: 0.73rem; font-weight: 600; line-height: 1.35;
}
#math-visual-studio-view .mv-accuracy-box {
  display: flex; flex-direction: column; gap: 0.42rem; margin-top: auto; padding-top: 0.5rem; border-top: 1px dashed var(--mv-border);
}
#math-visual-studio-view .mv-tikz-actions-row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap;
  margin-top: 0.45rem; font-size: 0.72rem; color: var(--mv-muted);
}
#math-visual-studio-view .mv-proof-cards { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
#math-visual-studio-view .mv-proof-mode-bar {
  display: flex; gap: 0.35rem;
  position: sticky; top: 2.3rem; z-index: 7; background: var(--mv-card);
  padding: 0.35rem 0 0.45rem; margin-bottom: 0.15rem !important;
  border-bottom: 1px solid var(--mv-border);
}
#math-visual-studio-view .mv-premise-steps-chips {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px;
  max-height: 152px; overflow-y: auto; padding-right: 4px; overscroll-behavior: contain; scrollbar-width: thin;
}
#math-visual-studio-view .mv-premise-step-chip.is-active {
  background: #2563eb !important; color: #ffffff !important; border-color: #1d4ed8 !important; box-shadow: 0 1px 4px rgba(37, 99, 235, 0.35);
}
#math-visual-studio-view .mv-proof-mode-btn {
  flex: 1; padding: 0.36rem 0.55rem; border-radius: 8px;
  border: 1px solid var(--mv-border); background: var(--mv-bg); color: var(--mv-muted);
  font-size: 0.74rem; font-weight: 700; cursor: pointer; transition: all 0.15s ease;
}
#math-visual-studio-view .mv-proof-mode-btn.active {
  border-color: #3b82f6; background: #2563eb; color: #ffffff;
}
#math-visual-studio-view .mv-diagram-layer-segmented {
  display: inline-flex; flex-wrap: wrap; flex-shrink: 0; align-items: center; gap: 3px; padding: 2px;
  border-radius: 9px; background: var(--mv-bg); border: 1px solid var(--mv-border); max-width: 100%;
}
#math-visual-studio-view .mv-layer-chip {
  border: 1px solid transparent !important; border-radius: 7px !important;
  padding: 0.22rem 0.58rem !important; font-size: 0.73rem !important; font-weight: 700 !important;
}
#math-visual-studio-view .mv-layer-chip.active[data-mv-layer-mode="premise"] {
  background: var(--mv-primary) !important; color: var(--mv-primary-fg) !important;
}
#math-visual-studio-view .mv-layer-chip.active[data-mv-layer-mode="proof"] {
  background: #d97706 !important; color: #ffffff !important;
}
#math-visual-studio-view .mv-aux-sync-banner {
  padding: 0.42rem 0.68rem; border-radius: 8px; cursor: pointer;
  background: rgba(245, 158, 11, 0.13); border: 1px dashed rgba(245, 158, 11, 0.55);
  color: var(--mv-fg); font-size: 0.74rem; font-weight: 700; line-height: 1.38;
}
#math-visual-studio-view .mv-proof-steps-list {
  display: flex; flex-direction: column; gap: 0.38rem; margin-top: 0.35rem;
}
#math-visual-studio-view .mv-step-nav-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 0.35rem;
  margin-top: 0.32rem; padding: 0.22rem 0.3rem; border-radius: 7px;
  background: var(--mv-bg); border: 1px solid var(--mv-border);
}
#math-visual-studio-view .mv-step-nav-btn {
  padding: 0.18rem 0.48rem; border-radius: 6px; border: 1px solid var(--mv-border);
  background: var(--mv-card); color: var(--mv-fg); font-size: 0.69rem; font-weight: 700; cursor: pointer;
}
#math-visual-studio-view .mv-step-nav-btn:hover { border-color: #f59e0b; color: #f59e0b; }
#math-visual-studio-view .mv-step-nav-status { font-size: 0.69rem; color: var(--mv-muted); font-weight: 600; text-align: center; }
#math-visual-studio-view .mv-proof-step-item {
  display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.46rem 0.58rem;
  border-radius: 8px; border: 1px solid var(--mv-border); background: var(--mv-card);
  cursor: pointer; transition: border-color 0.14s ease, background 0.14s ease;
}
#math-visual-studio-view .mv-proof-step-item:hover { border-color: #f59e0b; }
#math-visual-studio-view .mv-proof-step-item.is-highlighted {
  border-color: #f59e0b; background: rgba(245, 158, 11, 0.13); box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.35);
}
#math-visual-studio-view .mv-step-badge-pill {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 22px; padding: 0 0.38rem; border-radius: 6px;
  background: rgba(59, 130, 246, 0.16); color: #60a5fa; font-size: 0.7rem; font-weight: 800;
}
#math-visual-studio-view.mv-theme-light .mv-step-badge-pill { background: #dbeafe; color: #1d4ed8; }
#math-visual-studio-view .mv-proof-step-item.is-highlighted .mv-step-badge-pill {
  background: #d97706; color: #ffffff;
}
#math-visual-studio-view .mv-step-text-wrap {
  font-size: 0.76rem; color: var(--mv-fg); line-height: 1.5; min-width: 0; overflow-wrap: anywhere;
}
#math-visual-studio-view .mv-proof-synthesis-skeleton {
  padding: 0.72rem 0.82rem; border-radius: 10px;
  background: var(--mv-bg); border: 1px solid rgba(59, 130, 246, 0.38);
  display: flex; flex-direction: column; gap: 0.45rem;
}
#math-visual-studio-view .mv-skeleton-header { font-size: 0.77rem; font-weight: 800; color: #60a5fa; }
#math-visual-studio-view.mv-theme-light .mv-skeleton-header { color: #1d4ed8; }
#math-visual-studio-view .mv-skeleton-subtext { margin: 0; font-size: 0.73rem; color: var(--mv-muted); line-height: 1.42; }
#math-visual-studio-view .mv-skeleton-q-item { display: flex; flex-direction: column; gap: 0.28rem; padding-top: 0.3rem; border-top: 1px dashed var(--mv-border); }
#math-visual-studio-view .mv-skeleton-q-title { font-size: 0.75rem; font-weight: 700; color: var(--mv-fg); }
#math-visual-studio-view .mv-skeleton-bar {
  height: 9px; border-radius: 999px;
  background: linear-gradient(90deg, rgba(148,163,184,0.14) 25%, rgba(59,130,246,0.28) 50%, rgba(148,163,184,0.14) 75%);
  background-size: 200% 100%; animation: mvSkelPulse 1.5s ease-in-out infinite;
}
#math-visual-studio-view .mv-skeleton-bar-wide { width: 92%; }
#math-visual-studio-view .mv-skeleton-bar-mid { width: 68%; }
@keyframes mvSkelPulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
#math-visual-studio-view .mv-mobile-step-spotlight {
  position: absolute; top: 0.55rem; left: 0.65rem; right: 0.65rem; z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.35rem 0.65rem; border-radius: 9px;
  background: rgba(15, 23, 42, 0.88); border: 1px solid rgba(245, 158, 11, 0.55); color: #f8fafc;
  font-size: 0.74rem; font-weight: 700; backdrop-filter: blur(6px);
}
#math-visual-studio-view .mv-spotlight-actions { display: inline-flex; gap: 0.35rem; flex-shrink: 0; }
#math-visual-studio-view .mv-spotlight-btn {
  padding: 0.2rem 0.5rem; border-radius: 6px; border: 1px solid rgba(248, 250, 252, 0.28);
  background: rgba(255, 255, 255, 0.1); color: #ffffff; font-size: 0.7rem; font-weight: 700; cursor: pointer;
}
#math-visual-studio-view .mv-spotlight-back-mobile { display: none; }
#math-visual-studio-view .math-visual-problem-preview.is-expanded {
  max-height: none !important; -webkit-line-clamp: unset !important; display: block !important; overflow: visible !important;
}
#math-visual-studio-view .mv-proof-cards:not(:empty) ~ #math-visual-tabs-container,
#math-visual-studio-view .mv-proof-cards:not(:empty) ~ #math-visual-solution-container { display: none !important; }
#math-visual-studio-view .mv-proof-card {
  padding: 0.68rem 0.82rem; border-radius: 10px; background: var(--mv-bg); border: 1px solid var(--mv-border);
  transition: border-color 0.15s ease, transform 0.12s ease;
}
#math-visual-studio-view .mv-proof-card:hover { border-color: var(--mv-primary); }
#math-visual-studio-view .mv-proof-card-title { font-size: 0.78rem; font-weight: 800; color: var(--mv-fg); margin-bottom: 0.28rem; }
#math-visual-studio-view .mv-proof-card-body { margin: 0; font-size: 0.76rem; color: var(--mv-muted); line-height: 1.52; }
#math-visual-studio-view .mv-collapsible-details {
  border-radius: 9px; border: 1px solid var(--mv-border); background: var(--mv-bg);
  padding: 0.45rem 0.7rem; font-size: 0.75rem; color: var(--mv-secondary-fg);
}
#math-visual-studio-view .mv-collapsible-details summary { cursor: pointer; font-weight: 700; user-select: none; }
#math-visual-studio-view .mv-tikz-code-preview {
  margin: 0.5rem 0 0; padding: 0.6rem; border-radius: 8px; background: var(--mv-card);
  border: 1px solid var(--mv-border); color: var(--mv-fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.72rem; line-height: 1.45; overflow-x: auto;
}
#math-visual-studio-view .math-visual-pedagogical-card {
  margin-top: 0.5rem; background: var(--mv-card) !important; border: 1px solid var(--mv-border) !important;
  color: var(--mv-fg) !important; padding: 0.75rem !important;
}
#math-visual-studio-view .math-visual-pedagogical-label,
#math-visual-studio-view .math-visual-pedagogical-card h3 { color: var(--mv-fg) !important; }
#math-visual-studio-view .math-visual-pedagogical-value { color: var(--mv-muted) !important; }
#math-visual-studio-view .mv-inspector-footer-actions {
  padding-top: 0.7rem; margin-top: 0.35rem; border-top: 1px solid var(--mv-border);
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem;
}
#math-visual-studio-view .mv-inspector-footer-actions button { min-height: 38px; width: 100%; }

.geom-library-inline-dialog {
  display: none; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  padding: 0.65rem 0.85rem; margin-bottom: 0.5rem; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
}

/* --- 7b. Locus & Variable Component Control Bar --- */
#math-visual-studio-view .mv-locus-control-bar {
  display: flex; align-items: center; gap: 0.55rem; flex-wrap: wrap;
  padding: 0.42rem 0.85rem; background: var(--mv-card); border-bottom: 1px solid var(--mv-border);
}
#math-visual-studio-view .mv-locus-driver-group {
  display: inline-flex; align-items: center; gap: 0.4rem; min-width: 0;
}
#math-visual-studio-view .mv-locus-tag {
  font-size: 0.72rem; font-weight: 800; color: var(--mv-muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap;
}
#math-visual-studio-view .mv-locus-driver-badge {
  display: inline-flex; align-items: center; padding: 0.2rem 0.55rem; border-radius: 999px;
  background: rgba(168, 85, 247, 0.14); border: 1px solid rgba(168, 85, 247, 0.36);
  color: var(--mv-fg); font-size: 0.74rem; font-weight: 700; white-space: nowrap;
}
#math-visual-studio-view .mv-locus-scrub-group {
  display: flex; align-items: center; gap: 0.42rem; flex: 1 1 150px; min-width: 130px; max-width: 280px;
}
#math-visual-studio-view .mv-locus-slider {
  flex: 1; accent-color: #a855f7; cursor: pointer; height: 5px;
}
#math-visual-studio-view .mv-locus-pct {
  font-size: 0.72rem; font-weight: 800; color: var(--mv-secondary-fg); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums;
}
#math-visual-studio-view .mv-locus-actions-group {
  display: inline-flex; align-items: center; gap: 0.38rem; flex-wrap: wrap;
}
#math-visual-studio-view .mv-locus-btn {
  min-height: 30px; padding: 0.22rem 0.62rem; font-size: 0.73rem; font-weight: 700; border-radius: 7px;
}
#math-visual-studio-view .mv-locus-btn.active {
  background: rgba(168, 85, 247, 0.2) !important; border-color: #a855f7 !important; color: #c084fc !important;
}
#math-visual-studio-view.mv-theme-light .mv-locus-btn.active {
  background: rgba(124, 58, 237, 0.12) !important; border-color: #7c3aed !important; color: #6d28d9 !important;
}
#math-visual-studio-view .mv-locus-summary-pill {
  font-size: 0.72rem; font-weight: 700; color: #c084fc; background: rgba(168, 85, 247, 0.1);
  border: 1px dashed rgba(168, 85, 247, 0.42); border-radius: 6px; padding: 0.18rem 0.52rem;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#math-visual-studio-view.mv-theme-light .mv-locus-summary-pill { color: #6d28d9; }

/* --- 8. Responsive Breakpoints (320px -> 344px -> 768px -> 1032px -> 1376px -> 1440px+) --- */
.math-visual-mobile-tabs { display: none; }

@media (max-width: 1480px) {
  #math-visual-studio-view .mv-hint-pill { display: none !important; }
}

@media (min-width: 1081px) {
  #math-visual-studio-view .math-visual-problem-capsule {
    padding: 0.55rem 1rem !important;
    gap: 0.45rem;
  }
  #math-visual-studio-view .math-visual-problem-preview {
    max-height: 3.1em;
    overflow-y: auto !important;
  }
  #math-visual-studio-view .mv-canvas-stage {
    height: clamp(390px, calc(100dvh - 365px), 575px);
    min-height: 390px;
    max-height: 585px;
  }
  #math-visual-studio-view .math-visual-sidebar {
    height: 0 !important;
    min-height: 100% !important;
    max-height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }
  #math-visual-studio-view .mv-inspector-footer-actions {
    position: sticky;
    bottom: 0;
    z-index: 6;
    background: var(--mv-card);
    padding: 0.65rem 0 0.85rem;
    margin-bottom: -0.9rem;
  }
}

@media (min-width: 1081px) and (max-width: 1440px) {
  #math-visual-studio-view .math-visual-layout {
    grid-template-columns: minmax(0, 6.7fr) minmax(400px, 5.3fr);
  }
  #math-visual-studio-view .math-visual-subtitle {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

@media (max-width: 1080px) {
  #math-visual-studio-view .math-visual-layout { grid-template-columns: 1fr; }
  #math-visual-studio-view .math-visual-viewport-wrapper {
    border-right: none !important; border-bottom: 1px solid var(--mv-border) !important;
  }
  #math-visual-studio-view .mv-canvas-stage {
    height: clamp(380px, 46dvh, 520px);
  }
}

@media (max-width: 768px) {
  html.math-visual-mode .workspace-container,
  body.math-visual-mode .workspace-container,
  body.unauthenticated.math-visual-mode .workspace-container {
    padding: 0.35rem 0.45rem !important;
  }
  #math-visual-studio-view { border-radius: 12px !important; padding: 0 !important; }
  #math-visual-studio-view .math-visual-toolbar { flex-wrap: wrap; }
  #math-visual-studio-view .math-visual-problem-summary {
    flex-direction: column !important; align-items: stretch !important; gap: 0.45rem !important;
  }
  #math-visual-studio-view .math-visual-problem-summary-left {
    flex-direction: column !important; align-items: flex-start !important; gap: 0.45rem !important; width: 100% !important;
  }
  #math-visual-studio-view .math-visual-problem-summary-right {
    position: static !important; align-self: flex-start !important;
  }
  #math-visual-studio-view .mv-scenario-pills-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  #math-visual-studio-view .mv-scenario-pills-row::-webkit-scrollbar { display: none; }
  #math-visual-studio-view .mv-scen-btn { flex-shrink: 0; white-space: nowrap; }
  #math-visual-studio-view .math-visual-mobile-tabs {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.3rem;
    padding: 0.45rem 0.65rem; background: var(--mv-card); border-bottom: 1px solid var(--mv-border);
  }
  #math-visual-studio-view .math-visual-mobile-tab-btn {
    min-height: 40px; border-radius: 8px; border: 1px solid transparent;
    background: var(--mv-bg); color: var(--mv-muted); font-size: 0.76rem; font-weight: 700; padding: 0.3rem 0.35rem; cursor: pointer;
  }
  #math-visual-studio-view .math-visual-mobile-tab-btn.active {
    background: var(--mv-primary); color: var(--mv-primary-fg); font-weight: 800;
  }
  #math-visual-studio-view .mv-canvas-stage {
    height: clamp(310px, 48dvh, 410px);
    min-height: 310px;
  }
  #math-visual-studio-view .math-visual-svg-viewport {
    min-height: 310px;
    padding: 0.45rem 0.5rem 2.4rem;
  }
  #math-visual-studio-view .mv-stepper-top-row { display: flex !important; }
  #math-visual-studio-view .mv-spotlight-back-mobile { display: inline-flex; }
  #math-visual-studio-view .mv-diagram-layer-segmented { max-width: 100%; overflow-x: auto; }
  #math-visual-studio-view.mobile-pane-sidebar .math-visual-viewport-wrapper { display: none !important; }
  #math-visual-studio-view.mobile-pane-sidebar .math-visual-sidebar { display: flex !important; width: 100% !important; }
  #math-visual-studio-view.mobile-pane-steps .mv-proof-cards { display: none !important; }
  #math-visual-studio-view.mobile-pane-steps .mv-collapsible-details { display: block !important; }
}

@media (max-width: 380px) {
  #math-visual-studio-view .math-visual-mobile-tab-btn { font-size: 0.7rem; padding: 0.25rem 0.2rem; }
  #math-visual-studio-view .mv-inspector-footer-actions { grid-template-columns: 1fr; }
  #math-visual-studio-view .mv-theme-chip { padding: 0.18rem 0.42rem !important; font-size: 0.68rem !important; }
}

#math-visual-studio-view .mv-step-item-title {
  font-size: 0.78rem; font-weight: 800; color: var(--mv-text); margin-bottom: 0.2rem; line-height: 1.35;
}
#math-visual-studio-view .mv-step-item-body {
  font-size: 0.78rem; color: var(--mv-text-sub, var(--mv-text)); line-height: 1.5;
}
#math-visual-studio-view .mv-step-item-fact {
  margin-top: 0.28rem; display: inline-block; padding: 0.14rem 0.48rem;
  border-radius: 6px; background: rgba(37, 99, 235, 0.08); color: #1d4ed8;
  font-size: 0.73rem; font-weight: 700;
}
#math-visual-studio-view.mv-theme-dark .mv-step-item-fact {
  background: rgba(96, 165, 250, 0.16); color: #93c5fd;
}
#math-visual-studio-view .mv-proof-retry-btn {
  width: 100%; margin-bottom: 0.5rem; padding: 0.45rem 0.75rem; border-radius: 8px;
  border: 1px dashed #d97706; background: #fffbeb; color: #b45309;
  font-size: 0.76rem; font-weight: 700; cursor: pointer; text-align: center;
}
@keyframes mvStrokeDraw {
  from { stroke-dashoffset: 1; opacity: 0.35; }
  to { stroke-dashoffset: 0; opacity: 1; }
}
#math-visual-studio-view .geom-stroke-draw {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
  animation: mvStrokeDraw 0.46s cubic-bezier(0.22, 1, 0.36, 1) both;
}
