/* ============================================================================
   GoGG Laser & Motion Stage Simulator — Precision Nano CAD & 3D Studio Styles
   Supports SCANLAB RTC6, Delta Tau Power PMAC (.pmc), ACS Motion (ACSPL+), G-Code
   ============================================================================ */

:root {
  --ms-studio-height: 800px;
  --ms-bg-deep: #060b14;
  --ms-bg-panel: #0b1322;
  --ms-bg-card: #111c30;
  --ms-bg-input: #070d19;
  --ms-border: rgba(56, 189, 248, 0.18);
  --ms-border-subtle: rgba(148, 163, 184, 0.14);
  --ms-cyan: #38bdf8;
  --ms-emerald: #10b981;
  --ms-amber: #f59e0b;
  --ms-red: #f43f5e;
  --ms-purple: #a855f7;
  --ms-text-main: #f1f5f9;
  --ms-text-muted: #94a3b8;
  --ms-text-dim: #64748b;
  --ms-font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
}

.ms-page-container {
  max-width: 1260px;
  width: min(100% - 32px, 1260px);
  box-sizing: border-box;
  overflow-x: hidden;
  margin: 0 auto;
  padding: 0 0 30px;
}

/* Hero Banner */
.ms-hero {
  background: linear-gradient(135deg, rgba(11, 19, 34, 0.95) 0%, rgba(15, 23, 42, 0.9) 100%);
  border: 1px solid var(--ms-border);
  border-radius: 14px;
  padding: 16px 22px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.ms-hero-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.ms-hero-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: radial-gradient(circle at 30% 30%, rgba(56, 189, 248, 0.25), rgba(244, 63, 94, 0.2));
  border: 1px solid rgba(56, 189, 248, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  flex-shrink: 0;
}

.ms-hero-title {
  margin: 0;
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--ms-text-main);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ms-hero-badge-ver {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(244, 63, 94, 0.16);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fda4af;
  font-family: var(--ms-font-mono);
}

.ms-hero-desc {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--ms-text-muted);
}

.ms-hero-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}

.ms-pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--ms-border-subtle);
  color: var(--ms-text-main);
  text-decoration: none;
  transition: all 0.18s ease;
}

.ms-pill-badge.link-btn:hover {
  border-color: var(--ms-cyan);
  background: rgba(56, 189, 248, 0.14);
  color: #fff;
}

/* Language Switcher Dropdown (Matching Melsec Monitor & Port Tester) */
.lang-switcher-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--ms-bg-input);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 8px;
  padding: 3px 8px;
}

.lang-switcher-wrap select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 4px center;
  color: var(--ms-text-main);
  border: none;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding: 2px 20px 2px 4px;
}

.lang-switcher-wrap select option {
  background: var(--ms-bg-card);
  color: var(--ms-text-main);
}

/* Unified Outer Studio Panel & Interactive Height Resizer */
.ms-studio-outer-panel {
  background: var(--ms-bg-panel);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 14px;
  padding: 16px;
  height: var(--ms-studio-height, 800px);
  min-height: 450px;
  max-height: var(--ms-studio-height, 800px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Main Studio Grid: Left Code/Controller Panel + Right Viewport */
.ms-studio-grid {
  flex: 1 1 0%;
  display: grid;
  grid-template-columns: 450px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

/* Interactive Height Resizer Bar (MELSEC Monitor Style) */
.ms-studio-resizer {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  margin-top: 2px;
  margin-bottom: 16px;
  cursor: ns-resize;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 20;
  transition: opacity 0.15s ease;
}

.ms-studio-resizer .ms-resizer-line {
  flex: 1;
  height: 1px;
  background: rgba(56, 189, 248, 0.16);
  transition: background 0.18s ease, height 0.18s ease, box-shadow 0.18s ease;
}

.ms-studio-resizer .ms-resizer-handle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 12px;
  margin: 0 10px;
  border-radius: 999px;
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: #94a3b8;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--ms-font-mono);
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.ms-studio-resizer:hover .ms-resizer-line,
.ms-studio-resizer.is-dragging .ms-resizer-line {
  background: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.35);
}

.ms-studio-resizer:hover .ms-resizer-handle,
.ms-studio-resizer.is-dragging .ms-resizer-handle {
  border-color: #38bdf8;
  color: #e0f2fe;
  background: #132238;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

body.ms-resizing,
body.ms-resizing * {
  cursor: ns-resize !important;
  user-select: none !important;
}

/* ============================================================================
   LEFT COLUMN: Multi-Controller Vector Code Studio
   ============================================================================ */
.ms-editor-column {
  background: #070d19;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* Universal Grammar Auto-Detection Header */
.ms-grammar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #060b14;
  border-bottom: 1px solid var(--ms-border-subtle);
  padding: 8px 12px;
  gap: 8px;
}

.ms-grammar-left {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.ms-grammar-tag {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #64748b;
  white-space: nowrap;
}

.ms-grammar-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #38bdf8;
  font-family: var(--ms-font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

.ms-grammar-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
}

.ms-grammar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ms-btn-full-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 106px;
  min-width: 106px;
  max-width: 106px;
  height: 31px;
  min-height: 31px;
  max-height: 31px;
  box-sizing: border-box;
  padding: 0 8px;
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(56, 189, 248, 0.4);
  color: #bae6fd;
  font-family: var(--ms-font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ms-btn-full-check:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: rgba(56, 189, 248, 0.7);
  color: #fff;
}

.ms-btn-full-check.running {
  background: rgba(251, 191, 36, 0.15);
  border-color: rgba(251, 191, 36, 0.6);
  color: #fde68a;
}

.ms-btn-full-check.done-ok {
  background: rgba(34, 197, 94, 0.15);
  border-color: rgba(34, 197, 94, 0.55);
  color: #4ade80;
}

.ms-btn-full-check.done-err {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.65);
  color: #fda4af;
}

.ms-syntax-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--ms-font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ms-syntax-status-badge.ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.4);
  color: #4ade80;
}

.ms-syntax-status-badge.err {
  background: rgba(244, 63, 94, 0.18);
  border: 1px solid rgba(244, 63, 94, 0.65);
  color: #fda4af;
  box-shadow: 0 0 10px rgba(244, 63, 94, 0.25);
}

.ms-syntax-status-badge.err:hover {
  background: rgba(244, 63, 94, 0.28);
  color: #fff;
}

/* Preset & File Bar */
.ms-preset-bar {
  padding: 10px 12px;
  background: rgba(15, 23, 42, 0.7);
  border-bottom: 1px solid var(--ms-border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ms-preset-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  width: 100%;
}

.ms-select {
  flex: 1 1 0%;
  min-width: 0;
  width: 0;
  background: var(--ms-bg-input);
  border: 1px solid var(--ms-border-subtle);
  color: var(--ms-text-main);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 0.76rem;
  font-weight: 600;
  outline: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ms-select:focus {
  border-color: var(--ms-cyan);
}

.ms-btn-sm {
  flex-shrink: 0;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--ms-border-subtle);
  color: var(--ms-text-main);
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.ms-btn-sm:hover {
  border-color: var(--ms-cyan);
  background: rgba(56, 189, 248, 0.15);
}

.ms-btn-sm.primary {
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  border-color: #38bdf8;
  color: #fff;
}

.ms-btn-sm.primary:hover {
  filter: brightness(1.1);
}

/* Controller Parameter Strip (RTC6 K-Factor / FOV / Units) */
.ms-param-strip {
  padding: 8px 12px;
  background: rgba(7, 13, 25, 0.9);
  border-bottom: 1px solid var(--ms-border-subtle);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ms-param-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ms-param-item label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ms-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ms-param-input {
  background: #0b1322;
  border: 1px solid var(--ms-border-subtle);
  color: #38bdf8;
  border-radius: 6px;
  padding: 4px 7px;
  font-size: 0.76rem;
  font-family: var(--ms-font-mono);
  font-weight: 600;
  width: 100%;
  box-sizing: border-box;
  appearance: textfield;
  -moz-appearance: textfield;
}

.ms-param-input::-webkit-outer-spin-button,
.ms-param-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Syntax Quick-Insert Chips */
.ms-syntax-chips {
  padding: 6px 12px;
  background: rgba(15, 23, 42, 0.45);
  border-bottom: 1px solid var(--ms-border-subtle);
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.ms-syntax-chip {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #cbd5e1;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 0.7rem;
  font-family: var(--ms-font-mono);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.14s ease;
}

.ms-syntax-chip:hover {
  border-color: var(--ms-cyan);
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
}

/* Code Editor Area with Line Numbers & Full-Line Active Highlight */
.ms-code-editor-wrap {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  background: #050912;
  overflow: hidden;
}

.ms-active-line-bar {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 20px;
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.34) 0%, rgba(56, 189, 248, 0.22) 22%, rgba(56, 189, 248, 0.13) 100%);
  border-left: 3px solid #f43f5e;
  border-top: 1px solid rgba(56, 189, 248, 0.4);
  border-bottom: 1px solid rgba(56, 189, 248, 0.4);
  box-shadow: inset 0 0 12px rgba(56, 189, 248, 0.16);
  pointer-events: none;
  z-index: 1;
  display: none;
}

.ms-line-numbers {
  position: relative;
  z-index: 2;
  width: 48px;
  height: 100%;
  max-height: 100%;
  box-sizing: border-box;
  padding: 12px 6px 12px 0;
  background: rgba(7, 13, 25, 0.72);
  border-right: 1px solid rgba(148, 163, 184, 0.12);
  color: #475569;
  font-family: var(--ms-font-mono);
  font-size: 12.5px;
  line-height: 20px;
  text-align: right;
  user-select: none;
  overflow: hidden;
  flex-shrink: 0;
}

.ms-line-numbers .ln-item {
  height: 20px;
  line-height: 20px;
  padding-right: 4px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease;
}

.ms-line-numbers .ln-item:hover {
  background: rgba(56, 189, 248, 0.25);
  color: #e0f2fe;
}

.ms-line-numbers .ln-item.active-line {
  background: rgba(244, 63, 94, 0.45);
  color: #fff;
  font-weight: 800;
}

.ms-line-numbers .ln-item.err-line {
  background: rgba(244, 63, 94, 0.22);
  color: #fb7185;
  font-weight: 800;
  border-left: 2px solid #f43f5e;
}

.ms-code-backdrop {
  position: absolute;
  left: 48px;
  right: 0;
  top: 0;
  bottom: 0;
  margin: 0;
  box-sizing: border-box;
  padding: 12px;
  font-family: var(--ms-font-mono);
  font-size: 12.5px;
  line-height: 20px;
  white-space: pre;
  tab-size: 2;
  color: transparent;
  pointer-events: none;
  overflow: hidden;
  z-index: 1;
}

.ms-syntax-err-wave {
  color: transparent;
  text-decoration: underline wavy #fb7185;
  -webkit-text-decoration: underline wavy #fb7185;
  text-decoration-color: #fb7185;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  background: rgba(244, 63, 94, 0.16);
  border-bottom: 1.5px dashed rgba(251, 113, 133, 0.85);
  border-radius: 2px;
}

.ms-syntax-err-bar {
  position: absolute;
  left: 48px;
  right: 10px;
  bottom: 6px;
  z-index: 5;
  background: rgba(127, 29, 29, 0.92);
  border: 1px solid rgba(251, 113, 133, 0.65);
  border-radius: 6px;
  padding: 5px 10px;
  color: #ffe4e6;
  font-family: var(--ms-font-mono);
  font-size: 11px;
  line-height: 1.35;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ms-syntax-err-bar:hover {
  background: rgba(159, 18, 57, 0.96);
  border-color: #fda4af;
}

.ms-code-textarea {
  position: relative;
  z-index: 2;
  flex: 1 1 0;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  box-sizing: border-box;
  background: transparent;
  border: none;
  color: #e2e8f0;
  font-family: var(--ms-font-mono);
  font-size: 12.5px;
  line-height: 20px;
  padding: 12px;
  resize: none;
  outline: none;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

/* Left Column Split Resizer (Between Code Editor & Parsed Vectors Table) */
.ms-left-split-resizer {
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: ns-resize;
  user-select: none;
  -webkit-user-select: none;
  background: #060b14;
  border-top: 1px solid rgba(56, 189, 248, 0.16);
  border-bottom: 1px solid rgba(56, 189, 248, 0.16);
  position: relative;
  z-index: 10;
}

.ms-left-split-resizer .ms-resizer-line {
  flex: 1;
  height: 1px;
  background: rgba(56, 189, 248, 0.16);
  transition: background 0.18s ease, box-shadow 0.18s ease;
}

.ms-left-split-resizer .ms-resizer-handle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 10px;
  margin: 0 8px;
  border-radius: 999px;
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.32);
  color: #94a3b8;
  font-size: 10.5px;
  font-weight: 600;
  font-family: var(--ms-font-mono);
  transition: all 0.18s ease;
}

.ms-left-split-resizer:hover .ms-resizer-line,
.ms-left-split-resizer.is-dragging .ms-resizer-line {
  background: rgba(56, 189, 248, 0.7);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.35);
}

.ms-left-split-resizer:hover .ms-resizer-handle,
.ms-left-split-resizer.is-dragging .ms-resizer-handle {
  border-color: #38bdf8;
  color: #e0f2fe;
  background: #132238;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.3);
}

/* Parsed Vector Segment Table (Bottom of Left Panel) */
.ms-segment-inspector {
  height: var(--ms-seg-inspector-height, 210px);
  min-height: 90px;
  flex-shrink: 0;
  background: #080f1d;
  display: flex;
  flex-direction: column;
}

.ms-seg-header {
  padding: 7px 12px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid var(--ms-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ms-text-muted);
}

.ms-seg-table-wrap {
  position: relative;
  flex: 1;
  overflow-y: auto;
}

.ms-seg-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--ms-font-mono);
  font-size: 0.71rem;
}

.ms-seg-table th {
  position: sticky;
  top: 0;
  background: #0d1729;
  color: #94a3b8;
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--ms-border-subtle);
  font-weight: 700;
}

.ms-seg-table td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.07);
  color: #cbd5e1;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.ms-seg-table tr:hover td {
  background: rgba(56, 189, 248, 0.1);
}

.ms-seg-table tr.active-seg td {
  background: rgba(244, 63, 94, 0.22);
  color: #fff;
  font-weight: 700;
}

.seg-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
}

.seg-badge.jump {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.seg-badge.mark {
  background: rgba(244, 63, 94, 0.2);
  color: #fb7185;
}

.seg-badge.arc {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
}

.seg-badge.stage {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

/* ============================================================================
   RIGHT COLUMN: 2D Nano CAD & 3D Digital Twin Viewport
   ============================================================================ */
.ms-viewport-column {
  background: #070d19;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* Top Simulation Mode & Viewport Toolbar */
.ms-viewport-toolbar {
  padding: 9px 14px;
  background: #070d19;
  border-bottom: 1px solid var(--ms-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.ms-mode-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ms-seg-switch {
  display: inline-flex;
  background: #040810;
  border: 1px solid var(--ms-border-subtle);
  border-radius: 8px;
  padding: 2px;
}

.ms-seg-btn {
  background: transparent;
  border: none;
  color: var(--ms-text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.ms-seg-btn.active {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.15);
}

.ms-seg-btn.sync-active.active {
  background: rgba(168, 85, 247, 0.22);
  color: #c084fc;
}

/* Main Interactive Canvas Stage */
.ms-canvas-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  background: #040811;
  overflow: hidden;
  user-select: none;
}

#ms-cad-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

#ms-3d-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

/* Floating HUD Overlays inside Canvas */
.ms-canvas-hud-tl {
  position: absolute;
  top: 12px;
  left: 14px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.ms-hud-card {
  background: rgba(7, 13, 25, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.24);
  border-radius: 9px;
  padding: 7px 11px;
  font-family: var(--ms-font-mono);
  font-size: 0.73rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ms-text-main);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

#ms-cursor-readout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.ms-cursor-val {
  display: inline-block;
  width: 11ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #f8fafc;
}

.ms-legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.7rem;
}

.ms-legend-dot {
  display: inline-block;
  width: 10px;
  height: 3px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

/* Top-Right Nano Ruler Measurement Card */
.ms-canvas-hud-tr {
  position: absolute;
  top: 12px;
  right: 14px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.ms-ruler-readout {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 9px;
  padding: 8px 12px;
  font-family: var(--ms-font-mono);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: #fde68a;
  min-width: 260px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

/* Bottom-Right Dynamic Scale Bar & Cursor Nano Coordinates */
.ms-canvas-hud-br {
  position: absolute;
  bottom: 12px;
  right: 14px;
  z-index: 5;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ms-scale-bar-box {
  background: rgba(7, 13, 25, 0.88);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 7px;
  padding: 5px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: var(--ms-font-mono);
  font-size: 0.7rem;
  color: #38bdf8;
}

.ms-scale-line {
  height: 5px;
  border-left: 2px solid #38bdf8;
  border-right: 2px solid #38bdf8;
  border-bottom: 2px solid #38bdf8;
  width: 100px;
  transition: width 0.1s ease;
}

/* Bottom Timeline Scrubber & Playback Bar */
.ms-playback-bar {
  padding: 7px 14px;
  height: auto;
  min-height: 70px;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow: hidden;
  background: #080f1e;
  border-top: 1px solid var(--ms-border-subtle);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.ms-playback-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ms-play-btn {
  background: linear-gradient(135deg, #e11d48, #f43f5e);
  border: 1px solid #fb7185;
  color: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 98px;
  justify-content: center;
}

.ms-play-btn.playing {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  border-color: #fcd34d;
}

.ms-scrubber-wrap {
  flex: 1 1 100%;
  order: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  width: 100%;
  padding-top: 2px;
}

.ms-scrubber {
  flex: 1 1 0%;
  width: 100%;
  min-width: 120px;
  accent-color: #f43f5e;
  cursor: pointer;
}

.ms-time-label {
  font-family: var(--ms-font-mono);
  font-size: 0.74rem;
  color: var(--ms-text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  text-align: right;
}

#ms-speed-select {
  flex: 0 0 auto;
  width: auto;
  min-width: 118px;
  margin-left: auto;
}

/* Bottom Telemetry HUD Grid — Flexible Cards & Fixed Height to Prevent Layout Bounce */
.ms-telemetry-grid {
  padding: 8px 14px;
  height: 76px;
  min-height: 76px;
  max-height: 76px;
  flex-shrink: 0;
  box-sizing: border-box;
  overflow: hidden;
  background: #050a14;
  border-top: 1px solid var(--ms-border-subtle);
  display: flex;
  gap: 8px;
}

@media (max-width: 960px) {
  .ms-telemetry-grid {
    height: auto;
    max-height: none;
    flex-wrap: wrap;
  }
  .ms-telem-card {
    flex: 1 1 calc(50% - 8px);
  }
}

.ms-telem-card {
  flex: 1 1 0;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.14);
  border-radius: 8px;
  padding: 6px 12px;
  height: 60px;
  min-height: 60px;
  max-height: 60px;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 2px;
}

.ms-telem-title {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--ms-text-dim);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.ms-telem-badge {
  font-size: 0.6rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  flex-shrink: 0;
}

.ms-telem-val {
  font-family: var(--ms-font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ms-text-main);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.ms-telem-sub {
  font-family: var(--ms-font-mono);
  font-size: 0.66rem;
  color: var(--ms-cyan);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.ms-telem-coord-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: center;
}

.ms-coord-slot {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 6px;
  border-right: 1px solid rgba(148, 163, 184, 0.14);
}

.ms-coord-slot:last-child {
  border-right: none;
  padding-right: 0;
}

.ms-coord-lbl {
  color: #94a3b8;
  font-weight: 700;
  flex-shrink: 0;
}

.ms-coord-num {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  min-width: 7ch;
}

/* Technical Guide Section */
.ms-guide-section {
  margin-top: 28px;
  background: var(--ms-bg-panel);
  border: 1px solid var(--ms-border);
  border-radius: 14px;
  padding: 28px 32px;
  color: #cbd5e1;
  line-height: 1.72;
}

.ms-guide-section h2 {
  color: #fff;
  font-size: 1.45rem;
  margin-top: 0;
  border-bottom: 1px solid var(--ms-border-subtle);
  padding-bottom: 12px;
}

.ms-guide-section h3 {
  color: #38bdf8;
  font-size: 1.12rem;
  margin-top: 26px;
}

.ms-guide-table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 0.84rem;
}

.ms-guide-table th,
.ms-guide-table td {
  border: 1px solid var(--ms-border-subtle);
  padding: 9px 12px;
  text-align: left;
}

.ms-guide-table th {
  background: rgba(15, 23, 42, 0.9);
  color: #38bdf8;
}

.ms-guide-table code {
  font-family: var(--ms-font-mono);
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Instant Floating Button Tooltip */
.ms-floating-tooltip {
  position: fixed;
  z-index: 99999;
  pointer-events: none;
  max-width: 285px;
  background: rgba(8, 15, 30, 0.96);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(56, 189, 248, 0.48);
  border-radius: 10px;
  padding: 9px 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(56, 189, 248, 0.12);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.ms-floating-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.ms-tip-title {
  font-size: 0.76rem;
  font-weight: 800;
  color: #38bdf8;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.ms-tip-desc {
  font-size: 0.72rem;
  color: #e2e8f0;
  line-height: 1.45;
  font-weight: 500;
}

/* ============================================================================
   RESPONSIVE & MOBILE LAYOUT (Tablet <= 1080px, Mobile Phone <= 768px)
   ============================================================================ */
@media (max-width: 1080px) {
  .ms-studio-outer-panel {
    height: auto;
    max-height: none;
    min-height: 0;
    padding: 12px;
  }

  .ms-studio-grid {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    max-height: none;
    gap: 14px;
  }

  /* Show 2D/3D Trajectory Viewport FIRST on mobile/tablet so user immediately sees the drawing */
  .ms-viewport-column {
    order: -1;
    height: auto;
    max-height: none;
    min-width: 0;
  }

  .ms-canvas-stage {
    flex: none;
    height: 420px;
    min-height: 420px;
  }

  .ms-editor-column {
    height: auto;
    max-height: none;
    min-width: 0;
  }

  .ms-code-editor-wrap {
    flex: none;
    height: 280px;
    min-height: 240px;
  }

  .ms-segment-inspector {
    height: 220px;
    min-height: 160px;
  }

  .ms-studio-resizer,
  .ms-left-split-resizer {
    display: none;
  }
}

@media (max-width: 768px) {
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }

  .ms-page-container {
    width: calc(100% - 16px) !important;
    padding: 8px 0 28px !important;
    overflow-x: hidden;
  }

  .ms-hero {
    flex-direction: column;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 12px 14px;
    gap: 10px;
    overflow: hidden;
  }

  .ms-hero-left {
    width: 100%;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
  }

  .ms-hero-icon {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
    border-radius: 10px;
  }

  .ms-hero-title {
    flex-direction: column;
    align-items: flex-start;
    font-size: 1.15rem;
    gap: 5px;
    width: 100%;
    min-width: 0;
  }

  .ms-hero-badge-ver {
    border-radius: 6px !important;
    padding: 3px 8px;
    font-size: 0.68rem;
    line-height: 1.35;
    white-space: normal;
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
  }

  .ms-hero-actions {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
  }

  .ms-hero-desc {
    font-size: 0.76rem;
    line-height: 1.4;
  }

  .ms-studio-outer-panel {
    padding: 8px;
    border-radius: 10px;
  }

  .ms-viewport-toolbar {
    padding: 8px;
    gap: 6px;
  }

  .ms-mode-group {
    width: 100%;
    gap: 5px;
  }

  .ms-mode-group > .ms-btn-sm {
    flex: 1 1 calc(50% - 5px);
    justify-content: center;
  }

  .ms-seg-switch {
    flex: 1 1 100%;
    display: flex;
    width: 100%;
  }

  .ms-seg-switch .ms-seg-btn {
    flex: 1 1 50%;
    justify-content: center;
  }

  .ms-btn-sm {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  .ms-canvas-stage {
    height: 350px;
    min-height: 350px;
    touch-action: none;
  }

  .ms-canvas-hud-tl {
    top: 8px;
    left: 8px;
    right: 8px;
  }

  .ms-canvas-hud-tl .ms-hud-card {
    max-width: 100%;
    box-sizing: border-box;
    padding: 5px 8px;
    font-size: 0.66rem;
  }

  .ms-canvas-hud-tl .ms-legend-row {
    gap: 6px;
    font-size: 0.62rem;
  }

  .ms-canvas-hud-tl .ms-hud-card:nth-child(2) {
    display: none;
  }

  .ms-canvas-hud-br {
    bottom: 8px;
    right: 8px;
  }

  #ms-cursor-readout {
    display: none;
  }

  .ms-playback-bar {
    height: auto;
    max-height: none;
    padding: 8px;
  }

  .ms-playback-controls {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ms-play-btn {
    padding: 5px 10px;
    min-width: 80px;
    font-size: 0.74rem;
  }

  .ms-scrubber-wrap {
    flex: 1 1 100%;
    min-width: 0;
    order: 10;
    gap: 6px;
  }

  .ms-time-label {
    min-width: auto;
    font-size: 0.68rem;
  }

  .ms-telemetry-grid {
    height: auto;
    max-height: none;
    padding: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .ms-telemetry-grid .ms-telem-card:last-child {
    grid-column: 1 / -1;
  }

  .ms-grammar-header {
    flex-wrap: wrap;
    padding: 7px 10px;
    gap: 6px;
  }

  .ms-preset-row {
    flex-wrap: wrap;
    gap: 6px;
  }

  .ms-preset-row .ms-select {
    flex: 1 1 100%;
    max-width: 100%;
    min-width: 0;
  }

  .ms-preset-row .ms-btn-sm {
    flex: 1 1 0;
    justify-content: center;
  }

  .ms-param-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .ms-param-item label {
    font-size: 0.62rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ms-code-editor-wrap {
    height: 240px;
    min-height: 200px;
  }

  .ms-seg-header {
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.7rem;
  }

  .ms-seg-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ms-guide-section {
    padding: 16px 14px !important;
  }

  .ms-guide-table {
    display: block;
    overflow-x: auto;
  }
}

@media (max-width: 480px) {
  .ms-param-strip {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   CAD Drawing -> Motion Code Converter Modal
   ============================================================================ */
.ms-cad-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(2, 6, 23, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ms-cad-modal-card {
  width: 100%;
  max-width: 540px;
  background: linear-gradient(160deg, #0b1322 0%, #070d19 100%);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.7), 0 0 24px rgba(56, 189, 248, 0.12);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ms-cad-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(15, 23, 42, 0.9);
  border-bottom: 1px solid rgba(56, 189, 248, 0.18);
}

.ms-cad-modal-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ms-cad-modal-title {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 800;
  color: #f8fafc;
}

.ms-cad-modal-sub {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: #94a3b8;
}

.ms-cad-modal-close {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: #cbd5e1;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.ms-cad-modal-close:hover {
  background: rgba(244, 63, 94, 0.2);
  border-color: #f43f5e;
  color: #fff;
}

.ms-cad-modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ms-cad-dropzone {
  border: 1.5px dashed rgba(56, 189, 248, 0.4);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.65);
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.ms-cad-dropzone:hover,
.ms-cad-dropzone.drag-over {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.09);
}

.ms-cad-drop-icon {
  font-size: 1.45rem;
  margin-bottom: 4px;
}

.ms-cad-drop-text {
  font-size: 0.8rem;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 10px;
}

.ms-cad-drop-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ms-cad-summary-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  font-size: 0.76rem;
  font-family: var(--ms-font-mono);
}

.ms-cad-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ms-cad-field-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

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

.ms-cad-ctrl-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border-radius: 8px;
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ms-cad-ctrl-btn:hover {
  border-color: rgba(56, 189, 248, 0.5);
  color: #fff;
}

.ms-cad-ctrl-btn.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  color: #fff;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.2);
}

.ms-cad-ctrl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ms-cad-param-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.ms-cad-check-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.14);
}

.ms-cad-check-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.76rem;
  color: #e2e8f0;
  cursor: pointer;
  user-select: none;
}

.ms-cad-check-label input[type="checkbox"] {
  accent-color: #38bdf8;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.ms-cad-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: rgba(15, 23, 42, 0.9);
  border-top: 1px solid rgba(56, 189, 248, 0.16);
}

#ms-cad-btn-apply:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ms-cad-layer-toggle-all {
  background: transparent;
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.ms-cad-layer-toggle-all:hover {
  background: rgba(56, 189, 248, 0.14);
}

.ms-cad-layer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 92px;
  overflow-y: auto;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.16);
}

.ms-cad-layer-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-family: var(--ms-font-mono);
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  transition: all 0.14s ease;
}

.ms-cad-layer-chip.active {
  background: rgba(16, 185, 129, 0.14);
  border-color: rgba(16, 185, 129, 0.5);
  color: #ecfdf5;
}

@media (max-width: 520px) {
  .ms-cad-ctrl-grid,
  .ms-cad-param-grid {
    grid-template-columns: 1fr;
  }
}
