.ng-page {
  --ng-fill: #3a2e5a;
  --ng-fill-solved: #6d28d9;
  --ng-cross: #8b7fb0;
  --ng-grid-line: #d9d0ee;
  --ng-grid-strong: #2a2142;
  --ng-cell-bg: #fffdff;
  --ng-line: #f1eaff;
  --ng-clue-text: #2a1d4a;
  --ng-clue-bg: #f6f2ff;
  --ng-clue-active: #fde68a;
  --ng-given: #6d28d9;
  --ng-bad: #dc2626;
  --ng-bad-bg: #fde4e4;
}
[data-theme="dark"] .ng-page {
  --ng-fill: #e9e1ff;
  --ng-fill-solved: #c4b5fd;
  --ng-cross: #8d81b5;
  --ng-grid-line: #3d3360;
  --ng-grid-strong: #0d0914;
  --ng-cell-bg: #2f2747;
  --ng-line: #3b3159;
  --ng-clue-text: #f4efff;
  --ng-clue-bg: rgba(22, 16, 40, 0.62);
  --ng-clue-active: #fcd34d;
  --ng-given: #c4b5fd;
  --ng-bad: #fca5a5;
  --ng-bad-bg: #4a1d2a;
}

.ng-shell {
  max-width: 960px;
  margin: 0 auto;
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 16px;
  padding: 1rem;
  background: transparent;
}
/* Desktop: [title · coins] on the left, actions on the right. */
.ng-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.ng-head__bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1 1 auto;
  min-width: 0;
}
.ng-title {
  flex: 0 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.55rem;
}
/* The focus toggle only exists at tablet/phone widths (play-focus.css); keep it last in the bar. */
.ng-head__bar .word-search-game-shell__expand-btn {
  order: 0;
  flex: 0 0 auto;
  margin: 0;
}
.ng-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.ng-label-short {
  display: none;
}
.ng-head__bar .pv-coin-chip {
  flex: 0 0 auto;
  box-sizing: border-box;
  border-radius: 12px;
  min-height: 40px;
  padding: 0 0.75rem;
  border: 1px solid color-mix(in srgb, var(--accent-strong) 35%, var(--border));
  background: transparent;
  font-size: 0.95rem;
  font-weight: 700;
}


/* Desktop: the chips stack in the side panel so the board can start higher up. */
.ng-stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.4rem;
}
.ng-chip {
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 10px;
  padding: 0.45rem 0.6rem;
  background: var(--surface-strong);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  font-size: 0.92rem;
}

.ng-play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 1rem;
  align-items: start;
}

/* --- Board ---
   [corner | column clues]
   [row clues | grid      ]  — --ng-cell is set by nonogram.js to fit the space. */
.ng-board-wrap {
  position: relative;
  min-width: 0;
  overflow-x: auto;
  /* The board and the solved card share one grid cell: the card sits centred on the board,
     and on a small board (5x5) the cell grows to fit the card instead of scrolling it. */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.ng-board-wrap > .ng-board,
.ng-board-wrap > .ng-win {
  grid-area: 1 / 1;
}
.ng-board-wrap > .ng-board {
  align-self: start;
}
.ng-board {
  --ng-cell: 28px;
  /* Never below 12px: on a 20x20 phone board the cells are smaller than readable text. */
  --ng-clue-font: clamp(12px, calc(var(--ng-cell) * 0.6), 22px);
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  width: max-content;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  font-variant-numeric: tabular-nums;
}
.ng-colclues {
  display: grid;
  grid-template-columns: repeat(var(--ng-cols), var(--ng-cell));
  align-items: end;
  padding-left: 2px; /* line up with the grid's outer border */
}
.ng-rowclues {
  display: grid;
  grid-template-rows: repeat(var(--ng-rows), var(--ng-cell));
  padding-top: 2px;
}
.ng-clue {
  display: flex;
  color: var(--ng-clue-text);
  font-size: var(--ng-clue-font);
  font-weight: 800;
  line-height: 1.1;
  transition: background-color 0.12s ease, opacity 0.15s ease, color 0.15s ease;
}
.ng-clue--col {
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  padding: 0.25em 0 0.3em;
  border-radius: 6px 6px 0 0;
}
/* Two digits stacked in a column must still fit one cell's width. */
.ng-clue__wide {
  font-size: 0.82em;
  letter-spacing: -0.06em;
}
.ng-clue--row {
  align-items: center;
  justify-content: flex-end;
  gap: 0.3em;
  padding: 0 0.4em 0 0.4em;
  border-radius: 6px 0 0 6px;
}
.ng-clue:nth-child(even) {
  background: var(--ng-clue-bg);
}
.ng-clue--col.is-c5 {
  box-shadow: inset -1px 0 0 var(--ng-grid-line);
}
.ng-clue--row.is-r5 {
  box-shadow: inset 0 -1px 0 var(--ng-grid-line);
}
.ng-clue.is-active {
  background: var(--ng-clue-active);
  color: #22133f;
}
.ng-clue.is-done {
  opacity: 0.38;
}
.ng-clue.is-bad {
  color: var(--ng-bad);
  opacity: 1;
}

.ng-grid {
  display: grid;
  grid-template-columns: repeat(var(--ng-cols), var(--ng-cell));
  grid-template-rows: repeat(var(--ng-rows), var(--ng-cell));
  border: 2px solid var(--ng-grid-strong);
  border-radius: 4px;
  background: var(--ng-cell-bg);
  /* Drag-to-paint needs the pointer, so the page does not scroll while drawing on the grid. */
  touch-action: none;
  outline: none;
}
.ng-grid:focus-visible {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
}
.ng-cell {
  box-sizing: border-box;
  position: relative;
  border-right: 1px solid var(--ng-grid-line);
  border-bottom: 1px solid var(--ng-grid-line);
  background-color: var(--ng-cell-bg);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 58% 58%;
  cursor: pointer;
  transition: background-color 0.1s ease;
}
.ng-cell.is-c5 {
  border-right: 2px solid var(--ng-grid-strong);
}
.ng-cell.is-r5 {
  border-bottom: 2px solid var(--ng-grid-strong);
}
.ng-cell.is-clast {
  border-right: 0;
}
.ng-cell.is-rlast {
  border-bottom: 0;
}
.ng-cell.is-line {
  background-color: var(--ng-line);
}
.ng-cell.ng-cell--filled {
  background-color: var(--ng-fill);
}
.ng-cell.ng-cell--crossed {
  background-image:
    linear-gradient(45deg, transparent calc(50% - 1.2px), var(--ng-cross) calc(50% - 1.2px), var(--ng-cross) calc(50% + 1.2px), transparent calc(50% + 1.2px)),
    linear-gradient(-45deg, transparent calc(50% - 1.2px), var(--ng-cross) calc(50% - 1.2px), var(--ng-cross) calc(50% + 1.2px), transparent calc(50% + 1.2px));
}
.ng-cell.ng-cell--given.ng-cell--filled {
  background-color: var(--ng-given);
}
.ng-cell.ng-cell--given.ng-cell--crossed {
  --ng-cross: var(--ng-given);
}
@media (hover: hover) {
  .ng-cell:hover {
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 70%, transparent);
  }
}
/* The keyboard cursor only shows after an arrow key, not on every tap. */
.ng-board--kbd .ng-cell.is-cursor {
  box-shadow: inset 0 0 0 3px var(--accent);
  z-index: 1;
}
.ng-cell.ng-wrong {
  animation: ng-wrong-flash 2s ease-out;
}
@keyframes ng-wrong-flash {
  0%, 70% { background-color: var(--ng-bad-bg); box-shadow: inset 0 0 0 3px var(--ng-bad); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}
.ng-cell.ng-hint-flash {
  animation: ng-hint-pulse 1.6s ease-out;
}
@keyframes ng-hint-pulse {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; }
  18%, 42% { box-shadow: inset 0 0 0 3px var(--accent); }
}

/* Solved: drop the marks and grid lines so the picture stands on its own. */
.ng-board--solved .ng-cell {
  cursor: default;
  border-color: transparent;
  background-image: none;
  background-color: var(--ng-cell-bg);
  transition: background-color 0.6s ease, border-color 0.6s ease;
}
.ng-board--solved .ng-cell.ng-cell--filled {
  background-color: var(--ng-fill-solved);
}
.ng-board--solved .ng-cell:hover {
  box-shadow: none;
}
.ng-board--solved .ng-clue {
  opacity: 0.38;
  background: transparent;
}

/* --- Side panel --- */
.ng-side {
  display: grid;
  gap: 0.6rem;
}
.ng-modes,
.ng-tools {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}
/* Mode and tool buttons take their look from tactile-buttons.css; only sizes live here. */
.ng-modes .ng-mode {
  gap: 0.45rem;
  min-height: 52px;
  font-size: 1.02rem;
}
.ng-mode__ico {
  display: inline-grid;
  place-items: center;
  width: 1.05em;
  height: 1.05em;
  flex: 0 0 auto;
  line-height: 1;
}
.ng-mode__ico--fill {
  border-radius: 3px;
  background: var(--ng-fill);
}
.ng-mode__ico--cross {
  color: var(--ng-cross);
  font-weight: 900;
}

.ng-status {
  margin-top: 0.75rem;
  border: 1px solid rgba(56, 28, 109, 0.2);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  min-height: 44px;
  background: var(--surface-strong);
}
.ng-how {
  margin-top: 0.7rem;
  color: var(--text-muted);
  font-size: 0.93rem;
  line-height: 1.55;
}

/* --- Win overlay --- */
.ng-win {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(86%, 450px);
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.32) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.24) 0 20px, transparent 21px),
    radial-gradient(circle at 84% 82%, rgba(132, 214, 255, 0.22) 0 22px, transparent 23px),
    rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 34px rgba(36, 24, 85, 0.18);
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.45;
  color: #22133f;
  display: none;
  pointer-events: none;
  z-index: 6;
}
.ng-win.is-visible {
  display: block;
  pointer-events: auto;
  animation: ng-pop 0.55s ease-out;
}
@media (max-width: 560px) {
  /* Phones: tighten the solved card so the streak line and app prompt fit on the board. */
  .ng-win {
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    line-height: 1.32;
  }
  .ng-win .ng-win__title {
    font-size: 1rem;
  }
  .ng-win .ng-win__btn {
    margin-top: 0.45rem;
    min-height: 36px;
    padding: 0.25rem 0.75rem;
  }
  .ng-win .pv-win-streak {
    margin-top: 0.4rem;
  }
  .ng-win .pv-win-streak__line {
    font-size: 0.88rem;
  }
  .ng-win .pv-win-streak__next {
    margin-top: 0.1rem;
    font-size: 0.78rem;
  }
  .ng-win .pv-win-streak__share {
    margin-top: 0.3rem;
    padding: 0.18rem 0.75rem;
    font-size: 0.78rem;
  }
  .ng-win .pv-app-win-promo__title {
    font-size: 0.9rem;
  }
  .ng-win .pv-app-win-promo__text {
    margin: 0.05rem 0 0.3rem;
    font-size: 0.78rem;
  }
  .ng-win .pv-app-win-promo__badge img {
    height: 36px;
  }
  .ng-win .pv-app-win-promo__dismiss {
    margin-top: 0;
    padding: 0.1rem 0.4rem;
    font-size: 0.78rem;
  }
  /* When the app prompt is up, skip the next-game hint (the home strip and other wins show it). */
  .ng-win:has(.pv-app-win-promo:not([hidden])) .pv-win-streak__next {
    display: none;
  }
  .ng-win:has(.pv-app-win-promo:not([hidden])) .pv-win-streak__share {
    margin-top: 0.2rem;
    padding: 0.12rem 0.75rem;
  }
  /* Badge and "Not now" share one row instead of stacking. */
  .ng-win .pv-app-win-promo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: 0.7rem;
    margin-top: 0.35rem;
    padding-top: 0.3rem;
  }
  .ng-win .pv-app-win-promo__title,
  .ng-win .pv-app-win-promo__text {
    flex-basis: 100%;
  }
  /* Nonogram's board is a little shorter than Kakuro's: trim a few more pixels when the prompt shows. */
  .ng-win:has(.pv-app-win-promo:not([hidden])) {
    padding: 0.5rem 0.7rem;
    line-height: 1.25;
  }
  .ng-win:has(.pv-app-win-promo:not([hidden])) .ng-win__btn {
    margin-top: 0.35rem;
    min-height: 32px;
  }
  .ng-win:has(.pv-app-win-promo:not([hidden])) .pv-win-streak {
    margin-top: 0.3rem;
  }
  .ng-win .pv-app-win-promo {
    margin-top: 0.3rem;
    padding-top: 0.25rem;
  }
  .ng-win .pv-app-win-promo__text {
    margin-bottom: 0.2rem;
  }
  .ng-win .pv-app-win-promo__badge img {
    height: 32px;
  }
}
.ng-win__title,
.ng-win__detail {
  margin: 0;
}
.ng-win__title {
  font-weight: 800;
  font-size: 1.1rem;
}
.ng-win__detail + .ng-win__detail {
  margin-top: 0.2rem;
}
.ng-win__btn {
  margin-top: 0.65rem;
  width: 100%;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background: var(--surface-strong, #fff);
  border-radius: 10px;
  min-height: 40px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  color: #22133f;
}
@keyframes ng-pop {
  0% { opacity: 0; transform: translateY(8%) scale(0.94); }
  100% { opacity: 1; transform: none; }
}
[data-theme="dark"] .ng-win {
  border-color: rgba(185, 160, 255, 0.62);
  color: #f2f5ff;
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.24) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.18) 0 20px, transparent 21px),
    rgba(20, 24, 48, 0.94);
  box-shadow: 0 14px 36px rgba(4, 6, 18, 0.5);
}
[data-theme="dark"] .ng-win__btn {
  color: #f2f5ff;
  border-color: rgba(185, 160, 255, 0.45);
  background: rgba(31, 38, 72, 0.85);
}

/* --- Stats dialog --- */
.ng-stats-dialog {
  width: min(560px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1rem 1.1rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow-md);
}
.ng-stats-dialog::backdrop {
  background: rgba(18, 12, 26, 0.45);
}
.ng-stats-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.ng-stats-dialog__title {
  margin: 0;
  font-size: 1.2rem;
}
.ng-stats-dialog__close {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  min-width: var(--tap-target);
  min-height: var(--tap-target);
}
.ng-stats-dialog__table-wrap {
  overflow-x: auto;
}
.ng-stats-dialog__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  font-variant-numeric: tabular-nums;
}
.ng-stats-dialog__table th,
.ng-stats-dialog__table td {
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.ng-stats-dialog__table tbody th {
  text-align: left;
}
.ng-stats-dialog__note {
  margin: 0.7rem 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

[data-theme="dark"] .ng-shell { border-color: rgba(189, 166, 240, 0.35); }
[data-theme="dark"] .ng-chip,
[data-theme="dark"] .ng-status,
[data-theme="dark"] .ng-head__bar .pv-coin-chip {
  border-color: rgba(189, 166, 240, 0.35);
  background: rgba(22, 16, 40, 0.62);
  color: #f3e8ff;
}

@media (max-width: 1024px), (max-width: 1199px) and (orientation: portrait) {
  .ng-head {
    flex-direction: column;
    flex-wrap: nowrap; /* a wrapping column sizes each row to its content, not the card */
    align-items: stretch;
  }
  .ng-head__bar {
    flex: 0 0 auto;
  }
  .ng-controls {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .ng-controls button {
    min-width: 0;
    padding-inline: 0.35rem;
  }
}
@media (max-width: 820px), (min-width: 900px) and (max-width: 1199px) and (orientation: portrait) {
  /* One column: the side panel's pieces join the play grid so the chips can sit
     above the board and the mode / tool buttons below it. */
  .ng-play {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.4rem;
  }
  .ng-side {
    display: contents;
  }
  .ng-stats {
    order: -1;
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.55rem;
    margin-bottom: 0.4rem;
  }
  .ng-board-wrap {
    grid-column: 1 / -1;
    margin-bottom: 0.4rem;
  }
  .ng-modes .ng-mode {
    min-height: 46px;
  }
  .ng-side .ng-tool {
    padding-inline: 0.3rem;
    font-size: 0.9rem;
  }
}
@media (max-width: 560px) {
  /* Title, level badge, coins and the focus button share one row. */
  .ng-head__bar {
    gap: 0.25rem;
  }
  .ng-title {
    flex-shrink: 0;
    font-size: 1.2rem;
  }
  .ng-head__bar .pv-coin-chip {
    min-height: 36px;
    padding: 0 0.4rem;
  }
  .ng-shell {
    padding: 0.7rem;
  }
  /* Phones are short on width: let the board run almost to the card edge
     and keep the row clues tight so the grid cells get the space. */
  .ng-board-wrap {
    margin-inline: -0.6rem;
  }
  .ng-page--play-focus .ng-board-wrap {
    margin-inline: -0.4rem;
  }
  .ng-clue--row {
    gap: 0.25em;
    padding: 0 0.3em 0 0.15em;
  }
  .ng-label-long {
    display: none;
  }
  .ng-label-short {
    display: inline;
  }
  .ng-modes,
  .ng-tools {
    grid-column: 1 / -1;
  }
  .ng-stats {
    gap: 0.35rem;
  }
  .ng-chip {
    font-size: 0.8rem;
    padding: 0.4rem 0.3rem;
  }
}
