/* ===== Nonogram styles ===== */

.app {
  max-width: min(95vw, 600px);
  padding-bottom: 32px;
}

/* Mode bar */
.mode-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}

.mode-btn {
  opacity: 0.6;
  transition: opacity 0.15s, box-shadow 0.15s;
}
.mode-btn.active {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

/* Board wrapper */
.board-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-x: auto;
  padding: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.board-wrapper.is-paused { visibility: hidden; }

/* Nonogram grid: CSS Grid */
#nonogram-grid {
  display: inline-grid;
  border: 2px solid var(--text-muted);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

/* ── Clue cells ── */
.clue-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  font-weight: 700;
  font-size: 11px;
  color: var(--text-strong);
  min-width: clamp(20px, 5.2vw, 28px);
  min-height: clamp(20px, 5.2vw, 28px);
  box-sizing: border-box;
  border: 1px solid var(--border);
  line-height: 1.2;
  white-space: pre;   /* allow newlines in multi-clue */
}

/* column clues: stack numbers vertically */
.clue-cell.col-clue {
  flex-direction: column;
  justify-content: flex-end;
  padding: 3px 0 2px;
  font-size: 10px;
  gap: 1px;
}

/* row clues: align right */
.clue-cell.row-clue {
  flex-direction: row;
  justify-content: flex-end;
  padding: 0 5px 0 3px;
  gap: 3px;
}

/* corner cell */
.clue-cell.corner {
  background: var(--bg);
}

/* Clue numbers */
.clue-num {
  display: block;
  font-variant-numeric: tabular-nums;
}

/* ── Puzzle cells ── */
.puzzle-cell {
  /* Scale cells with viewport — 30 px on desktop, shrinks down to
     20 px on the narrowest phones so big puzzles (15×15) still fit. */
  width: clamp(20px, 5.5vw, 30px);
  height: clamp(20px, 5.5vw, 30px);
  border: 1px solid var(--border);
  box-sizing: border-box;
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.07s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: transparent;
}

/* Bold grid lines every 5 cells */
.puzzle-cell.thick-right  { border-right-color:  var(--text-muted); border-right-width: 2px; }
.puzzle-cell.thick-bottom { border-bottom-color: var(--text-muted); border-bottom-width: 2px; }

.puzzle-cell:hover {
  background: var(--surface-hover);
}

/* Filled */
.puzzle-cell.filled {
  background: var(--text-strong);
  color: var(--text-strong);
}
body.dark .puzzle-cell.filled {
  background: var(--text-strong);
}

/* X mark */
.puzzle-cell.marked {
  background: var(--surface);
  color: var(--text-muted);
}
.puzzle-cell.marked::before {
  content: '✕';
  font-size: 14px;
  color: var(--text-muted);
}

/* Error flash */
.puzzle-cell.error {
  background: var(--danger) !important;
  animation: flash-error 0.35s ease;
}
@keyframes flash-error {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* Correct completion highlight */
.puzzle-cell.correct {
  background: var(--text-strong);
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
  animation: fadein 0.3s ease;
}
.overlay[hidden] { display: none; }

.overlay-text {
  font-size: clamp(36px, 8vmin, 56px);
  font-weight: 800;
  color: var(--text-strong);
  text-align: center;
}
.overlay-sub {
  font-size: 16px;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  line-height: 1.6;
}
.overlay-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Responsive: scale down cells on very small screens */
@media (max-width: 400px) {
  /* Cell sizes now scale fluidly via clamp() above. Keep the font
     adjustment for narrower screens where clue numbers get cramped. */
  .clue-cell { font-size: 9px; }
}
