* {
  box-sizing: border-box;
}

:root {
  --purple: #4c2a9a;
  --purple-dark: #351c73;
  --cream: #fff8e9;
  --cream-2: #f7ead3;
  --border: #caa978;
  --text: #20203a;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(135deg, #fafcff, #eef2ff);
}

.game {
  width: min(1180px, 96%);
  margin: 0 auto;
  padding: 11px 0 14px;
}

header {
  text-align: center;
  margin-bottom: 8px;
}

h1 {
  margin: 0;
  color: var(--purple-dark);
  font-size: clamp(22px, 3.2vw, 38px);
}

header p {
  margin: 3px 0 0;
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 251px;
  gap: 20px;
  align-items: start;
}

.board-area {
  width: 85%;
  max-width: 524px;
  margin: auto;
}

.column-labels {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin-left: 42px;
  margin-bottom: 4px;
  font-weight: 700;
  text-align: center;
  font-size: 13px;
}

.board-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
}

.row-labels {
  display: grid;
  grid-template-rows: repeat(8, 1fr);
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  background: var(--cream);
  min-height: 0;
}

.cell {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid #ddc7a4;
  border-bottom: 1px solid #ddc7a4;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: clamp(17px, 2.8vw, 31px);
  user-select: none;
  transition: background-color 350ms ease;
}

.cell.light-square {
  background: #fff8e9;
}

.cell.dark-square {
  background: hsl(36 48% var(--darkness));
}

.cell.start {
  outline: 3px solid #70a94a;
  outline-offset: -3px;
}

.player {
  font-size: clamp(26px, 4.25vw, 46px);
  line-height: 1;
  position: relative;
  z-index: 2;
}

.player::after {
  content: "🙂";
}

.chocolate {
  font-size: clamp(25px, 4.25vw, 43px);
  line-height: 1;
  position: relative;
  z-index: 2;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.score-card,
.objective {
  border: 2px solid #d7c9ee;
  border-radius: 16px;
  padding: 11px;
  background: #fff;
  text-align: center;
}

.score-card {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 11px;
  border-color: #efc45b;
  background: #fffaf0;
}

.trophy {
  font-size: 38px;
}

.score-card span {
  display: block;
  font-size: 13px;
}

.score-card strong {
  display: block;
  font-size: 32px;
  color: #b52323;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 11px;
  border: 2px solid #d7c9ee;
  border-radius: 16px;
  background: #f7f5ff;
}

.direction {
  min-height: 71px;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(#6950c9, #4c2a9a);
  color: white;
  font-weight: 800;
  font-size: 31px;
  cursor: pointer;
  box-shadow: 0 4px 0 #351c73;
  touch-action: manipulation;
}

.direction span {
  display: block;
  font-size: 13px;
  letter-spacing: 1px;
}

.direction:hover {
  filter: brightness(1.08);
}

.direction:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #351c73;
}

.up,
.down {
  grid-column: 1 / -1;
  width: 104px;
  justify-self: center;
}

.objective {
  border-color: #7ba7ec;
  background: #f0f6ff;
  font-size: 13px;
}

.objective strong {
  font-size: 17px;
  color: #2456a6;
}

.objective p {
  margin-bottom: 8px;
}

.objective .hint {
  font-size: 11px;
  color: #4b5570;
  line-height: 1.45;
}

.new-game {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: #26733c;
  color: white;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}

.new-game:hover {
  filter: brightness(1.08);
}

.message {
  text-align: center;
  margin: 11px auto 0;
  padding: 9px;
  border: 2px solid #a9d18e;
  border-radius: 10px;
  background: #eff9e8;
  font-size: 14px;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(24, 17, 50, 0.55);
  z-index: 20;
  overflow: hidden;
}

.hidden {
  display: none;
}

.win-card {
  width: min(373px, 88%);
  padding: 22px;
  text-align: center;
  background: white;
  border-radius: 22px;
  box-shadow: 0 15px 50px rgba(0,0,0,.25);
  z-index: 22;
}

.win-card h2 {
  margin: 0 0 8px;
  color: #16833a;
  font-size: clamp(21px, 4vw, 31px);
}

.big-chocolate {
  font-size: 61px;
}

.win-card p {
  font-size: 17px;
  margin: 8px;
}

.win-card .optimal {
  font-size: 13px;
  color: #666;
}

.confetti-piece {
  position: absolute;
  top: -30px;
  width: 8px;
  height: 16px;
  animation: fall 2.8s linear forwards;
}

@keyframes fall {
  from {
    transform: translateY(-30px) rotate(0deg);
    opacity: 1;
  }
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: 0;
  }
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .controls {
    max-width: 500px;
    width: 100%;
    margin: auto;
  }

  .board-area {
    width: 85%;
    max-width: 427px;
  }
}

@media (max-width: 430px) {
  .game {
    width: 98%;
    padding-top: 8px;
  }

  header p {
    font-size: 13px;
  }

  .board-area {
    width: 85%;
  }

  .board-row {
    grid-template-columns: 23px minmax(0, 1fr);
  }

  .column-labels {
    margin-left: 23px;
    font-size: 13px;
  }

  .row-labels {
    font-size: 13px;
  }

  .direction {
    min-height: 61px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell {
    transition: none;
  }

  .confetti-piece {
    animation-duration: 0.01ms;
  }
}


.series-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  border: 2px solid #d7c9ee;
  border-radius: 12px;
  padding: 9px;
  background: #fff;
  text-align: center;
}

.series-card span {
  display: block;
  font-size: 11px;
}

.series-card strong {
  display: block;
  color: #4c2a9a;
  font-size: 20px;
  margin-top: 2px;
}

.score-card small {
  display: block;
  font-size: 10px;
  color: #666;
}

.results-card {
  border: 2px solid #d7c9ee;
  border-radius: 12px;
  padding: 9px;
  background: #fff;
}

.results-card > strong {
  display: block;
  text-align: center;
  color: #2456a6;
  font-size: 13px;
  margin-bottom: 6px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.result-item {
  border-radius: 6px;
  padding: 4px 2px;
  text-align: center;
  background: #f3f1f9;
  font-size: 10px;
}

.result-item strong {
  display: block;
  font-size: 13px;
}

.result-item.completed {
  background: #e8f5df;
}

.series-summary {
  color: #4c2a9a;
  font-weight: 700;
}

@media (max-width: 800px) {
  .results-grid {
    grid-template-columns: repeat(10, 1fr);
  }
}
