/* =========================================================
   BOX PUSH — BUILD 3
   Main stylesheet

   Mobile-first Sokoban-style puzzle game.
   ========================================================= */


/* =========================================================
   RESET
   ========================================================= */

* {
  box-sizing: border-box;

  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;

  margin: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;

  overflow: hidden;

  background: #0d1016;
  color: #ffffff;

  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;

  user-select: none;

  overscroll-behavior: none;
}


/* =========================================================
   APP
   ========================================================= */

.app {
  width: 100%;
  max-width: 480px;

  min-height: 100vh;
  min-height: 100dvh;

  margin: 0 auto;

  padding:
    18px 16px
    max(14px, env(safe-area-inset-bottom));

  display: flex;
  flex-direction: column;
}


/* =========================================================
   HEADER
   ========================================================= */

.header {
  text-align: center;
}

.title {
  margin: 0;

  font-size: 29px;
  line-height: 1;

  font-weight: 900;

  letter-spacing: -1px;
}

.subtitle {
  margin: 6px 0 0;

  color: #7f899b;

  font-size: 13px;
}


/* =========================================================
   STATS
   ========================================================= */

.stats {
  display: flex;
  justify-content: center;

  gap: 8px;

  margin-top: 13px;
}

.stat {
  min-width: 100px;

  padding: 7px 12px;

  border: 1px solid #252b35;
  border-radius: 11px;

  background: #151a22;

  text-align: center;
}

.stat-label {
  display: block;

  color: #697486;

  font-size: 8px;
  font-weight: 800;

  letter-spacing: 1px;
}

.stat-value {
  display: block;

  margin-top: 2px;

  font-size: 15px;
  font-weight: 850;
}
.home-btn {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;

  z-index: 1000;

  display: inline-flex;
  align-items: center;
  gap: 6px;

  padding: 8px 11px;

  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;

  background: rgba(15,18,32,.82);
  color: rgba(255,255,255,.8);

  text-decoration: none;

  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;

  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;

  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  box-shadow: 0 4px 18px rgba(0,0,0,.2);

  transition:
    transform .15s ease,
    background .15s ease,
    color .15s ease;
}

.home-btn svg {
  width: 15px;
  height: 15px;

  fill: none;
  stroke: currentColor;

  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.home-btn:active {
  transform: scale(.93);
}

.home-btn:hover {
  background: rgba(255,255,255,.1);
  color: white;
}


/* =========================================================
   LEVEL PROGRESS
   ========================================================= */

.progress {
  width: 100%;
  max-width: 280px;

  margin: 9px auto 0;
}

.progress-top {
  display: flex;
  justify-content: space-between;

  margin-bottom: 4px;

  color: #687386;

  font-size: 8px;
  font-weight: 800;

  letter-spacing: .8px;
}

.progress-track {
  height: 5px;

  overflow: hidden;

  border-radius: 99px;

  background: #202631;
}

.progress-bar {
  width: 0;
  height: 100%;

  border-radius: inherit;

  background:
    linear-gradient(
      90deg,
      #4d8dff,
      #6ca5ff
    );

  transition:
    width 250ms ease;
}


/* =========================================================
   GAME AREA
   ========================================================= */

.game-area {
  flex: 1;

  min-height: 0;

  display: flex;
  align-items: center;
  justify-content: center;
}


/* =========================================================
   BOARD
   ========================================================= */

.board {
  width: min(
    88vw,
    360px,
    calc(100dvh - 350px)
  );

  aspect-ratio: 1 / 1;

  display: grid;

  gap: 3px;

  padding: 5px;

  border-radius: 15px;

  background: #11161e;

  box-shadow:
    0 18px 45px rgba(0, 0, 0, .35);

  touch-action: none;
}


/* =========================================================
   CELLS
   ========================================================= */

.cell {
  position: relative;

  min-width: 0;
  min-height: 0;

  border-radius: 6px;

  background: #1c222c;
}

.cell.wall {
  background: #353d49;

  box-shadow:
    inset 0 1px 0
    rgba(255, 255, 255, .05);
}


/* =========================================================
   TARGET
   ========================================================= */

.target::after {
  content: "";

  position: absolute;

  left: 50%;
  top: 50%;

  width: 38%;
  height: 38%;

  transform:
    translate(-50%, -50%);

  border: 3px solid #e8c94a;

  border-radius: 50%;
}


/* =========================================================
   PLAYER
   ========================================================= */




/* =========================================================
   BOX
   ========================================================= */




/* =========================================================
   DIRECTION CONTROLS
   ========================================================= */

.controls {
  width: 190px;

  margin: 10px auto 0;

  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  grid-template-rows:
    repeat(2, 52px);

  gap: 7px;
}

.control {
  border: 1px solid #303744;
  border-radius: 13px;

  background: #191e27;
  color: #ffffff;

  font-size: 21px;
  font-weight: 800;

  cursor: pointer;

  touch-action: manipulation;

  transition:
    transform 100ms ease,
    background 100ms ease;
}

.control:active {
  transform: scale(.91);

  background: #252c37;
}

.control.up {
  grid-column: 2;
  grid-row: 1;
}

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

.control.down {
  grid-column: 2;
  grid-row: 2;
}

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


/* =========================================================
   RESTART
   ========================================================= */

.actions {
  display: flex;
  justify-content: center;

  margin-top: 8px;
}

.restart {
  min-width: 125px;
  min-height: 40px;

  border: 1px solid #303744;
  border-radius: 12px;

  background: #191e27;
  color: #dce1e9;

  font: inherit;

  font-size: 13px;
  font-weight: 750;

  cursor: pointer;

  transition:
    transform 100ms ease,
    background 100ms ease;
}

.restart:active {
  transform: scale(.94);

  background: #252c37;
}


/* =========================================================
   LEVEL COMPLETE MODAL
   ========================================================= */
/* =========================================================
   BUILD 6 — LEVEL COMPLETION / PROGRESSION
   ========================================================= */


/* =========================================================
   COMPLETION OVERLAY
   ========================================================= */

.message {
  position: fixed;

  inset: 0;

  z-index: 10;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;

  background:
    rgba(8, 10, 14, .84);

  backdrop-filter: blur(8px);

  opacity: 0;

  visibility: hidden;

  pointer-events: none;

  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}


.message.show {
  opacity: 1;

  visibility: visible;

  pointer-events: auto;
}


/* =========================================================
   COMPLETION CARD
   ========================================================= */

.message-card {
  width: min(100%, 330px);

  padding: 28px 21px 21px;

  border: 1px solid #303744;

  border-radius: 22px;

  background:
    linear-gradient(
      145deg,
      #181e27,
      #12171e
    );

  box-shadow:
    0 24px 70px
    rgba(0, 0, 0, .5);

  text-align: center;

  transform:
    translateY(18px)
    scale(.92);

  transition:
    transform 300ms
    cubic-bezier(.2, .8, .2, 1);
}


.message.show .message-card {
  transform:
    translateY(0)
    scale(1);
}


/* =========================================================
   SUCCESS ICON
   ========================================================= */

.message-icon {
  width: 62px;
  height: 62px;

  margin: 0 auto 8px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;

  background:
    rgba(85, 214, 138, .12);

  border:
    1px solid
    rgba(85, 214, 138, .25);

  font-size: 31px;

  animation:
    successPop 420ms
    cubic-bezier(.2, .8, .2, 1);
}


@keyframes successPop {

  0% {
    transform: scale(.45);
    opacity: 0;
  }

  65% {
    transform: scale(1.12);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }

}


/* =========================================================
   TITLE
   ========================================================= */

.message-title {
  margin: 8px 0 5px;

  color: #ffffff;

  font-size: 27px;
  line-height: 1.1;

  font-weight: 900;

  letter-spacing: -.5px;
}


/* =========================================================
   RESULT TEXT
   ========================================================= */

.message-text {
  margin: 0 0 19px;

  color: #8792a4;

  font-size: 13px;
  line-height: 1.5;
}


/* =========================================================
   NEXT BUTTON
   ========================================================= */

.next-button {
  width: 100%;

  min-height: 48px;

  border: 0;

  border-radius: 13px;

  background:
    linear-gradient(
      135deg,
      #4d8dff,
      #3f7ee8
    );

  color: #ffffff;

  font: inherit;

  font-size: 14px;
  font-weight: 850;

  cursor: pointer;

  box-shadow:
    0 7px 18px
    rgba(77, 141, 255, .2);

  transition:
    transform 100ms ease,
    filter 100ms ease;
}


.next-button:active {
  transform: scale(.96);

  filter: brightness(.9);
}


/* =========================================================
   FINAL GAME STATE
   ========================================================= */

.message.final .message-icon {
  background:
    rgba(255, 201, 72, .12);

  border-color:
    rgba(255, 201, 72, .25);
}


.message.final .next-button {
  background:
    linear-gradient(
      135deg,
      #e0ad35,
      #c98f20
    );

  box-shadow:
    0 7px 18px
    rgba(224, 173, 53, .18);
}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  .message,
  .message-card,
  .message-icon,
  .next-button {
    transition: none !important;
    animation: none !important;
  }

}



/* =========================================================
   SHORT PHONES
   ========================================================= */

@media (max-height: 650px) {

  .app {
    padding-top: 11px;
  }

  .title {
    font-size: 25px;
  }

  .subtitle {
    margin-top: 3px;
  }

  .stats {
    margin-top: 8px;
  }

  .progress {
    margin-top: 6px;
  }

  .board {
    width: min(
      82vw,
      300px,
      calc(100dvh - 285px)
    );
  }

  .controls {
    width: 160px;

    grid-template-rows:
      repeat(2, 43px);

    margin-top: 6px;
  }

  .actions {
    margin-top: 5px;
  }

}


/* =========================================================
   BUILD 5 — MOVEMENT ANIMATION
   ========================================================= */


/* ---------------------------------------------------------
   Make board cells ready for animated pieces
   --------------------------------------------------------- */

.cell {
  position: relative;

  min-width: 0;
  min-height: 0;

  border-radius: 6px;

  background: #1c222c;
}


/* ---------------------------------------------------------
   Player

   The player is now drawn as an inner element so it can
   animate independently from the board cell.
   --------------------------------------------------------- */

.player-piece {
  position: absolute;

  left: 50%;
  top: 50%;

  width: 54%;
  height: 54%;

  transform:
    translate(-50%, -50%);

  border-radius: 50%;

  background: #58a6ff;

  box-shadow:
    0 0 14px
    rgba(88, 166, 255, .35);

  z-index: 3;

  transition:
    transform 120ms
    cubic-bezier(.2, .8, .2, 1);
}


/* ---------------------------------------------------------
   Box

   Boxes also become independent visual pieces.
   --------------------------------------------------------- */

.box-piece {
  position: absolute;

  left: 50%;
  top: 50%;

  width: 60%;
  height: 60%;

  transform:
    translate(-50%, -50%);

  border-radius: 5px;

  background: #d9823b;

  box-shadow:
    inset 0 2px 0
    rgba(255, 255, 255, .12);

  z-index: 2;

  transition:
    transform 120ms
    cubic-bezier(.2, .8, .2, 1),
    background 120ms ease,
    box-shadow 120ms ease;
}


/* ---------------------------------------------------------
   Box on target
   --------------------------------------------------------- */

.box-piece.on-target {
  background: #55d68a;

  box-shadow:
    0 0 14px
    rgba(85, 214, 138, .35);
}


/* ---------------------------------------------------------
   Tiny push feedback
   --------------------------------------------------------- */

.box-piece.pushed {
  filter: brightness(1.08);
}


/* ---------------------------------------------------------
   Keep target underneath animated pieces
   --------------------------------------------------------- */

.target::after {
  z-index: 1;
}


/* ---------------------------------------------------------
   Disable transitions when loading/restarting a level.
   This prevents the pieces from animating across the board
   when a new level is loaded.
   --------------------------------------------------------- */

.board.no-animation .player-piece,
.board.no-animation .box-piece {
  transition: none !important;
}


/* ---------------------------------------------------------
   Respect reduced-motion preferences.
   --------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {

  .player-piece,
  .box-piece {
    transition: none !important;
  }

}


/* =========================================================
   BUILD 7 — LEVEL SELECT
   ========================================================= */

.level-select {
  position: fixed;

  inset: 0;

  z-index: 20;

  display: flex;
  align-items: center;
  justify-content: center;

  padding: 20px;

  background:
    rgba(8, 10, 14, .94);

  backdrop-filter: blur(10px);

  opacity: 0;

  visibility: hidden;

  pointer-events: none;

  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}


.level-select.show {
  opacity: 1;

  visibility: visible;

  pointer-events: auto;
}


/* =========================================================
   LEVEL SELECT CARD
   ========================================================= */

.level-select-card {
  width: min(100%, 340px);

  padding: 25px 20px 20px;

  border: 1px solid #303744;

  border-radius: 22px;

  background:
    linear-gradient(
      145deg,
      #181e27,
      #12171e
    );

  box-shadow:
    0 24px 70px
    rgba(0, 0, 0, .5);

  text-align: center;
}


.level-select-title {
  margin: 0;

  font-size: 27px;

  font-weight: 900;
}


.level-select-subtitle {
  margin: 5px 0 20px;

  color: #7f899b;

  font-size: 13px;
}


/* =========================================================
   LEVEL GRID
   ========================================================= */

.level-grid {
  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  gap: 9px;
}


/* =========================================================
   LEVEL BUTTON
   ========================================================= */

.level-button {
  aspect-ratio: 1 / 1;

  border: 1px solid #303744;

  border-radius: 14px;

  background: #191e27;

  color: #ffffff;

  font: inherit;

  font-size: 18px;

  font-weight: 850;

  cursor: pointer;

  transition:
    transform 100ms ease,
    background 100ms ease,
    border-color 100ms ease;
}


.level-button:active {
  transform: scale(.92);
}


.level-button.unlocked {
  border-color: #3b4758;

  background: #202733;
}


.level-button.completed {
  border-color:
    rgba(85, 214, 138, .45);

  background:
    rgba(85, 214, 138, .12);

  color: #69df98;
}


.level-button.current {
  border-color: #4d8dff;

  box-shadow:
    0 0 0 2px
    rgba(77, 141, 255, .12);
}


.level-button.locked {
  color: #525c6c;

  background: #141920;

  cursor: not-allowed;
}


.level-button .level-check {
  display: block;

  margin-top: 2px;

  font-size: 10px;
}


/* =========================================================
   CONTINUE
   ========================================================= */

.continue-button {
  width: 100%;

  min-height: 47px;

  margin-top: 18px;

  border: 0;

  border-radius: 13px;

  background:
    linear-gradient(
      135deg,
      #4d8dff,
      #3f7ee8
    );

  color: #ffffff;

  font: inherit;

  font-size: 14px;

  font-weight: 850;

  cursor: pointer;

  transition:
    transform 100ms ease,
    filter 100ms ease;
}


.continue-button:active {
  transform: scale(.97);

  filter: brightness(.9);
}


/* =========================================================
   LEVEL SELECT MOBILE
   ========================================================= */

@media (max-height: 650px) {

  .level-select-card {
    padding: 19px 17px 17px;
  }

  .level-select-title {
    font-size: 24px;
  }

  .level-select-subtitle {
    margin-bottom: 13px;
  }

  .level-grid {
    gap: 7px;
  }

}


/* =========================================================
   BOX PUSH — BUILD 8
   FINAL MOBILE POLISH
   ========================================================= */


/* =========================================================
   GLOBAL MOBILE SAFETY
   ========================================================= */

html {
  width: 100%;
  height: 100%;

  overflow: hidden;

  background: #0d1016;
}


body {
  width: 100%;
  min-width: 320px;

  margin: 0;

  overflow: hidden;

  overscroll-behavior: none;

  -webkit-text-size-adjust: 100%;
}


/* =========================================================
   APP LAYOUT
   ========================================================= */

.app {
  width: 100%;
  max-width: 480px;

  height: 100dvh;
  min-height: 0;

  margin: 0 auto;

  padding-top:
    max(12px, env(safe-area-inset-top));

  padding-right:
    max(14px, env(safe-area-inset-right));

  padding-bottom:
    max(10px, env(safe-area-inset-bottom));

  padding-left:
    max(14px, env(safe-area-inset-left));

  overflow: hidden;
}


/* =========================================================
   HEADER
   ========================================================= */

.header {
  flex: 0 0 auto;
}

.title {
  font-size: clamp(
    24px,
    7vw,
    29px
  );
}

.subtitle {
  font-size: 12px;
}


/* =========================================================
   STATS
   ========================================================= */

.stats {
  flex: 0 0 auto;

  margin-top: 10px;
}

.stat {
  min-width: 92px;

  min-height: 39px;

  display: flex;
  flex-direction: column;
  justify-content: center;
}


/* =========================================================
   PROGRESS
   ========================================================= */

.progress {
  flex: 0 0 auto;

  width: min(
    280px,
    78vw
  );

  margin-top: 8px;
}


/* =========================================================
   GAME AREA
   ========================================================= */

.game-area {
  /*
    Allow the board to shrink rather than pushing
    controls outside the viewport.
  */

  flex: 1 1 auto;

  min-height: 0;

  width: 100%;

  display: flex;

  align-items: center;
  justify-content: center;
}


/* =========================================================
   BOARD
   ========================================================= */

.board {
  /*
    Width is limited by BOTH screen width and
    available vertical space.
  */

  width: min(
    88vw,
    360px,
    calc(100vw - 28px),
    calc(100dvh - 350px)
  );

  max-width: 360px;

  max-height: 360px;

  flex: 0 1 auto;

  aspect-ratio: 1;

  padding: 5px;

  gap: 3px;

  border-radius: 15px;

  /*
    Prevent accidental page gestures.
  */

  touch-action: none;
}


/* =========================================================
   GAME CELLS
   ========================================================= */

.cell {
  border-radius: clamp(
    4px,
    1.5vw,
    7px
  );
}


/* =========================================================
   CONTROLS
   ========================================================= */

.controls {
  flex: 0 0 auto;

  width: min(
    190px,
    52vw
  );

  grid-template-rows:
    repeat(2, 48px);

  gap: 7px;

  margin-top: 9px;
}


.control {
  min-width: 0;
  min-height: 44px;

  border-radius: 13px;

  font-size: 19px;

  /*
    Remove the default browser button flash.
  */

  -webkit-appearance: none;
  appearance: none;
}


/* =========================================================
   RESTART
   ========================================================= */

.actions {
  flex: 0 0 auto;

  margin-top: 7px;
}


.restart {
  min-height: 40px;

  padding:
    7px 17px;

  /*
    Comfortable mobile touch target.
  */

  touch-action: manipulation;
}


/* =========================================================
   LEVEL SELECT
   ========================================================= */

.level-select {
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}


.level-select-card {
  width: min(
    100%,
    340px
  );

  max-height:
    calc(100dvh - 36px);

  overflow-y: auto;

  overscroll-behavior: contain;
}


.level-grid {
  width: 100%;
}


.level-button {
  min-width: 0;

  min-height: 64px;

  touch-action: manipulation;
}


/* =========================================================
   COMPLETION MODAL
   ========================================================= */

.message {
  padding:
    max(18px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}


.message-card {
  width: min(
    100%,
    330px
  );

  max-height:
    calc(100dvh - 36px);

  overflow-y: auto;

  overscroll-behavior: contain;
}


.next-button {
  min-height: 48px;

  touch-action: manipulation;
}


/* =========================================================
   TOUCH FEEDBACK
   ========================================================= */

@media (hover: none) {

  .control:hover,
  .restart:hover,
  .next-button:hover,
  .level-button:hover,
  .continue-button:hover {
    filter: none;
  }

}


/* =========================================================
   DESKTOP / LARGE SCREENS
   ========================================================= */

@media (min-width: 600px) {

  .app {
    padding-top: 18px;
  }

  .board {
    width: min(
      360px,
      calc(100dvh - 350px)
    );
  }

}


/* =========================================================
   SHORT PHONES
   ========================================================= */

@media (max-height: 700px) {

  .app {
    padding-top:
      max(8px, env(safe-area-inset-top));
  }

  .title {
    font-size: 24px;
  }

  .subtitle {
    margin-top: 3px;
  }

  .stats {
    margin-top: 7px;
  }

  .progress {
    margin-top: 5px;
  }

  .board {
    width: min(
      82vw,
      310px,
      calc(100dvh - 315px)
    );

    max-height: 310px;
  }

  .controls {
    width: 164px;

    grid-template-rows:
      repeat(2, 42px);

    gap: 6px;

    margin-top: 6px;
  }

  .control {
    min-height: 40px;

    font-size: 17px;
  }

  .actions {
    margin-top: 5px;
  }

  .restart {
    min-height: 36px;

    font-size: 12px;
  }

}


/* =========================================================
   VERY SHORT PHONES
   ========================================================= */

@media (max-height: 590px) {

  .subtitle {
    display: none;
  }

  .stats {
    margin-top: 5px;
  }

  .progress {
    margin-top: 4px;
  }

  .board {
    width: min(
      78vw,
      265px,
      calc(100dvh - 255px)
    );

    max-height: 265px;
  }

  .controls {
    width: 148px;

    grid-template-rows:
      repeat(2, 37px);

    gap: 5px;
  }

  .control {
    min-height: 36px;

    border-radius: 10px;

    font-size: 15px;
  }

  .actions {
    margin-top: 4px;
  }

  .restart {
    min-height: 33px;

    padding:
      4px 13px;
  }

}


/* =========================================================
   VERY NARROW PHONES
   ========================================================= */

@media (max-width: 350px) {

  .app {
    padding-left: 10px;
    padding-right: 10px;
  }

  .stat {
    min-width: 82px;
  }

  .controls {
    width: 145px;
  }

}


/* =========================================================
   REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .player-piece,
  .box-piece,
  .message,
  .message-card,
  .message-icon,
  .next-button,
  .level-button,
  .continue-button,
  .control,
  .restart {
    transition: none !important;
    animation: none !important;
  }

}

