:root {
  --cols: 10;
  --rows: 12;
  --ui-element-fix-height: 25px;
  --bottom-fix-height: 25svh;
  --gap-size: 4px;
  --available-width: calc(100svw - 2 * var(--gap-size));
  --available-height: calc(100svh - var(--ui-element-fix-height) - var(--bottom-fix-height) - 4 * var(--gap-size));
  --cell-size: min(var(--available-width) / var(--cols), var(--available-height) / var(--rows));
  --bg-color: #20232a;
  --text-muted: #888;
  --text-dark: #20232a;
  --color-btn: #d5a677;
  --color-btn-disabled: #666666;
}

html, * {
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

body {
  margin: 0;
  height: 100svh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  font-family: "Arial", sans-serif;
  background-color: var(--bg-color);
  overflow: hidden;
  touch-action: none;
}

#master-container {
  width: 100%;
  height: 100%;
  padding: var(--gap-size);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  box-sizing: border-box;
}

#content-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--gap-size);
}

#top-container {
  display: flex;
  flex-direction: column;
  gap: var(--gap-size);
  width: 100%;
  min-width: calc(var(--cols) * var(--cell-size));
  max-width: 100svh;
  margin: 0 auto;
}

.top-row {
  width: 0;
  min-width: 100%;
  display: flex;
  gap: var(--gap-size);
}

.ui-box {
  flex: 1;
  min-width: 0;
  height: var(--ui-element-fix-height);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-size: 1em;
  color: var(--text-muted);
  background-color: var(--bg-color);
  border: none;
  border-radius: 4px;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.btn {
  color: var(--text-dark);
  background-color: var(--color-btn);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn.active {
  opacity: 1;
  cursor: default;
}

.btn:disabled {
  background-color: var(--color-btn-disabled);
  color: var(--text-dark);
  opacity: 0.6;
  cursor: default;
  pointer-events: none;
}

@media (hover: hover) {
  .btn:not(.active):hover {
    opacity: 1;
  }
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  background-color: var(--bg-color);
  margin: 0 auto;
  transition: opacity 1s ease;
}

.player, .box {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform var(--move-speed) linear;
}

.player, .box, .wall {
  z-index: 5;
}

.tile {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  position: relative;
}

.target {
  z-index: 1;
}

.player img, .box img, .tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

#bottom-container {
  width: 100%;
  min-width: calc(var(--cols) * var(--cell-size));
  max-width: 100svh;
  height: var(--bottom-fix-height);
  margin-top: auto;
  margin-left: auto;
  margin-right: auto;
  touch-action: none;
  position: relative;
}

#bottom-container svg {
  width: 100%;
  height: 100%;
  display: block;
}

.control-btn {
  fill: var(--color-btn);
  stroke: var(--bg-color); 
  stroke-width: 4px; 
  stroke-linejoin: round; 
  vector-effect: non-scaling-stroke;
  opacity: 0.5;
  transition: opacity 0.1s;
  -webkit-tap-highlight-color: transparent;
  pointer-events: visibleFill; 
}

.control-btn.active {
  opacity: 1;
}

body.resizing .player, body.resizing .box {
  transition: none !important;
}

.box.on-target::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('images/ok.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 10;
  pointer-events: none;
  animation: popIn 0.2s ease-out forwards;
}

@keyframes popIn {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

body.game-won .board {
  opacity: 0;
}

.arrow-icon {
  position: absolute;
  height: 20%;
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 10;
  opacity: 0.7;
}

.arrow-up { left: 50%; top: 20%; }
.arrow-down { left: 50%; top: 80%; }
.arrow-left { left: 20%; top: 50%; }
.arrow-right { left: 80%; top: 50%; }

@media (hover: hover) and (pointer: fine) {
  #bottom-container {
    display: none !important;
  }
  
  :root {
    --bottom-fix-height: 0px;
  }
}

@media print {
    html, body {
        display: none !important;
    }
}

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(32, 35, 42, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background-color: var(--bg-color);
  border: 2px solid var(--color-btn);
  border-radius: 6px;
  padding: 24px;
  text-align: center;
  color: #fff;
  max-width: 280px;
  width: 80%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
}

.modal-content p {
  margin: 0 0 20px 0;
  font-size: 1.1em;
  font-weight: normal;
  line-height: 1.4;
}

.modal-content .btn {
  width: 100%;
  height: var(--ui-element-fix-height);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

.confetti {
    position: fixed;
    top: -10%;
    z-index: 105;
    pointer-events: none;
    opacity: 0;
}

@keyframes confettiFall {
    0% { top: -10%; opacity: 1; transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg); }
    80% { opacity: 1; }
    100% { top: 110%; opacity: 0; transform: rotateX(var(--rotX)) rotateY(var(--rotY)) rotateZ(var(--rotZ)); }
}

@keyframes confettiWave {
    0% { margin-left: 0; }
    100% { margin-left: var(--drift); }
}