:root {
  --c4-red: #ff6b55;
  --c4-yellow: #f4cf4f;
  --c4-blue: #5b91e5;
  --c4-blue-dark: #4779c7;
}

.c4-page {
  width: min(780px, calc(100% - 3rem));
  margin: 0 auto;
  padding: 3rem 0 clamp(6rem, 12vw, 9rem);
}

.c4-confetti {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  pointer-events: none;
}

.c4-confetti-piece {
  position: absolute;
  top: -1.5rem;
  left: var(--confetti-x);
  width: 0.55rem;
  height: 0.95rem;
  border-radius: 0.12rem;
  background: var(--confetti-color);
  opacity: 0;
  animation: c4-confetti-fall var(--confetti-duration) var(--confetti-delay) ease-in forwards;
}

@keyframes c4-confetti-fall {
  0% {
    opacity: 0;
    transform: translate3d(0, -5vh, 0) rotate(0deg);
  }

  10%,
  85% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--confetti-drift), 110vh, 0) rotate(var(--confetti-rotation));
  }
}

.c4-header {
  padding: clamp(4rem, 10vw, 6.5rem) 0 2.75rem;
  text-align: center;
}

.c4-header h1 {
  margin: 0;
  font-size: clamp(3.2rem, 10vw, 6rem);
  font-weight: 900;
  letter-spacing: -0.075em;
  line-height: 0.94;
}

.c4-header > p:last-child {
  max-width: 540px;
  margin: 1.35rem auto 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.65;
}

.c4-game {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 2rem;
  background: #fff;
  box-shadow: 0 14px 40px rgba(23, 23, 23, 0.08);
}

.c4-status {
  margin: 0 0 1.25rem;
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
}

.c4-board {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: clamp(0.22rem, 0.8vw, 0.55rem);
  padding: clamp(0.55rem, 1.8vw, 1rem);
  border: 2px solid var(--c4-blue-dark);
  border-radius: clamp(1rem, 2.5vw, 1.5rem);
  background: var(--c4-blue);
  box-shadow: inset 0 -5px 0 rgba(23, 23, 23, 0.12);
}

.c4-column {
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: clamp(0.22rem, 0.8vw, 0.55rem);
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.c4-column:hover:not(:disabled) .c4-cell.is-empty,
.c4-column:focus-visible .c4-cell.is-empty {
  background: #e8f0fc;
  transform: scale(0.94);
}

.c4-column:focus-visible,
.c4-rematch-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 5px;
}

.c4-column:disabled {
  cursor: default;
}

.c4-cell {
  display: block;
  aspect-ratio: 1;
  border: 2px solid rgba(23, 23, 23, 0.14);
  border-radius: 50%;
  background: #f7f7f5;
  box-shadow: inset 0 3px 0 rgba(23, 23, 23, 0.1);
  transition: background-color 120ms ease, transform 120ms ease;
}

.c4-cell.is-red {
  background: var(--c4-red);
}

.c4-cell.is-yellow {
  background: var(--c4-yellow);
}

.c4-cell.is-new {
  animation: c4-disc-drop 320ms cubic-bezier(0.22, 0.8, 0.3, 1.2);
}

.c4-cell.is-win {
  border-color: #171717;
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px #171717;
  animation: c4-winning-disc 700ms ease-in-out infinite alternate;
}

@keyframes c4-disc-drop {
  from {
    opacity: 0.5;
    transform: translateY(-320%) scale(0.86);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes c4-winning-disc {
  to {
    transform: scale(0.88);
  }
}

.c4-rematch {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid #e2bd3e;
  border-radius: 1rem;
  background: #fff7d8;
  animation: c4-rematch-pop 180ms ease-out;
}

.c4-rematch[hidden] {
  display: none;
}

.c4-rematch-button {
  width: 100%;
  min-height: 3.4rem;
  border: 0;
  border-radius: 0.85rem;
  background: #171717;
  color: #fff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.c4-rematch-button:hover {
  background: #343434;
}

@keyframes c4-rematch-pop {
  from {
    opacity: 0;
    transform: translateY(0.5rem) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 560px) {
  .c4-page {
    width: calc(100% - 1rem);
    padding-top: 2rem;
  }

  .c4-header {
    padding: 3.5rem 0 2.25rem;
  }

  .c4-game {
    padding: 0.65rem;
    border-radius: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .c4-confetti-piece {
    display: none;
  }

  .c4-cell,
  .c4-rematch {
    animation: none;
    transition: none;
  }
}
