:root {
  --bg: #1b1f27;
  --panel: #242a35;
  --line-strong: #4a5568;
  --line-soft: #333a47;
  --text: #e8eaf0;
  --text-dim: #9aa3b2;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.18);
  --peer: rgba(91, 140, 255, 0.08);
  --conflict: #ff5b6e;
  --conflict-soft: rgba(255, 91, 110, 0.16);
  --given: #c9cedb;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(circle at top, #232936 0%, #14171e 70%);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  overscroll-behavior-y: contain;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

.app {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

select,
button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 44px;
  cursor: pointer;
  touch-action: manipulation;
}

select:hover,
button:hover {
  border-color: var(--accent);
}

#new-game {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: #0e1116;
  font-weight: 600;
}

#difficulty {
  flex: 1;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

#status {
  color: var(--accent);
  font-weight: 600;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  background: var(--panel);
  border: 2px solid var(--line-strong);
  border-radius: 10px;
  overflow: hidden;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.05rem, 5.5vw, 1.4rem);
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
  transition: background-color 0.1s ease;
}

.cell.box-left {
  border-left: 2px solid var(--line-strong);
}
.cell.box-top {
  border-top: 2px solid var(--line-strong);
}
.cell.box-right {
  border-right: 2px solid var(--line-strong);
}
.cell.box-bottom {
  border-bottom: 2px solid var(--line-strong);
}

.cell.given {
  color: var(--given);
  font-weight: 600;
  cursor: default;
}

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

.cell.same-value {
  background: var(--accent-soft);
}

.cell.selected {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

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

.action-row {
  display: flex;
  justify-content: center;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.num-btn {
  padding: 0;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  user-select: none;
  -webkit-touch-callout: none;
}

@media (max-width: 380px) {
  .app-header h1 {
    font-size: 1.35rem;
  }

  .controls {
    font-size: 0.8rem;
    gap: 6px;
  }

  select,
  button {
    padding: 6px 8px;
  }

  .numpad {
    gap: 4px;
  }

  .num-btn {
    font-size: 1rem;
  }
}
