:root {
  --bg-dark: #0b0f19;
  --bg-panel: #151c2c;
  --bg-card: #1c2539;
  --bg-card-hover: #25314a;
  --border-color: rgba(255, 255, 255, 0.1);
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --accent-red: #ef4444;
  --accent-crimson: #dc2626;
  --accent-amber: #f59e0b;
  --accent-yellow: #facc15;
  --accent-purple: #a855f7;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-blue: #3b82f6;
  --radius-lg: 14px;
  --radius-md: 10px;
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: radial-gradient(circle at 15% 15%, #1a162b 0%, var(--bg-dark) 70%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* 頂部標題列 */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: rgba(21, 28, 44, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  gap: 16px;
  flex-wrap: wrap;
}

.title-group h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, #fca5a5, #fde047, #67e8f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.title-group p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 2px;
}

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

/* 主要雙欄版面 */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 370px;
  gap: 20px;
  padding: 18px 24px;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.simulation-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

/* 階段導覽列 (Stepper) */
.stage-stepper {
  display: flex;
  align-items: center;
  background: var(--bg-panel);
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow-x: auto;
  gap: 4px;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 7px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.step-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
}

.step-item.active {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.22);
}

.step-item.completed .step-num {
  background: var(--accent-green);
  color: #052e16;
}

.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.76rem;
  font-weight: 700;
}

.step-item.active .step-num {
  background: var(--accent-red);
  color: #fff;
}

.step-connector {
  flex: 1;
  min-width: 12px;
  height: 2px;
  background: rgba(255, 255, 255, 0.12);
}

/* 畫布容器 */
.canvas-container {
  position: relative;
  background: #090d16;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  aspect-ratio: 920 / 540;
  width: 100%;
}

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

/* 畫布上方浮動控制列 */
.canvas-overlay-top {
  position: absolute;
  top: 12px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  gap: 10px;
  flex-wrap: wrap;
}

.stage-badge {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(248, 113, 113, 0.45);
  color: #fecaca;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
  pointer-events: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.env-controls {
  display: flex;
  gap: 12px;
  pointer-events: auto;
  flex-wrap: wrap;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.slider-group label {
  color: #cbd5e1;
  font-weight: 600;
}

.slider-group input[type="range"] {
  width: 78px;
  accent-color: var(--accent-amber);
  cursor: pointer;
}

.val-tag {
  font-weight: 700;
  color: var(--accent-yellow);
  min-width: 44px;
  text-align: right;
}

/* 顯微懸停提示卡 */
.micro-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(250, 204, 21, 0.5);
  border-radius: 10px;
  padding: 9px 12px;
  max-width: 250px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 20;
  transform: translate(14px, -50%);
}

.tooltip-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fde047;
  margin-bottom: 3px;
}

.tooltip-desc {
  font-size: 0.77rem;
  color: #e2e8f0;
  line-height: 1.4;
}

/* 畫布下方提示文字 */
.canvas-prompt {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  white-space: nowrap;
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.stage-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
}

.stage-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  transition: width 0.15s linear;
}

/* 底部互動控制列 */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  gap: 10px;
  flex-wrap: wrap;
}

.interactive-tools {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

/* 按鈕樣式 */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-main);
  background: var(--bg-card);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.12);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff;
  border-color: rgba(252, 165, 165, 0.35);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-color);
}

.btn-secondary.active-toggle {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.55);
  color: #6ee7b7;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
}

.btn-outline:hover {
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.3);
}

.btn-nav {
  background: #222d44;
  border-color: rgba(255, 255, 255, 0.12);
}

.btn-tool-ldl {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fde68a;
}

.btn-tool-immune {
  background: rgba(168, 85, 247, 0.18);
  border-color: rgba(168, 85, 247, 0.45);
  color: #e9d5ff;
}

.btn-tool-hdl {
  background: rgba(6, 182, 212, 0.18);
  border-color: rgba(6, 182, 212, 0.45);
  color: #a5f3fc;
}

/* 右側資訊欄 */
.info-sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.stage-tag {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.6px;
}

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

.info-desc {
  font-size: 0.88rem;
  color: #cbd5e1;
  margin-bottom: 12px;
  line-height: 1.55;
}

.key-events h3,
.metrics-card h3,
.legend-card h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 8px;
}

.key-events ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.key-events li {
  font-size: 0.82rem;
  color: #cbd5e1;
  padding-left: 14px;
  position: relative;
  line-height: 1.45;
}

.key-events li::before {
  content: "•";
  color: var(--accent-amber);
  font-weight: bold;
  position: absolute;
  left: 0;
}

/* 指標進度條 */
.metric-row {
  margin-bottom: 10px;
}

.metric-row:last-child {
  margin-bottom: 0;
}

.metric-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #cbd5e1;
  margin-bottom: 4px;
}

.metric-label span:last-child {
  font-weight: 700;
}

.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.35s ease;
}

.fill-green {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.fill-amber {
  background: linear-gradient(90deg, #f59e0b, #facc15);
}

.fill-purple {
  background: linear-gradient(90deg, #8b5cf6, #c084fc);
}

.fill-red {
  background: linear-gradient(90deg, #ef4444, #f87171);
}

/* 角色圖鑑 */
.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.btn-tiny {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e2e8f0;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.74rem;
  cursor: pointer;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
}

.legend-item:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.18);
}

.legend-item.active-role {
  background: rgba(250, 204, 21, 0.14);
  border-color: var(--accent-yellow);
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.2);
}

.legend-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}

.icon-ldl {
  background: radial-gradient(circle at 35% 35%, #fef08a, #eab308 65%, #ca8a04);
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.6);
}

.icon-monocyte {
  background: radial-gradient(circle at 35% 35%, #e9d5ff, #9333ea 70%, #581c87);
  border: 2px solid #f3e8ff;
}

.icon-foam {
  background: radial-gradient(circle at 40% 40%, #fde047, #d97706 70%, #78350f);
  border: 2px dashed #fef08a;
}

.icon-smc {
  background: linear-gradient(135deg, #fda4af, #e11d48);
  border-radius: 999px;
  height: 14px;
}

.icon-platelet {
  background: radial-gradient(circle, #fef9c3, #f59e0b);
  clip-path: polygon(50% 0%, 68% 32%, 100% 50%, 68% 68%, 50% 100%, 32% 68%, 0% 50%, 32% 32%);
}

.icon-hdl {
  background: radial-gradient(circle at 35% 35%, #cffafe, #06b6d4 65%, #0e7490);
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.65);
}

.legend-text {
  display: flex;
  flex-direction: column;
}

.legend-text strong {
  font-size: 0.81rem;
  color: #f8fafc;
}

.legend-text span {
  font-size: 0.74rem;
  color: var(--text-muted);
}

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