/* 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 and board are measured from it and grow
   together, frame by frame. */
@property --nng-card {
  syntax: '<length>';
  inherits: true;
  initial-value: 500px;
}

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

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

.page-nonogram .game-clip--large {
  --nng-card: 640px;
}

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

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

/* Game */

#nng-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 (--nng-chrome is everything
   else on the screen), never under 240px. It is the same for every level, so that switching the level moves
   nothing. Its unit --nng-u is one cell: the grid has --nng-n cells and a clue area of --nng-k number slots,
   0.66 cells each, along both sides (the script sets n and k). */
#nng-game {
  --nng-pad: 16px;
  --nng-chrome: 190px;
  --nng-w: min(var(--nng-card), calc(100vw - 20px));
  --nng-board: max(240px, min(calc(var(--nng-w) - 2 * var(--nng-pad)), calc(100vh - var(--nng-chrome))));
  --nng-u: calc((var(--nng-board) - 2px) / (var(--nng-n, 10) + 0.66 * var(--nng-k, 5)));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "levels new" "board board" "tools tools" "status status";
  justify-items: center;
  gap: 10px 8px;
  box-sizing: border-box;
  width: var(--nng-w);
  padding: var(--nng-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). */
#nng-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). */
#nng-levels {
  grid-area: levels;
  justify-self: stretch;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf1ed;
  border: 1px solid #d6ded6;
  border-radius: 8px;
}

#nng-levels button,
#nng-mode 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;
}

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

/* The buttons of the other games (Games/shared/ui.css) as on the Sokoban page: light green with a green glow; under
   the mouse white with green letters and a thin green ring, no glow, because the card is white. */
#nng-new,
#nng-check,
#nng-tip {
  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;
}

#nng-new {
  grid-area: new;
  align-self: stretch;
}

/* the question: red with a red glow */
#nng-new.nng-ask {
  background: #e5534b;
  box-shadow: 0 0 8px rgba(229, 83, 75, 0.8);
}

/* The grid: a corner, a row of column clues, then per row its clue and its cells. Thin lines between cells,
   thick ones around the grid and after every fifth cell. */
#nng-board {
  grid-area: board;
  display: grid;
  grid-template-columns: calc(0.66 * var(--nng-k, 5) * var(--nng-u)) repeat(var(--nng-n, 10), var(--nng-u));
  grid-template-rows: calc(0.66 * var(--nng-k, 5) * var(--nng-u)) repeat(var(--nng-n, 10), var(--nng-u));
  box-sizing: border-box;
  width: var(--nng-board);
  height: var(--nng-board);
  align-content: center;
  justify-content: center;
  outline: none;
  touch-action: none;
}

.nng-cc,
.nng-rc {
  display: flex;
  font-size: min(26px, max(8px, calc(0.52 * var(--nng-u))));
  font-weight: 600;
  line-height: 1;
  color: #1f2d1f;
  border-radius: 3px;
  transition: opacity 0.2s, color 0.2s, background 0.12s;
}

.nng-cc {
  flex-direction: column;
  gap: calc(0.12 * var(--nng-u));
  justify-content: flex-end;
  align-items: center;
  padding-bottom: calc(0.2 * var(--nng-u));
}

.nng-rc {
  gap: calc(0.3 * var(--nng-u));
  justify-content: flex-end;
  align-items: center;
  padding-right: calc(0.25 * var(--nng-u));
}

/* A line whose filled cells already are its clue fades; one whose marks fit no arrangement turns red. */
.nng-cc.nng-ok,
.nng-rc.nng-ok {
  opacity: 0.35;
}

.nng-cc.nng-bad,
.nng-rc.nng-bad {
  color: #d9443d;
}

.nng-cc.nng-hot,
.nng-rc.nng-hot {
  background: #e3f1e3;
}

.nng-cell {
  position: relative;
  box-sizing: border-box;
  background: #fff;
  border-right: 1px solid #c3cfc3;
  border-bottom: 1px solid #c3cfc3;
  cursor: pointer;
  transition: background 0.08s;
}

.nng-cell.nng-vl { border-left: 2px solid #3c4a3c; }
.nng-cell.nng-ht { border-top: 2px solid #3c4a3c; }
.nng-cell.nng-vr { border-right: 2px solid #3c4a3c; }
.nng-cell.nng-hb { border-bottom: 2px solid #3c4a3c; }

.nng-cell.nng-peer {
  background: #f1f7f1;
}

.nng-cell.nng-f {
  background: #1f2d1f;
}

/* A cross: two strokes through the middle of the cell. */
.nng-cell.nng-x::before {
  content: '';
  position: absolute;
  inset: 26%;
  --nng-xw: max(0.75px, calc(0.045 * var(--nng-u)));
  background:
    linear-gradient(45deg, transparent calc(50% - var(--nng-xw)), currentColor calc(50% - var(--nng-xw)), currentColor calc(50% + var(--nng-xw)), transparent calc(50% + var(--nng-xw))),
    linear-gradient(-45deg, transparent calc(50% - var(--nng-xw)), currentColor calc(50% - var(--nng-xw)), currentColor calc(50% + var(--nng-xw)), transparent calc(50% + var(--nng-xw)));
}

.nng-cell.nng-x {
  color: #8a988a;
}

/* Revealed by a tip: blue, and locked. */
.nng-cell.nng-given.nng-f {
  background: #1e6fd9;
}

.nng-cell.nng-given.nng-x {
  color: #1e6fd9;
}

/* Marked by "Prüfen": a filled cell that should stay empty, a cross on a cell that should be filled. */
.nng-cell.nng-wrong.nng-f {
  background: #d9443d;
}

.nng-cell.nng-wrong.nng-x {
  color: #c62828;
  background: #ffdcd8;
}

/* The keyboard's cell. */
.nng-cell.nng-cur {
  box-shadow: inset 0 0 0 2px #f2b600;
}

/* Solved: the picture turns green, the crosses go, and the grid takes no more input. */
#nng-board.nng-done .nng-cell {
  cursor: default;
}

#nng-board.nng-done .nng-cell.nng-f {
  background: #1d7f42;
}

#nng-board.nng-done .nng-cell.nng-x::before {
  content: none;
}

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

/* Fill or cross: what a click or a tap puts down (the right mouse button always crosses). */
#nng-mode {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: #edf1ed;
  border: 1px solid #d6ded6;
  border-radius: 8px;
}

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

#nng-mode svg {
  flex: none;
  width: 14px;
  height: 14px;
}

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

#nng-status {
  grid-area: status;
  min-height: 18px;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
}

#nng-new:focus-visible,
#nng-check:focus-visible,
#nng-tip:focus-visible,
#nng-levels button:focus-visible,
#nng-mode button:focus-visible,
#nng-board: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 to the button. */
@media (hover: hover) {
  #nng-new:not(.nng-ask):hover,
  #nng-check:not(:disabled):hover,
  #nng-tip:not(:disabled):hover {
    color: #00b050;
    background: #fff;
    box-shadow: inset 0 0 0 1px #00b050;
  }

  #nng-new.nng-ask:hover {
    background: #ef6a62;
  }

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

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

@media (prefers-reduced-motion: reduce) {
  .page-nonogram .game-clip,
  .nng-cell,
  .nng-cc,
  .nng-rc {
    transition: none;
  }
}

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

/* The narrowest phones: a little less padding; the tool buttons keep only their symbols. */
@media (max-width: 380px) {
  #nng-game {
    --nng-pad: 12px;
  }

  #nng-new {
    padding: 10px;
  }

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

  #nng-mode span {
    display: none;
  }

  /* the switch with its symbols only needs little room; "Prüfen" and "Tipp" get the rest */
  #nng-tools {
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* Under 350px the three levels need the whole row: "Neues Rätsel" goes below the tools. */
@media (max-width: 350px) {
  #nng-game {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "levels" "board" "tools" "new" "status";
  }

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

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

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

  #nng-tools {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #nng-mode {
    grid-column: 1 / -1;
  }
}
