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

:root {
  --cyan: #22d3ee;
  --purple: #a855f7;
  --pink: #ec4899;
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.12);
}

html, body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color: #e2e8f0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(168, 85, 247, 0.25), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(34, 211, 238, 0.18), transparent 50%),
    linear-gradient(160deg, #0f0c29 0%, #1a1a40 55%, #160b2e 100%);
  background-attachment: fixed;
  display: flex;
  justify-content: center;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px 32px;
  width: 100%;
  max-width: 1100px;
}

.game-title {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 900;
  letter-spacing: 0.35em;
  margin-bottom: 14px;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(168, 85, 247, 0.55));
  animation: titleGlow 3s ease-in-out infinite alternate;
}

@keyframes titleGlow {
  from { filter: drop-shadow(0 0 8px rgba(34, 211, 238, 0.4)); }
  to { filter: drop-shadow(0 0 20px rgba(236, 72, 153, 0.6)); }
}

.game-layout {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

.panel {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 150px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.68rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #94a3b8;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 12px rgba(34, 211, 238, 0.65);
}

.board-wrap {
  position: relative;
  border-radius: 14px;
  padding: 6px;
  background:
    linear-gradient(rgba(8, 8, 20, 0.9), rgba(8, 8, 20, 0.9)),
    repeating-linear-gradient(0deg, transparent 0 29px, rgba(255, 255, 255, 0.05) 29px 30px),
    repeating-linear-gradient(90deg, transparent 0 29px, rgba(255, 255, 255, 0.05) 29px 30px);
  box-shadow:
    0 0 0 2px rgba(34, 211, 238, 0.5),
    0 0 28px rgba(34, 211, 238, 0.35),
    0 0 60px rgba(168, 85, 247, 0.25),
    0 12px 40px rgba(0, 0, 0, 0.5);
}

#board {
  display: block;
  width: min(92vw, calc((100dvh - 220px) / 2), 300px);
  height: auto;
  aspect-ratio: 1 / 2;
  border-radius: 8px;
}

#next {
  display: block;
  width: 100px;
  height: 100px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--glass-border);
  align-self: center;
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ui-btn {
  appearance: none;
  border: 1px solid rgba(34, 211, 238, 0.5);
  background: rgba(34, 211, 238, 0.08);
  color: #cffafe;
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.ui-btn:hover {
  background: rgba(34, 211, 238, 0.18);
  box-shadow: 0 0 16px rgba(34, 211, 238, 0.45);
}

.ui-btn:active {
  transform: scale(0.95);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 14px;
  background: rgba(8, 8, 20, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 5;
}

.overlay.hidden {
  display: none;
}

.overlay-content h2 {
  font-size: 1.8rem;
  letter-spacing: 0.2em;
  margin-bottom: 10px;
  background: linear-gradient(90deg, var(--cyan), var(--pink));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(236, 72, 153, 0.5));
}

.overlay-content p {
  color: #cbd5e1;
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 0 20px;
}

#touch-controls {
  display: none;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  width: 100%;
  max-width: 420px;
}

.tc-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.tc-btn {
  flex: 1;
  min-height: 64px;
  font-size: 1.6rem;
  font-weight: 800;
  color: #e0f2fe;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35), inset 0 0 12px rgba(34, 211, 238, 0.12);
  transition: transform 0.06s ease, background 0.15s ease;
}

.tc-btn:active {
  transform: scale(0.93);
  background: rgba(34, 211, 238, 0.25);
}

.tc-wide {
  font-size: 1.15rem;
  letter-spacing: 0.06em;
}

@media (pointer: coarse) {
  #touch-controls {
    display: flex;
  }
}

@media (max-width: 720px) {
  .game-layout {
    gap: 12px;
  }

  .panel-left {
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    justify-content: space-around;
    padding: 10px 12px;
    gap: 8px;
    min-width: 0;
  }

  .panel-left .stat {
    align-items: center;
  }

  .panel-left .stat-value {
    font-size: 1.1rem;
  }

  .panel-right {
    flex-direction: row;
    align-items: center;
    width: 100%;
    justify-content: space-between;
    padding: 10px 12px;
    min-width: 0;
  }

  .panel-right .stat {
    align-items: center;
  }

  #next {
    width: 72px;
    height: 72px;
  }

  .btn-row {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  .ui-btn {
    padding: 8px 12px;
    font-size: 0.78rem;
  }

  #board {
    width: min(92vw, calc((100dvh - 320px) / 2), 300px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
