/* BrickStudio Web — Next-Gen LEGO CAD Stylesheet */
:root {
  --bg-app: #0d1017;
  --bg-panel: #151923;
  --bg-panel-elevated: #1c2230;
  --bg-hover: #252d3f;
  --bg-active: #2563eb;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-main: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-blue: #3b82f6;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
  --accent-purple: #8b5cf6;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-lg: 0 14px 34px rgba(0, 0, 0, 0.52);
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr) 30px;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* Top Header Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-subtle);
  gap: 8px;
  z-index: 20;
  max-width: 100vw;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  min-width: 0;
}

.topbar::-webkit-scrollbar {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand-logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #ef4444 0%, #f59e0b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(239, 68, 68, 0.35);
  font-weight: 800;
  color: #fff;
  font-size: 14px;
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: rgba(59, 130, 246, 0.16);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-app);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.14s ease;
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.tool-btn.active {
  background: var(--bg-active);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.tool-btn.toggle-on {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.tool-btn.warn-on {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.kbd-hint {
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.75);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.color-trigger-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 11px;
  border-radius: 8px;
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-main);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.color-swatch-dot {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

/* Main Workspace 3-Column Layout */
.workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 290px;
  width: 100vw;
  max-width: 100vw;
  height: 100%;
  overflow: hidden;
  position: relative;
  min-width: 0;
  box-sizing: border-box;
}

/* Left Panel: Parts Library & Palette */
.panel-left {
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  min-width: 0;
  width: 100%;
}

.panel-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  color: var(--text-main);
  font-size: 12.5px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input {
  width: 100%;
  padding: 7px 10px 7px 28px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 12px;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent-blue);
}

.search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-muted);
  font-size: 12px;
}

/* Category Pills */
.category-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.18);
  max-height: 104px;
  overflow-y: auto;
}

.cat-pill {
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.12s;
}

.cat-pill:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.cat-pill.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

/* Parts Grid */
.parts-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-content: start;
}

.part-card {
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.14s ease;
  position: relative;
}

.part-card:hover {
  border-color: rgba(59, 130, 246, 0.55);
  background: var(--bg-hover);
  transform: translateY(-1px);
}

.part-card.active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.16);
  box-shadow: 0 0 0 1px var(--accent-blue);
}

.part-thumb {
  width: 112px;
  height: 82px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.45));
}

.part-id-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--text-secondary);
  background: rgba(13, 16, 23, 0.78);
  padding: 1px 5px;
  border-radius: 4px;
}

.part-conn-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9.5px;
  color: #38bdf8;
  background: rgba(6, 182, 212, 0.14);
  padding: 1px 4px;
  border-radius: 4px;
}

.part-name {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-main);
  text-align: center;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: 100%;
}

.part-dims {
  font-size: 10px;
  color: var(--text-muted);
}

/* 4-Phase Educational Kit Parts UI */
.kit-phase-strip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.45);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
}

.kit-phase-btn {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.12s;
}

.kit-phase-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.kit-phase-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #ffffff;
  font-weight: 600;
}

.kit-phase-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  color: #ffffff;
  pointer-events: none;
  z-index: 1;
}

.kit-phase-badge.p1 { background: #2563eb; } /* Phase 1 blue */
.kit-phase-badge.p2 { background: #059669; } /* Phase 2 emerald */
.kit-phase-badge.p3 { background: #d97706; } /* Phase 3 amber */
.kit-phase-badge.p4 { background: #7c3aed; } /* Phase 4 violet */

.kit-qty-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 9.5px;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
  pointer-events: none;
  z-index: 1;
}

.part-thumb.kit-thumb {
  width: 90px;
  height: 72px;
  object-fit: contain;
  margin-top: 14px;
  margin-bottom: 2px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

/* Center 3D Viewport */
.viewport-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at 50% 42%, #181f2e 0%, #0d1017 100%);
  overflow: hidden;
  min-width: 0;
}

#studio-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Floating Viewport HUD Overlays */
.hud-top-left {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hud-pill {
  pointer-events: auto;
  background: rgba(21, 25, 35, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-lg);
}

.snap-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
}

.status-dot.warn {
  background: var(--accent-red);
  box-shadow: 0 0 8px var(--accent-red);
}

.status-dot.neutral {
  background: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue);
}

/* ViewCube / Camera Preset Widget */
.hud-top-right {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(21, 25, 35, 0.86);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px;
  box-shadow: var(--shadow-lg);
}

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

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

.cam-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

/* Bottom Floating Transform & Rotation Controls */
.hud-bottom-center {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(21, 25, 35, 0.92);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 5px 8px;
  display: flex;
  align-items: center;
  gap: 5px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100% - 24px);
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 15;
}

.hud-bottom-center::-webkit-scrollbar {
  display: none;
}

/* Right Panel: Steps Timeline & Inspector */
.panel-right {
  background: var(--bg-panel);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10;
  min-width: 0;
  width: 100%;
}

.inspector-card {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.inspector-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

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

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
}

.stat-value {
  font-size: 12.5px;
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, monospace;
}

/* Steps List */
.steps-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-panel);
}

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

.step-block {
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 0.14s;
}

.step-block.active {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}

.step-header:hover {
  background: rgba(255, 255, 255, 0.06);
}

.step-parts-list {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border-subtle);
  max-height: 180px;
  overflow-y: auto;
}

.step-part-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

.step-part-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.step-part-item.selected {
  background: rgba(59, 130, 246, 0.22);
  color: #fff;
}

.step-part-item.has-collision {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.step-part-item.has-collision:hover {
  background: rgba(239, 68, 68, 0.22);
}

.step-part-item.has-collision.selected {
  background: rgba(239, 68, 68, 0.32);
  border-color: #ef4444;
  color: #fff;
}

.col-pill-badge {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  font-weight: 600;
  margin-left: 4px;
  cursor: pointer;
  transition: all 0.12s ease;
}

.col-pill-badge:hover {
  background: #ef4444;
  color: #fff;
}

.inspector-collision-alert {
  margin-top: 8px;
  padding: 8px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

/* Floating Collision Inspector HUD */
.collision-panel {
  position: absolute;
  top: 96px;
  left: 14px;
  width: 380px;
  max-width: calc(100% - 28px);
  max-height: calc(100% - 170px);
  background: rgba(21, 25, 35, 0.95);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(239, 68, 68, 0.5);
  border-radius: var(--radius-md);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.72);
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
  animation: colSlideIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes colSlideIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.collision-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.collision-badge-count {
  font-size: 11px;
  font-weight: 600;
  background: rgba(239, 68, 68, 0.22);
  color: #fca5a5;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.collision-panel-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.collision-panel-body {
  overflow-y: auto;
  max-height: 240px;
  padding-right: 2px;
}

.col-pair-card {
  background: rgba(13, 16, 23, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.col-brick-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: all 0.15s ease;
}

.col-brick-item.selected {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.14);
}

.col-brick-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}

.col-brick-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-brick-id {
  margin-left: auto;
  font-size: 10.5px;
  opacity: 0.6;
  font-family: monospace;
}

.col-brick-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-secondary);
}

.col-brick-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}

.col-conflict-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 11px;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border: 1px dashed rgba(239, 68, 68, 0.35);
  border-radius: 5px;
  padding: 4px 8px;
}

.tool-btn-compact {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 5px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s ease;
}

.tool-btn-compact:hover {
  background: var(--bg-hover);
}

.tool-btn-compact.active {
  background: var(--bg-active);
  border-color: var(--accent-blue);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.tool-btn-xs {
  padding: 2px 7px;
  font-size: 10.5px;
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  color: var(--text-main);
  cursor: pointer;
  transition: all 0.12s ease;
}

.tool-btn-xs:hover {
  background: var(--bg-hover);
}

.tool-btn-xs.warn {
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.tool-btn-xs.warn:hover {
  background: rgba(239, 68, 68, 0.25);
  color: #fff;
}

.collision-panel-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-top: 4px;
  max-width: 100%;
}

.col-pair-chip {
  padding: 3px 8px;
  font-size: 10.5px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s ease;
}

.col-pair-chip:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
}

.col-pair-chip.active {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fff;
}

.has-collision-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #fff !important;
  font-weight: 600;
  cursor: pointer;
  animation: colPulse 2.4s infinite ease-in-out;
  transition: all 0.15s ease;
}

.has-collision-pill:hover {
  background: rgba(239, 68, 68, 0.35);
  border-color: #ef4444;
  color: #fff !important;
  transform: translateY(-1px);
}

@keyframes colPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
  }
  50% {
    box-shadow: 0 0 8px 2px rgba(239, 68, 68, 0.28);
  }
}

/* Footer Status Bar */
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-subtle);
  font-size: 11.5px;
  color: var(--text-secondary);
  max-width: 100vw;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  min-width: 0;
  gap: 12px;
}

.statusbar::-webkit-scrollbar {
  display: none;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* Modals (Color Palette, Samples, Instruction Maker, BOM Export) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

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

.modal-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(760px, 92vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
}

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

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
  gap: 6px;
}

.color-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 7px;
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  font-size: 11.5px;
}

.color-item:hover {
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

.color-item.active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.18);
}

/* Sample Cards */
.samples-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.sample-card {
  background: var(--bg-panel-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.sample-card:hover {
  border-color: var(--accent-blue);
  background: var(--bg-hover);
}

/* Instruction Player Overlay Banner */
.instruction-banner {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 12px;
  padding: 10px 16px;
  display: none;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}

.instruction-banner.active {
  display: flex;
}

.callout-box {
  position: absolute;
  top: 76px;
  left: 14px;
  width: 240px;
  max-height: 55vh;
  overflow-y: auto;
  background: rgba(248, 250, 252, 0.95);
  color: #0f172a;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 10px;
  display: none;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 25;
}

.callout-box.active {
  display: flex;
}

.callout-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  font-size: 11.5px;
  font-weight: 600;
}

.code-textarea {
  width: 100%;
  height: 200px;
  background: var(--bg-app);
  color: #e2e8f0;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  resize: vertical;
}

/* Scrollbar polish */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.28);
}


/* --- Touch & Mobile / Tablet Responsive Enhancements --- */
#studio-canvas {
  touch-action: none;
  -webkit-touch-callout: none;
}

.mobile-drawer-btn {
  display: none;
}

.touch-confirm-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
  color: #fff !important;
  font-weight: 700 !important;
  padding: 7px 14px !important;
  box-shadow: 0 3px 12px rgba(16, 185, 129, 0.4);
}

/* Laptop & Compact Desktop Responsive Breakpoint (1025px - 1380px) */
@media (max-width: 1380px) and (min-width: 1025px) {
  .workspace {
    grid-template-columns: 255px minmax(0, 1fr) 265px;
  }
  .tool-btn {
    padding: 5px 8px;
    gap: 4px;
    font-size: 11.5px;
  }
  .kbd-hint {
    display: none;
  }
  .brand span {
    font-size: 13.5px;
  }
  .brand-badge {
    display: none;
  }
  .status-group {
    gap: 8px;
    font-size: 11px;
  }
}

@media (max-width: 1024px) {
  .app-shell {
    grid-template-rows: auto 1fr 28px;
  }
  .topbar {
    flex-wrap: wrap;
    padding: 6px 10px;
    gap: 6px;
  }
  .toolbar-group {
    overflow-x: auto;
    max-width: 100%;
  }
  .kbd-hint {
    display: none;
  }
  .workspace {
    grid-template-columns: 1fr;
  }
  .mobile-drawer-btn {
    display: inline-flex;
  }
  .panel-left, .panel-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 45;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.75);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .panel-left {
    left: 0;
    transform: translateX(-102%);
  }
  .panel-left.drawer-open {
    transform: translateX(0);
  }
  .panel-right {
    right: 0;
    transform: translateX(102%);
  }
  .panel-right.drawer-open {
    transform: translateX(0);
  }
  .hud-bottom-center {
    width: 94vw;
    overflow-x: auto;
    justify-content: flex-start;
    bottom: 10px;
    padding: 6px 8px;
  }
  .collision-panel {
    top: 56px;
    left: 8px;
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
    max-height: 60vh;
  }
  .tool-btn {
    padding: 8px 11px;
    font-size: 12.5px;
  }
}


/* ==========================================================================
   AI Copilot Engine Floating HUD & UI (Sprint 1)
   ========================================================================== */

.ai-copilot-panel {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(24px);
  width: min(780px, calc(100% - 32px));
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 14px;
  box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.75), 0 0 25px rgba(56, 189, 248, 0.18);
  padding: 13px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 85;
}

.ai-copilot-panel.open {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.ai-copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-copilot-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #f8fafc;
}

.ai-sparkle-icon {
  font-size: 16px;
  display: inline-block;
  animation: ai-pulse 2s infinite ease-in-out;
}

.ai-badge {
  font-size: 10px;
  font-weight: 700;
  background: linear-gradient(135deg, #a855f7, #3b82f6);
  color: #ffffff;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

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

.ai-copilot-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.ai-copilot-chips::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.22);
  color: #cbd5e1;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  user-select: none;
}
.ai-chip:hover {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.6);
  color: #38bdf8;
  transform: translateY(-1px);
}
.ai-chip:active {
  transform: translateY(0);
}

.ai-copilot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.45);
  border-radius: 9px;
  padding: 4px 6px 4px 12px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ai-copilot-input-row:focus-within {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25), inset 0 2px 4px rgba(0, 0, 0, 0.25);
}

.ai-input-prefix {
  font-size: 15px;
  color: #94a3b8;
}

.ai-copilot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f8fafc;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.4;
}
.ai-copilot-input::placeholder {
  color: #64748b;
  font-size: 12.5px;
}

.ai-copilot-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

.ai-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
  display: inline-block;
  flex-shrink: 0;
}
.ai-status-dot.idle {
  background: #10b981;
  box-shadow: 0 0 6px rgba(16, 185, 129, 0.6);
}
.ai-status-dot.thinking {
  background: #38bdf8;
  animation: ai-pulse 0.9s infinite alternate;
}
.ai-status-dot.snapping {
  background: #a855f7;
  animation: ai-pulse 0.7s infinite alternate;
}
.ai-status-dot.error {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.6);
}

.ai-result-banner {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #f1f5f9;
  line-height: 1.5;
}

.tool-btn.active-pulse {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.15), rgba(168, 85, 247, 0.2));
  border: 1px solid rgba(168, 85, 247, 0.5);
  color: #e2e8f0;
}
.tool-btn.active-pulse:hover {
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

@keyframes ai-pulse {
  0% { transform: scale(0.92); opacity: 0.75; }
  100% { transform: scale(1.15); opacity: 1; }
}

@media (max-width: 768px) {
  .ai-copilot-panel {
    width: calc(100vw - 20px);
    bottom: 10px;
    padding: 10px 12px;
  }
}
