:root {
  --green: #00a321;
  --green-dark: #008f1d;
  --mint: #c5ffd7;
  --text: #142019;
  --board-width: clamp(318px, 41.7vw, 480px);
  --hint-top-offset: 20px;
}

@font-face {
  font-family: "SB Sans Display";
  src: url("../fonts/SBSansDisplay-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "SB Sans Display";
  src: url("../fonts/SBSansDisplay-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "SB Sans Display";
  src: url("../fonts/SBSansDisplay-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

*::before,
*::after {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

img,
svg,
canvas,
button {
  touch-action: manipulation;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  color: var(--text);
  font-family: "SB Sans Display", Arial, Helvetica, sans-serif;
  background: #8a7563;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

.game {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-image: url("assets/background.png");
  background-position: center center;
  background-repeat: no-repeat;
  background-size: cover;
  touch-action: manipulation;
}

.game::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: rgba(34, 24, 17, 0.2);
}

.intro,
.solved-modal,
.final-modal {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}

.intro[hidden],
.solved-modal[hidden],
.final-modal[hidden] {
  display: none;
}

.intro-card {
  position: relative;
  width: min(801px, calc(100vw - 32px));
  min-height: 236px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 20px;
  padding: 42px 40px 30px;
  border-radius: 16px;
  background: linear-gradient(180deg, #c5ffd7 0%, #f8fffb 100%);
  text-align: center;
  box-shadow: 0 24px 80px rgba(24, 14, 8, 0.18);
}

.intro-icon {
  position: absolute;
  left: 50%;
  top: 0;
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ffffff;
  transform: translate(-50%, -48%);
  overflow: hidden;
}

.intro-icon::before {
  content: "";
  width: 64px;
  height: 64px;
}

.intro-icon img,
.intro-icon-water {
  position: absolute;
}

.intro-icon-frame {
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  object-fit: contain;
  z-index: 3;
  transform: translate(-50%, -50%);
}

.intro-icon-water {
  left: 50%;
  top: 50%;
  z-index: 2;
  width: 35px;
  height: 40px;
  border-radius: 2px;
  overflow: hidden;
  transform: translate(-50%, -50%);
}

.intro-icon-water::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0%;
  background:
    radial-gradient(circle at 26% 24%, rgba(255, 255, 255, 0.48) 0 2px, transparent 3px),
    radial-gradient(circle at 72% 42%, rgba(255, 255, 255, 0.36) 0 1.5px, transparent 2.5px),
    linear-gradient(180deg, #7be7ff 0%, #22bff5 56%, #0aa2e0 100%);
  box-shadow: inset 0 6px 10px rgba(255, 255, 255, 0.3);
  animation: introWaterCycle 4s ease-in-out infinite;
}

.intro-icon-vent {
  left: 50%;
  top: 50%;
  z-index: 4;
  width: 38px;
  height: 38px;
  object-fit: contain;
  transform: translate(-50%, -50%) rotate(0deg);
  animation: introVentCycle 4s ease-in-out infinite;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.22));
}

.intro-card h1 {
  margin: 0;
  max-width: 620px;
  font-size: clamp(17px, 1.7vw, 21px);
  line-height: 1.25;
  letter-spacing: 0;
  font-weight: 600;
}

.primary-button {
  min-width: 190px;
  height: 44px;
  padding: 0 28px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--green-dark);
  outline: none;
}

.primary-button:active {
  transform: translateY(1px);
}

.playground {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: clamp(18px, 3vw, 36px);
}

.game.is-intro .playground,
.game.is-final .playground {
  visibility: hidden;
}

.hint {
  position: absolute;
  left: max(16px, calc(50% - var(--board-width) / 2 - 170px));
  top: calc(clamp(34px, 5.4vh, 46px) + var(--hint-top-offset));
  width: 165px;
  min-height: 99px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
  padding: 8px 10px 6px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 8px;
  background: rgba(145, 113, 84, 0.72);
  color: #ffffff;
  text-align: center;
  box-shadow: none;
}

.hint[hidden] {
  display: none;
}

.hint-close {
  position: absolute;
  top: -21px;
  right: -8px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.hint-close::before,
.hint-close::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 1px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  transform-origin: center;
}

.hint-close::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.hint-close::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.hint-close:hover,
.hint-close:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.hint p {
  margin: 0;
  font-size: 12px;
  line-height: 1.05;
  font-weight: 400;
}

.hint img {
  width: 16px;
  height: 16px;
  object-fit: contain;
}

.pipe-board,
.blur-board {
  width: var(--board-width);
  aspect-ratio: 480 / 580;
  border-radius: 14px;
  background-image: url("assets/background_pipes.png");
  background-size: cover;
  background-position: center center;
  box-shadow: 0 24px 70px rgba(27, 17, 10, 0.32);
}

.pipe-board {
  position: relative;
  overflow: hidden;
}

.auto-solve-button {
  position: absolute;
  left: 50%;
  top: calc(50% + var(--board-width) * 0.604166 + 12px);
  z-index: 8;
  min-width: 186px;
  height: 42px;
  padding: 0 22px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #ffffff;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 12px 28px rgba(0, 93, 28, 0.22);
  transform: translateX(-50%);
  animation: helperButtonIn 260ms ease both;
}

.auto-solve-button:hover,
.auto-solve-button:focus-visible {
  background: var(--green-dark);
  outline: none;
}

.auto-solve-button:disabled {
  cursor: default;
  opacity: 0.86;
}

.pipe-grid {
  --tile: calc(var(--board-width) * 0.208333);
  --gap: 0px;
  --grid-left: calc(var(--board-width) * 0.083333);
  --grid-top: calc(var(--board-width) * 0.083333);
  --pipe-overlap: calc(var(--tile) * 0.045);
  position: absolute;
  left: var(--grid-left);
  top: var(--grid-top);
  z-index: 3;
  width: calc(var(--tile) * 4 + var(--gap) * 3);
  height: calc(var(--tile) * 5 + var(--gap) * 4);
}

.water-canvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.game.is-flowing .water-canvas,
.game.is-solved .water-canvas {
  opacity: 1;
}

.pipe-cell {
  position: absolute;
  width: var(--tile);
  height: var(--tile);
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(
    calc(var(--col) * (var(--tile) + var(--gap))),
    calc(var(--row) * (var(--tile) + var(--gap)))
  );
}

.pipe-cell:focus-visible {
  outline: 3px solid rgba(0, 163, 33, 0.56);
  outline-offset: 2px;
  border-radius: 8px;
}

.pipe-cell.is-fixed {
  cursor: default;
  pointer-events: none;
}

.pipe-graphic,
.vent,
.block-water {
  position: absolute;
  pointer-events: none;
}

.pipe-graphic {
  inset: 0;
  z-index: 6;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform: rotate(var(--rotation, 0deg));
  transition: transform 180ms ease;
  filter: drop-shadow(0 5px 5px rgba(48, 29, 14, 0.14));
}

.pipe-cell.is-instant .pipe-graphic {
  transition: none;
}

.pipe-cell:not(.is-fixed) .pipe-graphic {
  inset: calc(var(--pipe-overlap) * -1);
  width: calc(100% + var(--pipe-overlap) * 2);
  height: calc(100% + var(--pipe-overlap) * 2);
  max-width: none;
}

.pipe-cell.is-fixed .pipe-graphic {
  inset: 0;
  width: 100%;
  height: 100%;
  transform: none;
}

.block-water {
  left: 19%;
  top: 22%;
  z-index: 3;
  width: 54%;
  height: 56%;
  border-radius: 2px;
  overflow: hidden;
  opacity: 0;
}

.block-water::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--fill, 0%);
  background:
    radial-gradient(circle at 24% 22%, rgba(255, 255, 255, 0.46) 0 3px, transparent 4px),
    radial-gradient(circle at 72% 38%, rgba(255, 255, 255, 0.34) 0 2px, transparent 3px),
    linear-gradient(180deg, #7be7ff 0%, #22bff5 56%, #0aa2e0 100%);
  box-shadow: inset 0 10px 16px rgba(255, 255, 255, 0.34);
  transition: height 280ms ease;
  animation: waterWaver 900ms linear infinite;
}
.is-start{
  background-color: gray;
}
.is-end{
  background-color: gray;
}
.pipe-cell.is-start .block-water,
.pipe-cell.is-end .block-water {
  opacity: 1;
}

.pipe-cell.is-start .block-water,
.pipe-cell.is-end .block-water {
  left: 18%;
  top: 18%;
  width: 63%;
  height: 63%;
}

.vent {
  left: 50%;
  top: 50%;
  z-index: 7;
  width: 74%;
  height: 74%;
  object-fit: contain;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 3px 3px rgba(0, 0, 0, 0.22));
}

.game.is-flowing .vent {
  animation: spinVent 620ms linear infinite;
}

.solved-modal {
  background: rgba(35, 25, 16, 0.24);
}

.blur-board {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  transform: translate(-50%, -50%);
  filter: blur(8px);
  opacity: 0.88;
}

.solved-card,
.final-card {
  position: relative;
  z-index: 2;
  width: min(326px, calc(100vw - 40px));
  display: grid;
  justify-items: center;
  text-align: center;
  border-radius: 16px;
  background: linear-gradient(180deg, #c5ffd7 0%, #ffffff 100%);
  box-shadow: 0 18px 55px rgba(30, 18, 10, 0.26);
}

.solved-card {
  padding: 14px 16px 16px;
  height: 368px;
}

.check-mark {
  background-image: url(/pipe_game/assets/strophe_gpt-image-2_2026-06-24_13-27-Photoroom\ 1.png);
  height: 72px;
  width: 80px;
  background-size: contain;
  background-repeat: no-repeat;
  text-shadow: 0 3px 3px rgba(0, 0, 0, 0.14);
}

.solved-card h2,
.solved-card p,
.final-card h2 {
  margin: 0;

}

.solved-card h2 {
  margin-top: 8px;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 600;
}

.solved-card p {
  margin-top: 8px;
  font-size: 16px;
  line-height: 1.2;
  font-weight: 400;
}

.damage-pill {
  width: 90%;
  min-height: 39px;
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 9px;
  border-radius: 8px;
  background: #ffffff;
  text-align: left;
}

.damage-pill img {
  width: 28px;
  height: auto;
  justify-self: center;
}

.damage-pill span {
  font-size: 12px;
  line-height: 1.14;
  font-weight: 600;
}

.solved-card .primary-button {
  width: 90%;
  min-width: 0;
  height: 56px;
  margin-top: 24px;
  padding: 0 12px;
  font-size: 11px;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 500;
}

.final-modal {
  background: rgba(35, 25, 16, 0.2);
}

.final-card {
  width: min(326px, calc(100vw - 40px));
  padding: 17px 16px 15px;
  height: 245px;
}

.final-coin {
  width: 49px;
  height: auto;
  margin-bottom: 12px;
}

.final-card h2 {
  font-size: 16px;
  line-height: 1.2;
  font-weight: 500;
}

.final-card .primary-button {
  width: 90%;
  min-width: 0;
  height: 56px;
  margin-top: 16px;
  padding: 0 12px;
  font-size: 16px;
}

.coin-layer {
  position: absolute;
  inset: 0;
  z-index: 70;
  pointer-events: none;
}

.flying-coin {
  position: absolute;
  width: 36px;
  height: 26px;
  object-fit: contain;
  transform: translate(-50%, -50%);
  animation: flyCoin 760ms cubic-bezier(0.18, 0.84, 0.18, 1) forwards;
}

@keyframes spinVent {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

@keyframes waterWaver {
  from {
    background-position: 0 0, 0 0, 0 0;
  }
  to {
    background-position: 18px -10px, -14px -8px, 0 0;
  }
}

@keyframes introWaterCycle {
  0%,
  8% {
    height: 0%;
  }
  44%,
  56% {
    height: 100%;
  }
  92%,
  100% {
    height: 0%;
  }
}

@keyframes introVentCycle {
  0%,
  8% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
  44%,
  56% {
    transform: translate(-50%, -50%) rotate(360deg);
  }
  92%,
  100% {
    transform: translate(-50%, -50%) rotate(0deg);
  }
}

@keyframes flyCoin {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
  }
  70% {
    opacity: 1;
  }
  100% {
    left: var(--target-x);
    top: var(--target-y);
    opacity: 0;
    transform: translate(-50%, -50%) rotate(340deg) scale(0.38);
  }
}

@keyframes helperButtonIn {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (max-width: 1200px) and (min-width: 761px) {
  :root {
    --board-width: clamp(390px, 52vw, 480px);
    --hint-top-offset: 24px;
  }

  .playground {
    gap: 14px;
    padding: clamp(18px, 3vw, 34px);
  }

  .hint {
    left: max(18px, calc(50% - var(--board-width) / 2 - 154px));
    width: 150px;
    min-height: 92px;
    padding: 8px 9px 6px;
  }

  .hint p {
    font-size: 11px;
  }

  .auto-solve-button {
    top: calc(50% + var(--board-width) * 0.604166 + 14px);
  }
}

@media (max-width: 760px) {
  :root {
    --board-width: min(86vw, 430px);
  }

  .game {
    background-size: auto 100%;
  }

  .intro-card {
    min-height: 221px;
    padding: 40px 18px 24px;
  }
  .intro-icon{
    width: 72px;
    height: 72px;
  }
  .intro-icon-frame {
    width: 44px;
    height: 44px;
  }

  .intro-icon-water {
    width: 30px;
    height: 34px;
  }

  .intro-icon-vent {
    width: 32px;
    height: 32px;
  }


  .intro-card h1 {
    font-size: 16px;
  }

  .primary-button {
    min-width: 174px;
    height: 44px;
    font-size: 14px;
  }

  .hint {
    left: 5vw;
    top: 86px;
    width: 90vw;
    min-height: 48px;
    grid-template-columns: minmax(0, 1fr) auto;
    justify-items: center;
    align-items: center;
    align-content: center;
    gap: 8px;
    padding: 7px 42px 7px 14px;
    border-radius: 9px;
    text-align: left;
    transform: none;
  }

  .hint p {
    font-size: clamp(10px, 3.05vw, 12px);
    line-height: 1.12;
  }

  .hint p br {
    display: none;
  }

  .hint img {
    width: 19px;
    height: 19px;
  }

  .hint-close {
    top: -27px;
    right: 1px;
    width: 24px;
    height: 24px;
  }

  .hint-close::before,
  .hint-close::after {
    width: 16px;
  }
}

@media (min-width: 360px) and (max-width: 394px) and (max-height: 700px) {
  .hint {
    top: 86px;
  }

  .pipe-board {
    transform: translateY(28px);
  }

  .auto-solve-button {
    transform: translate(-50%, 28px);
  }
}

@media (min-width: 395px) and (max-width: 760px) and (max-height: 700px) {
  .hint {
    top: 76px;
  }

  .pipe-board {
    transform: translateY(56px);
  }

  .auto-solve-button {
    transform: translate(-50%, 56px);
  }
}

@media (min-width: 761px) and (max-height: 620px) {
  :root {
    --board-width: min(78vw, 390px);
  }

  .hint {
    transform: scale(0.86);
    transform-origin: left top;
  }
}
