:root {
  --navy-deep: #0a1624;
  --navy-mid: #1e4468;
  --copper: #c47a3a;
  --copper-lt: #e0a05a;
  --copper-btn: #8b4e20;
  --teal: #2f7a78;
  --teal-lt: #9ad8d6;
  --cream: #f4efe6;
  --font: "Figtree", "Segoe UI", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body.game-body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--cream);
  background: radial-gradient(ellipse 120% 80% at 50% -10%, rgba(30, 68, 104, 0.45), transparent 55%), var(--navy-deep);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

a {
  color: var(--copper-lt);
}

a:hover {
  color: var(--cream);
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

.game-skip {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: 100;
  background: var(--copper-btn);
  color: #fff;
  padding: 0.5rem 0.85rem;
  text-decoration: none;
  border-radius: 8px;
}

.game-skip:focus {
  top: 0.75rem;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
}

.game-logo img {
  width: min(180px, 44vw);
}

.game-call {
  flex-shrink: 0;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  border: 1px solid rgba(244, 239, 230, 0.28);
  color: var(--cream);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
}

.game-main {
  flex: 1;
  width: min(100%, 32rem);
  margin: 0 auto;
  padding: 0 1rem 1.5rem;
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

.game-intro {
  text-align: center;
  margin-bottom: 0.75rem;
}

.game-intro h1 {
  font-family: var(--display);
  font-size: clamp(1.65rem, 5vw, 2.2rem);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 0.35rem;
  color: var(--cream);
}

.game-lede {
  margin: 0;
  color: rgba(244, 239, 230, 0.78);
  font-size: 0.95rem;
}

.game-status {
  text-align: center;
  min-height: 1.5rem;
  margin-bottom: 0.65rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--copper-lt);
}

.game-status.is-win {
  color: var(--teal-lt);
}

.game-board-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.game-board {
  --cell: min(calc(92vw / var(--cols, 4)), calc(22rem / var(--cols, 4)), 4.25rem);
  display: grid;
  gap: 4px;
  width: calc(var(--cell) * var(--cols, 4) + 4px * (var(--cols, 4) - 1) + 12px);
  height: calc(var(--cell) * var(--rows, 4) + 4px * (var(--rows, 4) - 1) + 12px);
  padding: 6px;
  border-radius: 18px;
  background: rgba(7, 14, 22, 0.72);
  border: 1px solid rgba(244, 239, 230, 0.08);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
}

.pipe-cell {
  appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  width: var(--cell);
  height: var(--cell);
  aspect-ratio: 1;
  border-radius: 10px;
  background: rgba(22, 50, 79, 0.55);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.12s ease;
  position: relative;
  overflow: hidden;
}

.pipe-cell:not(.is-fixed):active {
  transform: scale(0.94);
  background: rgba(30, 68, 104, 0.75);
}

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

.pipe-svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pipe-svg .pipe-body {
  fill: var(--copper);
  transition: fill 0.35s ease;
}

.pipe-svg .pipe-shine {
  fill: var(--copper-lt);
  opacity: 0.55;
  transition: fill 0.35s ease, opacity 0.35s ease;
}

.pipe-svg .pipe-water {
  fill: var(--teal);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.pipe-cell.is-water .pipe-water {
  opacity: 0.9;
}

.pipe-svg .pipe-coupling-dark {
  fill: var(--copper-btn);
}

.pipe-svg .pipe-coupling {
  fill: var(--copper);
}

.pipe-svg .pipe-nut {
  fill: #0f2438;
}

.pipe-svg .pipe-nut-pin {
  fill: var(--copper-lt);
}

.pipe-svg .pipe-drop {
  fill: var(--teal);
}

.pipe-cell.is-water .pipe-drop {
  fill: var(--teal-lt);
}

.pipe-svg .pipe-drain-ring {
  fill: none;
  stroke: rgba(244, 239, 230, 0.55);
  stroke-width: 2.5;
}

.pipe-svg .pipe-drain-hole {
  fill: rgba(10, 22, 36, 0.85);
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  justify-content: center;
  margin-bottom: 1rem;
}

.game-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.game-btn-primary {
  appearance: none;
  border: 0;
  background: linear-gradient(180deg, var(--copper-lt), var(--copper-btn));
  color: #fff;
}

.game-btn-primary:active {
  transform: scale(0.98);
}

.game-btn-ghost {
  border: 1px solid rgba(244, 239, 230, 0.28);
  color: var(--cream);
  background: transparent;
}

.game-note {
  text-align: center;
  margin: 0;
  font-size: 0.88rem;
  color: rgba(244, 239, 230, 0.65);
  line-height: 1.55;
}

.game-footer {
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.78rem;
  color: rgba(244, 239, 230, 0.55);
  border-top: 1px solid rgba(244, 239, 230, 0.08);
}

.game-footer p {
  margin: 0;
}

@media (min-width: 720px) {
  .game-board {
    --cell: min(calc(24rem / var(--cols, 4)), 4.75rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pipe-cell,
  .pipe-svg .pipe-body,
  .pipe-svg .pipe-shine,
  .pipe-svg .pipe-water,
  .pipe-svg .pipe-drop {
    transition: none;
  }
}
