*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  background: #0d0d0d; color: #f0f0f0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100dvh; display: flex; flex-direction: column;
  overflow: hidden; max-width: 430px; margin: 0 auto;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#nextCanvas { display: none; }
#gameArea {
  flex: 1; min-height: 0;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  padding-top: max(4px, env(safe-area-inset-top, 4px));
  /* Gameplay background — shows around the playfield canvas. No scrim: the
     stats / next-pill overlays carry their own backgrounds for contrast. */
  background: #0d0d0d url('../media/game_background.png') center center / cover no-repeat;
}
#statsOverlay {
  position: absolute;
  top: 10px; left: 10px;
  display: flex; flex-direction: column;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
  background: rgba(0,0,0,0.52);
  border-radius: 8px;
  padding: 8px 10px;
}
.stat { text-align: center; }
.stat-lbl { font-size: 8px; letter-spacing: 0.8px; text-transform: uppercase; color: #666; }
.stat-val { font-size: 18px; font-weight: 700; line-height: 1.2; }
#nextPillWrapper {
  position: absolute;
  top: 6px; right: 6px;
  display: flex; flex-direction: column; align-items: center;
  z-index: 10;
  pointer-events: none;
}
#nextDaisyImg {
  width: 60px; height: 60px;
  object-fit: contain;
  display: block;
}
#nextLabel {
  font-size: 9px; font-weight: 700;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.5);
  margin-top: 2px;
}
#mainCanvas { display: block; }

/* ── Controls ────────────────────────────────────────────── */
#controls {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 4px;
  padding: 3px 8px;
  margin: 0 auto;
  width: 100%;
}
.ctrl-btn {
  background: linear-gradient(180deg, #1c1c1c, #111);
  color: #c9d1d9;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  padding: 7px 0;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: background 0.08s;
}
.ctrl-btn:active { background: #0d0d0d; transform: translateY(1px); }
.ctrl-btn.span2  { grid-column: span 2; font-size: 12px; font-weight: 600; letter-spacing: 0.3px; }
.ctrl-btn.accent { border-color: rgba(67,160,71,0.45); color: #81c784; }
.ctrl-btn.accent:active { background: #0a1a0a; }

/* controls safe-area bottom padding */
#controls {
  padding-bottom: max(5px, env(safe-area-inset-bottom, 5px));
}

/* Loading screen */
#loadScreen {
  position: fixed; inset: 0; z-index: 999;
  /* Loading-screen background with a soft dark scrim for logo/text legibility. */
  background:
    linear-gradient(rgba(13,13,13,0.45), rgba(13,13,13,0.65)),
    url('../media/loading_background.png') center center / cover no-repeat;
  background-color: #0d0d0d;
  transition: opacity 0.35s ease;
}
#loadScreen.out { opacity: 0; pointer-events: none; }
#loadLogoWrap {
  position: absolute;
  top: 10%;
  left: 50%; transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
}
#loadLogo {
  width: 220px; height: 220px; object-fit: contain; display: block;
  animation: ld-pulse 1.4s ease-in-out infinite;
}
@keyframes ld-pulse {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}

/* Syringe — absolutely positioned so plunger movement never shifts layout */
#syringe {
  position: absolute;
  left: 50%; top: 64%;
  transform: translate(-50%, -50%) scale(0.82);
  transform-origin: center;
  width: 84px;
  display: flex; flex-direction: column; align-items: center;
}
/* thumb pad (press surface) */
#syringeThumb {
  width: 46px; height: 7px;
  background: linear-gradient(180deg, rgba(255,255,255,0.30), rgba(255,255,255,0.12));
  border: 1.5px solid rgba(255,255,255,0.32);
  border-radius: 5px;
}
/* plunger rod */
#syringeRod {
  width: 8px; height: 20px;
  background: linear-gradient(90deg, rgba(255,255,255,0.10), rgba(255,255,255,0.26), rgba(255,255,255,0.10));
}
/* finger grips / flange — wider than the barrel */
#syringeFlange {
  width: 84px; height: 9px;
  background: linear-gradient(180deg, rgba(255,255,255,0.24), rgba(255,255,255,0.10));
  border: 1.5px solid rgba(255,255,255,0.30);
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
/* barrel */
#syringeBarrel {
  position: relative;
  width: 60px; height: 110px;
  margin-top: -1px;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid rgba(255,255,255,0.22);
  border-top: none;
  border-radius: 0 0 6px 6px;
  overflow: hidden;
}
/* tick marks */
#syringeBarrel::before {
  content: '';
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 24px,
    rgba(255,255,255,0.14) 24px,
    rgba(255,255,255,0.14) 25px
  );
  pointer-events: none;
  z-index: 3;
}
/* numbered measurement marks */
#syringeMarks {
  position: absolute; inset: 0; z-index: 4;
  pointer-events: none;
}
#syringeMarks span {
  position: absolute; right: 5px;
  font-size: 7px; font-weight: 600;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.3px;
}
/* glass reflection streak */
#syringeReflection {
  position: absolute; top: 5px; bottom: 5px; left: 8px;
  width: 9px; z-index: 5;
  background: linear-gradient(180deg, rgba(255,255,255,0.30), rgba(255,255,255,0.04));
  border-radius: 5px;
  pointer-events: none;
}
/* liquid — shared by both the syringe and the vial */
.load-liquid {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 0%;
  background: linear-gradient(180deg, #66bb6a, #43a047);
  transition: height 0.35s ease;
  box-shadow: 0 -2px 8px rgba(67,160,71,0.5);
  z-index: 1;
}
/* rounded glowing meniscus on the liquid surface */
.load-liquid::after {
  content: '';
  position: absolute; top: -4px; left: 0; right: 0;
  height: 9px;
  background: #7cc47f;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(124,196,127,0.7);
}
/* cure bubbles rising through the liquid */
.s-bubble {
  position: absolute; bottom: 6px;
  border-radius: 50%;
  background: rgba(255,255,255,0.55);
  z-index: 2;
  animation: s-bubble-rise 3s ease-in infinite;
}
.s-bubble.b1 { left: 28%; width: 5px; height: 5px; animation-delay: 0s;   }
.s-bubble.b2 { left: 56%; width: 4px; height: 4px; animation-delay: 1s;   }
.s-bubble.b3 { left: 42%; width: 3px; height: 3px; animation-delay: 2s;   }
@keyframes s-bubble-rise {
  0%   { transform: translateY(0) scale(0.5); opacity: 0; }
  15%  { opacity: 0.7; }
  85%  { opacity: 0.45; }
  100% { transform: translateY(-92px) scale(1); opacity: 0; }
}
/* nozzle — tapers barrel down to the needle */
#syringeNozzle {
  width: 18px; height: 11px;
  background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.08));
  clip-path: polygon(0 0, 100% 0, 68% 100%, 32% 100%);
}
/* needle — brighter metallic, longer, beveled tip */
#syringeNeedle {
  width: 4px; height: 28px;
  background: linear-gradient(90deg, rgba(255,255,255,0.25), rgba(255,255,255,0.62), rgba(255,255,255,0.25));
  clip-path: polygon(0 0, 100% 0, 100% 88%, 50% 100%, 0 88%);
}

/* ── Cure vial loader (alternate visual) ─────────────────────── */
#vial {
  position: absolute;
  left: 50%; top: 64%;
  transform: translate(-50%, -50%) scale(0.82);
  transform-origin: center;
  width: 64px;
  display: flex; flex-direction: column; align-items: center;
}
/* crimp cap */
#vialCap {
  width: 34px; height: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.34), rgba(255,255,255,0.14));
  border: 1.5px solid rgba(255,255,255,0.30);
  border-radius: 4px 4px 3px 3px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.18);
}
/* neck */
#vialNeck {
  width: 24px; height: 8px;
  background: rgba(255,255,255,0.10);
  border-left: 1.5px solid rgba(255,255,255,0.22);
  border-right: 1.5px solid rgba(255,255,255,0.22);
}
/* glass body */
#vialBody {
  position: relative;
  width: 56px; height: 108px;
  background: rgba(255,255,255,0.05);
  border: 1.5px solid rgba(255,255,255,0.22);
  border-radius: 6px 6px 12px 12px;
  overflow: hidden;
}
/* tick marks */
#vialBody::before {
  content: '';
  position: absolute; inset: 0; z-index: 3;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 22px,
    rgba(255,255,255,0.13) 22px,
    rgba(255,255,255,0.13) 23px
  );
  pointer-events: none;
}
/* glass reflection streak */
#vialReflection {
  position: absolute; top: 6px; bottom: 6px; left: 8px;
  width: 9px; z-index: 5;
  background: linear-gradient(180deg, rgba(255,255,255,0.30), rgba(255,255,255,0.04));
  border-radius: 5px;
  pointer-events: none;
}
/* medical label band */
#vialLabel {
  position: absolute; left: 0; right: 0; top: 40%;
  height: 26px; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.12);
  border-top: 1px solid rgba(255,255,255,0.18);
  border-bottom: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.6);
  font-size: 13px; font-weight: 700;
  pointer-events: none;
}

/* ── Loader selection: hide the inactive visual ──────────────── */
#vial { display: none; }
body[data-loader="vial"] #vial    { display: flex; }
body[data-loader="vial"] #syringe { display: none; }

#loadStep {
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 10%;
  font-size: 11px; color: #555; letter-spacing: 0.4px; white-space: nowrap;
}

/* ── Menu screen ─────────────────────────────────────────────── */
#menuScreen {
  position: fixed; inset: 0; z-index: 100;
  /* Menu background with a soft dark scrim so the logo, high-scores list,
     and buttons stay readable over the artwork. */
  background:
    linear-gradient(rgba(13,13,13,0.5), rgba(13,13,13,0.7)),
    url('../media/menu_background.png') center center / cover no-repeat;
  background-color: #0d0d0d;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px;
  padding: 32px 24px;
  transition: opacity 0.25s;
  padding-top: max(32px, env(safe-area-inset-top, 32px));
}
#menuScreen.hidden { opacity: 0; pointer-events: none; }
.menu-logo { font-size: 58px; line-height: 1; }
.menu-title { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; }
.menu-sub { font-size: 11px; color: #555; letter-spacing: 1px; text-transform: uppercase; margin-top: -8px; margin-bottom: 4px; }
.menu-btn {
  width: 100%; max-width: 260px;
  padding: 13px 20px; border-radius: 14px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  border: none; text-align: center;
}
.menu-btn.primary { background: #43a047; color: #fff; }
.menu-btn.secondary {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: #c9d1d9;
}
.menu-btn.danger {
  background: rgba(229,57,53,0.15);
  border: 1px solid rgba(229,57,53,0.4);
  color: #ef9a9a;
}
.menu-btn:active { opacity: 0.8; transform: translateY(1px); }
#lbSection { width: 100%; max-width: 260px; }
.lb-head { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #555; margin-bottom: 8px; }
.lb-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05); font-size: 13px; color: #ccc; gap: 6px; min-width: 0; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lb-rank { color: #555; font-size: 11px; width: 20px; }
.lb-row-empty { border-bottom-color: transparent; pointer-events: none; }
.lb-empty { color: #444; font-size: 12px; text-align: center; padding: 10px 0; }
.lb-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 8px; }
.lb-nav-btn { background: rgba(255,255,255,0.08); border: none; color: #ccc; border-radius: 6px; padding: 4px 12px; font-size: 13px; cursor: pointer; line-height: 1; }
.lb-nav-btn:disabled { opacity: 0.3; cursor: default; }
.lb-nav-btn:not(:disabled):active { background: rgba(255,255,255,0.16); }
.lb-range { font-size: 11px; color: #fff; letter-spacing: 0.5px; background: #1e88e5; padding: 4px 12px; border-radius: 6px; font-weight: 600; }

/* ── Pause modal ─────────────────────────────────────────────── */
#pauseModal {
  position: absolute; inset: 0; z-index: 20;
  background: rgba(0,0,0,0.8);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
}
#pauseModal.visible { display: flex; }
.pause-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.pause-btn {
  width: 190px; padding: 11px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.07);
  color: #f0f0f0; font-size: 14px; font-weight: 600; cursor: pointer;
}
.pause-btn.danger { border-color: rgba(229,57,53,0.35); color: #ef9a9a; }
.pause-btn:active { opacity: 0.75; }

/* ── In-game menu button ─────────────────────────────────────── */
#statsOverlay { pointer-events: none; }
#menuBtn {
  pointer-events: all;
  margin-top: 6px; width: 100%;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #777; font-size: 13px;
  padding: 3px 8px; cursor: pointer;
}
#menuBtn:active { background: rgba(255,255,255,0.14); }
.menu-logo-img { width: 190px; height: 190px; object-fit: contain; }

/* ── Settings overlay ────────────────────────────────────────── */
#settingsOverlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.82);
  align-items: center; justify-content: center;
}
#settingsOverlay.open { display: flex; }
.sov-panel {
  background: #161616;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 18px;
  padding: 24px 20px;
  width: 284px;
  display: flex; flex-direction: column; gap: 14px;
}
.sov-title {
  font-size: 15px; font-weight: 700; text-align: center; color: #f0f0f0;
}
.settings-row {
  display: flex; align-items: center; gap: 8px;
}
.settings-lbl {
  font-size: 10px; color: #555; text-transform: uppercase;
  letter-spacing: 0.8px; width: 60px; flex-shrink: 0;
}
.settings-btns { display: flex; gap: 4px; flex: 1; }
.stg-btn {
  flex: 1; padding: 7px 2px; border-radius: 8px;
  font-size: 11px; font-weight: 600; cursor: pointer;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05); color: #555;
  transition: all 0.15s;
}
.stg-btn.active {
  background: rgba(67,160,71,0.2);
  border-color: rgba(67,160,71,0.45);
  color: #81c784;
}
.stg-btn:active { opacity: 0.7; }
.stg-btn.danger { color: #e57373; border-color: rgba(229,83,83,0.3); }
.sov-divider { border: none; border-top: 1px solid rgba(255,255,255,0.07); margin: 0; }

/* ── How-to-play overlay (first-time + reopenable from menus) ────────── */
#controlsOverlay {
  display: none;
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0,0,0,0.88);
  align-items: center; justify-content: center;
}
#controlsOverlay.open { display: flex; }
.ctrl-panel {
  background: #161616;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 24px 20px 20px;
  width: 284px;
  display: flex; flex-direction: column; gap: 16px;
  max-height: 86vh; overflow-y: auto;
}
.ctrl-panel-title {
  font-size: 15px; font-weight: 700; text-align: center; color: #f0f0f0;
}
.ctrl-list {
  display: flex; flex-direction: column; gap: 10px;
}
.ctrl-item {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px;
}
.ctrl-item-key {
  color: #81c784; font-weight: 600; font-size: 12px;
  background: rgba(67,160,71,0.12);
  border: 1px solid rgba(67,160,71,0.3);
  border-radius: 6px; padding: 3px 8px;
  white-space: nowrap;
}
.ctrl-item-desc { color: #ccc; }
.ctrl-goal {
  font-size: 12px; color: #bbb; text-align: center; line-height: 1.55;
  padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,0.07);
}
.ctrl-goal b { color: #81c784; }

/* ── Win result panel ────────────────────────────────────────────────── */
#winPanel {
  position: absolute; inset: 0; z-index: 25;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  background: rgba(0,0,0,0.84);
}
#winPanel.hidden { display: none; }
.win-icon  { font-size: 44px; line-height: 1; }
.win-title { font-size: 21px; font-weight: 800; color: #43a047; letter-spacing: -0.3px; }
.win-stats { display: flex; gap: 22px; }
.win-stat  { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.win-stat-lbl { font-size: 8px; text-transform: uppercase; letter-spacing: 0.8px; color: #555; }
.win-stat-val { font-size: 22px; font-weight: 700; color: #f0f0f0; }
#winLabStatus { font-size: 11px; color: #43a047; letter-spacing: 0.3px; min-height: 15px; }

/* ── Floating virus decorations ──────────────────────────────────────── */
#virusFloaters {
  position: fixed; inset: 0; z-index: 1000;
  pointer-events: none; overflow: hidden;
}
#virusFloaters.hidden { display: none; }
.virus-floater {
  position: absolute;
  width: 64px; height: 64px;
  opacity: 0.5;
}
#floatG { top: 7%;    left: 5%;   animation: float-g 11s ease-in-out infinite; }
#floatO { top: 5%;    right: 7%;  animation: float-o 13s ease-in-out infinite; }
#floatP { bottom: 11%; left: 4%;  animation: float-p 10s ease-in-out infinite; }
#floatR { bottom: 7%;  right: 5%; animation: float-r 14s ease-in-out infinite; }

@keyframes float-g {
  0%   { transform: translate(0px,  0px);  }
  25%  { transform: translate(20px, 26px); }
  50%  { transform: translate(8px,  42px); }
  75%  { transform: translate(-12px,22px); }
  100% { transform: translate(0px,  0px);  }
}
@keyframes float-o {
  0%   { transform: translate(0px,   0px);  }
  25%  { transform: translate(-22px, 20px); }
  50%  { transform: translate(-8px,  38px); }
  75%  { transform: translate(14px,  18px); }
  100% { transform: translate(0px,   0px);  }
}
@keyframes float-p {
  0%   { transform: translate(0px,   0px);   }
  25%  { transform: translate(24px, -18px);  }
  50%  { transform: translate(12px, -34px);  }
  75%  { transform: translate(-10px, -16px); }
  100% { transform: translate(0px,   0px);   }
}
@keyframes float-r {
  0%   { transform: translate(0px,   0px);   }
  25%  { transform: translate(-18px, -22px); }
  50%  { transform: translate(-6px,  -40px); }
  75%  { transform: translate(12px,  -20px); }
  100% { transform: translate(0px,   0px);   }
}

/* ── Level splash ────────────────────────────────────────────────────── */
#levelSplash {
  display: none;
  position: fixed; inset: 0; z-index: 50;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 8px;
  background: rgba(0,0,0,0.72);
  opacity: 0; transition: opacity 0.25s ease;
  pointer-events: none;
}
#levelSplash.open { display: flex; }
#levelSplash.visible { opacity: 1; }
#splashLevel {
  font-size: 42px; font-weight: 800; color: #f0f0f0;
  letter-spacing: -1px;
}
#splashTier {
  font-size: 14px; font-weight: 700; letter-spacing: 2px;
  text-transform: uppercase;
}
