/* Pixelogic tokens: dark mode only changes these values. */
:root {
  --g-nonogram: #d9653b;
  --nono-cell: #ffffff;
  --nono-line: #dcdcd8;
  --nono-line-strong: #8e8e88;
  --nono-frame: #1b1b1b;
  --nono-ink: #262b36;
  --nono-cross: #9a9a93;
  --nono-clue-bg: #f4f3ef;
  --nono-clue-ink: #1b1b1b;
  --nono-key-bg: #f1f1ee;
  --nono-line-tint: #e3f1ee;
  --nono-on-accent: #ffffff;
}
:root[data-theme='dark'] {
  --g-nonogram: #f08a5d;
  --nono-cell: #1a1a1a;
  --nono-line: var(--board-grid);
  --nono-line-strong: #8a8a8a;
  --nono-frame: #f2f2f2;
  --nono-ink: #ecebe6;
  --nono-cross: #7c7c76;
  --nono-clue-bg: #232323;
  --nono-clue-ink: #f2f2f2;
  --nono-key-bg: #262626;
  --nono-line-tint: #1d3833;
  --nono-on-accent: #121212;
}

.nonogram-shell {
  --game-accent: var(--g-nonogram);
}
.nonogram-shell .shell-stage {
  /* Board at the top: a floating hint card then rarely covers it. */
  justify-content: flex-start;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4) 0;
}
.nonogram-shell .shell-board-area {
  display: flex;
  width: 100%;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
}
/* The wrapper takes a width; the board derives its cell size from it with container units. */
.nono-board-wrap {
  --span-w: calc(var(--cols) + var(--clue-w));
  --span-h: calc(var(--rows) + var(--clue-h));
  container-type: inline-size;
  width: min(calc(52px * var(--span-w)), calc(100vw - 32px), calc((100dvh - 300px) * var(--span-w) / var(--span-h)));
  margin: 0 auto;
}
.nono-board {
  --cell: calc(100cqw / var(--span-w));
  position: relative;
  display: grid;
  grid-template-columns: calc(var(--clue-w) * var(--cell)) repeat(var(--cols), var(--cell));
  grid-template-rows: calc(var(--clue-h) * var(--cell)) repeat(var(--rows), var(--cell));
  /* Painting must not scroll or zoom the page. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.nono-corner {
  grid-row: 1;
  grid-column: 1;
}
.nono-frame {
  z-index: 2;
  grid-row: 2 / -1;
  grid-column: 2 / -1;
  border: 2px solid var(--nono-frame);
  border-radius: 3px;
  pointer-events: none;
}

.nono-clue {
  display: flex;
  min-width: 0;
  min-height: 0;
  background: var(--nono-clue-bg);
  color: var(--nono-clue-ink);
  font: 700 clamp(9px, calc(var(--cell) * 0.46), 20px) / 1.1 var(--font-app);
  font-variant-numeric: tabular-nums;
  transition: opacity 200ms ease;
}
.nono-clue.row {
  align-items: center;
  justify-content: flex-end;
  gap: calc(var(--cell) * 0.16);
  padding-right: calc(var(--cell) * 0.2);
  border-bottom: 1px solid var(--nono-line);
  border-radius: 6px 0 0 6px;
}
.nono-clue.col {
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: calc(var(--cell) * 0.06);
  padding-bottom: calc(var(--cell) * 0.16);
  border-right: 1px solid var(--nono-line);
  border-radius: 6px 6px 0 0;
}
.nono-clue.done {
  opacity: 0.32;
}
.nono-clue.bad {
  color: var(--danger);
}
.nono-clue.hint-line {
  background: var(--nono-line-tint);
  box-shadow: inset 0 0 0 2px var(--hint-context);
  opacity: 1;
}

.nono-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--nono-line);
  border-bottom: 1px solid var(--nono-line);
  border-radius: 0;
  background: var(--nono-cell);
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nono-cell.edge-r {
  border-right-color: var(--nono-line-strong);
}
.nono-cell.edge-b {
  border-bottom-color: var(--nono-line-strong);
}
.nono-cell.on {
  background: var(--nono-ink);
}
.nono-cell.x::before,
.nono-cell.x::after,
.nono-cell.hint-cross::before,
.nono-cell.hint-cross::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56%;
  height: max(1.5px, 9%);
  border-radius: 2px;
  background: var(--nono-cross);
  content: '';
  transform: translate(-50%, -50%) rotate(45deg);
}
.nono-cell.x::after,
.nono-cell.hint-cross::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}
.nono-cell.hint-line:not(.on) {
  background: var(--nono-line-tint);
}
.nono-cell.hint-context {
  box-shadow: inset 0 0 0 3px var(--hint-context);
}
.nono-cell.hint-fill {
  background: color-mix(in srgb, var(--hint-target) 45%, var(--nono-cell));
  box-shadow: inset 0 0 0 2px var(--hint-target);
}
.nono-cell.hint-cross {
  box-shadow: inset 0 0 0 2px var(--hint-target);
}
.nono-cell.hint-cross::before,
.nono-cell.hint-cross::after {
  background: var(--hint-target);
}
.nono-cell.hint-wrong {
  box-shadow: inset 0 0 0 3px var(--danger);
}
.nono-cell:focus-visible {
  z-index: 3;
  outline: 0;
  box-shadow: inset 0 0 0 3px var(--game-accent);
}

/* Solved: the notes and the grid fade so the picture stands alone. */
.nono-board.solved .nono-cell {
  border-color: transparent;
  cursor: default;
}
.nono-board.solved .nono-cell.x::before,
.nono-board.solved .nono-cell.x::after {
  opacity: 0;
}
.nono-board.solved .nono-clue {
  opacity: 0.2;
}
.nono-board.solving .nono-cell.on {
  animation: nono-reveal 900ms ease-out;
}
@keyframes nono-reveal {
  40% {
    background: var(--game-accent);
  }
}
@media (prefers-reduced-motion: reduce) {
  .nono-board.solving .nono-cell.on {
    animation: none;
  }
}

.nono-status {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
}
.nono-status b {
  color: var(--text);
}
.nono-status.solved {
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}
.nono-status.solved b {
  color: var(--game-accent);
}
.nono-result-picture {
  margin: 0 0 var(--space-2);
  color: var(--game-accent);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}

/* Pen switch under the board. */
.nonogram-shell .shell-input {
  min-height: 0;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-4) var(--space-2);
}
.nono-modes {
  display: grid;
  width: min(320px, 100%);
  grid-template-columns: 1fr 1fr;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: 14px;
  background: var(--nono-key-bg);
}
.nono-mode {
  display: flex;
  height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: 600 15px var(--font-app);
  cursor: pointer;
}
.nono-mode.on {
  background: var(--game-accent);
  color: var(--nono-on-accent);
}
.nono-mode-glyph {
  position: relative;
  width: 16px;
  height: 16px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
}
.nono-mode-glyph.fill {
  background: currentColor;
}
.nono-mode-glyph.cross::before,
.nono-mode-glyph.cross::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  content: '';
  transform: translate(-50%, -50%) rotate(45deg);
}
.nono-mode-glyph.cross::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

/* Picture rules: mini boards drawn with the real clues and cells fill the demo stage. */
/* A one-row strip (with the pen switch under it) leaves room on its right for the ✓ or ✗. */
.nono-demo {
  container-type: inline-size;
  display: grid;
  width: 100%;
  box-sizing: border-box;
  gap: 8px;
  padding-right: 17%;
}
.nono-demo .nono-modes {
  width: 100%;
}
.nono-demo .nono-mode {
  height: 18.5cqw;
  font-size: 7cqw;
}
.nono-board-wrap.strip .shell-demo-mark {
  top: 50%;
  right: -42px;
  transform: translateY(-50%);
}
.shell-demo .nono-board-wrap {
  width: 100%;
}
.nono-demo-board {
  touch-action: auto;
}
.nono-demo-board .nono-cell,
.nono-demo .nono-mode {
  cursor: default;
}
