:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1c2029;
  --panel-2: #272c37;
  --text: #f4f0e8;
  --muted: #a9b0bd;
  --line: rgba(255, 255, 255, 0.16);
  --accent: #61d6b3;
  --danger: #ff6b75;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 14% 12%, rgba(97, 214, 179, 0.18), transparent 28rem),
    radial-gradient(circle at 84% 8%, rgba(255, 193, 105, 0.14), transparent 26rem),
    linear-gradient(145deg, #111318 0%, #171b22 48%, #101217 100%);
  color: var(--text);
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4f0e8;
  color: #151820;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 0 18px;
  transition: transform 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app {
  width: min(1120px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
  padding: 28px 0;
}

.topbar,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.75rem);
  line-height: 0.92;
}

h2 {
  font-size: 2rem;
}

.stats {
  display: flex;
  gap: 10px;
}

.stats div {
  min-width: 92px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 32, 41, 0.78);
  box-shadow: var(--shadow);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.stats strong {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 420px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(28, 32, 41, 0.72);
  box-shadow: var(--shadow);
}

.board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
  justify-items: center;
  align-items: end;
  gap: clamp(18px, 3vw, 34px);
}

.tube-button {
  width: 78px;
  height: 244px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: end center;
  position: relative;
}

.tube-button:hover {
  transform: translateY(-3px);
}

.tube-button.selected {
  transform: translateY(-14px);
}

.tube-button.invalid {
  animation: shake 260ms ease;
}

.tube {
  width: 64px;
  height: 216px;
  display: flex;
  flex-direction: column-reverse;
  overflow: hidden;
  border: 4px solid rgba(255, 255, 255, 0.72);
  border-top: 0;
  border-radius: 0 0 28px 28px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.24), transparent 22%, transparent 72%, rgba(255, 255, 255, 0.14)),
    rgba(255, 255, 255, 0.08);
  box-shadow:
    inset 0 -12px 24px rgba(255, 255, 255, 0.11),
    0 16px 28px rgba(0, 0, 0, 0.28);
}

.tube::before {
  content: "";
  position: absolute;
  width: 78px;
  height: 18px;
  top: 14px;
  left: 0;
  border: 4px solid rgba(255, 255, 255, 0.72);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
  pointer-events: none;
}

.liquid {
  height: 25%;
  width: 100%;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  box-shadow: inset 16px 0 22px rgba(255, 255, 255, 0.16);
  transition: height 180ms ease, transform 180ms ease;
}

.liquid:first-child {
  border-radius: 0 0 21px 21px;
}

.liquid:last-child {
  border-radius: 14px 14px 0 0;
}

.sparkle {
  position: absolute;
  inset: 24px 4px auto auto;
  color: #ffdd7a;
  opacity: 0;
  transform: scale(0.8);
}

.tube-button.complete .sparkle {
  animation: pop 520ms ease forwards;
}

.controls {
  justify-content: center;
  flex-wrap: wrap;
}

.controls button:first-child {
  width: 48px;
  padding: 0;
  font-size: 1.55rem;
}

#nextButton,
#continueButton {
  background: var(--accent);
}

#exitButton {
  background: transparent;
  color: var(--text);
}

.ended {
  max-width: 340px;
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.45;
  text-align: center;
}

.dialog {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  background: transparent;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.dialog-body {
  width: min(360px, calc(100vw - 36px));
  padding: 24px;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dialog-body p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

.dialog-body button {
  width: 100%;
  margin-top: 12px;
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

@keyframes pop {
  55% {
    opacity: 1;
    transform: scale(1.2) rotate(12deg);
  }
  100% {
    opacity: 0;
    transform: scale(1.8) rotate(24deg);
  }
}

@media (max-width: 640px) {
  .app {
    width: min(100vw - 20px, 520px);
    padding: 14px 0;
    gap: 14px;
  }

  .topbar {
    align-items: flex-start;
  }

  .stats {
    flex-direction: column;
  }

  .stats div {
    min-width: 74px;
    padding: 9px 10px;
  }

  .board-wrap {
    min-height: 470px;
    padding: 18px 10px;
  }

  .board {
    grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
    gap: 16px 10px;
  }

  .tube-button {
    width: 60px;
    height: 204px;
  }

  .tube {
    width: 50px;
    height: 178px;
    border-width: 3px;
    border-radius: 0 0 23px 23px;
  }

  .tube::before {
    width: 60px;
    height: 15px;
    top: 17px;
    border-width: 3px;
  }
}
