/* Page: green table on every width; the clip grows with the game instead of keeping 4:3,
   and "Spiel vergrößern" enlarges board and card instead of zooming the whole game. */

/* Registered, so that the width of the card can change smoothly: card, board and warehouse are all measured from
   it and grow together, frame by frame. */
@property --skb-card {
  syntax: '<length>';
  inherits: true;
  initial-value: 500px;
}

.page-sokoban .game-section {
  background: #005000;
}

.page-sokoban .game-clip {
  --skb-card: 500px;
  aspect-ratio: auto;
  transition: width 0.3s ease, --skb-card 0.3s ease;
}

.page-sokoban .game-clip--large {
  --skb-card: 640px;
}

.page-sokoban .game-clip--large .game-inner {
  zoom: 1;
}

@media (max-width: 850px) {
  .page-sokoban .game-section {
    padding: 20px 5px;
  }
}

/* Game */

#skb-app {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

/* The board is a square as wide as the card allows and as high as the window allows (--skb-chrome is
   everything else on the screen), never under 240px. It is the same for every level, so that switching the
   level moves nothing; --skb-n (cells a side, set by the script) divides it. */
#skb-game {
  --skb-pad: 16px;
  --skb-chrome: 250px;
  --skb-w: min(var(--skb-card), calc(100vw - 20px));
  --skb-board: max(240px, min(calc(var(--skb-w) - 2 * var(--skb-pad)), calc(100vh - var(--skb-chrome))));
  --skb-cell: calc(var(--skb-board) / var(--skb-n, 10));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "levels new" "score score" "stage stage" "tools tools";
  justify-items: center;
  gap: 10px 8px;
  box-sizing: border-box;
  width: var(--skb-w);
  padding: var(--skb-pad);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  color: #1f2d1f;
  font-family: 'Inter', system-ui, sans-serif;
  text-transform: uppercase;
  user-select: none;
}

/* Buttons do not inherit the capitals on their own (the browser sets text-transform: none on them). */
#skb-game button {
  text-transform: inherit;
}

/* The levels as one row of buttons; the one in play is lit (as the levels of Tic Tac Toe). */
#skb-levels {
  grid-area: levels;
  justify-self: stretch;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf1ed;
  border: 1px solid #d6ded6;
  border-radius: 8px;
}

#skb-levels button {
  flex: 1 1 0;
  min-width: 0;
  padding: 5px 6px;
  font: 600 13px 'Inter', system-ui, sans-serif;
  color: #556355;
  background: transparent;
  border: 0;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#skb-levels button.skb-on {
  color: #005000;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: default;
}

/* The buttons of the other games (.issTurnButton and .dropdown-btn in Games/shared/ui.css) as on the
   Kreuzworträtsel page: light green with a green glow, white with green letters and a white glow under the mouse. */
#skb-new,
#skb-tools button,
#skb-over-buttons button {
  padding: 10px 14px;
  font: 600 14px 'Inter', system-ui, sans-serif;
  color: #fff;
  background: #00b050;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 0 8px rgba(0, 176, 80, 0.8);
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

#skb-new {
  grid-area: new;
  align-self: stretch;
  display: grid;
  align-items: center;
}

/* "Neues Level" and "Wirklich neu?" lie on one another; the button is as wide as the longer one. */
#skb-new span {
  grid-area: 1 / 1;
}

#skb-new span + span,
#skb-new.skb-ask span:first-child {
  visibility: hidden;
}

#skb-new.skb-ask span + span {
  visibility: visible;
}

/* A question: red until it is answered or the three seconds are over. */
#skb-new.skb-ask,
#skb-tools button.skb-ask {
  background: #e5534b;
  box-shadow: 0 0 8px rgba(229, 83, 75, 0.8);
}

#skb-score {
  grid-area: score;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
  container-type: inline-size;
}

.skb-score-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 5px 2px;
  background: #f1f4f1;
  border-radius: 8px;
}

.skb-score-label {
  font-size: min(12px, 3.6cqw);
  color: #556355;
  white-space: nowrap;
}

.skb-score-value {
  font-size: min(20px, 6cqw);
  font-weight: 600;
  line-height: 1.1;
}

/* The board and, above it, the message when the warehouse is solved. */
#skb-stage {
  grid-area: stage;
  position: relative;
}

/* Outside the warehouse the board is the white of the card. */
#skb-board {
  position: relative;
  width: var(--skb-board);
  height: var(--skb-board);
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
}

/* The warehouse stands in the middle of the board; walls, floor and pieces sit at column --x and row --y. Their
   size and place are shares of the warehouse, not lengths: when the board grows the transform stays the same, so
   the pieces grow with it instead of sliding after it. */
#skb-level {
  position: absolute;
  left: calc((100% - var(--w) * var(--skb-cell)) / 2);
  top: calc((100% - var(--h) * var(--skb-cell)) / 2);
  width: calc(var(--w) * var(--skb-cell));
  height: calc(var(--h) * var(--skb-cell));
}

.skb-wall,
.skb-floor,
.skb-piece {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--w));
  height: calc(100% / var(--h));
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
}

/* Walls as stone blocks: light along the top edge, shade along the bottom one. */
.skb-wall {
  background: #3e4f3e;
  box-shadow: 0 0 0 0.5px #3e4f3e, inset 0 calc(var(--skb-cell) * 0.07) 0 rgba(255, 255, 255, 0.1), inset 0 calc(var(--skb-cell) * -0.09) 0 rgba(0, 0, 0, 0.22);
}

.skb-floor {
  background: #d8e2d8;
  box-shadow: inset 0 0 0 0.5px rgba(31, 45, 31, 0.08);
}

/* A goal: a golden ring in the floor. */
.skb-goal::after {
  content: '';
  position: absolute;
  inset: 27%;
  box-sizing: border-box;
  border: calc(var(--skb-cell) * 0.08) solid #e39e00;
  border-radius: 50%;
  background: rgba(255, 179, 0, 0.4);
}

/* Boxes and the keeper slide from cell to cell; they let clicks through to the floor below. */
.skb-piece {
  pointer-events: none;
  transition: transform 0.09s linear;
}

.skb-piece.skb-snap {
  transition: none;
}

/* A crate: wood with a frame and a cross brace; on a goal it turns green and glows. */
.skb-crate {
  --wood: #d9a24f;
  --edge: #9a6424;
  position: absolute;
  inset: 7%;
  box-sizing: border-box;
  border: calc(var(--skb-cell) * 0.09) solid var(--edge);
  border-radius: 12%;
  background:
    linear-gradient(45deg, transparent 43%, var(--edge) 43%, var(--edge) 57%, transparent 57%),
    linear-gradient(-45deg, transparent 43%, var(--edge) 43%, var(--edge) 57%, transparent 57%),
    var(--wood);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: box-shadow 0.2s;
}

.skb-box.skb-on .skb-crate {
  --wood: #48bf74;
  --edge: #1d6b3a;
  box-shadow: 0 0 calc(var(--skb-cell) * 0.22) rgba(72, 191, 116, 0.75);
}

/* The keeper: a green round body seen from above; its eyes look the way it went (--turn). */
.skb-keeper {
  z-index: 2;
}

.skb-face {
  position: absolute;
  inset: 13%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #5fd08a, #1d7f42 68%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transform: rotate(var(--turn, 0deg));
}

.skb-face::before,
.skb-face::after {
  content: '';
  position: absolute;
  top: 52%;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 68%, #1f2d1f 38%, #fff 42%);
}

.skb-face::before {
  left: 22%;
}

.skb-face::after {
  right: 22%;
}

#skb-over {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  box-sizing: border-box;
  background: rgba(238, 243, 238, 0.9);
  border-radius: 8px;
  text-align: center;
  animation: skb-fade 0.4s ease 0.15s both;
}

#skb-over.skb-show {
  display: flex;
}

#skb-over-title {
  margin: 0;
  font-size: calc(var(--skb-board) * 0.08);
  font-weight: 600;
  line-height: 1.2;
  color: #1d7f42;
}

#skb-over-text {
  max-width: 30em;
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

#skb-over-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#skb-tools {
  grid-area: tools;
  justify-self: stretch;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

#skb-tools button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#skb-tools svg {
  flex: none;
  width: 15px;
  height: 15px;
}

#skb-game button:disabled {
  opacity: 0.4;
  box-shadow: none;
  cursor: default;
}

/* Said to screen readers only; the message on the board says it to the eye. */
#skb-status {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#skb-new:focus-visible,
#skb-tools button:focus-visible,
#skb-over-buttons button:focus-visible,
#skb-levels button:focus-visible {
  outline: 3px solid #00b050;
  outline-offset: 2px;
}

/* Hover only where there is a mouse: after a tap on a phone it would stick. */
@media (hover: hover) {
  /* white with green letters as in the other games; on the white card a thin green ring and no glow (user, 2026-10-14) */
  #skb-new:not(.skb-ask):hover,
  #skb-tools button:not(:disabled):not(.skb-ask):hover,
  #skb-over-buttons button:hover {
    color: #00b050;
    background: #fff;
    box-shadow: inset 0 0 0 1px #00b050;
  }

  #skb-new.skb-ask:hover,
  #skb-tools button.skb-ask:hover {
    background: #ef6a62;
  }

  /* as in the other games: while one button is under the mouse, the others lose their glow */
  #skb-game:has(#skb-new:hover, #skb-tools button:not(:disabled):hover) #skb-new:not(:hover),
  #skb-game:has(#skb-new:hover, #skb-tools button:not(:disabled):hover) #skb-tools button:not(:hover),
  #skb-over-buttons:has(button:hover) button:not(:hover) {
    box-shadow: none;
  }

  #skb-levels button:not(.skb-on):hover {
    color: #1f2d1f;
    background: rgba(0, 0, 0, 0.05);
  }

  #skb-board:not(.skb-done) .skb-floor:hover {
    background: #cbd8cb;
  }
}

@keyframes skb-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .page-sokoban .game-clip,
  .skb-piece,
  .skb-crate,
  #skb-over {
    transition: none !important;
    animation: none !important;
  }
}

/* Tablets: the page header stands above the game. */
@media (min-width: 851px) and (max-width: 1024px) {
  #skb-game {
    --skb-chrome: 290px;
  }
}

/* The narrowest phones: a little less padding. */
@media (max-width: 360px) {
  #skb-game {
    --skb-pad: 12px;
  }

  #skb-levels button {
    font-size: 12px;
  }
}

/* On phones the three levels need the whole row: "Neues Level" goes below the tools. */
@media (max-width: 480px) {
  #skb-game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "levels" "score" "stage" "tools" "new";
  }

  #skb-new {
    justify-self: stretch;
  }
}

/* Phones held sideways: board on the left, everything else beside it. */
@media (orientation: landscape) and (max-height: 500px) {
  #skb-game {
    --skb-w: min(760px, calc(100vw - 20px));
    --skb-board: max(200px, calc(100vh - 96px));
    grid-template-areas: "stage levels" "stage new" "stage score" "stage tools" "stage .";
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: auto auto auto auto 1fr;
    align-items: start;
    column-gap: 16px;
    row-gap: 8px;
  }

  #skb-new {
    align-self: start;
    justify-self: stretch;
  }

  #skb-score {
    grid-template-columns: repeat(2, 1fr);
  }

  .skb-score-label {
    font-size: min(12px, 7cqw);
  }

  .skb-score-value {
    font-size: min(18px, 10cqw);
  }
}
