/* Nonogram board. Theme tokens come from the page (--bg, --fg, --ink, --line, --line5, --accent, --hl ...). */
.np {
  --cs: 24px;
  --ink: var(--np-ink, #1f2430);
  --paper: var(--np-paper, #ffffff);
  --gl: var(--np-line, #d5d9e2);
  --gl5: var(--np-line5, #6b7c99);
  --cluebg: var(--np-cluebg, #f3f5f9);
  --clue: var(--np-clue, #1f2430);
  --done: var(--np-done, #b3bac8);
  --hlc: var(--np-hl, rgba(58, 116, 255, .10));
  --acc: var(--np-accent, #3a6df0);
  --err: #e5484d;
  --fs: max(10px, calc(var(--cs) * .56));
  position: relative;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  width: 100%; max-width: 100%;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.np [hidden] { display: none !important; }
.np-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.np-info { display: flex; gap: 10px; align-items: baseline; font-weight: 600; color: var(--clue); }
.np-size { font-size: 15px; letter-spacing: .02em; }
.np-time { font-size: 15px; opacity: .7; min-width: 3.5em; }
.np-acts { display: flex; gap: 4px; flex-wrap: wrap; }
.np-b {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--gl); background: var(--paper); color: var(--clue); cursor: pointer; padding: 0;
  transition: background .12s, transform .08s;
}
.np-b:hover { background: var(--cluebg); }
.np-b:active { transform: scale(.94); }
.np-b:focus-visible, .np-mode:focus-visible, .np-sw:focus-visible { outline: 3px solid var(--acc); outline-offset: 2px; }

.np-msg { min-height: 0; font-size: 14px; line-height: 1.4; border-radius: 10px; padding: 0 12px; max-height: 0; overflow: hidden; transition: max-height .2s, padding .2s; }
.np-msg.on { max-height: 120px; padding: 8px 12px; background: var(--cluebg); color: var(--clue); }
.np-msg[data-kind="hint"] { background: color-mix(in srgb, var(--acc) 12%, var(--paper)); }
.np-msg[data-kind="warn"] { background: color-mix(in srgb, var(--err) 12%, var(--paper)); }
.np-msg[data-kind="ok"] { background: color-mix(in srgb, #2fa86b 14%, var(--paper)); }

.np-scroll {
  overflow: auto; max-width: 100%; overscroll-behavior: contain;
  border-radius: 12px; align-self: center;
  max-height: calc(100vh - 120px); max-height: calc(100dvh - 120px);
  scrollbar-width: thin;
}
.np-board {
  display: grid;
  grid-template-columns: max-content calc(var(--w) * var(--cs));
  grid-template-rows: max-content calc(var(--h) * var(--cs));
  background: var(--paper);
  width: max-content;
}
.np-corner { position: sticky; left: 0; top: 0; z-index: 3; background: var(--paper); display: grid; place-items: end; padding: 4px; }
.np-count { font-weight: 700; font-size: calc(var(--fs) * 1.25); color: var(--acc); opacity: 0; transition: opacity .1s; }
.np-count.on { opacity: 1; }

/* column clues */
.np-cols { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: repeat(var(--w), var(--cs)); background: var(--paper); border-bottom: 2px solid var(--gl5); }
.np-cc {
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 1px;
  padding: 4px 0 3px; background: var(--cluebg); border-right: 1px solid var(--gl);
  font-size: var(--fs); line-height: 1.05; color: var(--clue); font-weight: 600; min-height: calc(var(--cs) * 1.2);
}
.np-cc.np-m { border-right: 2px solid var(--gl5); }
.np-cc:nth-child(even) { background: color-mix(in srgb, var(--cluebg) 70%, var(--paper)); }
/* row clues */
.np-rows { position: sticky; left: 0; z-index: 2; display: grid; grid-template-rows: repeat(var(--h), var(--cs)); background: var(--paper); border-right: 2px solid var(--gl5); }
.np-rc {
  display: flex; justify-content: flex-end; align-items: center; gap: calc(var(--cs) * .22);
  padding: 0 calc(var(--cs) * .25) 0 8px; background: var(--cluebg); border-bottom: 1px solid var(--gl);
  font-size: var(--fs); color: var(--clue); font-weight: 600; white-space: nowrap;
}
.np-rc.np-m { border-bottom: 2px solid var(--gl5); }
.np-rc:nth-child(even) { background: color-mix(in srgb, var(--cluebg) 70%, var(--paper)); }
.np-cc .np-n2 { font-size: .8em; letter-spacing: -.06em; }
.np-n { min-width: .7em; text-align: center; transition: color .15s, opacity .15s; }
.np-cn { background: var(--k); color: var(--kt); border-radius: 3px; min-width: calc(var(--cs) * .66); padding: 0 1px; line-height: 1.15; }
.np-cc .np-cn { width: calc(var(--cs) * .78); }
.np-n.np-x { color: var(--done); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.np-cn.np-x { opacity: .32; text-decoration: none; }
.np-rc.np-done, .np-cc.np-done { background: var(--paper); }
.np-hl { box-shadow: inset 0 0 0 999px var(--hlc); }
.np-hint { animation: np-pulse 1s ease-in-out 3; }
@keyframes np-pulse { 50% { box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--acc) 30%, transparent); } }
.np-bad .np-n { color: var(--err); }

/* cells */
.np-cells {
  position: relative; display: grid; grid-template-columns: repeat(var(--w), var(--cs)); grid-auto-rows: var(--cs);
  touch-action: none; cursor: crosshair; outline: none; background: var(--paper);
}
.np-c { border-right: 1px solid var(--gl); border-bottom: 1px solid var(--gl); position: relative; transition: background-color .06s; }
.np-c.np-vr { border-right: 2px solid var(--gl5); }
.np-c.np-hr { border-bottom: 2px solid var(--gl5); }
.np-c[data-s="f"] { background: var(--k, var(--ink)); }
.np-c[data-s="x"]::after {
  content: ''; position: absolute; inset: 22%;
  background:
    linear-gradient(45deg, transparent calc(50% - 1px), var(--np-x, #8a93a6) calc(50% - 1px), var(--np-x, #8a93a6) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(-45deg, transparent calc(50% - 1px), var(--np-x, #8a93a6) calc(50% - 1px), var(--np-x, #8a93a6) calc(50% + 1px), transparent calc(50% + 1px));
}
.np-small .np-c[data-s="x"]::after { inset: 30%; }
.np-c[data-s="d"]::after { content: ''; position: absolute; inset: 38%; border-radius: 50%; background: var(--np-x, #8a93a6); }
.np-c.np-err { box-shadow: inset 0 0 0 2px var(--err); }
.np-c.np-err[data-s="x"]::after { --np-x: var(--err); }
.np-flash-err { animation: np-err 0.7s ease-in-out 3; }
@keyframes np-err { 50% { box-shadow: inset 0 0 0 3px var(--err); background-color: color-mix(in srgb, var(--err) 25%, transparent); } }
.np-flash-hint { animation: np-hintc 0.7s ease-in-out 3; }
@keyframes np-hintc { 50% { box-shadow: inset 0 0 0 3px var(--acc); } }
/* crosshair highlight of the hovered row and column */
.np.np-hov .np-cells::before, .np.np-hov .np-cells::after { content: ''; position: absolute; pointer-events: none; background: var(--hlc); z-index: 1; }
.np.np-hov .np-cells::before { left: 0; right: 0; top: calc(var(--hy) * var(--cs)); height: var(--cs); }
.np.np-hov .np-cells::after { top: 0; bottom: 0; left: calc(var(--hx) * var(--cs)); width: var(--cs); }
.np-cursor { position: absolute; left: calc(var(--x) * var(--cs)); top: calc(var(--y) * var(--cs)); width: var(--cs); height: var(--cs); box-shadow: 0 0 0 3px var(--acc); border-radius: 2px; pointer-events: none; z-index: 2; }

/* tools */
.np-tools { display: flex; justify-content: center; }
.np-modes { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; background: var(--cluebg); padding: 6px; border-radius: 16px; }
.np-mode {
  display: inline-flex; align-items: center; gap: 8px; height: 48px; min-width: 96px; padding: 0 16px; border-radius: 12px;
  border: 2px solid transparent; background: var(--paper); color: var(--clue); font: inherit; font-weight: 600; cursor: pointer; justify-content: center;
}
.np-mode[aria-checked="true"] { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 10%, var(--paper)); }
.np-ico-fill { width: 18px; height: 18px; border-radius: 3px; background: var(--ink); display: inline-block; }
.np-sw { width: 48px; height: 48px; border-radius: 12px; border: 2px solid transparent; background: var(--paper); cursor: pointer; display: grid; place-items: center; padding: 0; }
.np-sw span { width: 30px; height: 30px; border-radius: 8px; background: var(--k); box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.np-sw[aria-pressed="true"] { border-color: var(--acc); }
.np-sw[aria-pressed="true"] span { transform: scale(1.08); }

/* solved */
.np-solved .np-c { border-color: transparent !important; transition: border-color .6s, background-color .4s; }
.np-solved .np-cells { cursor: default; animation: np-pop .6s ease-out; }
.np-solved .np-cells::before, .np-solved .np-cells::after { display: none; }
@keyframes np-pop { 40% { transform: scale(1.035); } }
.np-solved .np-tools, .np-solved .np-acts .np-b:not(.np-zoom) { opacity: .35; pointer-events: none; }

@media (pointer: coarse) {
  .np-b { width: 44px; height: 44px; }
  .np-cells { cursor: default; }
}
@media (prefers-reduced-motion: reduce) {
  .np * { animation: none !important; transition: none !important; }
}

/* desktop: one compact unit centred on the page. Action bar on top (as wide as the puzzle), tool palette to the left
   of the board, both sticking near the board instead of spreading across the page. */
.np.np-wide {
  display: grid; grid-template-columns: auto auto; justify-content: center; align-content: start; column-gap: 16px; row-gap: 10px;
  grid-template-areas: "bar bar" "msg msg" "tools board" "won won";
}
.np-wide .np-bar { grid-area: bar; }
.np-wide .np-msg { grid-area: msg; }
.np-wide .np-scroll { grid-area: board; align-self: start; }
.np-wide .np-tools { grid-area: tools; align-self: start; position: sticky; top: 74px; }
.np-wide .np-won { grid-area: won; }
.np-wide .np-modes { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.np-wide .np-mode { justify-content: flex-start; min-width: 112px; }
.np-wide .np-sw { width: 100%; }
