* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --green: #367849;
  --green-dark: #285b37;
  --text: #26372b;
  --muted: #788b78;
  --border: #dce8d7;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px 16px;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse at 15% 10%, #ffffff 0, transparent 40%),
    linear-gradient(135deg, #edf5e7, #e1eedc);
}

.game-card {
  width: min(920px, 100%);
  padding: clamp(18px, 4vw, 34px);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(220, 232, 215, 0.95);
  border-radius: 26px;
  box-shadow:
    0 25px 70px rgba(52, 83, 43, 0.10),
    0 3px 10px rgba(52, 83, 43, 0.04);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 3px;
}

h1 {
  margin: 0;
  font-size: clamp(27px, 5vw, 40px);
  font-weight: 850;
  letter-spacing: -1.5px;
}

.scores {
  display: flex;
  gap: 10px;
}

.scores div {
  min-width: 82px;
  padding: 10px 15px;
  color: #71806d;
  text-align: center;
  font-size: 12px;
  font-weight: 650;
  background: #f0f6ec;
  border: 1px solid #e4eddd;
  border-radius: 14px;
}

.scores strong {
  display: block;
  margin-top: 2px;
  color: var(--green-dark);
  font-size: 25px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.game-area {
  position: relative;
  margin-top: 26px;
  overflow: hidden;
  border: 1px solid #dce8d4;
  border-radius: 18px;
  background: #edf6e7;
  box-shadow: inset 0 2px 8px rgba(49, 88, 41, 0.04);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
  touch-action: manipulation;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
  background: rgba(244, 250, 238, 0.76);
  backdrop-filter: blur(3px);
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin: 0 0 10px;
  font-size: clamp(23px, 4vw, 32px);
  font-weight: 850;
  letter-spacing: -0.7px;
}

.overlay p {
  max-width: 420px;
  margin: 0 0 19px;
  color: #657762;
  line-height: 1.5;
}

button {
  padding: 13px 25px;
  color: white;
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  background: linear-gradient(135deg, #4c9556, #347344);
  border: 1px solid #347344;
  border-radius: 12px;
  box-shadow: 0 5px 12px rgba(50, 111, 61, 0.20);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

button:hover {
  filter: brightness(1.06);
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(50, 111, 61, 0.24);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 3px 8px rgba(50, 111, 61, 0.17);
}

button:focus-visible {
  outline: 3px solid #a6cf8f;
  outline-offset: 4px;
}

.instructions {
  margin: 15px 0 0;
  color: #81917c;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 1.5px;
  text-align: center;
}

.leaderboard {
  margin-top: 29px;
  padding-top: 22px;
  border-top: 1px solid #e8eee3;
}

.leaderboard h2 {
  margin: 0 0 13px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

#results {
  display: grid;
  gap: 0;
  margin: 0;
  padding-left: 28px;
}

#results li {
  padding: 10px 8px 10px 3px;
  color: #536650;
  font-size: 13px;
  border-bottom: 1px solid #edf1e9;
}

#results li::marker {
  color: #5a8a4f;
  font-weight: 800;
}

.status {
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

@media (max-width: 560px) {
  body {
    padding: 12px 8px;
  }

  .game-card {
    padding: 16px 12px;
    border-radius: 19px;
  }

  header {
    align-items: flex-start;
    flex-direction: column;
  }

  .scores {
    width: 100%;
  }

  .scores div {
    flex: 1;
  }

  .game-area {
    margin-top: 18px;
    border-radius: 12px;
  }

  .overlay {
    padding: 10px;
  }

  .overlay p {
    margin-bottom: 12px;
    font-size: 12px;
  }

  button {
    padding: 10px 18px;
    font-size: 14px;
  }

  .instructions {
    font-size: 10px;
    letter-spacing: 0.7px;
  }
}

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


/* Уведомление о новом рекорде */
.record-toast {
  position: relative;
  z-index: 5;
  width: fit-content;
  max-width: calc(100% - 24px);
  margin: 14px auto -4px;
  padding: 12px 22px;
  color: #fff;
  text-align: center;
  font-weight: 850;
  background: linear-gradient(135deg, #267a43, #4da85c);
  border: 1px solid #8bd99a;
  border-radius: 14px;
  box-shadow: 0 8px 25px rgba(37, 120, 62, .25);
  opacity: 0;
  transform: translateY(-12px) scale(.96);
  pointer-events: none;
}

.record-toast.show {
  animation: recordToastIn 350ms ease-out both,
             recordToastOut 450ms ease-in 3.2s forwards;
}

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

@keyframes recordToastOut {
  to { opacity: 0; transform: translateY(-10px) scale(.98); }
}

.game-tools {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

button.secondary-button {
  padding: 8px 13px;
  color: var(--green-dark);
  font-size: 12px;
  background: #f0f6ec;
  border: 1px solid #dce8d4;
  box-shadow: none;
}

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

.stat-box {
  padding: 13px 8px;
  color: #71806d;
  text-align: center;
  font-size: 12px;
  background: #f0f6ec;
  border: 1px solid #e4eddd;
  border-radius: 12px;
}

.stat-box strong {
  display: block;
  margin-top: 6px;
  color: var(--green-dark);
  font-size: 23px;
  font-variant-numeric: tabular-nums;
}

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