/* ==============================================
   Circulatory System — 3D-feel simulation
   ============================================== */

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

:root {
  --bg: #05111f;
  --bg-2: #0a1e36;
  --panel: rgba(10, 30, 54, 0.85);
  --panel-border: rgba(120, 180, 255, 0.12);
  --ink: #e6f0ff;
  --ink-dim: #8ea5c9;
  --ink-faint: #4e668a;

  --artery: #e53947;          /* oxygenated blood (red) */
  --artery-glow: #ff6b78;
  --artery-deep: #9b1a24;
  --vein: #3b6fc9;            /* deoxygenated blood (blue) */
  --vein-glow: #5b8fee;
  --vein-deep: #1b3d7a;

  --heart: #c62634;
  --heart-dark: #7a1118;
  --lung: #f0a4b4;
  --kidney: #7a4a8a;
  --brain: #d4a08a;
  --liver: #6b2d24;

  --gold: #f5c518;
  --success: #1f9d55;
  --warning: #f59e0b;
  --danger: #e53947;

  --font: 'Heebo', system-ui, sans-serif;
  --font-display: 'Assistant', system-ui, sans-serif;

  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
}

html, body {
  font-family: var(--font);
  background: radial-gradient(ellipse at top, #0d2340 0%, #05111f 60%, #02060d 100%);
  color: var(--ink);
  min-height: 100vh;
  direction: rtl;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(2px 2px at 20% 30%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 60% 70%, rgba(150,200,255,0.3), transparent),
    radial-gradient(1px 1px at 80% 20%, rgba(255,150,180,0.2), transparent),
    radial-gradient(2px 2px at 40% 85%, rgba(200,220,255,0.3), transparent);
  background-size: 400px 400px;
  pointer-events: none;
  opacity: 0.5;
  z-index: 0;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr 340px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
  position: relative;
  z-index: 1;
}

/* ============ TOP BAR ============ */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-display);
  font-weight: 800; font-size: 17px;
  color: var(--ink);
  text-decoration: none;
}
.brand-mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--gold), #fde086);
  color: #061d47;
  display: grid; place-items: center;
  font-weight: 800; font-size: 12px;
  box-shadow: 0 0 20px rgba(245,197,24,0.3);
}
.page-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--ink);
  display: flex; align-items: center; gap: 10px;
}
.page-title .pulse-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 12px var(--danger);
  animation: pulse-beat 1s infinite;
}
@keyframes pulse-beat {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.4); opacity: 0.6; }
}
.back-link {
  color: var(--ink-dim);
  text-decoration: none;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.18s;
}
.back-link:hover { color: var(--ink); border-color: rgba(120,180,255,0.3); }

/* ============ LEFT PANEL ============ */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  backdrop-filter: blur(14px);
}
.panel-h {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--panel-border);
  display: flex; align-items: center; gap: 8px;
}
.panel-h::before {
  content: '';
  width: 4px; height: 16px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--gold), #e0a50a);
}

.sim-btns { display: grid; gap: 8px; }
.sim-btn {
  background: rgba(59, 111, 201, 0.08);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--ink);
  text-align: right;
  cursor: pointer;
  font-family: var(--font);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.sim-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s;
}
.sim-btn:hover { border-color: rgba(120,180,255,0.3); transform: translateX(-2px); }
.sim-btn:hover::before { transform: translateX(100%); }
.sim-btn.active {
  background: rgba(245, 197, 24, 0.12);
  border-color: var(--gold);
  color: var(--gold);
}
.sim-icon {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: rgba(255,255,255,0.04);
  display: grid; place-items: center;
  font-size: 14px;
  flex-shrink: 0;
}
.sim-btn.active .sim-icon { background: rgba(245,197,24,0.2); }
.sim-desc {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}

.vitals { display: flex; flex-direction: column; gap: 12px; }
.vital {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255,255,255,0.02);
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
}
.vital-label { font-size: 12px; color: var(--ink-dim); }
.vital-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.vital-num .unit { font-size: 11px; color: var(--ink-faint); font-weight: 500; margin-right: 4px; }

.vital-chart {
  grid-column: 1 / -1;
  height: 36px;
  margin-top: 8px;
  position: relative;
}
.ecg-line {
  position: absolute; inset: 0;
  overflow: hidden;
}
.ecg-line svg { position: absolute; left: 0; top: 0; height: 100%; width: 200%; animation: ecg-scroll 2.5s linear infinite; }
@keyframes ecg-scroll { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ============ STAGE (center) ============ */
.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at center, rgba(20, 50, 100, 0.3) 0%, transparent 60%),
    rgba(5, 17, 31, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  min-height: 640px;
  perspective: 1200px;
}
.stage-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(120,180,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120,180,255,0.04) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse at center, black 50%, transparent 85%);
  pointer-events: none;
}
.stage-title {
  position: absolute;
  top: 18px;
  right: 22px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(5, 17, 31, 0.6);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  z-index: 5;
}

.circulation-wrap {
  position: relative;
  width: 560px;
  height: 560px;
  transform-style: preserve-3d;
}

/* Heart */
.heart-core {
  position: absolute;
  left: 50%; top: 50%;
  width: 140px;
  height: 140px;
  transform: translate(-50%, -50%);
  z-index: 10;
  animation: heart-pulse calc(60s / var(--bpm, 72)) ease-in-out infinite;
  cursor: pointer;
  filter: drop-shadow(0 10px 30px rgba(230, 57, 71, 0.5));
}
@keyframes heart-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  20% { transform: translate(-50%, -50%) scale(1.14); }
  40% { transform: translate(-50%, -50%) scale(1); }
  55% { transform: translate(-50%, -50%) scale(1.08); }
  70% { transform: translate(-50%, -50%) scale(1); }
}
.heart-core svg { width: 100%; height: 100%; overflow: visible; }
.heart-glow {
  position: absolute;
  inset: -40px;
  background: radial-gradient(circle, rgba(230,57,71,0.3) 0%, transparent 70%);
  animation: heart-pulse calc(60s / var(--bpm, 72)) ease-in-out infinite;
  pointer-events: none;
  z-index: -1;
}

/* Organs around heart */
.organ {
  position: absolute;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.25s, box-shadow 0.25s;
  z-index: 6;
  color: var(--ink);
  text-align: center;
  line-height: 1.1;
  padding: 10px;
}
.organ:hover { transform: scale(1.1); z-index: 7; }
.organ::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1.5px dashed rgba(255,255,255,0.12);
  pointer-events: none;
}
.organ.active {
  box-shadow: 0 0 0 3px rgba(245,197,24,0.5), 0 0 40px rgba(245,197,24,0.4);
}

.organ-brain {
  top: 10px; left: 50%; transform: translateX(-50%);
  width: 120px; height: 90px;
  background: radial-gradient(ellipse at 30% 30%, #e8b89e 0%, #b87a5e 60%, #6b3a24 100%);
  border-radius: 60% 60% 52% 52% / 70% 70% 40% 40%;
  box-shadow: inset -6px -10px 20px rgba(0,0,0,0.35), 0 6px 20px rgba(0,0,0,0.4);
}
.organ-brain:hover { transform: translateX(-50%) scale(1.08); }
.organ-brain::after { border-radius: 60% 60% 52% 52% / 70% 70% 40% 40%; }

.organ-lung-l, .organ-lung-r {
  top: 170px;
  width: 90px; height: 130px;
  background: radial-gradient(ellipse at 30% 30%, #f8c4cd 0%, #e88499 50%, #a84a5e 100%);
  box-shadow: inset -6px -10px 20px rgba(0,0,0,0.25), 0 6px 20px rgba(0,0,0,0.35);
  animation: breathe 4s ease-in-out infinite;
}
.organ-lung-l { left: 80px; border-radius: 55% 45% 45% 55% / 40% 40% 60% 60%; }
.organ-lung-r { right: 80px; border-radius: 45% 55% 55% 45% / 40% 40% 60% 60%; animation-delay: -0.1s; }
.organ-lung-l::after { border-radius: 55% 45% 45% 55% / 40% 40% 60% 60%; }
.organ-lung-r::after { border-radius: 45% 55% 55% 45% / 40% 40% 60% 60%; }
@keyframes breathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.08); }
}

.organ-liver {
  bottom: 150px; right: 60px;
  width: 110px; height: 80px;
  background: radial-gradient(ellipse at 30% 30%, #a84228 0%, #6b2d24 60%, #3e1a15 100%);
  border-radius: 55% 55% 45% 45% / 60% 60% 40% 40%;
  box-shadow: inset -6px -10px 20px rgba(0,0,0,0.4), 0 6px 20px rgba(0,0,0,0.4);
}
.organ-liver::after { border-radius: 55% 55% 45% 45% / 60% 60% 40% 40%; }

.organ-kidney-l, .organ-kidney-r {
  bottom: 100px;
  width: 60px; height: 90px;
  background: radial-gradient(ellipse at 30% 30%, #a57cb8 0%, #7a4a8a 55%, #43264d 100%);
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  box-shadow: inset -4px -8px 16px rgba(0,0,0,0.35), 0 6px 16px rgba(0,0,0,0.35);
}
.organ-kidney-l { left: 80px; }
.organ-kidney-r { right: 180px; }

.organ-label {
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(5, 17, 31, 0.85);
  border: 1px solid var(--panel-border);
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  white-space: nowrap;
  color: var(--ink);
}

/* Blood vessels — drawn with SVG overlay */
.vessels {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

/* Blood particles flowing */
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  top: 0; left: 0;
  pointer-events: none;
  filter: blur(0.3px);
  offset-rotate: 0deg;
}
.particle.artery {
  background: radial-gradient(circle at 30% 30%, #ff8a95, var(--artery) 60%, var(--artery-deep));
  box-shadow: 0 0 8px rgba(255, 70, 90, 0.7);
}
.particle.vein {
  background: radial-gradient(circle at 30% 30%, #7ca6ff, var(--vein) 60%, var(--vein-deep));
  box-shadow: 0 0 8px rgba(80, 130, 230, 0.7);
}

/* Legend */
.legend {
  position: absolute;
  bottom: 18px;
  right: 22px;
  display: flex;
  gap: 14px;
  padding: 8px 14px;
  background: rgba(5, 17, 31, 0.7);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  z-index: 5;
  font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 6px; color: var(--ink-dim); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-artery { background: var(--artery); box-shadow: 0 0 6px var(--artery); }
.legend-vein { background: var(--vein); box-shadow: 0 0 6px var(--vein); }

/* Playback controls */
.controls {
  position: absolute;
  bottom: 18px;
  left: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(5, 17, 31, 0.7);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  z-index: 5;
}
.ctrl-btn {
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  width: 30px; height: 30px;
  border-radius: 50%;
  display: grid; place-items: center;
  transition: background 0.15s;
}
.ctrl-btn:hover { background: rgba(255,255,255,0.08); }
.ctrl-btn.primary {
  background: var(--gold);
  color: #061d47;
}
.ctrl-btn.primary:hover { background: #fde086; }

.speed-slider {
  width: 90px;
  accent-color: var(--gold);
}
.speed-label { font-size: 11px; color: var(--ink-dim); }

/* ============ RIGHT PANEL — Info ============ */
.info-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  backdrop-filter: blur(14px);
}
.info-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--panel-border);
}
.info-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--artery), var(--artery-deep));
  display: grid; place-items: center;
  font-size: 20px;
  box-shadow: 0 4px 16px rgba(230,57,71,0.3);
}
.info-header h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--ink);
}
.info-header .subtitle {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 2px;
}
.info-card p {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--ink-dim);
  margin-bottom: 14px;
  text-wrap: pretty;
}
.info-card p strong { color: var(--ink); font-weight: 600; }
.fact-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.fact-list li {
  font-size: 12.5px;
  color: var(--ink);
  display: flex; gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  border: 1px solid var(--panel-border);
}
.fact-list li::before {
  content: '◆';
  color: var(--gold);
  font-size: 10px;
  flex-shrink: 0;
  margin-top: 2px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}
.stat-box {
  padding: 12px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
}
.stat-box .v {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 19px;
  color: var(--gold);
  line-height: 1;
}
.stat-box .l {
  font-size: 11px;
  color: var(--ink-dim);
  margin-top: 4px;
}

@media (max-width: 1180px) {
  .app { grid-template-columns: 1fr; }
  .circulation-wrap { transform: scale(0.85); }
  .stage { min-height: 560px; }
}
