:root {
  --bg-darkest: #0b0e14;
  --bg-panel: #131822;
  --bg-ribbon: #171d29;
  --bg-card: #1c2433;
  --bg-input: #0f141d;
  --border-subtle: #263042;
  --border-focus: #38bdf8;
  --accent-orange: #f97316;
  --accent-orange-hover: #fb923c;
  --accent-cyan: #38bdf8;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, monospace;
}

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

html,
body {
  width: 100%;
  height: 100%;
  background: var(--bg-darkest);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 13px;
  overflow: hidden;
  user-select: none;
}

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

/* === APP SHELL === */
.app-shell {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
}

/* === TOP TITLE & WORKSPACE TABS BAR === */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px;
  background: var(--bg-darkest);
  border-bottom: 1px solid var(--border-subtle);
  gap: 10px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.brand-title {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-title strong {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-rust {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(249, 115, 22, 0.18);
  color: var(--accent-orange);
  border: 1px solid rgba(249, 115, 22, 0.4);
  font-weight: 600;
}

.brand-title small {
  font-size: 10.5px;
  color: var(--text-muted);
}

.workspace-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  background: var(--bg-panel);
  padding: 3px;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
}

.ws-tab {
  background: transparent;
  border: none;
  padding: 5px 11px;
  border-radius: 5px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.ws-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}

.ws-tab.active {
  background: var(--accent-orange);
  color: #fff;
  box-shadow: 0 1px 6px rgba(249, 115, 22, 0.35);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hdr-btn,
.hdr-select {
  height: 28px;
  padding: 0 9px;
  border-radius: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s;
}

.hdr-btn:hover,
.hdr-select:hover {
  border-color: var(--accent-cyan);
  background: var(--bg-card);
}

.hdr-btn.primary {
  background: linear-gradient(135deg, #f97316, #ea580c);
  border-color: #fb923c;
  color: #fff;
  font-weight: 600;
}

.hdr-btn.primary:hover {
  filter: brightness(1.08);
}

.hdr-btn.eco-btn {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.4);
  color: var(--accent-cyan);
  font-weight: 600;
}

.lang-switch {
  display: inline-flex;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  overflow: hidden;
}

.lang-switch button {
  background: transparent;
  border: none;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.lang-switch button.active {
  background: var(--accent-cyan);
  color: #0b0e14;
}

/* === RIBBON TOOLBAR === */
.ribbon-bar {
  display: flex;
  align-items: stretch;
  height: 68px;
  padding: 5px 10px;
  background: var(--bg-ribbon);
  border-bottom: 1px solid var(--border-subtle);
  gap: 8px;
  overflow-x: auto;
}

.ribbon-group {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-right: 8px;
  border-right: 1px solid var(--border-subtle);
}

.ribbon-group:last-child {
  border-right: none;
}

.ribbon-btns {
  display: flex;
  align-items: center;
  gap: 3px;
}

.ribbon-label {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  text-align: center;
  font-weight: 600;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  height: 44px;
  padding: 3px 6px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-main);
  cursor: pointer;
  gap: 2px;
  transition: all 0.14s;
}

.tool-btn .ico {
  font-size: 16px;
  line-height: 1;
}

.tool-btn .lbl {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-card);
  border-color: var(--border-subtle);
}

.tool-btn:hover .lbl {
  color: #fff;
}

.tool-btn.active,
.tool-btn.accent {
  background: rgba(249, 115, 22, 0.14);
  border-color: rgba(249, 115, 22, 0.45);
}

.tool-btn.active .ico,
.tool-btn.accent .ico {
  color: var(--accent-orange);
}

.tool-btn.cyan-accent {
  background: rgba(56, 189, 248, 0.11);
  border-color: rgba(56, 189, 248, 0.35);
}

.tool-btn.cyan-accent .ico {
  color: var(--accent-cyan);
}

/* === MAIN 3-COLUMN WORKSPACE === */
.studio-body {
  display: grid;
  grid-template-columns: 255px 1fr 335px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* === LEFT PANEL: FEATURE TREE BROWSER === */
.left-browser {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.browser-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tree-section {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  overflow: hidden;
}

.tree-sec-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-subtle);
}

.tree-list {
  list-style: none;
  max-height: 290px;
  overflow-y: auto;
}

.tree-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font-size: 12px;
  gap: 6px;
  transition: background 0.12s;
}

.tree-item:last-child {
  border-bottom: none;
}

.tree-item:hover {
  background: rgba(56, 189, 248, 0.08);
}

.tree-item.selected {
  background: rgba(249, 115, 22, 0.2);
  border-left: 3px solid var(--accent-orange);
}

.tree-item-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.tree-type-tag {
  font-size: 9.5px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.tree-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.tree-act-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 11px;
}

.tree-act-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.view-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 6px;
}

.mini-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
}

.mini-chip:hover {
  border-color: var(--accent-cyan);
  color: #fff;
}

.demo-cards {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
}

.demo-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 11.5px;
  cursor: pointer;
  text-align: left;
  transition: all 0.14s;
}

.demo-btn:hover {
  border-color: var(--accent-orange);
  background: rgba(249, 115, 22, 0.1);
}

/* === CENTER VIEWPORT === */
.center-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 42%, #222938 0%, #121620 100%);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#cad3dCanvas {
  width: 100%;
  height: 100%;
  display: block;
  flex: 1;
  outline: none;
}

/* Top-Left Telemetry Badge */
.viewport-telemetry {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
  z-index: 10;
}

.telemetry-pill {
  background: rgba(15, 20, 29, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  padding: 5px 10px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.telemetry-pill b {
  color: var(--accent-orange);
}

/* Top-Right ViewCube */
.view-cube-widget {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(15, 20, 29, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 10;
  width: 124px;
}

.vc-title {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.06em;
}

.vc-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
}

.vc-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 4px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
}

.vc-btn:hover {
  border-color: var(--accent-orange);
  color: var(--accent-orange);
}

/* Bottom Floating Viewport Bar (SolidCraft Style) */
.viewport-hud-bar {
  position: absolute;
  bottom: 42px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 8px;
  background: rgba(15, 20, 29, 0.9);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 10;
}

.hud-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 4px 8px;
  font-size: 11.5px;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.hud-btn:hover {
  color: #fff;
  background: var(--bg-card);
}

.hud-btn.active {
  color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.14);
  border-color: rgba(56, 189, 248, 0.4);
}

.hud-sep {
  width: 1px;
  height: 18px;
  background: var(--border-subtle);
  margin: 0 2px;
}

/* Bottom Parametric History Scrubber (SolidCraft Timeline) */
.timeline-bar {
  height: 30px;
  background: var(--bg-darkest);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  z-index: 12;
}

.tl-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tl-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-main);
}

.tl-btn:hover {
  border-color: var(--accent-orange);
}

/* === 2D SKETCHER OVERLAY === */
.sketch-overlay {
  position: absolute;
  inset: 0;
  background: rgba(11, 14, 20, 0.94);
  z-index: 25;
  display: flex;
  flex-direction: column;
}

.sketch-overlay[hidden] {
  display: none !important;
}

.sketch-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  gap: 8px;
  flex-wrap: wrap;
}

.sketch-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.sketch-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#sketch2dCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* === RIGHT PANEL: INSPECTOR, 3D PRINT & AI/MCP === */
.right-inspector {
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.inspector-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-darkest);
  border-bottom: 1px solid var(--border-subtle);
}

.insp-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 4px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.14s;
}

.insp-tab:hover {
  color: #fff;
}

.insp-tab.active {
  color: var(--accent-orange);
  border-bottom-color: var(--accent-orange);
  background: var(--bg-panel);
}

.insp-pane {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.insp-pane[hidden] {
  display: none !important;
}

.prop-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 7px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.prop-card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 92px;
  align-items: center;
  gap: 8px;
}

.field-row label {
  font-size: 11.5px;
  color: var(--text-muted);
}

.num-input,
.txt-input,
.sel-input {
  width: 100%;
  height: 28px;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 12px;
}

.num-input:focus,
.txt-input:focus,
.sel-input:focus,
.ai-textarea:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.xyz-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.xyz-box {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.xyz-box span {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}

.xyz-box span.x-lbl {
  color: #f87171;
}
.xyz-box span.y-lbl {
  color: #4ade80;
}
.xyz-box span.z-lbl {
  color: #38bdf8;
}

.swatches-row {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.12s;
}

.color-swatch:hover,
.color-swatch.active {
  transform: scale(1.12);
  border-color: #fff;
}

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

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

.action-btn {
  padding: 7px 9px;
  border-radius: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.14s;
}

.action-btn:hover {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.1);
}

.action-btn.orange {
  background: linear-gradient(135deg, #f97316, #ea580c);
  border-color: #fb923c;
  color: #fff;
}

.action-btn.danger:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

/* 3D Print Metrics Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.metric-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 7px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-box small {
  font-size: 10px;
  color: var(--text-muted);
}

.metric-box strong {
  font-family: var(--font-mono);
  font-size: 13.5px;
  color: #fff;
}

.metric-box.highlight strong {
  color: var(--accent-orange);
}

/* AI & MCP Console */
.ai-textarea {
  width: 100%;
  min-height: 76px;
  padding: 8px;
  border-radius: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 12px;
  resize: vertical;
}

.code-textarea {
  font-family: var(--font-mono);
  font-size: 11px;
  min-height: 150px;
  line-height: 1.4;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.prompt-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 3px 7px;
  font-size: 10.5px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
}

.prompt-chip:hover {
  border-color: var(--accent-orange);
  color: #fff;
}

/* === FOOTER BAR === */
.studio-footer {
  height: 28px;
  background: var(--bg-darkest);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: auto;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}

.footer-links a:hover {
  color: var(--accent-cyan);
}

/* === MODAL (4u-Labs Ecosystem & Help) === */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop[hidden] {
  display: none !important;
}

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  max-width: 620px;
  width: 100%;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 17px;
  color: #fff;
}

.links-grid-14 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 7px;
}

.links-grid-14 a {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.links-grid-14 a:hover {
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 40px;
  right: 20px;
  background: #1e293b;
  border: 1px solid var(--accent-cyan);
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: all 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .studio-body {
    grid-template-columns: 210px 1fr 290px;
  }
  .workspace-tabs {
    display: none;
  }
}

@media (max-width: 780px) {
  html,
  body {
    overflow: auto;
  }
  .app-shell {
    height: auto;
    min-height: 100vh;
  }
  .studio-body {
    grid-template-columns: 1fr;
    grid-template-rows: 420px auto auto;
  }
  .left-browser {
    order: 2;
  }
  .center-viewport {
    order: 1;
    height: 420px;
  }
  .right-inspector {
    order: 3;
  }
}

/* 1.2: controls remain reachable at 360px and at large text sizes. */
[hidden] { display: none !important; }
button, input, select, textarea, summary { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent-cyan); outline-offset: 3px; }
input, textarea { user-select: text; }
.top-header { height: auto; min-height: 52px; flex-wrap: wrap; padding: 8px 12px; flex-shrink: 0; }
.brand-group { flex: 1 1 240px; }
.brand-title strong { flex-wrap: wrap; }
.header-actions { flex-wrap: wrap; justify-content: flex-end; flex: 1 1 590px; min-width: 0; }
.hdr-btn { height: auto; min-height: 34px; padding: 7px 9px; white-space: nowrap; }
.lang-switch { flex-shrink: 0; order: -1; }
.lang-switch button { min-height: 34px; min-width: 34px; }
.workspace-tabs { display: flex; order: 3; flex: 1 1 100%; max-width: 100%; overflow-x: auto; }
.ws-tab { flex-shrink: 0; min-height: 34px; }
.ribbon-bar { flex-shrink: 0; max-width: 100%; scrollbar-width: thin; }
.studio-body { grid-template-columns: 230px minmax(0,1fr) 320px; }
.studio-body > *, .prop-card, .field-row { min-width: 0; }
.center-viewport { min-width: 0; }
#cad3dCanvas { min-height: 0; touch-action: none; }
.viewport-hud-bar { width: max-content; max-width: calc(100% - 16px); overflow-x: auto; justify-content: flex-start; bottom: 72px; padding: 4px; scrollbar-width: thin; }
.hud-btn { min-height: 32px; flex-shrink: 0; }
.hud-sep { flex-shrink: 0; }
.viewport-telemetry { max-width: calc(100% - 150px); }
.telemetry-pill { flex-wrap: wrap; gap: 4px; max-width: 100%; overflow-wrap: anywhere; }
.telemetry-pill b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.timeline-bar { height: auto; min-height: 62px; flex-shrink: 0; flex-wrap: wrap; gap: 3px; padding: 5px 8px; }
.timeline-bar > div { flex-wrap: wrap; min-width: 0; }
.timeline-bar [data-i18n="bedInfo"] { font-size: 10px; }
.tl-btn { min-height: 30px; white-space: nowrap; }
.tree-item { min-height: 38px; }
.tree-actions { flex-shrink: 0; }
.tree-act-btn { min-width: 30px; min-height: 30px; }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inspector-tabs { flex-shrink: 0; }
.insp-tab { flex: 1; min-height: 40px; }
.num-input, .txt-input, .sel-input { min-height: 34px; max-width: 100%; }
.action-btn { min-height: 38px; }
.btn-row, .btn-row-3 { flex-wrap: wrap; }
.feature-note { font-size: 12px; line-height: 1.55; color: var(--text-muted); padding: 4px 0; overflow-wrap: anywhere; }
.command-preview { max-width: 100%; overflow: auto; max-height: 220px; font: 11px/1.5 var(--font-mono); padding: 8px; background: var(--bg-input); white-space: pre-wrap; overflow-wrap: anywhere; user-select: text; }
.prop-card summary { cursor: pointer; font-weight: 600; min-height: 34px; }
.studio-footer { height: auto; min-height: 36px; flex-shrink: 0; flex-wrap: wrap; gap: 5px; padding: 8px 12px; }
.footer-links { max-width: 100%; flex-wrap: wrap; overflow: visible; gap: 5px 12px; }
.footer-links a { min-height: 25px; display: inline-flex; align-items: center; }
.modal-card { max-height: calc(100dvh - 32px); overflow-y: auto; }
.help-content { display: grid; gap: 10px; line-height: 1.65; color: var(--text-muted); user-select: text; }
.help-content h3 { color: var(--text-main); margin-top: 5px; font-size: 14px; }
.sketch-topbar { flex-wrap: wrap; padding: 6px; }
.sketch-properties { flex-shrink: 0; padding: 6px; background: var(--bg-panel); max-height: 160px; overflow: auto; }
#sketchEntityFields { display: flex; flex-direction: column; gap: 5px; }
#sketchEntityFields fieldset { border: 1px solid var(--border-subtle); padding: 5px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
#sketchEntityFields input { width: 62px; }
.sketch-canvas-wrap { min-height: 140px; }
#sketch2dCanvas { touch-action: none; }
.boot-overlay { position: fixed; inset: 0; display: grid; place-items: center; background: #0d1118; z-index: 300; color: var(--accent-cyan); }
.sketch-constraint-bar {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  background: var(--bg-ribbon);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}
.sketch-constraint-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}
.sketch-constraint-btn:hover {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.12);
}
.sketch-constraint-btn.active {
  background: var(--accent-cyan);
  color: #0b0e14;
  border-color: var(--accent-cyan);
}
.dof-badge {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
}
.dof-badge.under {
  background: rgba(56, 189, 248, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
}
.dof-badge.fully {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}
.dof-badge.over {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.joint-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.joint-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.joint-title {
  font-weight: 600;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.joint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
}
@media (max-width: 1280px) and (min-width: 781px) {
  .studio-body { grid-template-columns: 190px minmax(0,1fr) 290px; }
  .viewport-telemetry { max-width: calc(100% - 110px); left: 6px; }
  .view-cube-widget { width: 92px; right: 6px; }
}
@media (max-width: 780px) {
  html, body { overflow: auto; height: auto; }
  .app-shell { height: auto; min-height: 100dvh; width: 100%; }
  .top-header { padding: 7px 8px; gap: 6px; }
  .brand-group { flex-basis: 100%; }
  .header-actions { flex: 1 1 100%; justify-content: flex-start; gap: 4px; }
  .hdr-btn { font-size: 11px; min-height: 36px; padding: 6px 7px; }
  .workspace-tabs { border-radius: 4px; padding: 2px; }
  .ws-tab { font-size: 11px; padding: 4px 8px; }
  .ribbon-btn { min-width: 58px; }
  .studio-body { display: flex; flex-direction: column; overflow: visible; }
  .center-viewport { order: 1; height: 520px; flex: 0 0 520px; }
  .left-browser { order: 2; max-height: none; overflow: visible; border-right: none; }
  #featureTree { max-height: 260px; overflow: auto; }
  .right-inspector { order: 3; max-height: none; overflow: visible; border-left: none; }
  .insp-pane { overflow: visible; }
  .view-cube-widget { width: 92px; right: 6px; top: 8px; padding: 4px; }
  .viewport-telemetry { left: 6px; top: 8px; max-width: calc(100% - 112px); }
  .telemetry-pill { font-size: 10px; padding: 4px 6px; }
  .viewport-hud-bar { bottom: 92px; }
  .timeline-bar { min-height: 82px; font-size: 10px; }
  .timeline-bar .tl-controls { gap: 3px; }
  .timeline-bar [data-i18n="bedInfo"] { display: block; }
  .tree-act-btn { min-height: 40px; min-width: 40px; }
  .tree-item { min-height: 44px; }
  .modal-backdrop { padding: 8px; }
  .modal-card { padding: 14px; max-height: calc(100dvh - 16px); }
  .links-grid-14 { grid-template-columns: 1fr; }
  .sketch-tools { gap: 4px; }
  .sketch-topbar { max-height: 210px; overflow-y: auto; }
  .sketch-properties { max-height: 140px; }
  .studio-footer { padding: 10px 8px; }
}

/* Keep part names readable when the project tree is narrow. */
.tree-item-left { display: grid; grid-template-columns: 10px minmax(0, 1fr); column-gap: 6px; row-gap: 2px; }
.tree-item-left .color-dot { grid-row: 1 / 3; }
.tree-item-left .tree-name { min-width: 0; }
.tree-item-left .tree-type-tag { grid-column: 2; justify-self: start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tree-actions { flex-shrink: 0; }
.ribbon-bar { height: 78px; overflow-y: hidden; }
