.c4-page-wrap {
  max-width: 1180px;
  margin: auto;
  padding: 28px 24px 70px;
}

.c4-app {
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
  margin: 25px 0 24px;
}

.c4-rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
  margin-top: 24px;
}
@media (max-width: 720px) {
  .c4-page-wrap { padding: 16px 16px 50px; }
  .c4-rules-grid { grid-template-columns: 1fr; }
}

.c4-config-panel,
.c4-stage-card {
  background: #fff;
  border: 1px solid #d5e2dc;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 12px 28px rgba(17, 45, 42, .05);
}

.c4-config-panel {
  display: grid;
  gap: 16px;
}

.c4-fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.c4-legend {
  font-weight: 900;
  font-size: .92rem;
  color: #163b35;
  margin-bottom: 2px;
}

.c4-segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.c4-segmented.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.c4-seg-btn {
  appearance: none;
  border: 1.5px solid #cbdcd5;
  background: #f6faf8;
  color: #1c3d38;
  font: inherit;
  font-size: .9rem;
  font-weight: 800;
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
  text-align: center;
}

.c4-seg-btn:hover {
  border-color: #176b5c;
  background: #eef6f2;
}

.c4-seg-btn[aria-pressed="true"] {
  background: #176b5c;
  border-color: #176b5c;
  color: #fff;
  box-shadow: 0 6px 14px rgba(23, 107, 92, .2);
}

.c4-rows-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.c4-row-shortcuts {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.c4-mini-btn {
  appearance: none;
  border: 1px solid #cbdcd5;
  background: #fff;
  color: #204d45;
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.c4-mini-btn:hover {
  border-color: #176b5c;
  background: #eef7f3;
}

.c4-rows-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.c4-row-chip {
  appearance: none;
  border: 1.5px solid #cbdcd5;
  background: #f8fbf9;
  color: #234740;
  font: inherit;
  font-weight: 900;
  font-size: .92rem;
  padding: 8px 0;
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
}

.c4-row-chip[aria-pressed="true"] {
  background: #e3f4ee;
  border-color: #176b5c;
  color: #0f5346;
}

.c4-weak-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  background: #fffaf0;
  border: 1px solid #edd8a1;
  font-size: .88rem;
  color: #493a16;
  cursor: pointer;
}

.c4-weak-toggle input {
  margin-top: 3px;
  accent-color: #176b5c;
  width: 17px;
  height: 17px;
}

.c4-weak-toggle strong {
  display: block;
  color: #2b2108;
  font-weight: 800;
}

.c4-new-game-btn {
  width: 100%;
  justify-content: center;
}

.c4-stage-card {
  display: grid;
  gap: 16px;
}

.c4-scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
}

.c4-player-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid #dfe9e4;
  background: #f8fbf9;
  transition: border-color .2s ease, background .2s ease, transform .2s ease;
}

.c4-player-card.active.player-x {
  border-color: #d95d39;
  background: #fff4ef;
  transform: translateY(-1px);
}

.c4-player-card.active.player-o {
  border-color: #176b5c;
  background: #eaf7f3;
  transform: translateY(-1px);
}

.c4-player-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.c4-disc-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 900;
  font-size: 1.05rem;
  flex-shrink: 0;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18), 0 3px 8px rgba(0, 0, 0, .12);
}

.player-x .c4-disc-badge {
  background: radial-gradient(circle at 32% 30%, #ff8c6b, #d95d39 68%, #b34120);
  color: #fff;
  border: 2px solid #f7b29d;
}

.player-o .c4-disc-badge {
  background: radial-gradient(circle at 32% 30%, #37b89f, #176b5c 70%, #0f4c41);
  color: #fff;
  border: 2px solid #96dfd0;
}

.c4-player-name {
  font-weight: 900;
  color: #163b35;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.c4-player-sub {
  font-size: .78rem;
  color: #55706a;
  font-weight: 700;
}

.c4-score-num {
  font-size: 1.45rem;
  font-weight: 900;
  color: #163b35;
}

.c4-vs-pill {
  font-size: .8rem;
  font-weight: 900;
  color: #58726c;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef5f2;
}

.c4-status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 14px;
  background: #f2f8f5;
  border: 1px solid #cfe0da;
  font-weight: 800;
  color: #173d36;
  flex-wrap: wrap;
}

.c4-status-banner.win-x {
  background: #fff2ec;
  border-color: #f0b5a2;
  color: #9e3516;
}

.c4-status-banner.win-o {
  background: #e6f6f1;
  border-color: #9fd5c8;
  color: #0f5346;
}

.c4-status-banner.draw {
  background: #fff8e5;
  border-color: #e6cd86;
  color: #5c4610;
}

/* Connect 4 Rack & Grid */
.c4-rack {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  gap: 8px;
}

.c4-col-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  padding: 0 12px;
}

.c4-col-btn {
  appearance: none;
  border: 1.5px solid #c8ddd5;
  background: #f4faf7;
  color: #175246;
  font: inherit;
  font-size: .82rem;
  font-weight: 900;
  padding: 7px 4px;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform .14s ease, background .14s ease, border-color .14s ease, box-shadow .14s ease;
}

.c4-col-btn:hover:not(:disabled),
.c4-col-btn.col-hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: #d95d39;
  background: #fff3ee;
  color: #b5401e;
  box-shadow: 0 5px 12px rgba(217, 93, 57, .16);
}

.c4-rack.turn-o .c4-col-btn:hover:not(:disabled),
.c4-rack.turn-o .c4-col-btn.col-hover:not(:disabled) {
  border-color: #176b5c;
  background: #eaf7f3;
  color: #0f5346;
  box-shadow: 0 5px 12px rgba(23, 107, 92, .16);
}

.c4-col-btn:disabled {
  opacity: .42;
  cursor: not-allowed;
}

.c4-board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 9px;
  padding: 14px;
  border-radius: 22px;
  background: linear-gradient(180deg, #1d5349 0%, #143d35 100%);
  border: 3px solid #0f312b;
  box-shadow: inset 0 4px 12px rgba(0, 0, 0, .28), 0 14px 28px rgba(15, 49, 43, .18);
}

.c4-cell {
  position: relative;
  aspect-ratio: 1.08 / 1;
  min-height: 76px;
  border-radius: 50%;
  border: 3px solid #0e2e28;
  background: radial-gradient(circle at 50% 38%, #ffffff 0%, #edf5f2 78%, #d7e6e0 100%);
  color: #173d36;
  font: inherit;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: inset 0 4px 8px rgba(12, 38, 33, .22);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease, background .15s ease;
  user-select: none;
  overflow: hidden;
}

.c4-cell.special-extra:not(.owner-x):not(.owner-o) {
  background: radial-gradient(circle at 50% 38%, #fffef9 0%, #fff3c4 84%, #f4da82 100%);
  border-color: #d89b1c;
}

.c4-cell.special-magnet:not(.owner-x):not(.owner-o) {
  background: radial-gradient(circle at 50% 38%, #fbfaff 0%, #ebe6ff 84%, #d3c8fa 100%);
  border-color: #6b4ec7;
}

.c4-cell.special-gap:not(.owner-x):not(.owner-o) {
  background: radial-gradient(circle at 50% 38%, #f7fffc 0%, #def7ec 84%, #b9ebd6 100%);
  border-color: #1f8a65;
}

.c4-cell-special-tag {
  font-size: .58rem;
  font-weight: 900;
  padding: 1px 5px;
  border-radius: 999px;
  line-height: 1.15;
  white-space: nowrap;
}

.special-extra .c4-cell-special-tag {
  background: #fce18d;
  color: #6e4700;
}

.special-magnet .c4-cell-special-tag {
  background: #e1d8ff;
  color: #462b9e;
}

.special-gap .c4-cell-special-tag {
  background: #c5f0de;
  color: #0e593f;
}

.c4-cell.special-gap .c4-cell-task {
  font-size: clamp(.72rem, 1.15vw, .88rem);
}

.c4-cell.magnet-flipped {
  animation: c4MagnetFlip .55s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes c4MagnetFlip {
  0% { transform: rotateY(0deg) scale(1); }
  50% { transform: rotateY(90deg) scale(1.14); box-shadow: 0 0 0 4px #9a82f7; }
  100% { transform: rotateY(0deg) scale(1); }
}

.c4-legend-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.c4-legend-pill {
  font-size: .78rem;
  font-weight: 800;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid #d5e2dc;
  background: #f8fbf9;
  color: #21453e;
}

.c4-modal-special {
  margin: 0;
  text-align: center;
  font-size: .84rem;
  font-weight: 800;
  padding: 7px 10px;
  border-radius: 10px;
  background: #fff6db;
  border: 1px solid #ecd084;
  color: #6b4604;
}

.c4-modal-turn.steal-mode {
  background: #ffe5dc;
  color: #a83311;
}

.c4-cell.is-landing:not(.owner-x):not(.owner-o) {
  border-color: #f0b44c;
  background: radial-gradient(circle at 50% 38%, #fffdf7 0%, #fff6df 82%, #f5e5ba 100%);
  box-shadow: inset 0 3px 6px rgba(180, 125, 20, .18), 0 0 0 2px rgba(240, 180, 76, .45);
}

.c4-cell.col-highlight:not(.owner-x):not(.owner-o) {
  border-color: #ff9c7d;
}

.c4-cell.is-landing.col-highlight:not(.owner-x):not(.owner-o) {
  transform: scale(1.04);
  border-color: #ff7e57;
  box-shadow: 0 0 0 3px rgba(255, 126, 87, .55);
}

.c4-rack.turn-o .c4-cell.is-landing.col-highlight:not(.owner-x):not(.owner-o) {
  border-color: #36c2a7;
  box-shadow: 0 0 0 3px rgba(54, 194, 167, .55);
}

.c4-cell:focus-visible {
  outline: 3px solid #f0b44c;
  outline-offset: 2px;
}

.c4-cell.owner-x {
  background: radial-gradient(circle at 32% 28%, #ff9373 0%, #d95d39 68%, #ab3b1a 100%);
  border-color: #ffd0c2;
  color: #fff;
  cursor: default;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .22), 0 4px 10px rgba(0, 0, 0, .25);
  animation: c4DropDisc .38s cubic-bezier(.22, 1.28, .46, 1);
}

.c4-cell.owner-o {
  background: radial-gradient(circle at 32% 28%, #3ec7ac 0%, #176b5c 70%, #0d453b 100%);
  border-color: #b4f0e3;
  border-style: solid;
  color: #fff;
  cursor: default;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .22), 0 4px 10px rgba(0, 0, 0, .25);
  animation: c4DropDisc .38s cubic-bezier(.22, 1.28, .46, 1);
}

@keyframes c4DropDisc {
  0% {
    transform: translateY(-140%) scale(.88);
    opacity: .4;
  }
  70% {
    transform: translateY(6%) scale(1.03);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.c4-cell.winning-cell {
  box-shadow: 0 0 0 4px #ffd257, 0 8px 18px rgba(255, 210, 87, .45);
  animation: c4WinPulse .9s ease-in-out infinite alternate;
}

@keyframes c4WinPulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

.c4-cell-landing-tag {
  font-size: .62rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #9e6509;
  background: rgba(244, 188, 77, .28);
  padding: 1px 6px;
  border-radius: 999px;
  line-height: 1.2;
}

.c4-cell-mark {
  font-size: 1.05rem;
  font-weight: 900;
  line-height: 1;
}

.c4-cell-task {
  font-size: clamp(.86rem, 1.5vw, 1.08rem);
  font-weight: 900;
  color: #163b35;
  text-align: center;
  line-height: 1.15;
}

.c4-cell:not(.is-landing):not(.owner-x):not(.owner-o) .c4-cell-task {
  color: #496b63;
  font-size: clamp(.8rem, 1.35vw, .96rem);
}

.c4-cell.owner-x .c4-cell-task,
.c4-cell.owner-o .c4-cell-task {
  color: rgba(255, 255, 255, .95);
  font-size: .76rem;
  font-weight: 800;
}

.c4-board-hint {
  text-align: center;
  font-size: .86rem;
  color: #4c6761;
  margin: 0;
}

/* Modal dialog for solving a cell */
.c4-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(14, 34, 30, .48);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 900;
  backdrop-filter: blur(2px);
}

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

.c4-modal {
  background: #fff;
  border-radius: 22px;
  border: 2px solid #cfe0da;
  padding: 22px;
  width: min(100%, 390px);
  box-shadow: 0 22px 48px rgba(13, 38, 34, .22);
  display: grid;
  gap: 14px;
}

.c4-modal-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.c4-modal-turn {
  font-size: .85rem;
  font-weight: 900;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef6f2;
  color: #175246;
}

.c4-modal-close {
  appearance: none;
  border: 1px solid #cbdcd5;
  background: #fff;
  color: #35524c;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 1.1rem;
  font-weight: 900;
  cursor: pointer;
}

.c4-modal-equation {
  text-align: center;
  font-size: 2rem;
  font-weight: 900;
  color: #143731;
  background: #f5faf8;
  border: 1.5px solid #d5e5df;
  border-radius: 16px;
  padding: 16px 12px;
}

.c4-answer-input {
  width: 100%;
  box-sizing: border-box;
  text-align: center;
  font: inherit;
  font-size: 1.55rem;
  font-weight: 900;
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid #bdd2ca;
  color: #143731;
  background: #fff;
}

.c4-answer-input:focus {
  outline: none;
  border-color: #176b5c;
  box-shadow: 0 0 0 3px rgba(23, 107, 92, .16);
}

.c4-numpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.c4-pad-btn {
  appearance: none;
  border: 1.5px solid #cfe0da;
  background: #f7fbf9;
  color: #173d36;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 900;
  padding: 11px 0;
  border-radius: 12px;
  cursor: pointer;
}

.c4-pad-btn:hover {
  background: #eaf5f0;
  border-color: #176b5c;
}

.c4-pad-btn.submit {
  background: #176b5c;
  border-color: #176b5c;
  color: #fff;
}

.c4-pad-btn.submit:hover {
  background: #125649;
}

.c4-feedback {
  min-height: 1.3em;
  text-align: center;
  font-weight: 800;
  font-size: .9rem;
  color: #b5381a;
  margin: 0;
}

@media (max-width: 860px) {
  .c4-app {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .c4-col-buttons {
    gap: 5px;
    padding: 0 6px;
  }
  .c4-col-btn {
    font-size: .72rem;
    padding: 5px 2px;
  }
  .c4-board {
    gap: 6px;
    padding: 9px;
    border-radius: 16px;
  }
  .c4-cell {
    min-height: 54px;
    padding: 3px;
  }
  .c4-cell-landing-tag {
    display: none;
  }
}
