:root {
  --bg-dark: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #283548;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-plasma: #38bdf8;
  --accent-tissue: #facc15;
  --accent-lymph: #84cc16;
  --accent-blood: #f43f5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  touch-action: manipulation;
}

header {
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.badge {
  background: rgba(132, 204, 22, 0.18);
  color: #bef264;
  border: 1px solid rgba(132, 204, 22, 0.4);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #f8fafc;
}

/* 平板友善大尺寸雙分頁切換列 */
.tab-switcher {
  display: flex;
  gap: 8px;
  background: #0b1120;
  padding: 5px;
  border-radius: 14px;
  border: 1px solid #334155;
}

.main-tab-btn {
  background: transparent;
  color: #94a3b8;
  border: none;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.18s, color 0.18s;
}

.main-tab-btn:active {
  transform: scale(0.97);
}

.main-tab-btn.active {
  background: linear-gradient(135deg, #15803d, #166534);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(22, 163, 74, 0.4);
}

/* 主版面：集中聚焦，畫布為主、右側互動操作卡為輔 */
.main-container {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.75fr);
  gap: 16px;
  padding: 12px 18px;
  flex: 1;
  max-width: 1560px;
  width: 100%;
  margin: 0 auto;
  align-items: start;
}

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

.canvas-panel {
  background: radial-gradient(circle at 50% 45%, #ffffff 0%, #f8fafc 78%, #e2e8f0 100%);
  border: 2px solid #475569;
  border-radius: 16px;
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 900 / 620;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

#simCanvas {
  width: 100%;
  height: 100%;
  aspect-ratio: 900 / 620;
  display: block;
  cursor: pointer;
  touch-action: none;
}

/* 控制子區塊分組 (右側統一控制中心) */
.control-subgroup {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  padding-bottom: 11px;
}

.control-subgroup:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.subgroup-label {
  font-size: 0.84rem;
  font-weight: 700;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.02em;
}

.subgroup-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 分子切換網格 (集中於右側卡片，2欄工整排列) */
.mol-pill-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.mol-pill-grid .full-col,
.struct-chip-grid .full-col {
  grid-column: span 2;
}

.mol-tab-btn {
  background: rgba(15, 23, 42, 0.65);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.16s ease;
  touch-action: manipulation;
  user-select: none;
}

.mol-tab-btn:hover {
  background: rgba(51, 65, 85, 0.85);
  color: #f1f5f9;
}

.mol-tab-btn:active {
  transform: scale(0.97);
}

.mol-tab-btn.active {
  background: rgba(15, 23, 42, 0.98);
  color: #ffffff;
}

.mol-tab-btn[data-molmode="water"].active, .mol-tab-btn[data-molmode2="plasma"].active {
  border-color: #38bdf8;
  color: #e0f2fe;
  background: rgba(2, 132, 199, 0.22);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.mol-tab-btn[data-molmode="nutrient"].active {
  border-color: #22d3ee;
  color: #cffafe;
  background: rgba(8, 145, 178, 0.22);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.35);
}

.mol-tab-btn[data-molmode="waste"].active, .mol-tab-btn[data-molmode2="germ"].active {
  border-color: #c084fc;
  color: #f3e8ff;
  background: rgba(147, 51, 234, 0.22);
  box-shadow: 0 0 10px rgba(192, 132, 252, 0.35);
}

.mol-tab-btn[data-molmode="rbc"].active, .mol-tab-btn[data-molmode2="rbc"].active {
  border-color: #f87171;
  color: #fee2e2;
  background: rgba(225, 29, 72, 0.22);
  box-shadow: 0 0 10px rgba(248, 113, 113, 0.35);
}

.mol-tab-btn[data-molmode2="macrophage"].active {
  border-color: #38bdf8;
  color: #e0f2fe;
  background: rgba(14, 165, 233, 0.22);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.mol-tab-btn[data-molmode="all"].active, .mol-tab-btn[data-molmode2="all"].active {
  border-color: #facc15;
  color: #fef08a;
  background: rgba(202, 138, 4, 0.22);
  box-shadow: 0 0 10px rgba(250, 204, 21, 0.35);
}

.mol-tab-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

/* 顯示開關 Toggle 網格 (集中於右側卡片，2x2 對齊) */
.toggles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.chip-toggle {
  background: rgba(15, 23, 42, 0.65);
  color: #cbd5e1;
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.chip-toggle:hover {
  background: rgba(30, 41, 59, 0.9);
  border-color: #64748b;
  color: #f8fafc;
}

.chip-toggle:has(input:checked) {
  background: rgba(30, 41, 59, 0.95);
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.2);
}
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-toggle input {
  accent-color: #84cc16;
  width: 16px;
  height: 16px;
}

.canvas-legend {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(100, 116, 139, 0.55);
  padding: 8px 12px;
  border-radius: 12px;
  z-index: 10;
  pointer-events: none;
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.8rem;
  color: #f1f5f9;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
}
.dot-rbc { background: #ef4444; border: 1.5px solid #991b1b; }
.dot-plasma { background: #38bdf8; }
.dot-tissue-fluid { background: #facc15; }
.dot-lymph { background: #84cc16; }
.dot-macrophage { background: #f8fafc; border: 2.5px solid #0ea5e9; width: 13px; height: 13px; }
.dot-germ { background: #a855f7; border: 1.5px dashed #f0abfc; }

.hint-pill {
  font-size: 0.78rem;
  color: #fde047;
  background: rgba(51, 65, 85, 0.85);
  padding: 3px 10px;
  border-radius: 999px;
  font-weight: 600;
  align-self: flex-start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 右側平板友善大字體控制面板 */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  padding-bottom: 8px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: #f1f5f9;
}

.btn-group-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-text-action {
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #7dd3fc;
  border-radius: 7px;
  padding: 3px 9px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-text-action:hover {
  background: rgba(56, 189, 248, 0.28);
  border-color: #38bdf8;
  color: #ffffff;
}

.btn-text-action.active {
  background: rgba(56, 189, 248, 0.32);
  border-color: #38bdf8;
  color: #ffffff;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.35);
}

.btn-text-action.btn-reset {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.4);
  color: #cbd5e1;
}

.btn-text-action.btn-reset:hover {
  background: rgba(148, 163, 184, 0.22);
  border-color: #cbd5e1;
  color: #ffffff;
}

.btn-text-action.btn-reset.active {
  background: rgba(14, 165, 233, 0.22);
  border-color: #38bdf8;
  color: #7dd3fc;
}

/* 構造呈現可複選晶片按鈕網格 */
.struct-chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.struct-chip-btn {
  background: rgba(15, 23, 42, 0.65);
  color: #64748b;
  border: 1.5px dashed rgba(100, 116, 139, 0.45);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

.struct-chip-btn .chip-label {
  flex: 1;
  text-align: left;
}

.struct-chip-btn .chip-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  filter: grayscale(70%) opacity(40%);
  transition: all 0.18s;
}

.struct-chip-btn .chip-check {
  font-size: 0.85rem;
  font-weight: 900;
  color: #4ade80;
  opacity: 0;
  transform: scale(0.6);
  transition: all 0.18s;
}

/* 複選啟用中 (呈現該構造) */
.struct-chip-btn.active {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
  color: #f8fafc;
  border: 1.5px solid #38bdf8;
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.22);
}

.struct-chip-btn.active .chip-color-dot {
  filter: grayscale(0%) opacity(100%);
  box-shadow: 0 0 8px currentColor;
}

.struct-chip-btn.active .chip-check {
  opacity: 1;
  transform: scale(1);
}

.struct-chip-btn:hover {
  border-color: #94a3b8;
  color: #e2e8f0;
}

.tag-btn:active {
  transform: scale(0.97);
}

.tag-btn.full-span {
  grid-column: 1 / -1;
  justify-content: center;
}

.tag-btn:hover, .tag-btn.active {
  background: #365314;
  color: #ecfccb;
  border-color: #84cc16;
}

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

.action-btn {
  padding: 13px 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: transform 0.12s, background 0.2s;
  color: #fff;
}

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

.btn-pump { background: linear-gradient(135deg, #0284c7, #0369a1); border-color: #38bdf8; }
.btn-squeeze { background: linear-gradient(135deg, #4d7c0f, #3f6212); border-color: #a3e635; }
.btn-germ { background: linear-gradient(135deg, #7e22ce, #6b21a8); border-color: #c084fc; }
.btn-edema { background: linear-gradient(135deg, #b45309, #92400e); border-color: #fbbf24; }
.btn-edema.active { background: linear-gradient(135deg, #dc2626, #991b1b); border-color: #fca5a5; }

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(15, 23, 42, 0.55);
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(100, 116, 139, 0.25);
}

.slider-label-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
  color: #cbd5e1;
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 10px;
  accent-color: #84cc16;
  cursor: pointer;
}

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

.stat-item {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(100, 116, 139, 0.3);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.stat-val {
  font-size: 1.05rem;
  font-weight: 800;
  display: block;
}

.stat-name {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.hidden {
  display: none !important;
}
