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

:root {
  --board-size: min(90vw, 512px);
  --gap-size: 4px;
}

@media (max-width: 768px) {
  :root {
    --gap-size: 2px;
  }
}

@media (max-width: 480px) {
  :root {
    --gap-size: 1px;
  }
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0a0a0d;
  background-image: radial-gradient(circle at center, #1a1a2e 0%, #0a0a0d 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
  line-height: 1.5;
  color: #e0e0ff;
  overflow-x: hidden;
}

.game-container {
  text-align: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 
    0 8px 32px rgba(0, 0, 0, 0.7),
    inset 0 0 15px rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: var(--board-size);
  position: relative;
  overflow: hidden;
}

.game-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 20%),
    radial-gradient(circle at 90% 80%, rgba(100, 100, 255, 0.1) 0%, transparent 30%);
  z-index: 0;
  pointer-events: none;
}

.game-container > * {
  position: relative;
  z-index: 1;
}

h1 {
  font-size: 28px;
  margin-bottom: 12px;
  background: linear-gradient(45deg, #6a11cb 0%, #2575fc 100%);
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(106, 17, 203, 0.2);
  letter-spacing: -0.5px;
  font-weight: bold;
  padding: 0 8px;
}

.score {
  font-size: 24px;
  margin-bottom: 16px;
  color: #fff;
  font-weight: bold;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  background: rgba(30, 30, 60, 0.7);
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: var(--gap-size);
  background: #0f0f1a;
  padding: var(--gap-size);
  border-radius: 12px;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  box-shadow: 
    inset 0 0 20px rgba(0, 0, 0, 0.8),
    0 0 15px rgba(100, 100, 255, 0.2);
}

.game-board::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    radial-gradient(circle at 30% 30%, rgba(100, 100, 255, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 70% 70%, rgba(255, 100, 255, 0.1) 0%, transparent 50%);
  z-index: 0;
  pointer-events: none;
}

.ball {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.3s ease;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
  box-shadow: 
    0 3px 8px rgba(0, 0, 0, 0.4),
    inset 0 -2px 5px rgba(255, 255, 255, 0.2);
}

.ball[data-color="1"] { 
  background: linear-gradient(135deg, #ff4d4d, #cc0000); 
  border: 1px solid #b30000;
}
.ball[data-color="2"] { 
  background: linear-gradient(135deg, #4da6ff, #0078d7); 
  border: 1px solid #005a9e;
}
.ball[data-color="3"] { 
  background: linear-gradient(135deg, #4dff4d, #00cc00); 
  border: 1px solid #009900;
}
.ball[data-color="4"] { 
  background: linear-gradient(135deg, #ffe066, #ffb300); 
  border: 1px solid #e69500;
}
.ball[data-color="5"] { 
  background: linear-gradient(135deg, #d966ff, #9933cc); 
  border: 1px solid #7a29a3;
}
.ball[data-color="6"] { 
  background: linear-gradient(135deg, #4dffff, #00cccc); 
  border: 1px solid #009999;
}

.ball.selected {
  transform: scale(1.15);
  box-shadow: 
    0 0 20px rgba(255, 255, 255, 0.9),
    inset 0 0 15px rgba(255, 255, 255, 0.5);
  z-index: 10;
}

.ball.removing {
  opacity: 0;
  transform: scale(0.8);
}

@media (max-width: 768px) {
  .game-container {
    max-width: 95vw;
    padding: 12px;
  }

  .score {
    font-size: 20px;
    margin-bottom: 12px;
  }

  .game-board {
    padding: calc(var(--gap-size) * 0.5);
    border-radius: 10px;
  }
  
  h1 {
    font-size: 24px;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size: 95vw;
  }

  .score {
    font-size: 18px;
    margin-bottom: 10px;
    padding: 4px 12px;
  }
  
  .game-rules {
    font-size: 13px;
    padding: 10px 12px;
  }
  
  .game-rules h2 {
    font-size: 16px;
    margin-bottom: 8px;
  }
  
  .game-rules li {
    margin-bottom: 5px;
  }
  
  h1 {
    font-size: 20px;
  }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 10, 20, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal {
  background: rgba(30, 30, 60, 0.9);
  padding: 20px;
  border-radius: 16px;
  box-shadow: 
    0 10px 30px rgba(0, 0, 0, 0.7),
    0 0 20px rgba(100, 100, 255, 0.3);
  text-align: center;
  position: relative;
  max-width: 90vw;
  width: 400px;
  margin: 16px;
  border: 1px solid rgba(150, 150, 255, 0.3);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.modal p {
  margin: 0 0 20px;
  font-size: 18px;
  color: #fff;
  line-height: 1.4;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 20px;
  cursor: pointer;
  color: #fff;
  padding: 4px 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.modal-close:hover {
  color: #ff6b6b;
  background: rgba(255, 107, 107, 0.2);
  transform: scale(1.1);
}

.game-rules {
  margin-top: 20px;
  padding: 15px;
  background: rgba(20, 20, 40, 0.6);
  border: 1px solid rgba(100, 100, 255, 0.3);
  border-radius: 12px;
  font-size: 14px;
  color: #d0d0ff;
  text-align: left;
  max-width: 100%;
}

.game-rules h2 {
  font-size: 18px;
  margin-bottom: 10px;
  color: #a0a0ff;
}

.game-rules ul {
  list-style-position: inside;
  padding-left: 10px;
  margin-top: 8px;
}

.game-rules li {
  margin-bottom: 8px;
  position: relative;
  padding-left: 16px;
}

.game-rules li::before {
  content: "•";
  color: #6a5af9;
  position: absolute;
  left: 0;
  font-size: 1.2em;
  line-height: 0.8;
}