/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1a;
  font-family: 'Segoe UI', 'PingFang TC', 'Noto Sans TC', sans-serif;
  color: #e0e0e0;
}

/* === APP CONTAINER: 4:3 iPad landscape === */
#app {
  position: relative;
  max-width: 1024px;
  max-height: 768px;
  width: 100vw;
  height: 100vh;
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #0d1b2a;
  overflow: hidden;
}

#app::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('../assets/images/background.jpeg') center/cover no-repeat;
  opacity: 0.18;
  pointer-events: none;
  z-index: 0;
}

/* Ensure all direct children render above the pseudo-element background */
#top-bar,
#main-content {
  position: relative;
  z-index: 1;
}

/* === TOP BAR === */
#top-bar {
  flex-shrink: 0;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(13, 27, 42, 0.98);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 10;
}

#app-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #a8d8ea;
}

#top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

#restart-btn {
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 15px;
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

#restart-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

#progress-dots {
  display: flex;
  gap: 8px;
  align-items: center;
}

.progress-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.4s ease, box-shadow 0.4s ease, transform 0.3s ease;
  cursor: default;
}

.progress-dot.reached {
  transform: scale(1.15);
  box-shadow: 0 0 8px currentColor;
}

/* === MAIN CONTENT === */
#main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* === LEFT PANEL === */
#left-panel {
  width: 55%;
  height: 100%;
  background: rgba(13, 27, 42, 0.95);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
  overflow: hidden;
}

#body-container {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
}

#human-body {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 90%;
  max-width: 90%;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.9;
}


/* === BODY WRAPPER ===
   Sized and positioned by JS to match the exact rendered image rect.
   All interactive elements (overlays, food particle) go inside.
*/
#body-wrapper {
  position: absolute;
  /* width, height, left, top set by JS */
  pointer-events: none; /* children enable their own pointer-events */
  z-index: 5;
}

/* === MOUTH DROP ZONE (visible outside organ-layer, before journey starts) === */
#mouth-zone {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid transparent;
  background: transparent;
  pointer-events: none;
  z-index: 9;
  transition: border-color 0.3s ease, background 0.3s ease, box-shadow 0.3s ease;
}

#mouth-zone.mouth-hover {
  border-color: rgba(255, 107, 107, 0.9);
  background: rgba(255, 107, 107, 0.18);
  box-shadow:
    0 0 24px rgba(255, 107, 107, 0.6),
    0 0 48px rgba(255, 107, 107, 0.25),
    inset 0 0 16px rgba(255, 107, 107, 0.15);
  animation: mouth-pulse 0.5s ease-in-out infinite;
}

@keyframes mouth-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%       { transform: translate(-50%, -50%) scale(1.2); }
}

/* === X-RAY LENS LAYER ===
   CSS mask creates a circular reveal window for organ images.
   Lens position is driven by --lens-x / --lens-y on #body-wrapper.
   Initial position -200px ensures nothing is visible off-screen.
*/
#organ-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  transition: opacity 0.4s ease;
  -webkit-mask-image: radial-gradient(
    circle 70px at var(--lens-x, -200px) var(--lens-y, -200px),
    rgba(0,0,0,1) 0%,
    rgba(0,0,0,0.5) 70%,
    rgba(0,0,0,0) 100%
  );
  mask-image: radial-gradient(
    circle 70px at var(--lens-x, -200px) var(--lens-y, -200px),
    rgba(0,0,0,1) 0%,
    rgba(0,0,0,0.5) 70%,
    rgba(0,0,0,0) 100%
  );
}

#organ-layer.active {
  opacity: 1;
}

/* Lens border glow ring that follows cursor */
#lens-ring {
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 2px solid rgba(100, 200, 255, 0.4);
  box-shadow:
    0 0 15px rgba(100, 200, 255, 0.3),
    inset 0 0 15px rgba(100, 200, 255, 0.1);
  pointer-events: none;
  z-index: 9;
  transform: translate(-50%, -50%);
  left: var(--lens-x, -200px);
  top: var(--lens-y, -200px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#lens-ring.active {
  opacity: 1;
}

/* Individual organ images inside #organ-layer */
.organ-img {
  position: absolute;
  left: 50%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  pointer-events: none;
  /* Default appearance: fully visible inside the mask window */
  filter: none;
  transition: filter 0.3s ease;
}

/* Station active: bright glow highlights the current organ */
.organ-img.active {
  filter: brightness(1.4) drop-shadow(0 0 12px var(--organ-color, white));
  z-index: 2;
}

/* === PER-ORGAN KEYFRAME ANIMATIONS ===
   Preserved for future use; applied to .organ-img.active when needed.
   All keyframes include translate(-50%, -50%) for correct centering.
*/

/* Mouth: scaleY simulates chewing bite */
@keyframes chew {
  0%, 100% { transform: translate(-50%, -50%) scaleY(1); }
  50%       { transform: translate(-50%, -50%) scaleY(0.7); }
}

/* Esophagus: peristaltic wave — scaleX squeeze + translateY push */
@keyframes peristalsis {
  0%   { transform: translate(-50%, -50%) scaleX(1)   translateY(0);   }
  25%  { transform: translate(-50%, -50%) scaleX(0.8) translateY(3px); }
  50%  { transform: translate(-50%, -50%) scaleX(1)   translateY(6px); }
  75%  { transform: translate(-50%, -50%) scaleX(0.8) translateY(9px); }
  100% { transform: translate(-50%, -50%) scaleX(1)   translateY(12px);}
}

/* Stomach: churning — rotate + scale wobble */
@keyframes churn {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg)  scale(1);    }
  25%       { transform: translate(-50%, -50%) rotate(-3deg) scale(1.05); }
  50%       { transform: translate(-50%, -50%) rotate(0deg)  scale(0.95); }
  75%       { transform: translate(-50%, -50%) rotate(3deg)  scale(1.05); }
}

/* Small intestine: nutrient absorption — brightness pulse + glow */
@keyframes absorb-pulse {
  0%, 100% {
    transform: translate(-50%, -50%);
    filter: brightness(1);
  }
  50% {
    transform: translate(-50%, -50%);
    filter: brightness(1.4) drop-shadow(0 0 20px rgba(46, 204, 113, 0.6));
  }
}

/* Large intestine: dehydration — scaleX squeeze + brightness */
@keyframes dehydrate {
  0%, 100% {
    transform: translate(-50%, -50%) scaleX(1);
    filter: brightness(1);
  }
  50% {
    transform: translate(-50%, -50%) scaleX(0.9);
    filter: brightness(1.3);
  }
}

/* === FOOD PARTICLE (inside #body-wrapper) === */
#food-particle {
  position: absolute;
  left: 50%;
  /* top set by JS as percentage; transform centers it */
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  z-index: 20;
  pointer-events: none;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.5));
  /* No transition on top — JS updates continuously for instant cursor tracking */
}

#food-particle img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* === FOOD CHOICES (left and right flanks of body container) === */
#food-left,
#food-right {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#food-left  { left: 4px; }
#food-right { right: 4px; }

.food-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: grab;
  user-select: none;
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  pointer-events: auto;
}

.food-choice:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateY(-3px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.food-choice.dragging {
  opacity: 0.5;
  transform: scale(0.9);
  cursor: grabbing;
}

.food-choice img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  pointer-events: none;
}

.food-choice span {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.7);
  pointer-events: none;
}

/* === INSTRUCTION TEXT === */
#instruction-text {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.5px;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.5s ease;
}

#instruction-text.hidden {
  opacity: 0;
}

/* === DRAG GHOST === */
#drag-ghost {
  position: fixed;
  width: 56px;
  height: 56px;
  pointer-events: none;
  z-index: 9999;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

#drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* === RIGHT PANEL === */
#right-panel {
  width: 45%;
  height: 100%;
  background: rgba(13, 27, 42, 0.95);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  overflow-y: auto;
}

/* === RIGHT PLACEHOLDER === */
#right-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: rgba(255, 255, 255, 0.25);
  gap: 12px;
}

#placeholder-icon {
  font-size: 64px;
  opacity: 0.3;
}

#right-placeholder p {
  font-size: 14px;
  line-height: 1.7;
}

/* === INFO CARD === */
#info-card {
  background: rgba(20, 35, 55, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-left: 4px solid #ff6b6b;
  border-radius: 10px;
  padding: 14px 16px;
  animation: slide-in 0.35s ease-out;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0);    }
}

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

#station-emoji {
  font-size: 28px;
}

#station-label {
  font-size: 20px;
  font-weight: 700;
  color: #ffffff;
}

#station-description {
  font-size: 14px;
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.82);
  margin-bottom: 8px;
}

#station-analogy {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 220, 100, 0.85);
  font-style: italic;
}

/* === FUN FACT === */
#fun-fact {
  background: rgba(241, 196, 15, 0.08);
  border: 1px solid rgba(241, 196, 15, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  animation: slide-in 0.4s ease-out;
}

#fun-fact-label {
  font-size: 12px;
  font-weight: 600;
  color: rgba(241, 196, 15, 0.85);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

#fun-fact-text {
  font-size: 13px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.78);
}

/* === PROGRESS SECTION === */
#progress-section {
  animation: slide-in 0.45s ease-out;
}

#progress-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

#progress-bar-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

#progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3498db, #2ecc71, #f1c40f);
  border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

#progress-count {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  text-align: right;
}

/* === SCROLLBAR for right panel === */
#right-panel::-webkit-scrollbar       { width: 4px; }
#right-panel::-webkit-scrollbar-track { background: transparent; }
#right-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}
