@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=Noto+Sans+TC:wght@300;400;500;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-dark: #0a0e14;
  --bg-card: rgba(16, 23, 34, 0.78);
  --bg-card-hover: rgba(22, 32, 48, 0.9);
  --border-glass: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(74, 222, 128, 0.5);
  
  --primary-green: #10b981;
  --primary-glow: rgba(16, 185, 129, 0.35);
  --xylem-blue: #38bdf8;
  --phloem-amber: #fbbf24;
  --cambium-emerald: #34d399;
  --pith-cream: #fef08a;
  --bark-brown: #a16207;
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  
  --shadow-hud: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 1px 1px rgba(255, 255, 255, 0.08);
  --blur-glass: blur(16px);
}

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

body {
  font-family: 'Outfit', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  user-select: none;
}

#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* UI Overlays */
.ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
}

.interactive {
  pointer-events: auto;
}

/* Glass panel */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-hud);
  border-radius: var(--radius-lg);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Header */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.title-badge {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 20px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #059669, #10b981);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.logo-icon svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.title-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(120deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

/* Plant Type Switcher */
.mode-switcher {
  display: flex;
  background: rgba(10, 15, 25, 0.85);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  padding: 5px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.switch-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  font-family: inherit;
}

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

.switch-btn.active {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 4px 15px rgba(16, 185, 129, 0.45);
}

/* Top Right Actions */
.quick-tools {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: var(--bg-card);
  backdrop-filter: var(--blur-glass);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.icon-btn.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--primary-green);
  color: var(--primary-green);
}

/* Main Layout Middle: Left Tools, Right Details */
.main-hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  pointer-events: none;
  flex: 1;
  padding: 16px 0;
  gap: 20px;
}

/* Left Controller Sidebar */
.left-controls {
  width: 310px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 150px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  padding-right: 4px;
}

.control-card {
  padding: 16px;
}

.card-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.view-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.view-btn svg {
  width: 18px;
  height: 18px;
  opacity: 0.8;
}

.view-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.view-btn.active {
  background: rgba(16, 185, 129, 0.18);
  border-color: var(--primary-green);
  color: #34d399;
}

/* Cell Submode Buttons */
.cell-submode-grid {
  display: flex !important;
  flex-direction: column !important;
  gap: 8px !important;
}

.cell-submode-grid .view-btn {
  flex-direction: row !important;
  justify-content: flex-start !important;
  padding: 10px 14px !important;
  gap: 12px !important;
  font-size: 0.82rem !important;
  border-radius: var(--radius-md) !important;
}

.cell-submode-grid .view-btn svg {
  width: 20px !important;
  height: 20px !important;
  flex-shrink: 0 !important;
}

#cell-view-phloem.active {
  background: rgba(245, 158, 11, 0.2) !important;
  border-color: #f59e0b !important;
  color: #fbbf24 !important;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.25) !important;
}

#cell-view-xylem.active {
  background: rgba(56, 189, 248, 0.2) !important;
  border-color: #38bdf8 !important;
  color: #7dd3fc !important;
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.25) !important;
}

#cell-view-pair.active {
  background: rgba(16, 185, 129, 0.2) !important;
  border-color: #10b981 !important;
  color: #6ee7b7 !important;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.25) !important;
}

/* Sliders */
.slider-group {
  margin-bottom: 12px;
}

.slider-group:last-child {
  margin-bottom: 0;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.slider-val {
  color: #38bdf8;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
}

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

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  cursor: pointer;
  transition: transform 0.15s ease;
}

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

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.toggle-label {
  font-size: 0.82rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

/* Switch toggle */
.switch-input {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}

.switch-input input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.15);
  transition: 0.3s;
  border-radius: 20px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

input:checked + .switch-slider {
  background-color: #10b981;
}

input:checked + .switch-slider:before {
  transform: translateX(16px);
}

/* Right Detail Card */
.right-details {
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-card {
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

.structure-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  margin-bottom: 10px;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.detail-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 4px;
}

.detail-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.detail-desc {
  font-size: 0.84rem;
  line-height: 1.6;
  color: #cbd5e1;
  margin-bottom: 14px;
}

.features-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.features-list li {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.features-list li strong {
  color: var(--text-main);
  white-space: nowrap;
}

.features-list li::before {
  content: "•";
  color: var(--primary-green);
  font-weight: bold;
}

.highlight-box {
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border-left: 3px solid var(--primary-green);
  font-size: 0.76rem;
  color: #e2e8f0;
  line-height: 1.5;
}

/* Monkey Face Callout Mini-card */
.monkey-face-card {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 14px;
  border-radius: var(--radius-md);
  margin-top: 10px;
  display: none;
}

.monkey-face-card.visible {
  display: block;
}

.monkey-face-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.monkey-face-header h4 {
  font-size: 0.85rem;
  color: #38bdf8;
  font-weight: 600;
}

/* Bottom Bar Legend */
.bottom-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
}

.legend-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s ease;
}

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

.legend-color {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  box-shadow: 0 0 6px currentColor;
}

.hint-badge {
  padding: 8px 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.hint-badge kbd {
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
  color: #fff;
  font-size: 0.7rem;
}

/* Tooltip */
.tooltip-3d {
  position: absolute;
  z-index: 100;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, -120%);
  transition: opacity 0.15s ease, transform 0.15s ease;
  opacity: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tooltip-3d.visible {
  opacity: 1;
  transform: translate(-50%, -135%);
}

/* Comparison Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(12px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  width: 90%;
  max-width: 960px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 30px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #fff;
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

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

.comp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.comp-table th, .comp-table td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.comp-table th {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
}

.comp-table td:first-child {
  font-weight: 600;
  color: #fff;
  width: 22%;
}

.comp-table td:nth-child(2) {
  color: #6ee7b7;
  width: 39%;
}

.comp-table td:nth-child(3) {
  color: #93c5fd;
  width: 39%;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsiveness */
@media (max-width: 1024px) {
  .left-controls {
    width: 270px;
  }
  .right-details {
    width: 290px;
  }
}

@media (max-width: 768px) {
  .main-hud {
    flex-direction: column;
    overflow-y: auto;
  }
  .left-controls, .right-details {
    width: 100%;
    max-height: none;
  }
  .legend-panel {
    display: none;
  }
}
