:root {
  color-scheme: dark;
  --bg-0: #05070c;
  --bg-1: #0d121c;
  --panel: rgba(255, 255, 255, 0.05);
  --panel-strong: rgba(255, 255, 255, 0.09);
  --border: rgba(255, 255, 255, 0.14);
  --text: #eef1f8;
  --text-dim: #8b93a7;
  --gold: #ffcc4d;
  --gold-strong: #ffb020;
  --danger: #ff5566;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 90% at 50% -10%, #182236 0%, var(--bg-1) 45%, var(--bg-0) 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 460px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 18px 16px 22px;
  position: relative;
  overflow: hidden;
}

.app::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 118px,
    rgba(255, 255, 255, 0.045) 118px,
    rgba(255, 255, 255, 0.045) 121px
  );
  opacity: 0.6;
  z-index: 0;
}

.app > * {
  position: relative;
  z-index: 1;
}

/* Topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: var(--panel-strong);
}

.icon-btn:active {
  transform: scale(0.92);
}

.coin-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(255, 204, 77, 0.35);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.coin-pill__icon {
  color: var(--gold);
  font-size: 13px;
  filter: drop-shadow(0 0 4px rgba(255, 204, 77, 0.6));
}

/* Level info */

.level-name {
  text-align: center;
  margin: 18px 0 2px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.level-hint {
  text-align: center;
  margin: 0;
  min-height: 18px;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  padding: 0 10px;
}

/* Board */

.board-host {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 0;
}

.board {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 20px 16px;
  max-width: 420px;
}

.tube {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  width: 58px;
  transition: transform 0.18s ease;
}

.tube:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
  border-radius: 16px;
}

.tube--selected {
  transform: translateY(-16px);
}

.tube__glass {
  position: relative;
  height: 128px;
  border-radius: 14px 14px 26px 26px;
  border: 2px solid var(--border);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45), 0 6px 14px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.tube--selected .tube__glass {
  border-color: var(--gold);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.45), 0 0 0 3px rgba(255, 204, 77, 0.28), 0 8px 18px rgba(0, 0, 0, 0.4);
}

.tube--complete .tube__glass {
  border-color: rgba(255, 204, 77, 0.55);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 14px rgba(255, 204, 77, 0.35);
}

.tube--invalid .tube__glass {
  animation: shake 0.32s ease;
  border-color: var(--danger);
}

.tube__liquids {
  position: absolute;
  inset: 3px;
  display: flex;
  flex-direction: column-reverse;
  border-radius: 12px 12px 24px 24px;
  overflow: hidden;
}

.tube__segment {
  flex: 1 1 0;
  transform-origin: bottom center;
  transition: background 0.15s ease;
}

.tube__segment--empty {
  background: transparent;
}

.tube__segment--animating-in {
  animation: fillIn 220ms ease-out;
}

.tube__segment--animating-out {
  animation: fillOut 190ms ease-in;
}

.tube__shine {
  position: absolute;
  top: 4px;
  left: 8px;
  width: 8px;
  height: calc(100% - 24px);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.tube--tilt-right .tube__glass {
  animation: tiltRight 420ms ease;
}

.tube--tilt-left .tube__glass {
  animation: tiltLeft 420ms ease;
}

@keyframes fillIn {
  from {
    transform: scaleY(0);
    opacity: 0;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes fillOut {
  from {
    transform: scaleY(1);
    opacity: 1;
  }
  to {
    transform: scaleY(0);
    opacity: 0;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes tiltRight {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  32% {
    transform: translateY(-20px) rotate(24deg);
  }
  68% {
    transform: translateY(-20px) rotate(24deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

@keyframes tiltLeft {
  0% {
    transform: translateY(0) rotate(0deg);
  }
  32% {
    transform: translateY(-20px) rotate(-24deg);
  }
  68% {
    transform: translateY(-20px) rotate(-24deg);
  }
  100% {
    transform: translateY(0) rotate(0deg);
  }
}

/* Toast */

.toast {
  align-self: center;
  margin: 0 0 6px;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 85, 102, 0.16);
  border: 1px solid rgba(255, 85, 102, 0.4);
  color: #ffd0d5;
  font-size: 13px;
  text-align: center;
}

/* Powerups */

.powerups {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding-top: 6px;
}

.powerup {
  display: flex;
  flex-direction: column;
  align-items: center;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text);
  padding: 0;
}

.powerup__icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(160deg, #1b2740, #0f1626);
  border: 1px solid var(--border);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.powerup:hover .powerup__icon {
  border-color: rgba(255, 204, 77, 0.4);
}

.powerup:active .powerup__icon {
  transform: scale(0.92);
}

.powerup:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.powerup:disabled .powerup__icon {
  transform: none;
}

.powerup__cost {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: -10px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #0b1220;
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
}

/* Overlays */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 5, 10, 0.72);
  backdrop-filter: blur(3px);
  padding: 24px;
}

.overlay[hidden] {
  display: none;
}

.overlay__card {
  width: 100%;
  max-width: 340px;
  background: linear-gradient(165deg, #182236, #0c1220);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  text-align: center;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.5);
  animation: popIn 0.22s ease;
}

@keyframes popIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.overlay__title {
  font-size: 21px;
  font-weight: 800;
  margin: 0 0 8px;
}

.overlay__subtitle {
  color: var(--text-dim);
  margin: 0 0 22px;
  font-size: 14px;
}

.overlay__actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.button {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  padding: 12px 18px;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
}

.button--primary {
  background: linear-gradient(160deg, var(--gold), var(--gold-strong));
  color: #241a04;
  border: none;
}

.button:active {
  transform: scale(0.98);
}
