:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #131b2e;
  --bg-card: rgba(22, 33, 56, 0.75);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-glow: rgba(0, 229, 255, 0.25);
  
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-bright: #ffffff;

  --accent-cyan: #06b6d4;
  --accent-blood: #f43f5e;
  --accent-liver: #10b981;
  --accent-atp: #f59e0b;
  --accent-purple: #8b5cf6;

  --font-family: 'Outfit', 'Noto Sans TC', sans-serif;
}

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

body {
  font-family: var(--font-family);
  background: radial-gradient(circle at 20% 15%, #182238 0%, #0b0f19 70%);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

.app-container {
  max-width: 1720px;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Header Styles */
.app-header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.1rem 1.5rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.header-content {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.logo-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
  padding: 0.3rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid rgba(6, 182, 212, 0.3);
  width: fit-content;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-cyan);
  box-shadow: 0 0 10px var(--accent-cyan);
  animation: pulse-glow 2s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
}

.app-header h1 {
  font-size: 1.85rem;
  font-weight: 900;
  background: linear-gradient(135deg, #ffffff 30%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Main Simulation Layout: Left large Canvas, Right Control Panel */
.simulation-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1.25rem;
  align-items: stretch;
}

@media (max-width: 1100px) {
  .simulation-layout {
    grid-template-columns: 1fr;
  }
}

/* Canvas Panel */
.canvas-panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1rem 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.canvas-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.75rem;
}

.canvas-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-bright);
}

.indicator.live {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.canvas-legend {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

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

.glucose-dot { background: #38bdf8; box-shadow: 0 0 6px rgba(56, 189, 248, 0.7); }
.glycogen-core-dot { background: #10b981; box-shadow: 0 0 6px rgba(16, 185, 129, 0.7); }
.glycogen-tip-dot { background: #facc15; box-shadow: 0 0 7px rgba(250, 204, 21, 0.8); }
.atp-dot { background: #f97316; box-shadow: 0 0 8px rgba(249, 115, 22, 0.9); }

.canvas-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1120 / 700;
  background: #090e18;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#simCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* In-Canvas Contextual Overlay Layout */
.canvas-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none; /* 让未遮挡區域的滑鼠事件穿透到 canvas */
  z-index: 10;
}

/* 懸浮情境按鈕通用樣式 */
.spot-btn {
  pointer-events: auto; /* 恢復按鈕可點擊 */
  position: absolute;
  width: auto;
  min-width: 118px;
  max-width: 156px;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  gap: 0.45rem;
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.55), 0 0 1px rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(8px);
  transform: translateZ(0);
}

.spot-btn:hover {
  transform: translateY(-2px) scale(1.03);
}

.spot-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.spot-btn .btn-text strong {
  font-size: 0.82rem;
  line-height: 1.2;
}

.spot-btn .btn-text small {
  font-size: 0.68rem;
  line-height: 1.1;
  opacity: 0.85;
}

.spot-group {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  pointer-events: none;
}

.spot-group .spot-btn {
  position: static;
}

/* 1. 血管起點：進食升糖 (緊貼血管左側起點入口外部空隙，整齊對齊血管水平中心線) */
.spot-blood-start {
  left: 2.2%;
  top: 24.2%;
  border-color: rgba(244, 63, 94, 0.7);
  background: rgba(190, 18, 60, 0.78);
  animation: pulse-border 2.5s infinite alternate;
}

@keyframes pulse-border {
  0% { box-shadow: 0 4px 14px rgba(244, 63, 94, 0.35); }
  100% { box-shadow: 0 4px 22px rgba(244, 63, 94, 0.75); }
}

/* 2. 肝臟區域按鈕 (位於肝臟內部右半邊平坦開闊區，縱向整齊排列) */
.spot-liver-group {
  left: 31%;
  top: 4%;
  flex-direction: column;
  gap: 0.45rem;
}

/* 3. 骨骼肌細胞按鈕 (放置於骨骼肌右上角開闊空白處，縱向排列，完全在骨骼肌框線內) */
.spot-muscle-group {
  left: 17%;
  top: 55.5%;
  flex-direction: column;
  gap: 0.4rem;
}

/* 4. 脂肪細胞按鈕 (放置於脂肪細胞右上角空白處，不擋左上標題與下方油滴) */
.spot-adipose-group {
  left: 49%;
  top: 55.5%;
}

/* 5. 組織細胞按鈕 (放置於組織細胞上方開闊細胞質區，避開左側細胞標題與下方粒線體) */
.spot-cell-group {
  left: 81%;
  top: 56.5%;
}

/* 操作指南卡片 */
.legend-card {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0.85rem;
  font-size: 0.85rem;
}

.legend-card h4 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 0.35rem;
}

.legend-card p {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

.guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.78rem;
}

.guide-list li {
  color: var(--text-main);
  line-height: 1.35;
}

/* Right Sidebar Control Panel */
.sidebar-control-panel {
  display: flex;
  flex-direction: column;
}

.sidebar-card {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  height: 100%;
}

.sidebar-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 0.75rem;
}

.sidebar-card-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-bright);
}

.sub-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(6, 182, 212, 0.3);
}

.btn-vertical-group {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 0.25rem 0;
}

.sidebar-settings {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(30, 41, 59, 0.65);
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  text-align: left;
  width: 100%;
}

.btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.15);
}

.btn:active {
  transform: translateY(1px);
}

.btn-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.btn-text strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
}

.btn-text small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.25), rgba(225, 29, 72, 0.4));
  border-color: rgba(244, 63, 94, 0.4);
}
.btn-primary:hover {
  box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}

.btn-liver {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(5, 150, 105, 0.4));
  border-color: rgba(16, 185, 129, 0.4);
}
.btn-liver:hover {
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.btn-break {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.2), rgba(202, 138, 4, 0.35));
  border-color: rgba(234, 179, 8, 0.4);
}
.btn-break:hover {
  box-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
}

.btn-muscle {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.2), rgba(190, 18, 60, 0.35));
  border-color: rgba(244, 63, 94, 0.4);
}
.btn-muscle:hover {
  box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}

.btn-muscle-use {
  background: linear-gradient(135deg, rgba(225, 29, 72, 0.25), rgba(159, 18, 57, 0.45));
  border-color: rgba(251, 113, 133, 0.4);
}
.btn-muscle-use:hover {
  box-shadow: 0 0 15px rgba(244, 63, 94, 0.45);
}

.btn-adipose {
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.22), rgba(180, 83, 9, 0.38));
  border-color: rgba(234, 179, 8, 0.45);
}
.btn-adipose:hover {
  box-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
}

.btn-mito {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25), rgba(109, 40, 217, 0.4));
  border-color: rgba(139, 92, 246, 0.4);
}
.btn-mito:hover {
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}

.secondary-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  background: rgba(15, 23, 42, 0.45);
  padding: 0.65rem 1rem;
  border-radius: 12px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-toggle {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.05);
}

.btn-toggle.active {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.btn-secondary {
  padding: 0.5rem 0.9rem;
  font-size: 0.85rem;
}

.speed-control {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.speed-control input[type="range"] {
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 0.75rem 0;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
