:root {
  --bg-1: #200a3a;
  --bg-2: #ff4bb8;
  --bg-3: #36d6ff;
  --panel: rgba(255, 255, 255, 0.14);
  --panel-strong: rgba(255, 255, 255, 0.22);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.78);
  --dark: #170822;
  --shadow: 0 24px 70px rgba(20, 8, 35, 0.42);
  --board-size: min(82vw, 560px);
  --gap: clamp(14px, 3vw, 32px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Montserrat", Arial, sans-serif;
  color: var(--text);
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% 16%, rgba(255, 232, 85, 0.9) 0 5%, transparent 19%),
    radial-gradient(circle at 85% 12%, rgba(54, 214, 255, 0.75) 0 4%, transparent 18%),
    radial-gradient(circle at 80% 86%, rgba(255, 75, 184, 0.75) 0 5%, transparent 22%),
    linear-gradient(135deg, var(--bg-1), #6426b6 45%, var(--bg-2));
  background-attachment: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(14px, 3vw, 34px);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.07) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, black, transparent 76%);
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 14px 22px;
  min-height: 48px;
  font: inherit;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, #17d6ff, #6657ff 52%, #ff4bb8);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.42);
  transition: transform 0.18s ease, filter 0.18s ease, box-shadow 0.18s ease;
  touch-action: manipulation;
}

button:hover {
  transform: translateY(-2px);
  filter: saturate(1.12) brightness(1.05);
}

button:active {
  transform: translateY(1px) scale(0.98);
}

.game-shell {
  width: min(1180px, 100%);
  display: grid;
  gap: var(--gap);
  position: relative;
  z-index: 1;
}

.hero-card,
.scoreBoard,
.board-wrap,
.mode-card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.24);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.hero-card {
  border-radius: 30px;
  padding: clamp(18px, 3vw, 30px);
  text-align: center;
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 900;
  font-size: 0.78rem;
  color: #ffe86b;
  margin-bottom: 8px;
}

.hero-card h1,
.mode-card h2 {
  font-size: clamp(2.2rem, 7vw, 5.6rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
  text-shadow: 0 10px 32px rgba(0, 0, 0, 0.34);
}

.intro,
.mode-card p {
  max-width: 680px;
  margin: 14px auto 0;
  color: var(--muted);
  font-weight: 600;
  line-height: 1.55;
}

.game-area {
  display: grid;
  grid-template-columns: minmax(230px, 280px) 1fr;
  align-items: center;
  gap: var(--gap);
}

.scoreBoard {
  border-radius: 28px;
  padding: 22px;
  min-height: 260px;
  display: none;
  align-content: center;
  justify-items: stretch;
  gap: 16px;
}

.score-box {
  background: rgba(255, 255, 255, 0.92);
  color: var(--dark);
  border-radius: 24px;
  padding: 18px;
  text-align: center;
  box-shadow: inset 0 1px 0 #fff;
}

.score-box span {
  display: block;
  text-transform: uppercase;
  color: #8957bd;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  font-weight: 900;
}

.score-box strong {
  display: block;
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  line-height: 1;
  color: #ff3cae;
}

.timer {
  display: none;
  border-radius: 18px;
  padding: 12px 14px;
  text-align: center;
  font-weight: 900;
  color: #fff;
  background: rgba(255, 255, 255, 0.18);
}

.timer:not(:empty) {
  display: block;
}

#changeMode {
  background: linear-gradient(135deg, #ff477e, #ff9a3d);
}

.board-wrap {
  border-radius: 34px;
  padding: clamp(10px, 2vw, 18px);
  justify-self: center;
}

.grid {
  width: var(--board-size);
  height: var(--board-size);
  display: none;
  flex-wrap: wrap;
  padding: clamp(6px, 1.5vw, 10px);
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0.08));
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.26), inset 0 18px 40px rgba(255, 255, 255, 0.12);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.grid div {
  width: calc((var(--board-size) - clamp(12px, 3vw, 20px)) / 8);
  height: calc((var(--board-size) - clamp(12px, 3vw, 20px)) / 8);
  border-radius: clamp(9px, 2vw, 18px);
  background-size: 82%;
  background-repeat: no-repeat;
  background-position: center;
  background-color: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 -8px 14px rgba(116, 50, 148, 0.18), 0 8px 16px rgba(33, 10, 46, 0.2);
  transition: transform 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
  cursor: grab;
}

.grid div:hover,
.grid div.is-selected {
  transform: scale(1.07);
  box-shadow: inset 0 -8px 14px rgba(116, 50, 148, 0.18), 0 0 0 4px rgba(255, 232, 107, 0.72), 0 14px 26px rgba(33, 10, 46, 0.28);
  z-index: 2;
}

.grid div:active {
  cursor: grabbing;
  transform: scale(0.94);
}

.mobile-hint {
  display: none;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
  margin-top: 10px;
}

.mode-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(19, 4, 35, 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.mode-card {
  width: min(520px, 100%);
  border-radius: 34px;
  padding: clamp(24px, 5vw, 42px);
  text-align: center;
}

.mode-buttons-container {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

#endlessMode {
  background: linear-gradient(135deg, #18d67b, #17d6ff);
}

#timedMode {
  background: linear-gradient(135deg, #ffcc33, #ff477e);
}

@media (max-width: 860px) {
  body {
    align-items: flex-start;
  }

  .game-area {
    grid-template-columns: 1fr;
  }

  .scoreBoard {
    order: 2;
    width: min(100%, var(--board-size));
    min-height: 0;
    justify-self: center;
    grid-template-columns: 1fr;
  }

  .board-wrap {
    order: 1;
  }

  .mobile-hint {
    display: block;
  }
}

@media (max-width: 520px) {
  :root {
    --board-size: min(94vw, 390px);
  }

  body {
    padding: 10px;
  }

  .hero-card {
    border-radius: 22px;
    padding: 16px 14px;
  }

  .intro {
    font-size: 0.9rem;
  }

  .board-wrap {
    border-radius: 24px;
    padding: 7px;
  }

  .grid {
    border-radius: 20px;
  }

  .grid div {
    background-size: 86%;
  }

  .scoreBoard {
    border-radius: 22px;
    padding: 14px;
  }

  button {
    width: 100%;
    min-height: 52px;
  }
}

@media (hover: none) {
  .grid div:hover {
    transform: none;
  }
}
