/* ==========================================================================
   3D 葉片橫切面微觀解剖模型 - 樣式表 (style.css)
   進階科學實驗室風格、玻璃擬態 (Glassmorphism)、暗黑模式與精美動態微交互
   ========================================================================== */

:root {
  --bg-dark: #0a0e17;
  --bg-panel: rgba(16, 24, 39, 0.78);
  --bg-panel-hover: rgba(24, 35, 58, 0.88);
  --border-glass: rgba(255, 255, 255, 0.12);
  --border-focus: #10b981;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-highlight: #34d399;
  
  --primary: #10b981;
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.35);
  
  --accent-cyan: #06b6d4;
  --accent-lime: #84cc16;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --accent-chloroplast: #00ff88;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --shadow-panel: 0 16px 36px -8px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--border-glass);
  --shadow-glow: 0 0 20px rgba(16, 185, 129, 0.25);
  
  --font-family-sans: 'Outfit', 'Noto Sans TC', system-ui, -apple-system, sans-serif;
  --transition-fast: 0.18s ease;
  --transition-normal: 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  user-select: none;
}

#app-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   頂部導覽列 Main Header
   ========================================================================== */
#main-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(10, 14, 23, 0.85) 0%, rgba(10, 14, 23, 0) 100%);
  z-index: 50;
  pointer-events: none;
}

#main-header * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10b981 0%, #047857 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #fff;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.45);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-text .subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

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

.view-preset-group {
  display: flex;
  background: rgba(16, 24, 39, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  padding: 3px;
  border-radius: var(--radius-full);
  gap: 3px;
}

.preset-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 6px;
}

.preset-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.preset-btn.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 2px 10px var(--primary-glow);
}

.icon-action-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(16, 24, 39, 0.75);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 0.9rem;
}

.icon-action-btn:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.icon-action-btn.active {
  color: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

/* ==========================================================================
   3D 畫布與視窗 Canvas Wrapper
   ========================================================================== */
#canvas-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#webgl-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* 懸停指示 Tooltip */
.hover-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 60;
  padding: 6px 12px;
  background: rgba(12, 19, 31, 0.88);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(16, 185, 129, 0.4);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -130%);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.hover-tooltip.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.tooltip-badge {
  font-size: 0.65rem;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.tooltip-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

/* 視角操作導覽小標籤 */
.viewport-hints {
  position: absolute;
  bottom: 56px;
  left: 360px;
  display: flex;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.hint-item {
  background: rgba(10, 14, 23, 0.65);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-glass);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* 狀態指示晶片條 */
.status-bar {
  position: absolute;
  top: 76px;
  left: 360px;
  display: flex;
  gap: 10px;
  z-index: 30;
  pointer-events: none;
}

.status-chip {
  background: rgba(10, 14, 23, 0.7);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-glass);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-chip .dot.green {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-chip .dot.cyan {
  background: #06b6d4;
  box-shadow: 0 0 8px #06b6d4;
  animation: pulse-dot 1.8s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.9); opacity: 0.7; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.7; }
}

/* ==========================================================================
   側邊玻璃面控板 Common Panel Styles
   ========================================================================== */
.glass-panel {
  position: absolute;
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-panel);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
}

.panel-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-glass);
  background: rgba(255, 255, 255, 0.02);
}

.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.3px;
}

.panel-header h2 i {
  color: var(--primary);
}

.mini-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mini-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.icon-mini-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.icon-mini-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* ==========================================================================
   左側：構造控制與過濾面板 Sidebar Controls
   ========================================================================== */
#sidebar-controls {
  top: 76px;
  left: 20px;
  bottom: 56px;
  width: 320px;
  border-radius: var(--radius-lg);
}

.control-section {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.control-section.highlight-box {
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08) 0%, rgba(16, 185, 129, 0.02) 100%);
  border-bottom: 1px solid rgba(16, 185, 129, 0.2);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.section-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #e5e7eb;
  display: flex;
  align-items: center;
  gap: 7px;
}

.section-title i {
  color: var(--primary);
}

.section-desc {
  font-size: 0.71rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 10px;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.badge.secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

/* 滑桿美化 */
.slider-wrapper {
  margin: 8px 0;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  transition: background var(--transition-fast);
}

input[type="range"]:hover {
  background: rgba(255, 255, 255, 0.18);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: #f0fdf4;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* 快速切換按鈕群組 */
.quick-toggle-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.quick-toggle-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.quick-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.quick-toggle-btn.active {
  background: rgba(16, 185, 129, 0.22);
  border-color: var(--primary);
  color: #34d399;
  font-weight: 600;
}

/* 顯示模式切換網格 */
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.switch-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.switch-card:hover {
  background: rgba(255, 255, 255, 0.08);
}

.switch-card input {
  display: none;
}

.switch-indicator {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.switch-card input:checked + .switch-indicator {
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 8px var(--primary-glow);
}

.switch-card input:checked + .switch-indicator::after {
  content: '✓';
  font-size: 10px;
  color: #fff;
  font-weight: bold;
}

.switch-label {
  font-size: 0.72rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* 組織構造樹狀列表 */
.structures-list-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 8px;
}

.structures-tree {
  flex: 1;
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.structures-tree::-webkit-scrollbar {
  width: 4px;
}

.structures-tree::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.tree-node {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.tree-node:hover {
  background: rgba(255, 255, 255, 0.07);
}

.tree-node.highlighted {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.4);
}

.tree-node.hidden-node {
  opacity: 0.45;
}

.node-info-left {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
  overflow: hidden;
}

.node-color-tag {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-title-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.node-name {
  font-size: 0.78rem;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.node-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.node-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  transition: all var(--transition-fast);
}

.node-action-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.node-action-btn.active-focus {
  color: #34d399;
}

.node-action-btn.is-hidden {
  color: #ef4444;
}

/* ==========================================================================
   右側：解剖生理知識卡 Sidebar Info
   ========================================================================== */
#sidebar-info {
  top: 76px;
  right: 20px;
  bottom: 56px;
  width: 360px;
  border-radius: var(--radius-lg);
}

#sidebar-info.collapsed {
  transform: translateX(390px);
  pointer-events: none;
}

#info-content-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#info-content-scroll::-webkit-scrollbar {
  width: 4px;
}

#info-content-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

.selected-entity-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entity-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-tag {
  background: rgba(6, 182, 212, 0.2);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.35);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.status-tag {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  font-size: 0.68rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.selected-entity-card h3 {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.selected-entity-card h4 {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-muted);
  font-style: italic;
  margin-top: -6px;
}

.meta-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-val {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
}

.info-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.block-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-highlight);
  display: flex;
  align-items: center;
  gap: 6px;
}

.block-text {
  font-size: 0.8rem;
  color: #d1d5db;
  line-height: 1.55;
  background: rgba(255, 255, 255, 0.02);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border-left: 2px solid rgba(16, 185, 129, 0.4);
}

.highlight-insight {
  background: rgba(245, 158, 11, 0.06);
  border: 1px solid rgba(245, 158, 11, 0.2);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.highlight-insight .block-title {
  color: #fbbf24;
}

.highlight-insight .block-text {
  background: transparent;
  border-left: none;
  padding: 0;
  color: #fef3c7;
}

.card-action-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 6px;
}

.btn-primary-action {
  background: var(--primary);
  border: none;
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: 0 4px 12px var(--primary-glow);
  transition: all var(--transition-fast);
}

.btn-primary-action:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: #fff;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all var(--transition-fast);
}

.btn-secondary-action:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* 折疊手冊 */
.quick-guide-accordion {
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.accordion-header {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 600;
  color: #e5e7eb;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

.accordion-body {
  padding: 10px 12px;
  font-size: 0.74rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-glass);
  background: rgba(0, 0, 0, 0.2);
}

.accordion-body.collapsed {
  display: none;
}

.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guide-list li strong {
  color: #fff;
}

.guide-list ul {
  margin-top: 4px;
  margin-left: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ==========================================================================
   底部圖例列 Bottom Bar
   ========================================================================== */
#bottom-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: rgba(10, 14, 23, 0.88);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 20px;
  z-index: 50;
}

.legend-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.legend-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.legend-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #d1d5db;
  background: rgba(255, 255, 255, 0.05);
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.legend-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ==========================================================================
   響應式設計 Responsive Media Queries
   ========================================================================== */
@media (max-width: 1024px) {
  #sidebar-controls {
    width: 280px;
    left: 12px;
  }
  #sidebar-info {
    width: 300px;
    right: 12px;
  }
  .viewport-hints, .status-bar {
    left: 305px;
  }
}

@media (max-width: 768px) {
  #main-header {
    height: 56px;
    padding: 0 12px;
  }
  .brand-text .subtitle {
    display: none;
  }
  .view-preset-group {
    display: none;
  }
  #sidebar-controls {
    width: calc(100% - 24px);
    height: auto;
    max-height: 40vh;
    bottom: auto;
    top: 64px;
  }
  #sidebar-info {
    width: calc(100% - 24px);
    right: 12px;
    bottom: 54px;
    top: auto;
    max-height: 45vh;
  }
  .viewport-hints, .status-bar {
    display: none;
  }
}
