* {
  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: 900px;
  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;
}

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

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

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

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

/* Base cell styles */
.cell {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: 600;
  color: #2c2c2c;
  position: relative;
  border: 1px solid #ddd;
}

.kakuro-grid.size-8 .cell {
  font-size: 18px;
}

.kakuro-grid.size-10 .cell {
  font-size: 16px;
}

/* Blocked cells */
.cell.blocked {
  background: #52595c;
  cursor: default;
}

/* Clue cells */
.cell.clue {
  background: #52595c;
  cursor: default;
  overflow: hidden;
}

.clue-diagonal {
  position: absolute;
  top: 0;
  left: 0;
  width: 141.4%;
  height: 1px;
  background: #666;
  transform-origin: top left;
  transform: rotate(45deg);
  z-index: 1;
}

.clue-down {
  position: absolute;
  top: 40px;
  left: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  z-index: 2;
}

.clue-right {
  position: absolute;
  bottom: 40px;
  right: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  z-index: 2;
}

.kakuro-grid.size-10 .clue-down,
.kakuro-grid.size-10 .clue-right {
  top: 30px;
}

.kakuro-grid.size-10 .clue-right {
  top: auto;
  left: auto;
  bottom: 30px;
}

/* Fillable cells */
.cell.fillable {
  background: #fff;
  cursor: pointer;
  transition: background-color 0.15s;
}

.cell.fillable:hover {
  background: #f5f5f5;
}

.cell.selected {
  background: #bbdefb !important;
}

.cell.run-highlight {
  background: #e3f2fd;
}

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

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

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

/* Side panel */
.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 */
.number-pad {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.number-btn {
  padding: 10px 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;
}

/* Buttons */
.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 */
.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 */
.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;
}

/* Rules card */
.rules-card {
  background: #e3f2fd;
  border-color: #bbdefb;
}

.rules-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.rules-list li {
  font-size: 12px;
  color: #1565c0;
  padding: 4px 0;
  padding-left: 16px;
  position: relative;
}

.rules-list li::before {
  content: '\2022';
  position: absolute;
  left: 0;
}

/* Modal styles */
.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;
}

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

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

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

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

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

.preset-content {
  padding: 16px 20px;
}

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

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

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

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

.preset-btn {
  padding: 8px 14px;
  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;
}

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

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

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

@media (max-width: 480px) {
  .clue-down {
    top: 20px;
    left: 4px;
    font-size: 9px;
  }

  .clue-right {
    bottom: 20px;
    right: 4px;
    font-size: 9px;
  }

  .cell {
    font-size: 20px;
  }

  .kakuro-grid.size-8 .cell {
    font-size: 15px;
  }

  .kakuro-grid.size-10 .cell {
    font-size: 14px;
  }

  .kakuro-grid.size-10 .clue-down {
    top: 14px
  }

  .kakuro-grid.size-10 .clue-right {
    top: 2px;
  }

}