/* Notan: a quiet nonogram. Black, white and grays only; the board is the page.
 * Chrome follows Hexsweeper's sphere: a tiny mono readout at top center and
 * bare line icons in the bottom corners. */

@font-face {
  font-family: "Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/IBMPlexMono-500.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/IBMPlexSans-400.woff2") format("woff2");
}

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --ink: #000000;
  --text: #111111;
  --sub: #5e5e5e;
  --done: #949494;
  --line: #d4d4d4;
  --guide: #8f8f8f;
  --frame: #1c1c1c;
  --mark: #8a8a8a;
  --band: rgba(0, 0, 0, 0.05);
  --icon: #262626;
  --scrim: rgba(255, 255, 255, 0.84);
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --ink: #ffffff;
    --text: #ededed;
    --sub: #a6a6a6;
    --done: #5e5e5e;
    --line: #2f2f2f;
    --guide: #6c6c6c;
    --frame: #e4e4e4;
    --mark: #7c7c7c;
    --band: rgba(255, 255, 255, 0.07);
    --icon: #dddddd;
    --scrim: rgba(0, 0, 0, 0.8);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

button { font: inherit; color: inherit; }

/* ---------- top readout ---------- */
.hud {
  position: fixed;
  top: max(6px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font: 500 13px/1 var(--mono);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--sub);
  white-space: nowrap;
}
.hud svg { width: 14px; height: 14px; flex: none; }
.hud-lvl {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--sub);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.hud-lvl:hover { color: var(--text); }
.hud-time { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0 10px; min-width: 6ch; }

/* ---------- board ---------- */
.board {
  position: absolute;
  --cell: 32px;
  --f: 13px;
  --cw: 40px;
  --ch: 40px;
  --dot: 5px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  transition: transform 0.7s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.board.instant, .board.instant * , .board.instant *::before, .board.instant *::after { transition: none !important; }
.band {
  position: absolute;
  background: var(--band);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.cursor {
  position: absolute;
  z-index: 3;
  width: var(--cell);
  height: var(--cell);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 1px var(--bg), inset 0 0 0 1px var(--bg);
  pointer-events: none;
  display: none;
}
.cursor.on { display: block; }

.grid { position: relative; z-index: 1; }
.gr { display: flex; }
.corner { flex: none; width: var(--cw); height: var(--ch); }

.clue {
  flex: none;
  display: flex;
  font: 500 var(--f)/1.18 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color 0.3s, opacity 0.5s;
  position: relative;
}
.cc {
  width: var(--cell);
  height: var(--ch);
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: calc(var(--f) * 0.4);
}
.rc {
  width: var(--cw);
  height: var(--cell);
  justify-content: flex-end;
  align-items: center;
  gap: calc(var(--f) * 0.5);
  padding-right: calc(var(--f) * 0.55);
}
.clue.ok { color: var(--done); }
/* Each number fades on its own once its run is finished, and pops once as it does. */
.clue span { display: inline-block; transition: color 0.3s; }
.clue span.n-done { color: var(--done); }
.clue span.pop { animation: clue-pop 0.45s ease-out; }
@keyframes clue-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); color: var(--text); }
  100% { transform: scale(1); }
}
/* A line that can't work as marked gets a short dashed tick beside it. */
.clue.bad::after {
  content: "";
  position: absolute;
  border: 0 dashed var(--text);
}
.cc.bad::after { left: 25%; right: 25%; bottom: 2px; border-bottom-width: 1px; }
.rc.bad::after { top: 25%; bottom: 25%; right: 2px; border-right-width: 1px; }

.cell {
  flex: none;
  position: relative;
  width: var(--cell);
  height: var(--cell);
  --lt: transparent;
  --ll: transparent;
  --lr: var(--line);
  --lb: var(--line);
  box-shadow:
    inset -1px 0 0 var(--lr),
    inset 0 -1px 0 var(--lb),
    inset 1px 0 0 var(--ll),
    inset 0 1px 0 var(--lt);
  outline: none;
  cursor: pointer;
  transition: box-shadow 0.6s;
}
.cell.gx { --lr: var(--guide); }
.cell.gy { --lb: var(--guide); }
.cell.t { --lt: var(--frame); }
.cell.l { --ll: var(--frame); }
.cell.rt { --lr: var(--frame); }
.cell.bt { --lb: var(--frame); }
.cell::before {
  content: "";
  position: absolute;
  left: 0; top: 0; right: 1px; bottom: 1px;
  background: var(--ink);
  transform: scale(0);
  transition: transform 0.12s ease-out, right 0.6s, bottom 0.6s, top 0.6s, left 0.6s;
}
.cell.t::before { top: 1px; }
.cell.l::before { left: 1px; }
.cell.ink::before { transform: scale(1); }
.cell::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: var(--dot); height: var(--dot);
  margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2);
  border-radius: 50%;
  background: var(--mark);
  opacity: 0;
  transition: opacity 0.12s;
}
.cell.mark::after { opacity: 1; }
/* Level 1, first visit: a faint fill grows and fades in one square until the first move. */
.cell.nudge::before { animation: nudge 1.8s ease-in-out 0.2s infinite; }
@keyframes nudge {
  0%, 100% { transform: scale(0); opacity: 0.28; }
  50% { transform: scale(0.62); opacity: 0.28; }
}

/* Solved: the lines, marks and clues go; the picture stays and moves to center. */
.board { transform-origin: 0 0; }
.board.solved { --line: transparent; --guide: transparent; --frame: transparent; transform: var(--solved); }
.board.solved .cell { cursor: default; }
/* Fills overlap by a pixel so the scaled picture shows no seams. */
.board.solved .cell::before { top: 0; left: 0; right: -1px; bottom: -1px; }
.board.solved .cell::after,
.board.solved .clue,
.board.solved .band,
.board.solved .cursor { opacity: 0; }

.caption {
  position: absolute;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.6s 0.5s;
  pointer-events: none;
}
.caption[hidden] { display: none; }
.caption.show { opacity: 1; pointer-events: auto; }
.caption p { margin: 0; font: 500 13px/1.3 var(--mono); letter-spacing: 0.04em; color: var(--sub); }

/* ---------- corner icons ---------- */
.bar {
  position: fixed;
  left: max(6px, env(safe-area-inset-left));
  right: max(6px, env(safe-area-inset-right));
  bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.group { display: flex; gap: 2px; pointer-events: auto; }
.ib {
  appearance: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--icon);
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s, transform 0.1s;
}
.ib svg { width: 24px; height: 24px; }
.ib:active { transform: scale(0.94); }
.ib[aria-disabled="true"] { opacity: 0.32; cursor: default; }
.ib:focus-visible,
.hud-lvl:focus-visible,
.lv:focus-visible,
.pill:focus-visible,
.sheet-x:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}
@media (hover: hover) {
  .ib:hover:not([aria-disabled="true"]) { background: var(--band); }
}

/* ---------- sheets ---------- */
dialog.sheet {
  width: min(23rem, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--frame);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  overflow: auto;
}
dialog.sheet::backdrop { background: var(--scrim); }
.sheet-in {
  position: relative;
  padding: 22px 22px 20px;
  font: 400 14px/1.55 var(--sans);
}
.sheet h2 {
  margin: 0 0 14px;
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sub);
}
.sheet h3 {
  margin: 18px 0 10px;
  font: 500 12px/1 var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sub);
}
.sheet p { margin: 0 0 12px; }
.sheet h2:focus { outline: none; }
.sheet-x {
  position: absolute;
  top: 6px; right: 6px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  padding: 0; border: 0; border-radius: 6px;
  background: none;
  color: var(--icon);
  cursor: pointer;
}
.sheet-x svg { width: 20px; height: 20px; }

.eg { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.eg li { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.eg-row { display: flex; align-items: center; gap: 8px; }
.eg-clue { font: 500 13px/1 var(--mono); min-width: 2.4em; text-align: right; }
.eg-cells { display: flex; border: 1px solid var(--frame); }
.eg-cells i { width: 16px; height: 16px; border-right: 1px solid var(--line); position: relative; }
.eg-cells i:last-child { border-right: 0; }
.eg-cells i.on { background: var(--ink); border-right-color: var(--ink); }
.eg-cells i.q::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 4px; height: 4px; margin: -2px 0 0 -2px; border-radius: 50%; background: var(--mark);
}
.eg-note { font-size: 13px; line-height: 1.4; color: var(--sub); }

.keys { list-style: none; margin: 0 0 16px; padding: 0; font-size: 13px; color: var(--sub); }
.keys li { padding: 3px 0; }
.keys b { font: 500 12px var(--mono); color: var(--text); }

.pill {
  appearance: none;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid var(--frame);
  border-radius: 999px;
  background: none;
  color: var(--text);
  font: 500 13px/1 var(--mono);
  letter-spacing: 0.04em;
  cursor: pointer;
}
.pill[aria-current="true"] { background: var(--ink); color: var(--bg); }

/* quiet footer of the ? sheet: erase progress, and home */
.sheet-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 16px; margin-top: 20px; padding-top: 8px; border-top: 1px solid var(--frame); }
.foot-btn { appearance: none; background: none; border: 0; padding: 0; min-height: 44px; display: inline-flex; align-items: center; color: var(--sub); font: 400 12px/1.2 var(--mono); letter-spacing: 0.03em; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.foot-btn[data-armed="true"] { color: var(--text); font-weight: 500; }
.foot-btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.lv-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
}
.lv {
  appearance: none;
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: none;
  color: var(--sub);
  font: 500 11px/1 var(--mono);
  cursor: pointer;
}
.lv svg { width: 70%; height: 70%; fill: var(--ink); }
.lv[aria-current="true"] { border-color: var(--frame); color: var(--text); box-shadow: inset 0 0 0 1px var(--frame); }
.sizes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.sizes .pill { padding: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
  .cell.nudge::before { transform: scale(0.62); opacity: 0.2; }
}
@media (forced-colors: active) {
  :root { --ink: CanvasText; --text: CanvasText; --bg: Canvas; --line: GrayText; --guide: GrayText; --frame: CanvasText; --mark: CanvasText; --done: GrayText; --icon: ButtonText; }
  .board, .eg-cells, .lv svg { forced-color-adjust: none; }
  .cursor { border-color: Highlight; }
}
