:root {
  --bg:           #f8f8f8;
  --surface:      #ffffff;
  --text:         #1a1a1a;
  --text-mid:     #555555;
  --text-muted:   #888888;
  --border:       #d4d4d4;
  --border-dark:  #999999;
  --accent:       #e05a00;
  --accent-light: #fff4ed;
  --error:        #cc2936;
  --error-light:  #ffecee;
  --success:      #1e7d4a;
  --cell-size:    32px;
  --clue-gap:     0.35rem;
}

.nonogram-root,
.nonogram-root * {
  box-sizing: border-box;
}

.nonogram-root {
  color: var(--text);
  font-family: "IBM Plex Sans", sans-serif;
  --cell-size: clamp(22px, calc((100vw - 8.5rem) / 10), 32px);
}

.nonogram-root button,
.nonogram-root select {
  font: inherit;
}

.nonogram-root .screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 1rem;
}

.nonogram-root .screen.active {
  display: flex;
}

.nonogram-root .home-panel {
  width: 100%;
  max-width: 360px;
}

.nonogram-root .game-shell {
  width: 100%;
  max-width: 620px;
}

.nonogram-root .home-header {
  margin-bottom: 1.5rem;
}

.nonogram-root .eyebrow,
.nonogram-root .helper-text {
  color: var(--text-muted);
}

.nonogram-root .eyebrow {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nonogram-root .home-header h1,
.nonogram-root .game-header h1,
.nonogram-root .clue-line,
.nonogram-root .cell {
  font-family: "IBM Plex Mono", monospace;
}

.nonogram-root .home-header h1,
.nonogram-root .game-header h1 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.nonogram-root .home-header h1 {
  font-size: 1.75rem;
}

.nonogram-root .game-header h1 {
  font-size: 1.1rem;
}

.nonogram-root .intro,
.nonogram-root .helper-text,
.nonogram-root .status {
  line-height: 1.5;
}

.nonogram-root .intro {
  margin: 0.85rem 0 0;
  color: var(--text-mid);
}

.nonogram-root .home-card,
.nonogram-root .board-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
}

.nonogram-root .home-card {
  padding: 1rem;
}

.nonogram-root .field-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-mid);
}

.nonogram-root .difficulty-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.nonogram-root .difficulty-option {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-mid);
  min-height: 70px;
  padding: 0.7rem 0.55rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.nonogram-root .difficulty-option:hover,
.nonogram-root .difficulty-option:focus-visible {
  border-color: var(--border-dark);
  color: var(--text);
}

.nonogram-root .difficulty-option.is-selected {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--text);
}

.nonogram-root .option-title,
.nonogram-root .option-meta {
  display: block;
}

.nonogram-root .option-title {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.82rem;
  font-weight: 600;
}

.nonogram-root .option-meta {
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.nonogram-root .controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.nonogram-root .controls-home {
  margin-bottom: 0.75rem;
}

.nonogram-root .start-btn {
  width: 100%;
}

.nonogram-root .game-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.nonogram-root .back-btn {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
}

.nonogram-root .back-btn:hover,
.nonogram-root .back-btn:focus-visible {
  color: var(--text);
}

.nonogram-root .meta-row {
  margin-bottom: 1rem;
}

.nonogram-root .meta-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
}

.nonogram-root .btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-mid);
  padding: 0.6rem 1rem;
  min-height: 44px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

.nonogram-root .btn:hover,
.nonogram-root .btn:focus-visible {
  border-color: var(--border-dark);
  color: var(--text);
}

.nonogram-root .btn.primary {
  background: var(--text);
  color: var(--surface);
}

.nonogram-root .btn.primary:hover,
.nonogram-root .btn.primary:focus-visible {
  background: var(--text-mid);
  color: var(--surface);
}

.nonogram-root .btn.active {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.nonogram-root .board-wrap {
  width: fit-content;
  max-width: 100%;
  padding: 0.75rem;
  margin: 0 auto 1rem;
}

.nonogram-root .puzzle-grid {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: var(--clue-gap);
  width: max-content;
  justify-content: center;
  align-items: end;
}

.nonogram-root .corner {
  grid-column: 1;
  grid-row: 1;
}

.nonogram-root .column-clues {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  gap: 0;
  align-self: end;
  justify-self: start;
  align-content: end;
  align-items: end;
}

.nonogram-root .row-clues {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  gap: 0;
  align-self: start;
  justify-self: end;
  align-content: start;
  justify-items: end;
}

.nonogram-root .column-clue,
.nonogram-root .row-clue {
  display: flex;
  color: var(--text-mid);
  font-size: 0.85rem;
}

.nonogram-root .column-clue {
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 0.2rem;
}

.nonogram-root .row-clue {
  justify-content: flex-end;
  align-items: center;
  gap: 0.35rem;
  padding-right: 0.5rem;
}

.nonogram-root .board {
  grid-column: 2;
  grid-row: 2;
  display: grid;
}

.nonogram-root .cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-mid);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: background-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.nonogram-root .cell:hover,
.nonogram-root .cell:focus-visible {
  background: #f2f2f2;
}

.nonogram-root .cell.filled {
  background: var(--text);
  color: var(--surface);
}

.nonogram-root .cell.marked {
  color: var(--text-muted);
}

.nonogram-root .cell.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.nonogram-root .cell.highlight {
  background: #f7f7f7;
}

.nonogram-root .cell.filled.highlight {
  background: #2f2f2f;
}

.nonogram-root .cell.error {
  background: var(--error-light);
  color: var(--error);
}

.nonogram-root .clue-line.done {
  color: var(--success);
}

.nonogram-root .status {
  margin: 0;
  min-height: 1.5rem;
  color: var(--text-mid);
}

.nonogram-root .status.error {
  color: var(--error);
}

.nonogram-root .status.won {
  color: var(--success);
}

@media (max-width: 480px) {
  .nonogram-root .screen {
    padding: 1.5rem 0;
  }

  .nonogram-root .game-shell,
  .nonogram-root .home-panel {
    max-width: 100%;
  }

  .nonogram-root .btn {
    flex: 1 1 120px;
  }

  .nonogram-root .difficulty-picker {
    grid-template-columns: 1fr;
  }

  .nonogram-root .board-wrap {
    padding: 0.5rem;
  }

  .nonogram-root .puzzle-grid {
    gap: 0.25rem;
  }

  .nonogram-root .column-clue,
  .nonogram-root .row-clue {
    font-size: 0.68rem;
  }

  .nonogram-root .row-clue {
    gap: 0.2rem;
    padding-right: 0.25rem;
  }
}
