/* Nonogram — every selector is scoped to .g-nonogram */

.g-nonogram {
  --gn-ink: color-mix(in srgb, var(--accent) 62%, var(--text));
  --gn-line: color-mix(in srgb, var(--text) 18%, var(--surface));
  --gn-line5: color-mix(in srgb, var(--text) 64%, var(--surface));
  --gn-x: color-mix(in srgb, var(--text) 58%, var(--surface));
}
.g-nonogram [hidden] { display: none !important; }
.g-nonogram .gn-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- title bar + level picker ---------- */
.g-nonogram .gn-titlebar { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 0 0 10px; min-height: 40px; }
.g-nonogram .gn-title { font-weight: 900; font-size: 1.15rem; text-align: center; font-variant-numeric: tabular-nums; }
.g-nonogram .gn-nav { min-width: 44px; min-height: 40px; padding: 4px 0; font-size: 1.35rem; line-height: 1; }
.g-nonogram .gn-pick { min-height: 40px; min-width: 7.4em; font-size: 1.05rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.g-nonogram .gn-caret { display: inline-block; font-size: .8em; color: var(--muted); }
.g-nonogram .gn-pick[aria-expanded="true"] .gn-caret { transform: rotate(180deg); }
.g-nonogram .gn-picker { max-height: 252px; overflow-y: auto; padding: 3px; margin: 0 0 12px; }
.g-nonogram .gn-picker .pz-level { align-content: center; gap: 1px; padding: 0; line-height: 1.1; color: var(--text); font-family: inherit; }
.g-nonogram .gn-picker .pz-level small { font-size: .62rem; font-weight: 700; color: var(--muted); }
.g-nonogram .gn-picker .pz-level.done::after { content: "✓"; position: absolute; top: 3px; right: 6px; font-size: .62rem; line-height: 1; color: var(--accent); }

/* ---------- hud ---------- */
.g-nonogram .pz-hud { gap: 6px; }
.g-nonogram .pz-hud .pz-pill { padding: 5px 10px; font-size: .86rem; }

/* ---------- board ----------
   The script sets, on .gn-wrap:
     --cols / --rows   board size
     --gl / --gt       left / top clue gutters, measured in cells
     --f               clue font size as a fraction of one cell
     --cellmax         the biggest a cell may grow
   --u is one cell. It comes from the container width, so the whole board,
   clues included, always fits the space it is given. */
.g-nonogram .gn-wrap {
  container-type: inline-size;
  width: 100%;
  max-width: calc((var(--cols, 10) + var(--gl, 2.5)) * var(--cellmax, 38px));
  margin: 0 auto;
}
.g-nonogram .gn-building { min-height: 240px; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.g-nonogram .gn-board {
  --u: calc(100cqw / (var(--cols) + var(--gl)));
  --gn-xw: max(.7px, calc(var(--u) * .055));
  display: grid;
  grid-template-columns: calc(var(--gl) * var(--u)) minmax(0, 1fr);
  grid-template-rows: calc(var(--gt) * var(--u)) calc(var(--rows) * var(--u));
  font-size: min(calc(var(--u) * var(--f)), 20px);
  line-height: 1;
  touch-action: none;
  -webkit-touch-callout: none;
}

.g-nonogram .gn-corner {
  grid-column: 1; grid-row: 1;
  display: grid; place-items: center;
  font-size: 1.5em; font-weight: 900; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.g-nonogram .gn-top {
  grid-column: 2; grid-row: 1;
  display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  padding: 0 2px;
}
.g-nonogram .gn-left {
  grid-column: 1; grid-row: 2;
  display: grid; grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  padding: 2px 0;
}

/* clue chips */
.g-nonogram .gn-clue {
  display: flex; min-width: 0; min-height: 0; margin: 1px;
  border-radius: .32em; background: var(--surface-2); color: var(--text);
  font-weight: 800; font-variant-numeric: tabular-nums;
  transition: opacity .15s, background-color .15s;
}
.g-nonogram .gn-clue span { display: block; letter-spacing: -.05em; }
.g-nonogram .gn-ct { flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: .22em; }
.g-nonogram .gn-ct span { line-height: 1.1; }
.g-nonogram .gn-cl { flex-direction: row; justify-content: flex-end; align-items: center; gap: .42em; padding-right: .38em; white-space: nowrap; }
.g-nonogram .gn-ct.gn-v5 { margin-right: 2px; }
.g-nonogram .gn-cl.gn-h5 { margin-bottom: 2px; }
.g-nonogram .gn-clue.gn-hot { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
/* a satisfied line: its clue fades and loses its weight */
.g-nonogram .gn-clue.gn-ok { opacity: .4; font-weight: 500; }

/* the grid */
.g-nonogram .gn-grid {
  grid-column: 2; grid-row: 2;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  aspect-ratio: var(--cols) / var(--rows);
  width: 100%;
  border: 2px solid var(--gn-line5);
  border-radius: 5px;
  background: var(--surface);
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
}
.g-nonogram .gn-cell {
  min-width: 0; min-height: 0;
  border-right: 1px solid var(--gn-line);
  border-bottom: 1px solid var(--gn-line);
}
/* heavier rule every five cells */
.g-nonogram .gn-cell.gn-v5 { border-right: 2px solid var(--gn-line5); }
.g-nonogram .gn-cell.gn-h5 { border-bottom: 2px solid var(--gn-line5); }
.g-nonogram .gn-cell.gn-ve { border-right: 0; }
.g-nonogram .gn-cell.gn-he { border-bottom: 0; }

.g-nonogram .gn-cell.gn-f { background-color: var(--gn-ink); }
.g-nonogram .gn-cell.gn-x {
  background-image:
    linear-gradient(45deg, transparent calc(50% - var(--gn-xw)), var(--gn-x) calc(50% - var(--gn-xw)), var(--gn-x) calc(50% + var(--gn-xw)), transparent calc(50% + var(--gn-xw))),
    linear-gradient(-45deg, transparent calc(50% - var(--gn-xw)), var(--gn-x) calc(50% - var(--gn-xw)), var(--gn-x) calc(50% + var(--gn-xw)), transparent calc(50% + var(--gn-xw)));
  background-size: 62% 62%;
  background-position: center;
  background-repeat: no-repeat;
}
/* keyboard cursor: a ring, shown only while the keyboard is driving */
.g-nonogram .gn-grid.gn-kbd:focus .gn-cell.gn-cur { outline: 2px solid var(--warn); outline-offset: -2px; box-shadow: inset 0 0 0 3px var(--surface); }

/* solved: drop the marks and the rules so the picture stands alone */
.g-nonogram .gn-board.gn-done .gn-grid { cursor: default; }
.g-nonogram .gn-board.gn-done .gn-cell { border-color: transparent; transition: border-color .3s; }
.g-nonogram .gn-board.gn-done .gn-cell.gn-x { background-image: none; }

/* ---------- tools ---------- */
.g-nonogram .gn-toolrow { margin: 14px 0 8px; flex-wrap: nowrap; }
.g-nonogram .gn-tool { flex: 1 1 0; max-width: 170px; padding-left: 12px; padding-right: 12px; }
/* the active tool also gets a ring, so it is not told apart by colour alone */
.g-nonogram .gn-tool.on { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 32%, transparent); }
.g-nonogram .gn-ico { display: inline-block; flex: none; font-weight: 900; line-height: 1; }
.g-nonogram .gn-ico-f { width: .78em; height: .78em; border-radius: 2px; background: currentColor; }
.g-nonogram .gn-actrow { margin: 8px 0; }
.g-nonogram .gn-act { min-height: 40px; }

.g-nonogram .gn-note { margin: 8px 0 4px; }
.g-nonogram .gn-note.gn-bad { color: var(--bad); font-weight: 700; }
.g-nonogram .gn-note.gn-good { color: var(--good); font-weight: 700; }
.g-nonogram .gn-after { margin-bottom: 0; }

@media (prefers-reduced-motion: reduce) {
  .g-nonogram .gn-clue,
  .g-nonogram .gn-board.gn-done .gn-cell { transition: none; }
}
