:root {
  --bg-color: #e8fbe3;
  --text-color: #333;
  --grid-border-color: #333;
  --tile-border-color: #ddd;
  --win-color: #b7efb8;
  --win-text: #044b06;
  --button-bg-color: #4caf50;
  --button-hover-bg-color: #45a049;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-color: #1a1a1a;
    --text-color: #f0f0f0;
    --grid-border-color: #888;
    --tile-border-color: #555;
    --button-bg-color: #45a049;
    --button-hover-bg-color: #4caf50;
  }
}

body {
  font-family: Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  min-height: 100vh;
}

.controls {
  margin-bottom: 20px;
  text-align: center;
  align-items: center;
  display: flex;
  flex-direction: column;
  row-gap: 8px;
  max-width: 340px;
  width: 100%;
  box-sizing: border-box;
}

.controls-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  box-sizing: border-box;
  width: 100%;
}

h1,
.controls p {
  text-align: center !important;
  width: 100%;
  margin: 0;
}

.button {
  display: inline-block;
  background-color: var(--button-bg-color);
  color: white;
  padding: 10px 0;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
  margin: 7px 0;
  width: 100%;
  min-width: 120px;
  max-width: 320px;
  box-sizing: border-box;
  align-self: center;
}

.button:disabled {
  background-color: #ffd6cc !important; /* нежно-коралловый */
  color: #fff !important;
  cursor: not-allowed;
  opacity: 1;
}

#puzzleGrid {
  position: relative;
}

.empty-tile {
  background: repeating-linear-gradient(
    135deg,
    #e8fbe3 0 10px,
    #d0eac7 10px 20px
  );
  opacity: 0.7;
  cursor: default;
  z-index: -1;
}

.label {
  margin-right: 10px;
}

select {
  padding: 8px;
  border-radius: 5px;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin-right: 15px;
}

.button {
  display: inline-block;
  background-color: var(--button-bg-color);
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  transition: background-color 0.3s;
  margin: 5px;
}

.button:hover {
  background-color: var(--button-hover-bg-color);
}

input[type="file"] {
  display: none;
}

.tile {
  position: absolute;
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    top 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  box-sizing: border-box;
}

.tile canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none;
}

#gameContainer {
  flex: 3;
  justify-content: center;
}

#winMessage {
  font-size: 1.2em;
  padding: 14px 0;
  max-width: 340px;
  border-radius: 16px;
  font-weight: bold;
align-self: center;
  line-height: 1.4;
  color: var(--win-text);
  background: linear-gradient(
    120deg,
    var(--win-color) 0%,
    #fff 20%,
    var(--win-color) 40%,
    #fff 60%,
    var(--win-color) 80%,
    #fff 100%
  );
  background-size: 200% 200%;
  animation: win-gradient-wave 2.5s linear infinite;
  box-shadow: 0 2px 16px 0 rgba(76, 175, 80, 0.1);
  letter-spacing: 0.5px;
  z-index: 2;
}

@keyframes win-gradient-wave {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

@media (max-width: 600px) and (orientation: portrait) {
  html,
  body {
    font-size: 16px;
    padding: 0;
    overflow: hidden;
  }
  body {
    justify-content: flex-start;
    padding: 0 2vw;
  }
  h1 {
    font-size: 1.5em;
    margin-top: 18px;
    margin-bottom: 10px;
  }
  .label,
  select,
  .button {
    font-size: 1em;
  }
}

@media (orientation: landscape) {
  body {
    flex-direction: row;
    padding: 0;
  }
  .controls {
    align-items: flex-end;
    min-width: 180px;
    max-width: 40vw;
    margin-right: 2vw;
    margin-bottom: 0;
    gap: 14px;
    padding: 18px 10px 18px 10px;
  }
  .controls-row {
    gap: 10px;
    padding: 0;
  }
  .button {
    margin: 7px 0;
  }
}

@media (min-width: 1024px) {
  body {
    flex-direction: row;
  }
  .controls {
    flex: 1;
    min-width: 220px;
  }
  #gameContainer {
    flex: 2;
  }
}
