:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --text: #e8eef5;
  --muted: #8b9bb4;
  --pipe: #c5d4e8;
  --pipe-shadow: rgba(0, 0, 0, 0.35);
  --accent: #3ddc97;
  --blocked: #2a3545;
  --win: #ffd166;
  --focus: #6eb5ff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% 0%, #1b2636, var(--bg));
  color: var(--text);
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 12px 16px;
  background: var(--panel);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.topbar__back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: color 0.15s;
}

.topbar__back:hover {
  color: var(--accent);
}

.topbar__back:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
}

.stats {
  display: flex;
  gap: 20px;
  margin-left: auto;
  font-size: 0.95rem;
  color: var(--muted);
}

.stats strong {
  color: var(--text);
  font-weight: 700;
}

.btn {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 14px 0 12px;
}

.hint .formula {
  display: block;
  margin-top: 6px;
  font-size: 0.82rem;
  opacity: 0.9;
}

.board {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--panel);
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  width: min(92vw, 560px);
  margin: 0 auto;
  touch-action: manipulation;
}

.board.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.board.is-winning .cell {
  animation: winPulse 0.55s ease;
}

@keyframes winPulse {
  0%,
  100% {
    filter: none;
  }
  50% {
    filter: brightness(1.25);
  }
}

@media (prefers-reduced-motion: reduce) {
  .board.is-winning .cell,
  .status--win {
    animation: none;
  }

  .cell__svg {
    transition: none;
  }

  .cell:not(.cell--blocked):active {
    transform: none;
  }
}

.cell {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #222c3a;
  border: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.12s;
}

.cell:not(.cell--blocked):active {
  transform: scale(0.97);
}

.cell:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  z-index: 1;
}

.cell--blocked {
  cursor: default;
  background: var(--blocked);
}

.cell--blocked:active {
  transform: none;
}

.cell__svg {
  position: absolute;
  inset: 8%;
  width: 84%;
  height: 84%;
  transform-origin: 50% 50%;
  transition: transform 0.18s ease;
}

.cell--start .cell__svg .pipe-stroke {
  stroke: var(--accent);
}

.cell--end .cell__svg .pipe-stroke {
  stroke: var(--win);
}

.cell--blocked .cell__svg {
  opacity: 0.35;
}

.cell--filled:not(.cell--blocked) {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--liquid) 55%, transparent);
  background: color-mix(in srgb, var(--liquid) 12%, #222c3a);
}

.cell--filled.cell--start:not(.cell--blocked),
.cell--filled.cell--end:not(.cell--blocked) {
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--liquid) 70%, transparent);
}

.status {
  text-align: center;
  min-height: 1.4em;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.status--win {
  color: var(--win);
  font-weight: 600;
  animation: statusPop 0.45s ease;
}

@keyframes statusPop {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
