:root {
  --bg: #0f1220;
  --panel: #161a2e;
  --panel-2: #1d2240;
  --text: #eef1ff;
  --muted: #b7bdd9;
  --accent: #6c8cff;
  --accent-2: #55d0ff;
  --danger: #ff6b6b;
  /* Increase contrast of grid lines */
  --grid: #3e4a83;          /* thin lines */
  --grid-strong: #9bb2ff;   /* thick lines and board edges */
  --highlight: #24305f;
  --select: #2f3a77;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  background: radial-gradient(1000px 600px at 20% 0%, #101534 0%, #0c0f24 60%, #0a0c1c 100%), var(--bg);
  color: var(--text);
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto auto;
  gap: 16px;
  min-height: 100%;
}

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

.header h1 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.status {
  display: flex;
  gap: 16px;
  align-items: center;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.06);
  padding: 8px 12px;
  border-radius: 12px;
}

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

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.06);
  padding: 10px 12px;
  border-radius: 12px;
  gap: 12px;
}

.left-controls, .right-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

select, .btn {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
}

.btn {
  cursor: pointer;
  transition: transform 0.05s ease, background 0.2s ease, border-color 0.2s ease;
}

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

.btn:hover:not([disabled]) {
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.btn:active:not([disabled]) {
  transform: translateY(0);
}

.btn-accent {
  background: linear-gradient(90deg, rgba(108,140,255,0.12), rgba(85,208,255,0.12));
  border-color: rgba(108,140,255,0.4);
}

.howto {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.06);
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
}

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

.board {
  width: min(90vw, 560px);
  height: min(90vw, 560px);
  background: var(--panel);
  border-radius: 14px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 0;
  border: 4px solid var(--grid-strong);
  position: relative;
  box-shadow: 0 10px 30px rgba(12, 16, 36, 0.45), inset 0 0 0 1px rgba(255,255,255,0.02);
}

.cell {
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(18px, 4vw, 26px);
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  color: var(--text);
  user-select: none;
  position: relative;
  outline: none;
  border: 1px solid var(--grid);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  min-width: 0;
}

.cell.edge-left { border-left-width: 4px; border-left-color: var(--grid-strong); }
.cell.edge-top { border-top-width: 4px; border-top-color: var(--grid-strong); }
.cell.edge-right { border-right-width: 4px; border-right-color: var(--grid-strong); }
.cell.edge-bottom { border-bottom-width: 4px; border-bottom-color: var(--grid-strong); }

.cell.thick-right { border-right-width: 3px; border-right-color: var(--grid-strong); }
.cell.thick-bottom { border-bottom-width: 3px; border-bottom-color: var(--grid-strong); }

.cell.readonly {
  color: #cfd6ff;
  background: linear-gradient(180deg, rgba(108,140,255,0.08), rgba(85,208,255,0.05));
  border-color: var(--grid);
}

.cell.selected {
  background: var(--select);
  border-color: var(--grid-strong);
  box-shadow: 0 0 0 2px rgba(108,140,255,0.3) inset;
}

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

.cell.conflict {
  background: rgba(255, 107, 107, 0.12);
  border-color: rgba(255, 107, 107, 0.6);
  box-shadow: 0 0 0 2px rgba(255, 107, 107, 0.2) inset;
}

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

.cell .pencil {
  font-size: 12px;
  color: var(--muted);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, minmax(56px, 1fr));
  gap: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01));
  border: 1px solid rgba(255,255,255,0.06);
  padding: 12px;
  border-radius: 12px;
  width: min(90vw, 560px);
  margin: 0 auto;
}

.key {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.2s ease, border-color 0.2s ease;
}

.key:hover {
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px);
}

.key:active {
  transform: translateY(0);
}

.key-erase {
  grid-column: span 2;
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.4);
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

@media (min-width: 640px) {
  .keypad {
    grid-template-columns: repeat(10, minmax(40px, 1fr));
    width: min(90vw, 560px);
  }
  .key-erase {
    grid-column: span 2;
  }
}