:root {
  --bg: #f3f6ff;
  --bg-accent: #dbe8ff;
  --card: #ffffff;
  --ink: #1f2a44;
  --muted: #54658a;
  --primary: #2b66ff;
  --primary-strong: #1949d6;
  --board-outer: #0f4cd5;
  --board-inner: #145fe8;
  --hole: #0d38ab;
  --red: #ff3f45;
  --yellow: #ffd83d;
  --success: #27ae60;
  --shadow: 0 18px 40px rgba(17, 43, 106, 0.15);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 12%, #ffffff 0%, transparent 32%),
    radial-gradient(circle at 85% 18%, #e7efff 0%, transparent 36%),
    linear-gradient(165deg, var(--bg) 0%, var(--bg-accent) 100%);
  overflow-x: hidden;
}

.page {
  width: 100%;
  padding: 16px;
  display: flex;
  justify-content: center;
}

.game-card {
  width: min(980px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  border: 1px solid rgba(20, 95, 232, 0.12);
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 1.1rem + 1.2vw, 2rem);
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
}

.top-highscore {
  margin-bottom: 14px;
  background: #f8fbff;
  border: 1px solid #dce6ff;
  border-radius: 12px;
  padding: 10px 12px;
}

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

.top-highscore-header h2 {
  margin: 0;
  font-size: 1rem;
  color: var(--ink);
}

#top-highscore-toggle {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.88rem;
}

.top-highscore-list {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.top-highscore-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #e6eeff;
  font-size: 0.92rem;
}

.top-highscore-list li:last-child {
  border-bottom: none;
}

.top-highscore-list .meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.top-highscore-empty {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.93rem;
}

select,
.field input,
.btn {
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid #ccdafd;
  padding: 0 14px;
  font-size: 1rem;
}

select {
  background: #f7faff;
  color: var(--ink);
}

.field input {
  background: #f7faff;
  color: var(--ink);
}

.btn {
  cursor: pointer;
  font-weight: 700;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(160deg, var(--primary) 0%, var(--primary-strong) 100%);
  border: none;
}

.btn-secondary {
  color: var(--ink);
  background: #eef3ff;
}

#reset-scores-btn {
  background: #fff4f4;
  border-color: #ffd4d4;
  color: #8d2323;
}

.btn:focus-visible,
select:focus-visible,
.field input:focus-visible,
.cell:focus-visible {
  outline: 3px solid rgba(43, 102, 255, 0.4);
  outline-offset: 2px;
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat-pill {
  background: #f4f7ff;
  border: 1px solid #d6e2ff;
  border-radius: 12px;
  padding: 8px 12px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat-pill span {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-pill strong {
  font-size: 1rem;
}

.stat-pill.wide {
  grid-column: span 1;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.score {
  border-radius: 12px;
  border: 1px solid #dce6ff;
  padding: 10px;
  background: #f8faff;
  text-align: center;
}

.score h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
}

.score p {
  margin: 6px 0 0;
  font-size: 1.45rem;
  font-weight: 800;
}

.score.red p {
  color: #d62027;
}

.score.yellow p {
  color: #c49600;
}

.score.draw p {
  color: var(--primary-strong);
}

.board-shell {
  background: linear-gradient(180deg, #f7faff 0%, #edf3ff 100%);
  border: 1px solid #d5e2ff;
  border-radius: 16px;
  padding: 12px;
}

.series-info {
  margin-top: 10px;
  min-height: 24px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 600;
}

.board {
  position: relative;
  background: linear-gradient(160deg, var(--board-inner) 0%, var(--board-outer) 100%);
  border-radius: 14px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(7, minmax(40px, 1fr));
  gap: 8px;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 20%, #2f73ff 0%, var(--hole) 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.disc {
  width: 86%;
  height: 86%;
  border-radius: 50%;
  box-shadow:
    inset -7px -8px 12px rgba(0, 0, 0, 0.18),
    inset 7px 7px 10px rgba(255, 255, 255, 0.34);
  transform: scale(0.96);
}

.disc.disc-drop {
  animation: discDrop 320ms cubic-bezier(0.2, 0.85, 0.25, 1);
}

.disc.red {
  background: radial-gradient(circle at 30% 24%, #ff8a8f 0%, var(--red) 64%, #cb0b11 100%);
}

.disc.yellow {
  background: radial-gradient(circle at 30% 24%, #fff4a8 0%, var(--yellow) 64%, #c89400 100%);
}

.cell.winning .disc {
  animation: winPulse 0.9s ease-in-out infinite;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.92),
    0 0 0 8px rgba(39, 174, 96, 0.5),
    inset -7px -8px 12px rgba(0, 0, 0, 0.16),
    inset 7px 7px 10px rgba(255, 255, 255, 0.3);
}

.floating-disc {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 30, 67, 0.54);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 1200;
}

.modal-card {
  width: min(520px, 100%);
  border-radius: 16px;
  background: #ffffff;
  border: 1px solid #d6e4ff;
  box-shadow: 0 26px 52px rgba(12, 30, 74, 0.28);
  padding: 16px;
}

.modal-card h2 {
  margin: 0;
}

.modal-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.modal-score-save {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-score-save input {
  flex: 1 1 180px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid #cfdcff;
  padding: 0 10px;
  background: #f7faff;
  color: var(--ink);
}

.modal-highscore {
  margin-top: 10px;
  border: 1px solid #dce6ff;
  border-radius: 10px;
  background: #f8fbff;
  padding: 10px;
  max-height: 240px;
  overflow: auto;
}

.modal-highscore h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--ink);
}

.modal-highscore-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.modal-highscore-list li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #e7eeff;
  font-size: 0.92rem;
}

.modal-highscore-list li:last-child {
  border-bottom: none;
}

.modal-highscore .meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.modal-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

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

@keyframes winPulse {
  0% {
    transform: scale(0.96);
  }
  50% {
    transform: scale(1);
  }
  100% {
    transform: scale(0.96);
  }
}

@keyframes discDrop {
  0% {
    transform: translateY(calc(-1 * var(--drop-distance, 0px))) scale(0.96);
  }
  70% {
    transform: translateY(6px) scale(0.96);
  }
  100% {
    transform: translateY(0) scale(0.96);
  }
}

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

  #sound-toggle,
  #reset-scores-btn {
    grid-column: 1 / -1;
  }

  .status-bar,
  .scoreboard {
    grid-template-columns: 1fr 1fr;
  }

  .stat-pill.wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .page {
    padding: 10px;
  }

  .game-card {
    padding: 12px;
  }

  .settings,
  .status-bar,
  .scoreboard {
    grid-template-columns: 1fr;
  }

  .game-header {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-primary {
    width: 100%;
  }

  .board {
    grid-template-columns: repeat(7, minmax(34px, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }
}
