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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  background-size: 400% 400%;
  animation: gradientShift 15s ease infinite;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  padding: 10px;
  overflow-x: hidden;
  position: relative;
}

/* Анімація градієнта фону */
@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Додаємо декоративні елементи */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at 20% 50%,
    rgba(102, 126, 234, 0.1) 0%,
    transparent 50%
  ),
    radial-gradient(
      circle at 80% 80%,
      rgba(118, 75, 162, 0.1) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: 0;
}

.game-container {
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset,
    0 1px 0 rgba(255, 255, 255, 0.2) inset;
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  gap: 30px;
  align-items: flex-start;
  max-width: 100%;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* Десктоп: відцентрувати по горизонталі */
@media (min-width: 769px) {
  body {
    justify-content: center;
  }

  .game-container {
    max-width: fit-content;
    margin: 0 auto;
  }
}

.game-main {
  display: flex;
  flex-direction: column;
  align-items: center;
}

h1 {
  background: linear-gradient(135deg, #ffffff 0%, #e0e0e0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  margin-bottom: 20px;
  font-size: 2.8em;
  font-weight: 800;
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.5);
  letter-spacing: 2px;
  position: relative;
  animation: titleGlow 3s ease-in-out infinite;
}

@keyframes titleGlow {
  0%,
  100% {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(255, 255, 255, 0.6));
  }
}

#game-canvas {
  display: block;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: #0a0a1a;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset,
    0 0 40px rgba(102, 126, 234, 0.2);
  max-width: 100%;
  height: auto;
  transition: all 0.3s ease;
}

#game-canvas:hover {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.15) inset,
    0 0 60px rgba(102, 126, 234, 0.3);
}

.controls {
  margin-top: 20px;
  color: white;
  text-align: center;
  font-size: 0.9em;
  opacity: 0.9;
}

.controls p {
  margin: 5px 0;
}

.key {
  background: rgba(255, 255, 255, 0.2);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: bold;
  display: inline-block;
  margin: 0 2px;
}

.game-controls {
  margin-top: 20px;
  display: flex;
  gap: 15px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

#restart-button {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 50%, #dc3545 100%);
  color: white;
  border: none;
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 1em;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(238, 90, 111, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#restart-button::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  transition: left 0.5s;
}

#restart-button:hover::before {
  left: 100%;
}

#restart-button:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 30px rgba(238, 90, 111, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

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

.speed-control {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
}

.speed-control label {
  font-weight: bold;
  font-size: 0.9em;
}

#speed-select {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.25) 0%,
    rgba(255, 255, 255, 0.15) 100%
  );
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(15px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transition: all 0.3s ease;
}

#speed-select:hover {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.3) 0%,
    rgba(255, 255, 255, 0.2) 100%
  );
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

#speed-select option {
  background: #1a1a2e;
  color: white;
}

#speed-select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.5);
}

.game-info {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 200px;
}

.info-section {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.12) 0%,
    rgba(255, 255, 255, 0.08) 100%
  );
  backdrop-filter: blur(15px);
  border-radius: 16px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  transition: all 0.3s ease;
}

.info-section:hover {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.15) 0%,
    rgba(255, 255, 255, 0.1) 100%
  );
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  transform: translateY(-2px);
}

.info-section h3 {
  color: white;
  font-size: 0.9em;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
}

.info-value {
  background: linear-gradient(135deg, #ffffff 0%, #e0e7ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 2.2em;
  font-weight: 800;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  letter-spacing: 1px;
}

#next-piece-canvas {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  display: block;
  margin: 0 auto;
}

.high-score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 0.9em;
}

.high-score-item:last-child {
  border-bottom: none;
}

.high-score-item .rank {
  font-weight: bold;
  opacity: 0.7;
  min-width: 30px;
}

.high-score-item .name {
  flex: 1;
  margin: 0 10px;
  text-align: left;
}

.high-score-item .score {
  font-weight: bold;
  background: linear-gradient(135deg, #f0f000 0%, #ffd700 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 10px rgba(240, 240, 0, 0.3);
}

#high-scores-list {
  max-height: 200px;
  overflow-y: auto;
}

/* Модалка для введення імені рекордсмена */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 24px;
  padding: 35px;
  max-width: 420px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
    0 0 0 1px rgba(255, 255, 255, 0.2) inset,
    0 0 40px rgba(102, 126, 234, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.25);
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.modal-content::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.1) 0%,
    transparent 70%
  );
  animation: rotate 20s linear infinite;
  pointer-events: none;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content h2 {
  background: linear-gradient(135deg, #ffffff 0%, #f0f0f0 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0 0 15px 0;
  font-size: 2em;
  font-weight: 800;
  text-align: center;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
  letter-spacing: 1px;
  position: relative;
  z-index: 1;
}

.modal-score {
  background: linear-gradient(135deg, #f0f000 0%, #ffd700 50%, #ffed4e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-size: 1.8em;
  font-weight: 800;
  text-align: center;
  margin: 0 0 25px 0;
  text-shadow: 0 0 30px rgba(240, 240, 0, 0.6);
  letter-spacing: 1px;
  position: relative;
  z-index: 1;
  animation: scorePulse 2s ease-in-out infinite;
}

@keyframes scorePulse {
  0%,
  100% {
    filter: drop-shadow(0 0 10px rgba(240, 240, 0, 0.4));
  }
  50% {
    filter: drop-shadow(0 0 20px rgba(240, 240, 0, 0.8));
  }
}

.modal-label {
  color: white;
  font-size: 1.05em;
  font-weight: 600;
  margin: 0 0 12px 0;
  opacity: 0.95;
  letter-spacing: 0.5px;
  position: relative;
  z-index: 1;
}

.modal-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.25) 0%,
    rgba(255, 255, 255, 0.15) 100%
  );
  color: white;
  font-size: 1em;
  font-weight: 500;
  margin-bottom: 25px;
  box-sizing: border-box;
  backdrop-filter: blur(15px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
  position: relative;
  z-index: 1;
}

.modal-input::placeholder {
  color: rgba(255, 255, 255, 0.6);
}

.modal-input:focus {
  outline: none;
  border-color: rgba(255, 255, 255, 0.6);
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.3) 0%,
    rgba(255, 255, 255, 0.2) 100%
  );
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3),
    0 0 0 2px rgba(255, 255, 255, 0.2) inset,
    0 0 20px rgba(102, 126, 234, 0.4);
  transform: translateY(-2px);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 1em;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 120px;
}

.modal-btn-primary {
  background: linear-gradient(135deg, #00f000 0%, #00c000 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 240, 0, 0.4);
}

.modal-btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 240, 0, 0.6);
}

.modal-btn-primary:active {
  transform: translateY(0);
}

.modal-btn-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.modal-btn-secondary:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Мобільна адаптація для модалки */
@media (max-width: 768px) {
  .modal-content {
    padding: 20px;
    max-width: 90%;
  }

  .modal-content h2 {
    font-size: 1.5em;
  }

  .modal-score {
    font-size: 1.3em;
  }

  .modal-buttons {
    flex-direction: column;
  }

  .modal-btn {
    width: 100%;
  }
}

/* Мобільні кнопки керування */
.mobile-controls {
  display: none;
  margin-top: 15px;
  width: 100%;
}

.mobile-controls-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 0 auto;
}

.mobile-btn {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.25) 0%,
    rgba(255, 255, 255, 0.15) 100%
  );
  backdrop-filter: blur(15px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 14px;
  color: white;
  font-size: 1.5em;
  font-weight: bold;
  padding: 12px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 55px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2),
    0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}

.mobile-btn:active {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.35) 0%,
    rgba(255, 255, 255, 0.25) 100%
  );
  transform: scale(0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3),
    0 0 0 1px rgba(255, 255, 255, 0.15) inset;
}

.mobile-btn.rotate {
  grid-column: 2;
  grid-row: 1;
}

.mobile-btn.left {
  grid-column: 1;
  grid-row: 2;
}

.mobile-btn.down {
  grid-column: 2;
  grid-row: 2;
}

.mobile-btn.right {
  grid-column: 3;
  grid-row: 2;
}

.mobile-btn.pause {
  grid-column: 1 / 4;
  grid-row: 3;
  font-size: 0.9em;
  padding: 10px;
  min-height: 45px;
}

@media (max-width: 480px) {
  .mobile-controls-grid {
    max-width: 100%;
    gap: 6px;
  }

  .mobile-btn {
    padding: 10px;
    min-height: 50px;
    font-size: 1.3em;
  }

  .mobile-btn.pause {
    font-size: 0.85em;
    padding: 8px;
    min-height: 40px;
  }
}

/* Планшети та менші екрани */
@media (max-width: 1024px) {
  .game-container {
    gap: 20px;
    padding: 20px;
  }

  .game-info {
    min-width: 180px;
  }

  .info-value {
    font-size: 1.5em;
  }
}

/* Мобільні пристрої */
@media (max-width: 768px) {
  body {
    padding: 5px;
    align-items: flex-start;
  }

  .game-container {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border-radius: 15px;
  }

  .game-main {
    flex: 1;
    min-width: 0;
  }

  .game-info {
    flex: 0 0 auto;
    min-width: 140px;
    max-width: 180px;
  }

  h1 {
    font-size: 1.8em;
    margin-bottom: 10px;
  }

  #game-canvas {
    width: 100%;
    max-width: 100%;
    border-width: 2px;
    margin: 0 auto;
  }

  .controls {
    display: none; /* Приховуємо інструкції на мобільних */
  }

  .game-controls {
    margin-top: 10px;
    gap: 10px;
    flex-direction: column;
    width: 100%;
  }

  #restart-button {
    width: 100%;
    padding: 10px 20px;
    font-size: 0.9em;
  }

  .speed-control {
    width: 100%;
    justify-content: space-between;
  }

  .game-info {
    flex: 0 0 auto;
    min-width: 90px;
    max-width: 110px;
    gap: 5px;
  }

  .info-section {
    padding: 6px;
  }

  .info-section h3 {
    font-size: 0.65em;
    margin-bottom: 3px;
  }

  .info-value {
    font-size: 1.1em;
  }

  /* Приховуємо надпис "Наступна фігура" на мобільних */
  .info-section:nth-child(3) h3 {
    display: none;
  }

  #next-piece-canvas {
    width: 55px;
    height: 55px;
  }

  .mobile-controls {
    display: block;
    width: 100%;
    flex-basis: 100%;
    order: 2; /* Кнопки керування внизу */
  }

  #high-scores-list {
    max-height: 120px;
    font-size: 0.8em;
  }

  .high-score-item {
    padding: 5px 0;
  }
}

/* Маленькі мобільні пристрої */
@media (max-width: 480px) {
  body {
    padding: 0;
  }

  .game-container {
    border-radius: 0;
    padding: 8px;
    min-height: 100vh;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .game-main {
    flex: 1;
    min-width: 0;
  }

  .game-info {
    flex: 0 0 auto;
    min-width: 85px;
    max-width: 100px;
    gap: 4px;
  }

  .info-section {
    padding: 5px;
  }

  .info-section h3 {
    font-size: 0.6em;
    margin-bottom: 2px;
  }

  .info-value {
    font-size: 1em;
  }

  /* Приховуємо надпис "Наступна фігура" на мобільних */
  .info-section:nth-child(3) h3 {
    display: none;
  }

  #next-piece-canvas {
    width: 50px;
    height: 50px;
  }

  h1 {
    font-size: 1.5em;
    margin-bottom: 8px;
  }

  .controls {
    display: none; /* Приховуємо інструкції на маленьких мобільних */
  }

  #high-scores-list {
    max-height: 100px;
  }
}

/* Ландшафтна орієнтація на мобільних */
@media (max-width: 768px) and (orientation: landscape) {
  .game-container {
    flex-direction: row;
    gap: 10px;
    padding: 10px;
  }

  .game-main {
    flex: 1;
    order: 0;
  }

  .game-info {
    min-width: 150px;
    order: 1;
  }

  .mobile-controls {
    display: none; /* Приховуємо кнопки в ландшафтній орієнтації */
  }

  #game-canvas {
    max-width: 100%;
  }

  h1 {
    font-size: 1.2em;
    margin-bottom: 5px;
  }

  .controls {
    display: none; /* Приховуємо інструкції в ландшафтній орієнтації */
  }

  .info-value {
    font-size: 1.2em;
  }

  #next-piece-canvas {
    width: 60px;
    height: 60px;
  }
}
