* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #f8f8f8;
  padding: 20px;
}

.container {
  max-width: 800px;
  width: 100%;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.header {
  background: #2c2c2c;
  color: #fff;
  padding: 20px;
  text-align: center;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 20px;
}

.stats-bar {
  display: flex;
  justify-content: space-around;
  margin-top: 12px;
  font-size: 14px;
}

.stat-item {
  text-align: center;
}

.stat-label {
  font-size: 12px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 5px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
}

.difficulty-badge {
  display: inline-block;
  padding: 4px 16px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
}

.difficulty-badge.easy {
  background: #4caf50;
  color: #fff;
}

.difficulty-badge.medium {
  background: #ff9800;
  color: #fff;
}

.difficulty-badge.hard {
  background: #f44336;
  color: #fff;
}

.difficulty-badge.custom {
  background: #00b4d8;
  color: #fff;
}

.game-area {
  display: flex;
  padding: 30px;
  gap: 30px;
}

@media (max-width: 800px) {
  .game-area {
    flex-direction: column;
    padding: 20px;
    align-items: center;
  }
}

.board-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.board-wrapper {
  width: 100%;
  max-width: 500px;
}

.sudoku-grid {
  display: grid;
  background: #2c2c2c;
  border: 3px solid #2c2c2c;
  border-radius: 4px;
  overflow: visible;
  aspect-ratio: 1;
  width: 100%;
  position: relative;
}

.sudoku-grid.size-4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.sudoku-grid.size-6 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.sudoku-grid.size-9 {
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
}

.cell {
  background: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  font-weight: 600;
  color: #2c2c2c;
  cursor: pointer;
  transition: background-color 0.15s;
  position: relative;
  border: 1px solid #ddd;
}

.sudoku-grid.size-6 .cell {
  font-size: 20px;
}

.sudoku-grid.size-9 .cell {
  font-size: 18px;
}

.cell.given {
  background: #f0f0f0;
  color: #2c2c2c;
  cursor: default;
}

.cell.selected {
  background: #bbdefb;
}

.cell.highlighted {
  background: #f1f8fe;
}

.cell.same-value {
  background: #90caf9;
}

.cell.error {
  background: #ffcdd2;
  color: #c62828;
}

.cell.target-subgrid {
  background: #f0f7ff;
}

.cell.target-subgrid.given {
  background: #e3eef8;
}

.subgrid-highlight {
  position: absolute;
  border: 3px solid #2196F3;
  border-radius: 4px;
  pointer-events: none;
  z-index: 10;
}

.cell.correct-flash {
  background: #c8e6c9;
}

/* Sub-grid borders for 4x4 */
.sudoku-grid.size-4 .cell:nth-child(4n+2) {
  border-right: 2px solid #2c2c2c;
}

.sudoku-grid.size-4 .cell:nth-child(n+5):nth-child(-n+8) {
  border-bottom: 2px solid #2c2c2c;
}

/* Sub-grid borders for 6x6 (2x3 subgrids) */
.sudoku-grid.size-6 .cell:nth-child(6n+3) {
  border-right: 2px solid #2c2c2c;
}

.sudoku-grid.size-6 .cell:nth-child(n+7):nth-child(-n+12) {
  border-bottom: 2px solid #2c2c2c;
}

.sudoku-grid.size-6 .cell:nth-child(n+19):nth-child(-n+24) {
  border-bottom: 2px solid #2c2c2c;
}

/* Sub-grid borders for 9x9 */
.sudoku-grid.size-9 .cell:nth-child(9n+3),
.sudoku-grid.size-9 .cell:nth-child(9n+6) {
  border-right: 2px solid #2c2c2c;
}

.sudoku-grid.size-9 .cell:nth-child(n+19):nth-child(-n+27) {
  border-bottom: 2px solid #2c2c2c;
}

.sudoku-grid.size-9 .cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid #2c2c2c;
}

.side-panel {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

@media (max-width: 800px) {
  .side-panel {
    width: 100%;
    max-width: 500px;
  }
}

.panel-card {
  background: #f5f5f5;
  padding: 15px;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.panel-card h3 {
  font-size: 12px;
  margin-bottom: 10px;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-message {
  font-size: 16px;
  font-weight: 600;
  color: #2c2c2c;
  line-height: 1.4;
}

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

.number-pad.size-4 {
  grid-template-columns: repeat(6, 1fr);
}

.number-pad.size-6 {
  grid-template-columns: repeat(4, 1fr);
}

.number-btn {
  padding: 12px 8px;
  font-size: 18px;
  font-weight: 500;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.number-btn:hover {
  background: #e8e8e8;
}

.number-btn:active {
  background: #d8d8d8;
}

.number-btn.clear {
  background: #2c2c2c;
  color: #fff;
}

.number-btn.clear:hover {
  background: #444;
}

.number-btn.undo {
  background: #2c2c2c;
  color: #fff;
}

.number-btn.undo:hover {
  background: #444;
}

.btn {
  width: 100%;
  padding: 14px 20px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid #ddd;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  background: #fff;
  color: #2c2c2c;
}

.btn:hover {
  background: #f5f5f5;
}

.btn.primary {
  background: #2c2c2c;
  color: #fff;
  border-color: #2c2c2c;
}

.btn.primary:hover {
  background: #444;
}

.btn.hint {
  background: #f44336;
  color: #fff;
  border-color: #f44336;
}

.btn.hint:hover {
  background: #d32f2f;
}

.settings-group {
  margin-bottom: 12px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
  font-weight: 500;
}

/* Custom Select Dropdown */
.custom-select {
  position: relative;
  width: 100%;
}

.select-trigger {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}

.select-trigger:hover {
  border-color: #2c2c2c;
}

.select-trigger.open {
  border-color: #2c2c2c;
  box-shadow: 0 0 0 3px rgba(44, 44, 44, 0.1);
}

.select-trigger.open .select-arrow {
  transform: rotate(180deg);
}

.select-value {
  font-weight: 500;
  color: #2c2c2c;
}

.select-arrow {
  color: #666;
  transition: none;
  flex-shrink: 0;
}

.select-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  overflow: hidden;
}

.select-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.select-option {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #444;
}

.select-option:hover {
  background: #f5f5f5;
  color: #2c2c2c;
}

.select-option.active {
  background: #2c2c2c;
  color: #fff;
}

.select-option.active:hover {
  background: #444;
}

.toggle-group {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.toggle-btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 13px;
  border: none;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s;
  border-right: 1px solid #ddd;
  font-weight: 500;
}

.toggle-btn:last-child {
  border-right: none;
}

.toggle-btn.active {
  background: #2c2c2c;
  color: #fff;
}

.toggle-btn:hover:not(.active) {
  background: #f5f5f5;
}

.setting-desc {
  font-size: 11px;
  color: #888;
  line-height: 1.4;
  margin-top: 8px;
}

.custom-input-area {
  display: none;
  margin-top: 12px;
}

.custom-input-area.active {
  display: block;
}

/* Custom Puzzle Modal Styles */
.custom-puzzle-modal {
  max-width: 480px;
  padding: 0;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 15px;
  border-bottom: 1px solid #eee;
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 28px;
  color: #999;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close-btn:hover {
  color: #333;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid #eee;
}

.modal-tab {
  flex: 1;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 500;
  background: #f9f9f9;
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  color: #666;
}

.modal-tab:hover {
  background: #f0f0f0;
}

.modal-tab.active {
  background: #fff;
  color: #2c2c2c;
  box-shadow: inset 0 -2px 0 0 #2196F3;
}

.modal-tab-content {
  display: none;
  padding: 12px 15px;
}

.modal-tab-content.active {
  display: block;
}

.preset-grid-section {
  margin-bottom: 16px;
}

.preset-grid-section:last-child {
  margin-bottom: 0;
}

.preset-grid-section label {
  display: flex;
  font-size: 12px;
  color: #666;
  margin-bottom: 12px;
  font-weight: 500;
}

.preset-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.preset-btn:hover {
  background: #e8e8e8;
  border-color: #ccc;
}

.preset-btn:active {
  background: #ddd;
}

.custom-grid-size-select {
  margin-bottom: 16px;
}

.custom-grid-size-select label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 6px;
  font-weight: 500;
}

.custom-grid-size-select select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.custom-grid-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

.custom-grid {
  display: grid;
  background: #2c2c2c;
  border: 2px solid #2c2c2c;
  border-radius: 4px;
  overflow: hidden;
  width: 270px;
  height: 270px;
}

.custom-grid.size-4 {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

.custom-grid.size-6 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
}

.custom-grid.size-9 {
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
}

.custom-cell {
  background: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
  color: #2c2c2c;
  cursor: pointer;
  border: 1px solid #ddd;
  transition: background-color 0.1s;
}

.custom-grid.size-4 .custom-cell {
  font-size: 20px;
}

.custom-grid.size-6 .custom-cell {
  font-size: 18px;
}

.custom-cell:hover {
  background: #f0f0f0;
}

.custom-cell.selected {
  background: #bbdefb;
}

.custom-cell.conflict {
  background: #ffcdd2;
  color: #c62828;
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {

  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

/* Custom grid sub-grid borders */
.custom-grid.size-4 .custom-cell:nth-child(4n+2) {
  border-right: 2px solid #2c2c2c;
}

.custom-grid.size-4 .custom-cell:nth-child(n+5):nth-child(-n+8) {
  border-bottom: 2px solid #2c2c2c;
}

.custom-grid.size-6 .custom-cell:nth-child(6n+3) {
  border-right: 2px solid #2c2c2c;
}

.custom-grid.size-6 .custom-cell:nth-child(n+7):nth-child(-n+12) {
  border-bottom: 2px solid #2c2c2c;
}

.custom-grid.size-6 .custom-cell:nth-child(n+19):nth-child(-n+24) {
  border-bottom: 2px solid #2c2c2c;
}

.custom-grid.size-9 .custom-cell:nth-child(9n+3),
.custom-grid.size-9 .custom-cell:nth-child(9n+6) {
  border-right: 2px solid #2c2c2c;
}

.custom-grid.size-9 .custom-cell:nth-child(n+19):nth-child(-n+27) {
  border-bottom: 2px solid #2c2c2c;
}

.custom-grid.size-9 .custom-cell:nth-child(n+46):nth-child(-n+54) {
  border-bottom: 2px solid #2c2c2c;
}

.custom-number-pad {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.custom-num-btn {
  width: 40px;
  height: 40px;
  font-size: 18px;
  font-weight: 600;
  background: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.custom-num-btn:hover {
  background: #e8e8e8;
}

.custom-num-btn.clear-btn {
  background: #2c2c2c;
  color: #fff;
  border-color: #2c2c2c;
}

.custom-num-btn.clear-btn:hover {
  background: #444;
}

.custom-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.custom-actions .btn {
  flex: 1;
  min-width: 100px;
}

.custom-error-message {
  display: none;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: #ffebee;
  border: 1px solid #ffcdd2;
  border-radius: 6px;
  color: #c62828;
  font-size: 13px;
  text-align: center;
}

.custom-error-message.active {
  display: block;
}

.subgrid-info {
  display: none;
  background: #e3f2fd;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  color: #1565c0;
  margin-top: 10px;
}

.subgrid-info.active {
  display: block;
}

.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.active {
  display: flex;
}

.confetti-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.modal-overlay .modal {
  z-index: 2;
  position: relative;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 5px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  padding: 20px;
}

.modal h2 {
  font-size: 28px;
  margin-bottom: 12px;
  color: #2c2c2c;
}

.modal p {
  font-size: 16px;
  color: #666;
  margin-bottom: 24px;
  line-height: 1.5;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal .btn {
  width: auto;
  min-width: 120px;
}

.timer-display {
  font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
}

@media (min-width: 900px) {
  .number-btn {
    padding: 8px 8px;
  }
}

@media (max-width: 780px) {
  .board-container {
    width: 98%;
  }

  .side-panel {
    width: 100%;
  }
}