:root {
  --bg: #0f1316;
  --panel: #171c21;
  --border: #2a3138;
  --text: #e7edf3;
  --muted: #9fb0c2;
  --primary: #4ea8ff;
  --primary-acc: #7bc3ff;
  --error: #ff5c5c;
  --fixed: #cde6ff;
  --highlight: #283241;
  --box-highlight: #223046;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1200px 600px at 20% -10%, #17202a 0%, var(--bg) 40%), var(--bg);
  color: var(--text);
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 12px;
}

.controls label {
  font-size: 0.9rem;
  color: var(--muted);
}

select, button {
  appearance: none;
  border: 1px solid var(--border);
  background: #12161b;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: border-color 120ms ease, transform 120ms ease, background 120ms ease;
}

select:focus, button:focus {
  outline: none;
  border-color: var(--primary);
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

button.primary {
  background: linear-gradient(180deg, var(--primary-acc), var(--primary));
  color: #07253b;
  border-color: #94d1ff;
  font-weight: 600;
}

.status {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 12px;
}

.stat .label {
  color: var(--muted);
  margin-right: 8px;
}

/* Board */

.board {
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 0;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  max-width: min(90vw, 560px);
  max-height: min(90vw, 560px);
  aspect-ratio: 1/1;
}

/* Each cell is an input for accessibility and mobile keyboards */
.cell {
  position: relative;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: clamp(18px, 6vw, 28px);
  color: var(--text);
  background: #12161b;
}

.cell input {
  width: 100%;
  height: 100%;
  text-align: center;
  border: none;
  outline: none;
  background: transparent;
  color: inherit;
  font: inherit;
  caret-color: var(--primary);
}

.cell input::placeholder {
  color: #3d4b5a;
}

/* Stronger borders for 3x3 boxes */
.cell[data-col="0"], .cell[data-col="3"], .cell[data-col="6"] { border-left-width: 2px; }
.cell[data-col="8"] { border-right-width: 2px; }
.cell[data-row="0"], .cell[data-row="3"], .cell[data-row="6"] { border-top-width: 2px; }
.cell[data-row="8"] { border-bottom-width: 2px; }

/* Fixed (given) cells */
.cell.fixed {
  background: #0f141a;
}
.cell.fixed input {
  color: var(--fixed);
}

/* Selected and highlights */
.cell.selected {
  background: var(--highlight);
}

.cell.highlight {
  background: #192131;
}

.cell.box-highlight {
  background: var(--box-highlight);
}

/* Conflicts */
.cell.error input {
  color: var(--error);
  animation: pulse 300ms ease;
}

@keyframes pulse {
  0% { transform: scale(1.0); }
  50% { transform: scale(1.03); }
  100% { transform: scale(1.0); }
}

/* Footer */
.footer {
  margin-top: 12px;
  color: var(--muted);
  text-align: center;
}

/* Responsive tweaks */
@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 1fr;
  }
  .controls, .status {
    justify-content: space-between;
  }
}