:root {
  --bottle-width: 65px;
  --bottle-height: 190px;
  --pour-duration: 500ms;
}

body {
  font-family: "Inter", sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html,
body {
  overflow: hidden;
  height: 100%;
}

.game-background {
  background: radial-gradient(
    circle at 50% 0%,
    #7c3aed 0%,
    #4c1d95 40%,
    #2e1065 100%
  );
  position: relative;
}

#star-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

.bottle-container {
  width: var(--bottle-width);
  height: var(--bottle-height);
  position: relative;
  cursor: pointer;
  transition:
    transform 0.3s cubic-bezier(0.25, 1, 0.5, 1),
    filter 0.3s,
    box-shadow 0.3s;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25));
  will-change: transform, filter, box-shadow;
  backface-visibility: hidden;
}

.bottle-base-img,
.bottle-shade-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
}

.bottle-base-img {
  z-index: 1;
}

.bottle-shade-img {
  z-index: 4;
}

.bottle-container.selected {
  transform: translateY(-30px) scale(1.08);

  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25))
    drop-shadow(0 0 15px rgba(167, 139, 250, 0.8));
}

.bottle-container.completed {
  cursor: default;
  pointer-events: none;
}

.liquid-container {
  position: absolute;
  width: 77.33%; /* 58/75 */
  height: 76.36%; /* 168/220 */
  bottom: 5.9%; /* 13/220 */
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  z-index: 2;
  border-bottom-left-radius: 43% 15%;
  border-bottom-right-radius: 43% 15%;
  mask-image: linear-gradient(to top, black, black);
  -webkit-mask-image: linear-gradient(to top, black, black);
  clip-path: polygon(0% 25%, 18% 0, 82% 0, 100% 25%, 100% 100%, 0% 100%);
  -webkit-clip-path: polygon(
    0% 25%,
    18% 0,
    82% 0,
    100% 25%,
    100% 100%,
    0% 100%
  );
  padding-top: 4.7%; /* 8/168 */
  box-sizing: border-box;
  transition: opacity 0.2s ease-out;
}

.liquid-container.is-pouring {
  overflow: visible;
}

.color-segment {
  width: 100%;
  position: relative;
  margin-top: -1px;
  backface-visibility: hidden;
  transform: translateZ(0);
}

.bottle-container.selected .color-segment {
  margin-top: -1.2px;
}

.color-segment.is-hidden {
  background: #2e1065;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.color-segment.is-hidden::before {
  display: none;
}
.color-segment.is-hidden::after {
  content: "?";
  font-family: "Inter", sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.5);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

@keyframes reveal-segment {
  from {
    filter: brightness(0.2) blur(5px);
    transform: scale(0.9);
  }
  to {
    filter: brightness(1) blur(0);
    transform: scale(1);
  }
}
.color-segment.is-revealing > div {
  /* Target inner filler div */
  animation: reveal-segment 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fill-surface-up {
  from {
    top: var(--fill-start-top, 100%);
  }
  to {
    top: -8px;
  }
}

.color-segment:last-child:not(.is-hidden)::before,
.color-segment.is-new-top::before,
.color-segment.is-filling::before {
  content: "";
  position: absolute;
  left: -10%;
  width: 120%;
  height: 16px;
  background: var(--liquid-gradient);
  border-radius: 50%;
  box-shadow:
    inset 0px 6px 8px -4px rgba(0, 0, 0, 0.35),
    inset 0px -5px 6px -3px rgba(255, 255, 255, 0.5);
  backface-visibility: hidden;
  transform: translateZ(0);
  z-index: 2;
}

.color-segment:last-child:not(.is-hidden):not(.is-filling)::before,
.color-segment.is-new-top::before {
  top: -8px;
}

.color-segment.is-filling::before {
  top: var(--fill-start-top, 80%);
  animation-name: fill-surface-up;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-duration: var(--fill-surface-duration, 600ms);
  animation-delay: var(--fill-surface-delay, 0s);
}

.pour-point {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  height: 1px;
}

.pouring {
  transition: transform var(--pour-duration)
    cubic-bezier(0.6, -0.28, 0.735, 0.045); /* EaseInBack */
}

.pour-stream {
  position: fixed;
  width: 9px;
  background: red;
  border-radius: 4px;
  opacity: 0;
  z-index: 11;
  transform-origin: top;
  will-change: transform, opacity;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  25% {
    transform: translateX(-5px) rotate(-3deg);
  }
  75% {
    transform: translateX(5px) rotate(3deg);
  }
}

.shake {
  animation: shake 0.3s ease-in-out;
}

@keyframes jump-in {
  0%,
  100% {
    transform: scaleY(1);
    transform-origin: bottom;
  }
  50% {
    transform: scaleY(0.95) translateY(3px);
    transform-origin: bottom;
  }
}

.jump-in {
  animation: jump-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  80% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.win-modal,
.menu-container,
#booster-modal > div,
#settings-modal > div {
  animation: pop-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confetti {
  position: absolute;
  background: #f00;
  top: -30px;
  opacity: 0;
  animation-name: fall;
  animation-timing-function: ease-in;
  animation-fill-mode: forwards;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

@keyframes fall {
  from {
    transform: translateY(-30px) rotate(var(--start-rotation));
    opacity: 1;
  }
  to {
    transform: translateY(105vh) rotate(var(--end-rotation));
    opacity: 0;
  }
}

.cork {
  position: absolute;
  width: 54%;
  height: 22%;
  background-image: url("kork.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  top: -5%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.cork.animate-in {
  animation: cork-in 0.6s cubic-bezier(0.42, 0, 1, 1) 0.2s forwards;
  opacity: 0;
}

@keyframes cork-in {
  from {
    transform: translate(-50%, -150px) rotate(-45deg);
    opacity: 0;
  }
  to {
    transform: translateX(-50%);
    opacity: 1;
  }
}

.bottle-squash-animation {
  animation: bottle-squash 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: bottom;
}

@keyframes bottle-squash {
  0%,
  100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(0.9);
  }
}

.bubble {
  position: absolute;
  bottom: 0;
  border-radius: 50%;
  opacity: 0;
  animation: rise-and-fade 0.6s ease-out forwards;
  background-color: var(--bubble-color, #fff);
  z-index: 3;
  pointer-events: none;
}

@keyframes rise-and-fade {
  0% {
    transform: translateY(0) scale(0.5);
    opacity: 0.9;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: translateY(-60px) scale(1);
    opacity: 0;
  }
}

.sparkle-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  contain: strict;
  overflow: visible;
  width: 100px;
  margin-left: -20px;
  height: 250px;
  margin-top: -50px;
  -webkit-mask-image: linear-gradient(
    to top,
    #000 0%,
    #000 86%,
    transparent 100%
  );
  mask-image: linear-gradient(to top, #000 0%, #000 86%, transparent 100%);
}

.sparkle {
  position: absolute;
  bottom: -12px;
  left: var(--x, 50%);
  opacity: 0;
  animation: sparkle-rise var(--dur, 1s) linear var(--delay, 0s) forwards;
  will-change: transform, opacity;
}

.sparkle::before {
  content: "";

  display: block;

  width: var(--size, 12px);

  height: var(--size, 12px);

  background: #fff;

  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50 2 L60 34 L98 34 L66 55 L78 92 L50 70 L22 92 L34 55 L2 34 L40 34 Z' fill='black'/></svg>")
    center / contain no-repeat;

  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><path d='M50 2 L60 34 L98 34 L66 55 L78 92 L50 70 L22 92 L34 55 L2 34 L40 34 Z' fill='black'/></svg>")
    center / contain no-repeat;

  position: relative;

  backface-visibility: hidden;

  transform: translateZ(0);
}

@keyframes sparkle-rise {
  0% {
    transform: translate3d(0, 0, 0) scale(0.6);
    opacity: 0;
  }
  10% {
    opacity: 0.95;
  }
  70% {
    opacity: 0.95;
  }
  100% {
    transform: translate3d(0, calc(-1 * var(--rise, 320px)), 0) scale(1.12);
    opacity: 0;
  }
}

#pixel-art-container {
  width: 100px;
  height: 100px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  transition:
    transform 0.3s,
    box-shadow 0.3s;
}

.pixel-square {
  position: relative;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.2);
}
.pixel-image {
  position: absolute;
  inset: 0;
  background-size: 400% 400%;
  image-rendering: pixelated;
}
.pixel-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(46, 16, 101, 0.8);
  backdrop-filter: blur(2px);
  transition: opacity 0.3s ease-in-out;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
}
.pixel-overlay svg {
  width: 20px;
  height: 20px;
  opacity: 0.5;
}

#level-selection-grid {
  height: 250px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#level-selection-grid::-webkit-scrollbar {
  width: 8px;
}
#level-selection-grid::-webkit-scrollbar-track {
  background: transparent;
}
#level-selection-grid::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}

#collection-grid {
  display: flex;
  justify-content: flex-start;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}
#collection-grid::-webkit-scrollbar {
  height: 8px;
}
#collection-grid::-webkit-scrollbar-track {
  background: transparent;
}
#collection-grid::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}

#collection-grid .collection-thumbnail {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  background-size: cover;
  background-position: center;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}
#collection-grid .collection-thumbnail:hover {
  transform: scale(1.05);
  box-shadow: 0 0 15px rgba(167, 139, 250, 0.5);
}
.collection-thumbnail .progress-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: bold;
}

.flying-star {
  position: fixed;
  width: 25px;
  height: 25px;
  z-index: 100;
  pointer-events: none;
  background-color: #fde047; /* yellow-400 */
  clip-path: polygon(
    50% 0%,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
  transition:
    transform 0.7s cubic-bezier(0.5, 0, 0.9, 0.5),
    opacity 0.7s ease-out;
  filter: drop-shadow(0 0 15px #fef08a);
  will-change: transform, opacity;
  backface-visibility: hidden;
}

.toggle-bg:after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  background-color: white;
  border: 1px solid #d1d5db; /* gray-300 */
  border-radius: 9999px;
  height: 1.25rem; /* 20px */
  width: 1.25rem; /* 20px */
  transition: all 0.2s ease-in-out;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
input:checked + .toggle-bg:after {
  transform: translateX(100%);
  border-color: white;
}
input:checked + .toggle-bg {
  background-color: #22c55e; /* green-500 */
}

.bottle-cover-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  z-index: 6;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  opacity: 1;
  transform: translateY(0) scale(1);
}

.unlock-color-swatch {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 3px solid white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  margin-top: 25%;
}
@media (min-width: 768px) {
  #pixel-art-container {
    width: 140px;
    height: 140px;
  }
}
@media screen and (max-height: 750px) {
  :root {
    --bottle-width: 50px !important;
    --bottle-height: 146px !important;
  }
  #game-board {
    gap: 1rem 0.5rem !important;
  }
  /* You can also add rules for the main menu here if needed */
  .menu-container h1 {
    font-size: 3rem; /* Example: Make title smaller */
  }
  #level-selection-grid {
    height: 200px; /* Example: Reduce grid height */
  }
}
@media screen and (max-height: 580px) {
  :root {
    --bottle-width: 40px !important;
    --bottle-height: 117px !important;
  }
  #game-board {
    gap: 0.8rem 0.4rem !important;
  }
  /* You can also add rules for the main menu here if needed */
  .menu-container h1 {
    font-size: 2rem; /* Example: Make title smaller */
  }
  #level-selection-grid {
    height: 160px; /* Example: Reduce grid height */
  }
  .flex.justify-center.w-full.space-x-2 img {
    width: 9vh !important; /* Make them smaller relative to screen width */
    max-width: 60px !important; /* Lower the maximum size */
  }
  #collection-grid .collection-thumbnail {
    width: 65px !important; /* Change from 80px */
    height: 65px !important; /* Change from 80px */
  }
  #pixel-art-container {
    width: 110px;
    height: 110px;
  }
}
@media screen and (max-height: 479px) {
  :root {
    --bottle-width: 36px !important;
    --bottle-height: 99px !important;
  }
  #select-level {
    display: none;
  }
  #game-board {
    gap: 0.8rem 0.4rem !important;
  }
  /* You can also add rules for the main menu here if needed */
  .menu-container h1 {
    font-size: 2rem; /* Example: Make title smaller */
  }
  #level-selection-grid {
    height: 160px; /* Example: Reduce grid height */
    margin-top: 10px;
  }
  .flex.justify-center.w-full.space-x-2 img {
    width: 8vh !important; /* Make them smaller relative to screen width */
    max-width: 50px !important; /* Lower the maximum size */
  }
  #collection-grid .collection-thumbnail {
    width: 65px !important; /* Change from 80px */
    height: 65px !important; /* Change from 80px */
  }
  #pixel-art-container {
    width: 90px;
    height: 90px;
  }
}
