/* macOS Apple Design System - MRI 3D Virtual Simulation */
:root {
  --sf-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --system-blue: #007aff;
  --system-blue-hover: #0062cc;
  --system-cyan: #32ade6;
  --system-green: #34c759;
  --system-red: #ff3b30;
  --system-orange: #ff9500;
  --white: #ffffff;
  --muted: rgba(255, 255, 255, 0.65);
  --glass-bg: rgba(22, 26, 35, 0.76);
  --glass-border: rgba(255, 255, 255, 0.14);
  --mac-shadow: 0 20px 40px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1);
  --panel-radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--sf-font);
  background: radial-gradient(circle at 20% 20%, #1a2336 0%, #0d121c 60%, #05070c 100%);
  color: var(--white);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }

button:focus-visible, input:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--system-blue);
  outline-offset: 2px;
}

/* macOS 统一毛玻璃 (Vibrancy Glass) 材质 */
.blue-glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--mac-shadow);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border-radius: var(--panel-radius);
}

/* 3D Viewport */
#viewport { position: fixed; inset: 0; overflow: hidden; }
#scene-canvas { display: block; width: 100%; height: 100%; cursor: grab; outline: none; }
#scene-canvas:active { cursor: grabbing; }
#scene-canvas.part-dragging { cursor: move; }

#hover-tip {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  padding: 8px 14px;
  border-radius: 8px;
  color: white;
  background: rgba(18, 22, 30, 0.9);
  border: 1px solid var(--glass-border);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.drag-hint {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 4;
  padding: 6px 16px;
  border-radius: 980px;
  color: var(--muted);
  background: rgba(20, 24, 32, 0.7);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px);
  font-size: 11px;
  pointer-events: none;
}

/* macOS Traffic Lights 红黄绿控制按键 */
.traffic-lights {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  display: inline-block;
  cursor: pointer;
}

.dot.close { background-color: #ff5f56; }
.dot.minimize { background-color: #ffbd2e; }
.dot.maximize { background-color: #27c93f; }

/* macOS Standard Top Toolbar Header */
#topbar {
  position: fixed;
  z-index: 25;
  left: 0;
  top: 0;
  right: 0;
  height: 44px;
  padding: 0 18px;
  background: rgba(20, 24, 32, 0.8);
  backdrop-filter: blur(25px) saturate(180%);
  -webkit-backdrop-filter: blur(25px) saturate(180%);
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  gap: 20px;
}

.topbar-title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

#topbar h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--white);
}

#topbar span {
  color: var(--system-cyan);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

/* 交互说明 macOS Status Badge Pill */
#interaction-guide {
  position: fixed;
  z-index: 22;
  right: 24px;
  top: 8px;
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 980px;
  border: 1px solid var(--glass-border);
}

#interaction-guide span {
  padding: 4px 10px;
  text-align: center;
  color: var(--white);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#interaction-guide b {
  color: var(--system-cyan);
  font-size: 10px;
  font-weight: 700;
}

/* 左侧 macOS Sidebar 构造目录 */
#control-panel {
  position: fixed;
  z-index: 20;
  left: 20px;
  top: 60px;
  width: 220px;
  max-height: calc(100vh - 140px);
  overflow: hidden;
}

.panel-title {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--glass-border);
}

.panel-title h2 { font-size: 13px; font-weight: 700; }
.panel-title span { color: var(--system-cyan); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; }

.panel-section { padding: 8px; }

.parts-list {
  list-style: none;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.part-row {
  min-height: 32px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: background 0.15s, transform 0.15s;
}

.part-row:hover {
  background: rgba(255, 255, 255, 0.08);
}

.part-row.selected {
  background: var(--system-blue);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 122, 255, 0.35);
}

.part-vis {
  width: 100%;
  min-width: 0;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
}

.part-vis input { display: none; }
.part-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.mini-btn { display: none; }

/* 中央 macOS Inspector 知识卡片 */
#info-panel {
  position: fixed;
  z-index: 18;
  left: 50%;
  top: 60px;
  transform: translateX(-50%);
  width: 500px;
  padding: 16px 20px;
}

.info-header { margin-bottom: 8px; }
.info-kicker { color: var(--system-cyan); font-size: 10px; font-weight: 700; letter-spacing: 0.12em; }
.info-header h2 { display: inline; margin-left: 10px; color: var(--white); font-size: 15px; font-weight: 700; }
.info-id { color: var(--muted); font-size: 11px; margin-top: 4px; }
.info-card { display: inline; }
.info-card h3 { display: none; }
.info-card p { display: inline; color: var(--white); font-size: 13px; line-height: 1.6; }
.info-card.safety::before { content: "  ·  "; color: var(--system-cyan); }
.info-card.safety p { color: rgba(255, 255, 255, 0.85); }

/* 右侧 macOS 操作矩阵 */
#action-panel {
  position: fixed;
  z-index: 20;
  right: 20px;
  top: 60px;
  width: 200px;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-btn {
  position: relative;
  min-height: 46px;
  padding: 6px 4px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  color: var(--white);
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(20px);
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.action-btn:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.25);
}

.action-btn:active { transform: scale(0.96); }

.action-btn.active, .action-toggle:has(input:checked) {
  background: var(--system-blue);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.4);
}

.action-btn b { display: block; font-size: 12px; font-weight: 700; }
.action-btn span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; letter-spacing: 0.06em; }

.action-toggle { display: grid; align-content: center; }
.action-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.progress-control {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
}

.progress-control > div { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 6px; }
.progress-control b { color: var(--system-cyan); font-weight: 700; }

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 20px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 980px;
  background: linear-gradient(to right, var(--system-blue) 0 var(--range-progress, 0%), rgba(255, 255, 255, 0.2) var(--range-progress, 0%) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  margin-top: -6px;
  background: white;
  border: 2px solid var(--system-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* 右侧标准视角 Presets Tool Palette */
#view-presets {
  position: fixed;
  z-index: 21;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 6px;
}

#view-presets button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--glass-border);
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, background 0.15s;
}

#view-presets button:hover {
  transform: translateX(-2px);
  background: var(--system-blue);
}

/* 底部 macOS Segmented Pill Bar (Layer Tabs) */
#layer-tabs {
  position: fixed;
  z-index: 18;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 5px;
  background: rgba(20, 24, 32, 0.75);
  backdrop-filter: blur(25px);
  border: 1px solid var(--glass-border);
  border-radius: 980px;
  box-shadow: var(--mac-shadow);
}

#layer-tabs button {
  min-width: 90px;
  padding: 8px 16px;
  border-radius: 980px;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

#layer-tabs button:hover {
  color: var(--white);
  background: rgba(255, 255, 255, 0.08);
}

#layer-tabs button.active {
  background: var(--system-blue);
  color: white;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 122, 255, 0.4);
}

/* 底部 macOS Window Status Bar */
#status-bar {
  position: fixed;
  z-index: 19;
  left: 20px;
  bottom: 20px;
  display: flex;
  gap: 16px;
  padding: 6px 14px;
  border-radius: 980px;
  color: var(--muted);
  font-size: 11px;
}

#status-state b { color: var(--system-cyan); }
#status-fps { color: var(--system-green); }

@media (max-width: 1150px) {
  #info-panel { width: 420px; }
  #action-panel { right: 16px; width: 180px; }
  #control-panel { width: 190px; }
  #layer-tabs button { min-width: 76px; padding-inline: 10px; }
}
