
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #121212;
  color: #cbd5f7;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px;
  box-sizing: border-box;
  min-height: 100vh;
  overflow-x: hidden;
}

#container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 100vw;
  flex-grow: 1;
}

#puzzle {
  display: grid;
  gap: 1px;
  background: #222;
  border: 6px solid green;
  border-radius: 10px;
  max-width: 100vw;
  max-height: 70vh;
  user-select: none;
  overflow: hidden;
  transition: border-color 0.3s ease;
}

.piece {
  cursor: pointer;
  user-select: none;
  border-radius: 3px;
  border: 0px solid rgba(255, 255, 255, 0.1);
  box-sizing: border-box;
  will-change: transform;
  position: relative;
  transition: transform 0.3s ease;
}

.piece-image-inner {
    width: 100%;
    height: 100%;
    background-size: cover;
    transition: transform 0.3s ease;
    will-change: transform;
}

#puzzle:not(.hints-on) .piece:hover {
  border-color: rgba(100, 150, 255, 0.8);
}

.hint-correct {
  border: 1px solid rgba(76, 175, 80, 0.8);
  box-sizing: border-box;
}

.hint-wrong {
  border: 1px solid rgba(244, 67, 54, 0.8);
  box-sizing: border-box;
}

#controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 10px;
  width: fit-content;
  max-width: 90vw;
}

select,
input[type=file],
button,
.file-label {
  font-size: 14px;
  padding: 10px 16px;
  background: #1e1e3a;
  color: #a3b8ff;
  border: 2px solid #4a6ef7;
  border-radius: 5px;
  transition: 0.3s ease;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}

select:hover,
input[type=file]:hover,
button:hover,
.file-label:hover {
  background: #2a2a5c;
  border-color: #7a94ff;
  color: #7a94ff;
}

select:focus,
input[type=file]:focus,
button:focus {
  outline: none;
  box-shadow: 0 0 8px #7a94ff;
}

.file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}

.file-label input {
  display: none;
}

@media (max-width: 480px) {
  #controls {
    grid-template-columns: 1fr;
    width: 100%;
  }

  select,
  input[type=file],
  button,
  .file-label {
    width: 100%;
  }
}

/* Scrollbars */
#puzzle::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#puzzle::-webkit-scrollbar-track {
  background: #121212;
  border-radius: 8px;
}

#puzzle::-webkit-scrollbar-thumb {
  background: #4a6ef7;
  border-radius: 8px;
}

#puzzle {
  scrollbar-width: thin;
  scrollbar-color: #4a6ef7 #121212;
}

#errorCount {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  padding: 0 8px;
  text-align: center;
}

#puzzle {
  position: relative;
  display: grid;
  gap: 1px;
  background: #222;
  border: 6px solid green;
  border-radius: 10px;
  max-width: 100vw;
  max-height: 70vh;
  user-select: none;
  overflow: hidden;
  transition: border-color 0.3s ease;
}

/* Modal styles for Cropper.js integration */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0,0,0,0.8);
  justify-content: center;
  align-items: center;
  padding: 15px;
  box-sizing: border-box;
}

.modal.active {
  display: flex;
}

.modal-content {
  background-color: #222;
  margin: auto;
  padding: 20px;
  border: 1px solid #888;
  width: 95%;
  max-width: 700px;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  position: relative;
}

.close-button {
  color: #aaa;
  position: absolute;
  top: 10px;
  right: 20px;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close-button:hover,
.close-button:focus {
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}

.img-container {
  max-height: 60vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #333;
}

.img-container img {
  display: block;
  max-width: 100%;
  height: auto;
}

#cropButtons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

/* Ensure Cropper.js elements are responsive */
.cropper-view-box,
.cropper-face {
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.hint-number {
    position: absolute;
    top: 5px;
    left: 5px;
    font-size: 0.8em;
    font-weight: bold;
    color: red;
    z-index: 10;
    transition: color 0.3s ease;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    pointer-events: none;
}

.hint-number-correct {
    color: green;
}

.hints-on .hint-number {
    display: block;
}

.hints-on.flips-mode .hint-number {
    display: none;
}

.hints-on .empty-spot .hint-number {
    display: none;
}

.hint-arrow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2em;
  font-weight: bold;
  pointer-events: none;
  transition: color 0.3s ease;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.hints-on .hint-arrow {
  display: block;
}

.hint-arrow-correct {
  color: green;
}

.hint-arrow-wrong {
  color: red;
}

.flip-indicator {
  position: absolute;
  font-size: 1.5em; /* Размер зависит от font-size родительского .piece */
  font-weight: bold;
  pointer-events: none;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  z-index: 10;
  display: none;
  top: 50%;
  transform: translateY(-50%);
}

.hints-on .flip-indicator {
  display: block;
}

.flip-indicator-h {
  right: 20%;
}

.flip-indicator-v {
  left: 20%;
}

.flip-indicator-correct {
  color: green;
}

.flip-indicator-wrong {
  color: red;
}
