:root {
  --action-bottom-offset: max(28px, calc(env(safe-area-inset-bottom) + 18px));
  color-scheme: dark;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: #06161f;
  touch-action: none;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 50% 40%, rgba(23, 100, 102, 0.2), transparent 43%),
    linear-gradient(180deg, #0a2630 0%, #06161f 62%, #030c12 100%);
}

.scene {
  position: relative;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 560px;
  place-items: center;
  isolation: isolate;
}

.scene::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(rgba(99, 191, 178, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 191, 178, 0.018) 1px, transparent 1px);
  background-size: 24px 24px;
  content: "";
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.scene::after {
  position: absolute;
  right: 0;
  bottom: 4.5%;
  left: 0;
  z-index: -1;
  height: 18%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.65), transparent 66%);
  content: "";
  transform: scaleX(0.72);
}

.ambient {
  position: absolute;
  z-index: -1;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #72e9c0;
  box-shadow: 0 0 10px 2px rgba(114, 233, 192, 0.4);
  opacity: 0.45;
  animation: drift 8s ease-in-out infinite alternate;
}

.ambient--one { left: 16%; top: 22%; }
.ambient--two { right: 18%; top: 35%; animation-delay: -4s; }

.experiment {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.game-status {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 20;
  display: flex;
  width: min(92vw, 440px);
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 5vw, 28px);
  padding: 8px 14px;
  border: 1px solid rgba(119, 211, 190, 0.16);
  border-radius: 15px;
  color: rgba(180, 231, 220, 0.62);
  background: rgba(5, 27, 34, 0.64);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18), inset 0 1px rgba(255, 255, 255, 0.03);
  font-size: clamp(19px, 5.4vw, 24px);
  backdrop-filter: blur(8px);
  transform: translateX(-50%);
}

.mood-meter,
.daily-meter {
  display: flex;
  align-items: center;
  gap: clamp(7px, 2vw, 10px);
}

.mood-meter {
  gap: clamp(9px, 2.4vw, 12px);
  padding-right: 2px;
}

.mood-meter span {
  opacity: 0.14;
  transform: scale(0.9);
  transition: color 180ms ease, opacity 180ms ease, text-shadow 180ms ease, transform 180ms ease;
}

.mood-meter span.is-active {
  color: #b9f4df;
  opacity: 1;
  text-shadow: 0 0 11px rgba(87, 222, 184, 0.62);
  transform: scale(1.2);
}

.mood-meter [data-mood="dead"] { display: none; }
.mood-meter [data-mood="dead"].is-active { display: inline; color: rgba(211, 118, 118, 0.82); }

.daily-meter__icon {
  width: clamp(25px, 7vw, 31px);
  height: clamp(25px, 7vw, 31px);
  object-fit: contain;
  image-rendering: pixelated;
}

.daily-slot {
  position: relative;
  display: inline-grid;
  width: 17px;
  place-items: center;
  color: rgba(144, 206, 191, 0.46);
  text-align: center;
}

.daily-slot.is-complete { color: #78dfb7; }

.daily-slot.is-pop {
  z-index: 2;
  animation: care-success-pop 760ms cubic-bezier(0.2, 0.9, 0.25, 1.3);
}

.daily-slot.is-pop::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  aspect-ratio: 1;
  border: 2px solid rgba(126, 239, 191, 0.8);
  border-radius: 50%;
  content: "";
  pointer-events: none;
  animation: care-success-ring 620ms ease-out both;
}

.jar {
  position: relative;
  width: min(76vw, 360px, 51vh);
  aspect-ratio: 0.64;
  filter: drop-shadow(0 25px 22px rgba(0, 0, 0, 0.42));
  user-select: none;
  -webkit-user-select: none;
}

.jar__lid {
  position: absolute;
  top: 0;
  left: 17%;
  z-index: 8;
  display: flex;
  width: 66%;
  height: 11.5%;
  align-items: stretch;
  justify-content: space-around;
  overflow: hidden;
  border: 3px solid #7b8c88;
  border-radius: 8px 8px 5px 5px;
  background: linear-gradient(180deg, #aab6ae 0 18%, #52635f 20% 42%, #879690 44% 62%, #394b49 64% 100%);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.28), 0 5px 0 #263b3c;
}

.jar__lid span {
  width: 3px;
  background: rgba(20, 40, 40, 0.34);
  box-shadow: 2px 0 rgba(255, 255, 255, 0.13);
}

.jar__neck {
  position: absolute;
  top: 9%;
  left: 22%;
  z-index: 2;
  width: 56%;
  height: 13%;
  border: 4px solid rgba(170, 224, 217, 0.48);
  background: rgba(89, 154, 151, 0.1);
  box-shadow: inset 10px 0 rgba(202, 255, 247, 0.08), inset -8px 0 rgba(9, 54, 59, 0.16);
}

.jar__body {
  position: absolute;
  inset: 16% 0 0;
  z-index: 3;
  border: 5px solid rgba(157, 219, 211, 0.54);
  border-top-width: 7px;
  border-radius: 18% 18% 24% 24% / 10% 10% 9% 9%;
  background: linear-gradient(90deg, rgba(164, 246, 231, 0.09), rgba(48, 137, 137, 0.03) 40%, rgba(5, 39, 47, 0.13));
  box-shadow:
    inset 9px 0 13px rgba(182, 255, 241, 0.08),
    inset -12px 0 16px rgba(2, 21, 27, 0.23),
    inset 0 -8px 12px rgba(150, 239, 220, 0.12),
    0 0 0 2px rgba(11, 50, 57, 0.8);
}

.jar__interior {
  position: absolute;
  inset: 5px;
  overflow: hidden;
  border-radius: 17% 17% 23% 23% / 9% 9% 8% 8%;
  background: linear-gradient(90deg, rgba(44, 102, 103, 0.12), rgba(1, 22, 29, 0.08));
}

#liquid,
#liquidOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#liquidOverlay {
  z-index: 3;
  pointer-events: none;
}

.brain {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 55%;
  height: auto;
  image-rendering: pixelated;
  filter: drop-shadow(0 10px 6px rgba(2, 29, 25, 0.48)) saturate(0.9);
  pointer-events: none;
  transform-origin: 50% 48%;
  will-change: transform;
}

.liquid-glow {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-radius: inherit;
  background:
    linear-gradient(90deg, rgba(130, 255, 202, 0.08), transparent 22%, transparent 76%, rgba(1, 49, 51, 0.12)),
    linear-gradient(0deg, rgba(13, 106, 88, 0.2), transparent 60%);
  mix-blend-mode: screen;
  pointer-events: none;
}

.jar__shine {
  position: absolute;
  z-index: 5;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(229, 255, 248, 0.42), rgba(183, 247, 234, 0.02));
  pointer-events: none;
}

.jar__shine--left {
  top: 13%;
  left: 7%;
  width: 3.2%;
  height: 58%;
  transform: rotate(2deg);
}

.jar__shine--right {
  top: 22%;
  right: 6%;
  width: 1.4%;
  height: 31%;
  opacity: 0.4;
}

.jar__rim {
  position: absolute;
  top: -1.5%;
  left: 11%;
  z-index: 6;
  width: 78%;
  height: 6%;
  border: 4px solid rgba(166, 225, 215, 0.58);
  border-radius: 50%;
  background: rgba(30, 79, 80, 0.25);
  box-shadow: inset 0 3px rgba(218, 255, 247, 0.16);
}

.motion-button {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: none;
  align-items: center;
  width: 48px;
  height: 44px;
  justify-content: center;
  gap: 0;
  margin: 0;
  padding: 0;
  border: 1px solid rgba(117, 222, 193, 0.38);
  border-radius: 999px;
  color: #b9e8dc;
  background: rgba(9, 39, 45, 0.72);
  font: inherit;
  font-size: 16px;
  letter-spacing: 0.05em;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-actions {
  position: absolute;
  bottom: var(--action-bottom-offset);
  left: 50%;
  z-index: 20;
  display: flex;
  gap: 16px;
  margin: 0;
  transform: translateX(-50%);
}

.game-action,
.game-modal__actions button {
  display: grid;
  width: clamp(60px, 17vw, 68px);
  height: clamp(54px, 15vw, 62px);
  padding: 0;
  place-items: center;
  border: 1px solid rgba(117, 222, 193, 0.34);
  border-radius: 13px;
  color: #bcebdd;
  background: rgba(9, 39, 45, 0.74);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.05);
  font: inherit;
  font-size: clamp(23px, 6.5vw, 28px);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-action__icon {
  width: 72%;
  height: 72%;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.game-modal__actions button[hidden] { display: none; }

.game-action:active:not(:disabled),
.game-modal__actions button:active:not(:disabled) { transform: scale(0.95); }

.game-action:disabled,
.game-modal__actions button:disabled {
  cursor: default;
  opacity: 0.25;
}

.cooldown {
  position: absolute;
  bottom: calc(var(--action-bottom-offset) + 70px);
  left: 50%;
  z-index: 20;
  min-height: 13px;
  margin: 0;
  color: rgba(166, 215, 207, 0.48);
  font-size: 11px;
  letter-spacing: 0.1em;
  transform: translateX(-50%);
}

.game-modal {
  width: min(90vw, 380px);
  max-height: min(82dvh, 560px);
  padding: 0;
  border: 1px solid rgba(133, 224, 200, 0.4);
  border-radius: 18px;
  color: #caeee4;
  background: rgba(5, 28, 35, 0.96);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.65), inset 0 1px rgba(255, 255, 255, 0.06);
}

.game-modal::backdrop {
  background: rgba(1, 10, 14, 0.72);
  backdrop-filter: blur(3px);
}

.game-modal__card {
  display: flex;
  min-height: clamp(270px, 40dvh, 340px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(28px, 7vw, 38px);
}

.game-modal__icon {
  display: grid;
  width: 60px;
  min-height: 60px;
  place-items: center;
  color: #8ee0c5;
  font-size: 30px;
  line-height: 1;
}

.game-modal__icon:empty { display: none; }

.game-modal__icon img {
  width: 100%;
  height: 60px;
  object-fit: contain;
  image-rendering: pixelated;
}

.dice-rack {
  display: flex;
  min-height: 60px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.dice-rack:empty { display: none; }

.die {
  width: clamp(50px, 14vw, 58px);
  height: clamp(50px, 14vw, 58px);
  padding: 0;
  border: 1px solid rgba(143, 217, 198, 0.35);
  border-radius: 8px;
  color: #d7f3eb;
  background: rgba(43, 91, 89, 0.52);
  font: clamp(35px, 10vw, 42px)/1 system-ui, sans-serif;
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.die.is-selected {
  border-color: #87e1c3;
  background: rgba(53, 147, 119, 0.56);
  box-shadow: 0 0 10px rgba(75, 220, 172, 0.2);
  transform: translateY(-3px);
}

.die.is-held {
  border-color: rgba(135, 225, 195, 0.65);
  box-shadow: 0 0 12px rgba(75, 220, 172, 0.24);
}

.die.is-rolling {
  animation: dice-roll 110ms steps(2, jump-none) infinite;
}

.die:disabled { cursor: default; }

.game-modal__message {
  min-height: 18px;
  margin: 18px 0 0;
  color: rgba(191, 228, 218, 0.7);
  font-size: clamp(11px, 3.2vw, 13px);
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-align: center;
  text-transform: uppercase;
}

.game-modal__icon:empty + .dice-rack:empty + .game-modal__message { margin-top: 0; }

.game-modal__actions {
  display: flex;
  min-height: 52px;
  gap: 12px;
  margin-top: 20px;
}

.game-modal__actions button {
  width: 58px;
  height: 52px;
  font-size: 24px;
}

.motion-button.is-visible { display: flex; }
.motion-button:active { transform: scale(0.97); }
.motion-button__icon { font-size: 23px; line-height: 0; }

@keyframes drift {
  to { transform: translate(12px, -18px); opacity: 0.15; }
}

@keyframes dice-roll {
  0% { transform: translate(-2px, -2px) rotate(-4deg); }
  50% { transform: translate(2px, 1px) rotate(4deg) scale(0.96); }
  100% { transform: translate(-1px, 2px) rotate(-2deg); }
}

@keyframes care-success-pop {
  0% { color: #eafff6; opacity: 0; transform: scale(0.2) rotate(-12deg); }
  34% { color: #eafff6; opacity: 1; text-shadow: 0 0 18px rgba(126, 239, 191, 0.95); transform: scale(2.5) rotate(8deg); }
  58% { transform: scale(1.25) rotate(-4deg); }
  78% { transform: scale(1.65) rotate(2deg); }
  100% { color: #78dfb7; text-shadow: none; transform: scale(1) rotate(0); }
}

@keyframes care-success-ring {
  0% { opacity: 0.9; transform: translate(-50%, -50%) scale(0.3); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.8); }
}

@media (max-height: 650px) {
  .jar { width: min(69vw, 45vh); }
}

@media (max-width: 350px) {
  .game-status {
    width: 94vw;
    gap: 13px;
    padding-inline: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ambient { animation: none; }
}
