:root {
  --bg: #ffffff;
  --text: #141414;
  --muted: #8a8a8a;
  --panel: #ffffff;
  --panel-2: #f5f5f5;

  --line-strong: #141414;   /* board edges + 3x3 dividers */
  --line-thin: #d4d4d4;     /* thin cell lines */

  --given: #111111;         /* pre-filled clue digits */
  --entry: #444444;         /* user-entered digits */

  --given-bg: #f2f2f2;      /* subtle fill behind clues */
  --highlight: #f0f0f0;     /* row / col / box peers */
  --selected: #d9d9d9;      /* active cell */
  --conflict: #e5484d;      /* duplicate / wrong digits */
  --conflict-bg: #fdeaea;   /* duplicate cell fill */

  --border: #e2e2e2;
  --border-strong: #141414;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
  min-height: 100dvh;
}

/* Header --------------------------------------------------------------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.status {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.status-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
}

/* Board ---------------------------------------------------------------- */
.board-wrapper {
  display: grid;
  place-items: center;
}

.board {
  width: min(92vw, 460px);
  height: min(92vw, 460px);
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--panel);
  border: 2px solid var(--line-strong);
}

.cell {
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: clamp(18px, 5.5vw, 26px);
  color: var(--entry);
  background: var(--panel);
  border: 1px solid var(--line-thin);
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  outline: none;
  min-width: 0;
  touch-action: manipulation;
  transition: background 0.12s ease;
}

/* Thick 3x3 dividers (no edges — board border handles the outside) */
.cell.thick-right { border-right: 2px solid var(--line-strong); }
.cell.thick-bottom { border-bottom: 2px solid var(--line-strong); }

.cell.readonly {
  color: var(--given);
  background: var(--given-bg);
  cursor: default;
}

.cell.highlight { background: var(--highlight); }
.cell.readonly.highlight { background: #e9e9e9; }

.cell.selected {
  background: var(--selected);
  box-shadow: inset 0 0 0 2px var(--line-strong);
}

.cell.conflict {
  background: var(--conflict-bg);
  color: var(--conflict);
}

.cell.error { color: var(--conflict); }

/* Keypad --------------------------------------------------------------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: min(92vw, 460px);
  margin: 0 auto;
}

/* 1-9 plus Erase fill an even 5x2 grid */

.key {
  padding: 14px 0;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, color 0.12s ease;
}

.key:active { background: var(--text); color: var(--bg); }

.key-erase {
  font-size: 13px;
  letter-spacing: 0.5px;
}

@media (min-width: 560px) {
  .keypad { grid-template-columns: repeat(10, 1fr); }
}

/* Controls ------------------------------------------------------------- */
.controls {
  display: flex;
  justify-content: center;
  width: min(92vw, 460px);
  margin: 0 auto;
}

.btn {
  appearance: none;
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--border-strong);
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.btn:active:not([disabled]) { background: var(--text); color: var(--bg); }

.btn-primary {
  background: var(--text);
  color: var(--bg);
}

.btn-primary:active:not([disabled]) { background: #000; }

.btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Modal ---------------------------------------------------------------- */
.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.55);
  backdrop-filter: blur(2px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 360px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 26px 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  animation: modal-in 0.18s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-mark {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  font-size: 22px;
  font-weight: 700;
}

.modal-danger .modal-mark {
  border-color: var(--conflict);
  color: var(--conflict);
}

.modal-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
}

.modal-message {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.modal-list {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-list li {
  position: relative;
  padding-left: 24px;
  font-size: 14px;
  line-height: 1.45;
  color: #333;
}

.modal-list li::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text);
}

.modal-stats {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 0 20px;
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.modal-stats-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}

.modal-button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease;
}

.modal-button:active { background: #000; }

body.modal-open { overflow: hidden; }
