/* Nonogram uses the same quiet grid, semantic tokens and crisp states as Sudoku/Akari.
   The selected paint tool must be visible in both themes, including on Android. */
.nonogram-shell {
  --nonogram-paper: var(--surface);
  --nonogram-ink: var(--text);
  --nonogram-quiet: var(--surface2);
  --nonogram-rules: var(--line);
  --nonogram-group: var(--brand-violet);
  --nonogram-success: var(--brand-yellow);
  --nonogram-active: var(--brand-aqua);
  --nonogram-content-width: min(680px, 100%);
  --nonogram-frame: var(--brand-violet);
  --nonogram-fill: var(--brand-aqua);
  --nonogram-cross: var(--text-subtle);
  width: min(740px, 100%);
  min-width: 0;
  margin: auto;
  display: grid;
  justify-items: center;
  gap: 10px;
}
html[data-theme="light"] .nonogram-shell {
  --nonogram-fill: var(--brand-violet);
  --nonogram-active: var(--brand-violet);
}
.nonogram-puzzle {
  width: var(--nonogram-content-width);
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, var(--nonogram-side-width)) minmax(0, 1fr);
  grid-template-rows: var(--nonogram-top-height) auto;
  align-items: stretch;
  margin-inline: auto;
  filter: none;
}
.nonogram-corner {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  place-items: end center;
  padding: 0 4px 8px;
  color: var(--text-subtle);
  font: 800 .7rem/1 var(--font-mono, monospace);
}
.nonogram-col-clues,
.nonogram-row-clues {
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--nonogram-quiet);
  border: 1px solid var(--line-strong);
}
.nonogram-col-clues {
  grid-column: 2;
  grid-row: 1;
  align-items: stretch;
  border-radius: 10px 10px 0 0;
  border-top: 3px solid var(--brand-aqua);
}
/* The playing area is sized by a square frame. Clues overlay its left edge,
   so their intrinsic text size cannot stretch the game grid on tablets. */
.nonogram-playarea {
  grid-column: 1 / -1;
  grid-row: 2;
  width: 100%;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: flex-start;
}
.nonogram-board-frame {
  margin-left: var(--nonogram-side-width);
  width: calc(100% - var(--nonogram-side-width));
  min-width: 0;
  flex: none;
  aspect-ratio: 1;
  position: relative;
}
.nonogram-row-clues {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--nonogram-side-width);
  box-sizing: border-box;
  border-radius: 10px 0 0 10px;
  border-left: 3px solid var(--brand-aqua);
}
.nonogram-col-clue,
.nonogram-row-clue {
  min-width: 0;
  min-height: 0;
  display: flex;
  color: var(--nonogram-ink);
  font: 800 clamp(.56rem, 1.35vw, .76rem)/1 var(--font-mono, monospace);
  font-variant-numeric: tabular-nums;
  position: relative;
  transition: background-color .16s ease, color .16s ease, box-shadow .16s ease;
}
.nonogram-col-clue {
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding: 4px 0;
}
.nonogram-row-clue {
  align-items: center;
  justify-content: flex-end;
  gap: clamp(2px, .45vw, 6px);
  padding: 0 5px;
  white-space: nowrap;
}
.nonogram-col-clue.is-active,
.nonogram-row-clue.is-active {
  background: var(--surface-strong);
  box-shadow: inset 0 0 0 2px var(--nonogram-active);
}
.nonogram-col-clue.is-done,
.nonogram-row-clue.is-done {
  color: var(--neutral-ink);
  background: var(--nonogram-success);
  box-shadow: inset 0 0 0 1px var(--nonogram-success);
}
.nonogram-col-clue.is-done span,
.nonogram-row-clue.is-done span {
  text-decoration: line-through;
  text-decoration-color: var(--brand-violet);
  text-decoration-thickness: 2px;
  text-decoration-skip-ink: none;
}
.nonogram-col-clue.is-done::after,
.nonogram-row-clue.is-done::after {
  content: '✓';
  position: absolute;
  top: 2px;
  left: 2px;
  display: grid;
  place-items: center;
  width: clamp(10px, 1.3vw, 15px);
  aspect-ratio: 1;
  border-radius: 4px;
  background: var(--brand-violet);
  color: var(--neutral-paper);
  font: 900 clamp(8px, .85vw, 11px)/1 var(--font-sans);
  pointer-events: none;
}
.nonogram-col-clue.is-done::after { left: 50%; transform: translateX(-50%); }
.nonogram-col-clue.is-done.is-active,
.nonogram-row-clue.is-done.is-active {
  box-shadow: inset 0 0 0 2px var(--nonogram-active);
}
.nonogram-col-clue.is-conflict,
.nonogram-row-clue.is-conflict {
  color: var(--neutral-ink);
  background: var(--brand-coral);
  box-shadow: inset 0 0 0 2px var(--brand-coral);
}
.nonogram-col-clue.is-conflict span,
.nonogram-row-clue.is-conflict span { text-decoration: none; }
.nonogram-col-clue.is-conflict::after,
.nonogram-row-clue.is-conflict::after {
  content: '!';
  position: absolute;
  top: 2px;
  left: 3px;
  color: var(--neutral-ink);
  background: var(--brand-coral);
  font: 900 .9rem/1 var(--font-sans);
}
.nonogram-col-clue.is-conflict::after { left: 50%; transform: translateX(-50%); }
.nonogram-col-clue.group-edge { border-right: 2px solid var(--nonogram-group); }
.nonogram-row-clue.group-edge { border-bottom: 2px solid var(--nonogram-group); }
.nonogram-col-clue.is-celebrating,
.nonogram-row-clue.is-celebrating { animation: nonogram-line-complete .48s ease-out; }
@keyframes nonogram-line-complete {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.45); }
  100% { filter: brightness(1); }
}
.nonogram-board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
  min-width: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  gap: 0;
  overflow: hidden;
  border: 2px solid var(--nonogram-frame);
  border-radius: 0 0 12px 0;
  background: var(--nonogram-rules);
  box-shadow: var(--shadow-soft);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.nonogram-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: inset -1px -1px 0 var(--nonogram-rules);
  background: var(--nonogram-paper);
  color: var(--nonogram-cross);
  cursor: crosshair;
  display: grid;
  place-items: center;
  touch-action: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  font: 900 clamp(.65rem, 2vw, 1.25rem)/1 var(--font-mono, monospace);
  transition: background-color .12s ease, box-shadow .12s ease;
}
@media (hover: hover) and (pointer: fine) {
  .nonogram-cell:hover { background: var(--nonogram-quiet); }
}
.nonogram-cell.is-filled,
html[data-theme="light"] .nonogram-cell.is-filled {
  background: var(--nonogram-fill);
  color: var(--neutral-ink);
}
.nonogram-cell.is-cross,
html[data-theme="light"] .nonogram-cell.is-cross {
  background: var(--nonogram-quiet);
  color: var(--nonogram-cross);
}
.nonogram-cell.is-cross::before,
.nonogram-cell.is-cross::after {
  content: '';
  position: absolute;
  width: 65%;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  pointer-events: none;
}
.nonogram-cell.is-cross::before { transform: rotate(45deg); }
.nonogram-cell.is-cross::after { transform: rotate(-45deg); }
.nonogram-cell.is-cross { font-size: 0; }
.nonogram-cell.is-line-active:not(.is-filled):not(.is-cross) {
  background: var(--nonogram-quiet);
}
.nonogram-cell.is-line-complete:not(.is-filled):not(.is-cross):not(.is-line-active) {
  background: var(--surface-strong);
}
.nonogram-cell.is-current {
  z-index: 1;
  box-shadow: inset 0 0 0 2px var(--brand-yellow);
}
.nonogram-cell.is-current.is-filled {
  box-shadow: inset 0 0 0 2px var(--brand-yellow);
}
.nonogram-cell.group-right { border-right: 3px solid var(--nonogram-group); }
.nonogram-cell.group-bottom { border-bottom: 3px solid var(--nonogram-group); }
.nonogram-cell:focus-visible {
  z-index: 2;
  outline: 3px solid var(--brand-yellow);
  outline-offset: -3px;
}
.nonogram-board.is-complete { box-shadow: 0 0 0 2px var(--brand-aqua), var(--shadow-soft); }
.nonogram-progress-track {
  width: var(--nonogram-content-width);
  height: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface2);
  overflow: hidden;
  box-sizing: border-box;
}
.nonogram-progress-fill {
  height: 100%;
  width: 0;
  background: var(--nonogram-fill);
  border-radius: inherit;
  transition: width .24s ease;
}
.nonogram-instructions {
  max-width: 65ch;
  margin: 0;
  color: var(--text-subtle);
  font-size: var(--type-caption, .75rem);
  line-height: 1.4;
  text-align: center;
}
/* Drawing modes are choices, not disabled actions. Always expose their labels
   and use a solid selected state rather than a barely visible outline. */
body.puzzles-app .game-board-actions .nonogram-tools .game-board-tool--toggle {
  min-width: 0;
}
body.puzzles-app .game-board-actions .nonogram-tools .game-board-tool--toggle .game-board-tool-label {
  position: static;
  width: auto;
  height: auto;
  padding: 0;
  margin: 0;
  clip: auto;
  overflow: visible;
  white-space: normal;
  text-align: center;
}
body.puzzles-app .game-board-actions .nonogram-tools .game-board-tool--toggle.is-active {
  /* premium.css forces the neutral surface on active tool buttons. Keep this
     drawing-mode state explicit so its light label stays readable. */
  border-color: var(--brand-violet) !important;
  background: var(--brand-violet) !important;
}
body.puzzles-app .game-board-actions .nonogram-tools .game-board-tool--toggle.is-active .game-board-tool-icon,
body.puzzles-app .game-board-actions .nonogram-tools .game-board-tool--toggle.is-active .game-board-tool-label {
  color: var(--neutral-paper);
}
.nonogram-extra-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* A narrow game card, rather than the physical device, controls HUD density.
   This prevents the extra KPIs from pushing the selectors off-screen. */
@container (max-width: 860px) {
  /* Preserve two explicit columns over the shared extra-indicator rule:
     selectors and timer above one full-width row of secondary metrics. */
  body.puzzles-app .game-controlbar.nonogram-controlbar:has(.game-indicator:not(.game-timer)) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    align-items: center;
    column-gap: 6px;
    row-gap: 6px;
    overflow: visible;
  }
  body.puzzles-app .nonogram-controlbar .game-options {
    grid-column: 1;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
    width: 100%;
    min-width: 0;
  }
  body.puzzles-app .nonogram-controlbar .game-options .game-control {
    width: 100%;
    min-width: 0;
  }
  body.puzzles-app .nonogram-controlbar .game-options .game-select {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  body.puzzles-app .nonogram-controlbar .game-indicators {
    display: contents;
  }
  body.puzzles-app .nonogram-controlbar .game-timer {
    grid-column: 2;
    grid-row: 1;
    white-space: nowrap;
  }
  body.puzzles-app .nonogram-controlbar .nonogram-extra-stats {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
    min-width: 0;
    gap: 5px;
  }
  body.puzzles-app .nonogram-extra-stats .game-indicator {
    min-width: 0;
    padding-inline: 6px;
    justify-content: center;
    overflow: hidden;
    gap: 4px;
  }
  body.puzzles-app .nonogram-extra-stats .game-indicator-icon {
    display: none;
  }
  body.puzzles-app .nonogram-extra-stats .game-indicator-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .68rem;
    letter-spacing: 0;
  }
  body.puzzles-app .nonogram-extra-stats .game-indicator strong {
    min-width: 0;
    font-size: .79rem;
  }
}

@container (max-width: 480px) {
  body.puzzles-app .nonogram-extra-stats .game-indicator {
    flex-direction: column;
    gap: 2px;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  body.puzzles-app .nonogram-shell {
    --nonogram-content-width: min(680px, 100%, calc(100cqh - var(--nonogram-top-height) + var(--nonogram-side-width) - 88px));
  }
}
@media (max-width: 420px) {
  .nonogram-shell { gap: 7px; }
  .nonogram-puzzle { grid-template-columns: minmax(0, var(--nonogram-side-width)) minmax(0, 1fr); }
  .nonogram-row-clue { padding-inline: 3px; gap: 2px; }
  .nonogram-col-clue { padding-block: 3px; gap: 1px; }
  .nonogram-cell.group-right { border-right-width: 2px; }
  .nonogram-cell.group-bottom { border-bottom-width: 2px; }
  .nonogram-instructions { font-size: .68rem; }
}
@media (prefers-reduced-motion: reduce) {
  .nonogram-cell, .nonogram-col-clue, .nonogram-row-clue, .nonogram-progress-fill { transition: none; }
  .nonogram-col-clue.is-celebrating, .nonogram-row-clue.is-celebrating { animation: none; }
}
