/* ============================================================
   Water Sort Puzzle - game-specific styles
   ============================================================ */

#level-select-view {
  width: 100%;
}

#game-stage {
  position: relative;
}

.ws-intro {
  text-align: center;
  color: var(--ink-soft);
  font-weight: 600;
  margin: 0 0 22px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
}

.level-btn {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 2px solid var(--ink);
  background: var(--surface);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 4px 0 rgba(34, 49, 74, 0.12);
  transition: transform 0.1s ease, background 0.15s ease;
}
.level-btn:hover:not(:disabled) { transform: translateY(-2px); }
.level-btn.completed {
  background: var(--simon-green);
  color: #fff;
}
.level-btn .best {
  font-family: var(--font-body);
  font-size: 0.5rem;
  font-weight: 800;
  line-height: 1;
  opacity: 0.9;
}
.level-btn .diff-dot {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.diff-easy { background: var(--simon-green); }
.diff-medium { background: var(--yellow-deep); }
.diff-hard { background: var(--pink-deep); }
.diff-expert { background: var(--purple-deep); }

.ws-legend {
  display: flex;
  gap: 18px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 20px 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.ws-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ws-legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.ws-play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.ws-level-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.difficulty-chip {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--ink-soft);
}

#game-play-view:not([hidden]) {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

#game-play-view .scoreboard {
  margin-bottom: 10px;
}

.ws-rack {
  position: relative;
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  gap: 22px 16px;
  justify-items: center;
  align-items: end;
  margin: 2px auto 0;
}

.ws-tube {
  position: relative;
  width: clamp(58px, 11vw, 76px);
  height: clamp(174px, 33vw, 214px);
  border: 3px solid var(--ink);
  border-top-width: 0;
  border-radius: 0 0 26px 26px;
  background: rgba(255, 255, 255, 0.55);
  padding: 10px 8px 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: visible;
  cursor: pointer;
  box-shadow: 0 7px 0 rgba(34, 49, 74, 0.14);
  transition: transform 0.28s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.ws-tube::before {
  content: "";
  position: absolute;
  left: -7px;
  right: -7px;
  top: -5px;
  height: 11px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--surface);
}
.ws-tube:hover:not(:disabled) {
  transform: translateY(-3px);
}
.ws-tube.is-selected {
  transform: translateY(-12px);
  border-color: var(--purple-deep);
  box-shadow: 0 12px 0 rgba(155, 126, 222, 0.18);
}
.ws-tube.is-receiving {
  animation: ws-receive 0.26s ease;
}
.ws-tube.is-animation-source {
  opacity: 0;
}

.ws-pour-canvas {
  position: absolute;
  inset: 0 auto auto 0;
  z-index: 1003;
  pointer-events: none;
}

.ws-live-fill {
  position: absolute;
  box-sizing: border-box;
  height: 0;
  border: 1.5px solid rgba(34, 49, 74, 0.18);
  border-bottom-width: 0;
  border-radius: 0;
  pointer-events: none;
  z-index: 2;
}
.ws-live-fill.is-bottom {
  border-bottom-width: 1.5px;
  border-radius: 0 0 17px 17px;
}

.ws-tube.is-moving-source {
  transform: translate(var(--move-x, 0), var(--move-y, 0)) translateY(-10px);
  border-color: var(--purple-deep);
  box-shadow: 0 12px 0 rgba(155, 126, 222, 0.18);
  z-index: 3;
}
.ws-tube.is-pouring-source {
  transform: translate(var(--move-x, 0), var(--move-y, 0)) translateY(-20px) rotate(var(--pour-tilt, -17deg));
  border-color: var(--purple-deep);
  transform-origin: 50% 12%;
  z-index: 3;
}
.ws-tube.is-pouring-target {
  animation: ws-target 0.56s ease;
}
.ws-rack.is-complete .ws-tube.is-complete {
  animation: ws-complete-tube 0.9s cubic-bezier(0.2, 0.9, 0.2, 1.1) var(--complete-delay, 0s) both;
}
.ws-rack.is-complete {
  animation: ws-rack-victory 1.2s ease-out both;
}
.ws-rack.is-complete::before {
  content: "";
  position: absolute;
  inset: -18px -10px;
  border-radius: 24px;
  background: radial-gradient(circle at 50% 55%, rgba(53, 196, 106, 0.2), rgba(95, 193, 238, 0.1) 44%, transparent 72%);
  opacity: 0;
  pointer-events: none;
  animation: ws-victory-glow 1.2s ease-out forwards;
}
.ws-tube:disabled {
  cursor: default;
}

.ws-stage-victory {
  position: absolute;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transform: translateZ(0);
  will-change: opacity;
}
.ws-stage-victory.is-active {
  opacity: 1;
}
.ws-stage-victory span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  color: var(--yellow-deep);
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 7vw, 2rem);
  font-weight: 800;
  text-shadow:
    0 2px 0 #fff,
    0 0 12px rgba(255, 201, 61, 0.55);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.4);
  animation: ws-victory-spark 1.08s ease-out var(--delay, 0s) forwards;
}

.ws-pour-clone {
  position: absolute;
  margin: 0;
  pointer-events: none;
  z-index: 1002;
  transform: translateY(0);
  transition: left 0.28s ease, top 0.28s ease, transform 0.18s ease;
}
.ws-pour-clone.is-clone-moving {
  left: var(--clone-left) !important;
  top: var(--clone-top) !important;
  transform: translateY(-2px);
}
.ws-pour-clone.is-clone-pouring {
  left: var(--clone-left) !important;
  top: var(--clone-top) !important;
  transform: translateY(-10px) rotate(var(--pour-tilt, -17deg));
  transform-origin: 50% 12%;
}

.ws-pour-fx {
  position: absolute;
  z-index: 1001;
  pointer-events: none;
  height: 18px;
  transform: rotate(var(--pour-angle, 0deg));
  transform-origin: left center;
}
.ws-pour-stream,
.ws-pour-shine {
  position: absolute;
  left: 0;
  top: 50%;
  border-radius: 999px;
  transform: translateY(-50%) scaleX(0);
  transform-origin: left center;
}
.ws-pour-stream {
  width: 100%;
  height: 13px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.4), rgba(255, 255, 255, 0) 42%),
    var(--pour-color);
  box-shadow: 0 0 0 1px rgba(34, 49, 74, 0.18), 0 6px 12px rgba(34, 49, 74, 0.18);
  opacity: 0;
  filter: saturate(1.08);
  clip-path: polygon(0 0, 100% 22%, 100% 78%, 0 100%);
}
.ws-pour-shine {
  width: calc(100% - 8px);
  height: 3.5px;
  margin-left: 4px;
  background: rgba(255, 255, 255, 0.55);
  opacity: 0;
  clip-path: polygon(0 0, 100% 30%, 100% 70%, 0 100%);
}
.ws-pour-droplets {
  position: absolute;
  inset: 0;
}
.ws-pour-droplets span {
  position: absolute;
  top: 9px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--pour-color);
  opacity: 0;
  box-shadow: 0 0 0 1px rgba(34, 49, 74, 0.08);
}
.ws-pour-fx.is-active .ws-pour-stream {
  animation: ws-stream 0.56s ease forwards, ws-wobble 0.14s ease-in-out infinite alternate;
}
.ws-pour-fx.is-active .ws-pour-shine {
  animation: ws-shine 0.56s ease forwards;
}
.ws-pour-fx.is-active .ws-pour-droplets span {
  animation: ws-droplet 0.42s ease-in forwards;
}

.ws-fill {
  width: 100%;
  height: 25%;
  border: 1.5px solid rgba(34, 49, 74, 0.18);
  border-bottom-width: 0;
  transform-origin: center bottom;
}
.ws-fill.is-bottom {
  border-bottom-width: 1.5px;
  border-radius: 0 0 17px 17px;
}
.ws-empty {
  width: 100%;
  height: 25%;
}

.ws-fill-preview {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(12px + (var(--slot) * ((100% - 22px) / 4)));
  height: calc((100% - 22px) / 4);
  border: 1.5px solid rgba(34, 49, 74, 0.18);
  border-bottom-width: 0;
  transform: scaleY(0);
  transform-origin: center bottom;
  opacity: 0;
  animation: ws-fill-up 0.34s ease-out var(--delay, 0s) forwards;
  z-index: 2;
}
.ws-fill-preview.is-bottom {
  border-bottom-width: 1.5px;
  border-radius: 0 0 17px 17px;
}
.instructions.ws {
  margin-top: 0;
}

#game-stage:fullscreen,
#game-stage.is-ios-fullscreen {
  border-radius: 0;
  border: none;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  height: calc(var(--obg-vh, 1vh) * 100);
  justify-content: flex-start;
  background: var(--bg-soft);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#game-stage:fullscreen .ws-rack,
#game-stage.is-ios-fullscreen .ws-rack {
  width: min(760px, 100%);
}

@keyframes ws-receive {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-4px) scale(1.03); }
  100% { transform: translateY(0) scale(1); }
}

@keyframes ws-target {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-5px); }
}

@keyframes ws-complete-tube {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 7px 0 rgba(34, 49, 74, 0.14);
  }
  32% {
    transform: translateY(-14px) scale(1.04);
    box-shadow: 0 16px 0 rgba(53, 196, 106, 0.18), 0 0 0 5px rgba(53, 196, 106, 0.18);
  }
  60% {
    transform: translateY(2px) scale(0.99);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 7px 0 rgba(34, 49, 74, 0.14);
  }
}

@keyframes ws-rack-victory {
  0% {
    transform: scale(1);
    filter: saturate(1);
  }
  28% {
    transform: scale(1.015);
    filter: saturate(1.18);
  }
  100% {
    transform: scale(1);
    filter: saturate(1);
  }
}

@keyframes ws-victory-spark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4) rotate(0deg);
  }
  18% {
    opacity: 1;
  }
  72% {
    opacity: 1;
    transform: translate(calc(-50% + var(--drift-mid, 18px)), -92%) scale(1.08) rotate(var(--spin, 22deg));
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--drift-end, 26px)), -132%) scale(0.72) rotate(var(--spin, 22deg));
  }
}

@keyframes ws-stream {
  0% { opacity: 0; transform: translateY(-50%) scaleX(0); }
  18% { opacity: 0.96; transform: translateY(-50%) scaleX(1); }
  74% { opacity: 0.96; transform: translateY(-50%) scaleX(1); }
  100% { opacity: 0; transform: translateY(-50%) scaleX(0.18); }
}

@keyframes ws-shine {
  0%, 12% { opacity: 0; transform: translateY(-50%) scaleX(0); }
  28%, 70% { opacity: 0.78; transform: translateY(-50%) scaleX(1); }
  100% { opacity: 0; transform: translateY(-50%) scaleX(0.2); }
}

@keyframes ws-droplet {
  0%, 12% { opacity: 0; transform: translateY(-2px) scale(0.7); }
  24% { opacity: 0.85; }
  100% { opacity: 0; transform: translateY(15px) scale(0.4); }
}

@keyframes ws-wobble {
  0% { height: 12px; }
  100% { height: 14px; }
}

@keyframes ws-fill-up {
  0% {
    opacity: 0.75;
    transform: scaleY(0);
  }
  55% {
    opacity: 1;
    transform: scaleY(1.06);
  }
  100% {
    opacity: 1;
    transform: scaleY(1);
  }
}

@media (max-width: 560px) {
  .ws-rack {
    grid-template-columns: repeat(auto-fit, minmax(54px, 1fr));
    gap: 18px 9px;
    padding-top: 12px;
  }
  .ws-tube {
    width: clamp(48px, 15vw, 62px);
    height: clamp(148px, 42vw, 184px);
    padding: 9px 6px 10px;
  }
  .ws-fill-preview {
    left: 6px;
    right: 6px;
    bottom: calc(10px + (var(--slot) * ((100% - 19px) / 4)));
    height: calc((100% - 19px) / 4);
  }
  .ws-play-header {
    justify-content: center;
  }
  .ws-stage-victory {
    position: fixed;
    inset: 0;
    z-index: 1045;
  }
}

@keyframes ws-victory-glow {
  0% { opacity: 0; transform: scale(0.96); }
  22% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.04); }
}

@media (max-width: 480px) {
  .level-grid { grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 8px; }
  .level-btn { font-size: 0.9rem; }
}
