:root {
  --bg-dark: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #1e293b;
  --border-color: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-red: #ef4444;
  --accent-red-glow: rgba(239, 68, 68, 0.35);
  --accent-amber: #f59e0b;
  --accent-blue: #38bdf8;
  --accent-green: #10b981;
  --accent-purple: #a855f7;
  --radius-lg: 14px;
  --radius-md: 10px;
}

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

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

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 12px;
}

.title-group h1 {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #fff;
}

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

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

/* Layout */
.main-layout {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 20px;
  padding: 20px 24px;
  max-width: 1520px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

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

/* Stepper */
.stage-stepper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-panel);
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
  overflow-x: auto;
  gap: 6px;
}

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

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

.step-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #334155;
  color: #cbd5e1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  transition: all 0.25s ease;
}

.step-item.active {
  color: #fff;
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.45);
}

.step-item.active .step-num {
  background: var(--accent-red);
  color: #fff;
  box-shadow: 0 0 10px var(--accent-red-glow);
}

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

.step-connector {
  flex: 1;
  height: 2px;
  min-width: 12px;
  background: #334155;
}

/* Canvas Area */
.canvas-container {
  position: relative;
  background: #0b1120;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  aspect-ratio: 900 / 520;
  width: 100%;
}

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

.canvas-overlay-top {
  position: absolute;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  flex-wrap: wrap;
  gap: 8px;
}

.stage-badge {
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.speed-control {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 5px 12px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #e2e8f0;
}

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

.canvas-prompt {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fde68a;
  padding: 7px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
  white-space: nowrap;
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
}

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

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

/* Action Bar */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
  flex: 1;
  min-width: 210px;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.5);
}

.btn-accent {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

.btn-accent:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.5);
}

.btn-secondary {
  background: #334155;
  color: #f1f5f9;
}

.btn-secondary:hover:not(:disabled) {
  background: #475569;
}

.btn-Secondary-active {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid #10b981;
  color: #6ee7b7;
}

.btn-outline {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
}

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

.btn-nav {
  background: #1e293b;
  border: 1px solid var(--border-color);
  color: #e2e8f0;
}

.btn-nav:hover:not(:disabled) {
  background: #334155;
}

/* Sidebar Cards */
.info-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.card-header {
  margin-bottom: 10px;
}

.stage-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1px;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.18);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 4px;
}

.card-header h2 {
  font-size: 1.2rem;
  color: #fff;
}

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

.key-events h3,
.metrics-card h3,
.legend-card h3 {
  font-size: 0.92rem;
  color: #f8fafc;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.key-events ul {
  padding-left: 18px;
  font-size: 0.85rem;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.key-events li {
  line-height: 1.45;
}

/* Metrics */
.metric-row {
  margin-bottom: 12px;
}

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

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

.progress-track {
  height: 8px;
  background: #0f172a;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

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

.bar-vessel {
  background: linear-gradient(90deg, #38bdf8, #0284c7);
}

.bar-bleed {
  background: linear-gradient(90deg, #f87171, #dc2626);
}

.bar-clot {
  background: linear-gradient(90deg, #fbbf24, #d97706);
}

.bar-heal {
  background: linear-gradient(90deg, #34d399, #059669);
}

/* Legend */
.legend-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

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

.icon-rbc {
  background: radial-gradient(circle at 35% 35%, #f87171, #dc2626 60%, #7f1d1d);
  border: 2px solid #b91c1c;
}

.icon-platelet {
  background: #fde047;
  clip-path: polygon(50% 0%, 65% 32%, 100% 38%, 73% 62%, 82% 100%, 50% 78%, 18% 100%, 27% 62%, 0% 38%, 35% 32%);
}

.icon-wbc {
  background: radial-gradient(circle at 35% 35%, #f8fafc, #93c5fd 70%, #3b82f6);
  border: 2px solid #60a5fa;
}

.icon-fibrin {
  background: repeating-linear-gradient(
    45deg,
    #f59e0b,
    #f59e0b 3px,
    #78350f 3px,
    #78350f 6px
  );
  border: 1px solid #fbbf24;
}

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

.legend-text strong {
  font-size: 0.84rem;
  color: #f1f5f9;
}

.legend-text small {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.35;
}
