/* ====== GAME VARIABLES ====== */
:root {
  --cell-size: 46px;
  --cell-gap: 2px;
  --block-gap: 6px;
  
  /* Colors */
  --cell-bg: #fff;
  --cell-border: #e0e0e0;
  --cell-fixed: #f5f5f5;
  --cell-hover: #f0f0ff;
  --cell-selected: #e6e6ff;
  --cell-highlight: #f0f1ff;
  --cell-same: #d6d8ff;
  --cell-conflict: #ffe5e5;
  --cell-affected: #f0f1ff;
  --cell-marked: #ffe1cc;
  --cell-marked2: #cde4cd;
  --text-fixed: #2c2c2c;
  --text-user: #4a5568;
  --text-pencil: #9ca3af;
  --text-conflict: #ef4444;
  --bi-value-color: #a0a7b3;
  --danger-color: #dc3545;
  --danger-hover: #c82333;
}

@media (max-width: 768px) {
  :root {
    --cell-size: 38px;
    --cell-gap: 1px;
    --block-gap: 5px;
  }
}

@media (max-width: 600px) {
  :root {
    --cell-size: 34px;
    --cell-gap: 1px;
    --block-gap: 4px;
  }
}

/* ====== OVERRIDE HEADER HEIGHT ====== */
@media (max-width: 600px) {
  :root {
    --headerH: 80px;
  }
  
  .header {
    padding-top: 15px;
  }
}

/* ====== PREVENT SCROLL ====== */
html {
  overflow: hidden;
  height: 100vh;
}

body {
  overflow: hidden !important;
  height: 100vh !important;
  overscroll-behavior: none;
}

/* ====== MAIN APP ====== */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 5px;
  margin-top: -30px;
  height: calc(100vh - var(--headerH) - 20px);
  justify-content: center;
}

@media (max-width: 768px) {
  #app {
    gap: 10px;
    padding: 5px;
    margin-top: -50px;
    height: calc(100vh - var(--headerH) - 15px);
  }
}

@media (max-width: 600px) {
  #app {
    gap: 8px;
    padding: 5px;
    margin-top: -20px;
    height: calc(100vh - var(--headerH) - 10px);
  }
}

/* ====== NEW GAME BUTTON WITH DIFFICULTY ====== */
.new-game-wrapper {
  position: relative;
}

.btn-with-indicator {
  display: flex !important;
  align-items: center;
  padding: 0 !important;
  overflow: hidden;
}

.btn-text {
  padding: 10px 16px;
  flex: 1;
}

.btn-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.3);
  margin: 0;
}

.btn-indicator {
  padding: 10px 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
  position: relative;
  width: 42px;
  text-align: center;
  font-family: monospace;
}

.btn-indicator:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Difficulty dropdown */
.difficulty-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  z-index: 100;
  min-width: 260px;
}

.difficulty-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.slider-group {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.slider-group label {
  font-weight: 600;
  min-width: 70px;
  font-size: 0.95rem;
}

.slider-group input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #e0e0e0;
  border-radius: 3px;
  outline: none;
}

.slider-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.slider-group input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(108, 99, 255, 0.4);
}

.slider-group input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.slider-group input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 2px 8px rgba(108, 99, 255, 0.4);
}

.difficulty-display {
  text-align: center;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 8px;
  font-size: 1.05rem;
}

@media (max-width: 600px) {
  .btn-text {
    padding: 10px 12px;
    font-size: 0.95rem;
  }
  
  .btn-indicator {
    padding: 10px 10px;
    font-size: 0.9rem;
    width: 38px;
  }
  
  .difficulty-dropdown {
    min-width: 240px;
    padding: 16px;
  }
  
  .slider-group label {
    min-width: 60px;
    font-size: 0.9rem;
  }
  
  .difficulty-display {
    font-size: 0.95rem;
  }
}

/* ====== CONTROLS ====== */
.controls {
  display: flex;
  gap: 12px;
}

@media (max-width: 600px) {
  .controls {
    gap: 8px;
  }
}

.tool-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #fff;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
}

@media (max-width: 600px) {
  .tool-btn {
    width: 40px;
    height: 40px;
  }
  
  .tool-btn svg {
    width: 18px;
    height: 18px;
  }
}

@media (hover: hover) {
  .tool-btn:hover {
    background: #f5f5f5;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }
  
  .tool-btn.active:hover {
    background: var(--accent-dark);
  }
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108,99,255,0.3);
}

/* Marker mode cursor */
body.marker-mode #board .cell {
  cursor: crosshair;
}

/* Prevent unwanted touch behaviors in marker mode */
body.marker-mode #board {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.tool-btn.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.tool-btn.disabled:hover {
  background: #fff;
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* ====== BOARD ====== */
#boardWrap {
  background: #d0d0d0;
  padding: 8px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

@media (max-width: 600px) {
  #boardWrap {
    padding: 6px;
    border-radius: 10px;
  }
}

#board {
  display: grid;
  grid-template-columns: 
    repeat(3, var(--cell-size)) var(--block-gap)
    repeat(3, var(--cell-size)) var(--block-gap)
    repeat(3, var(--cell-size));
  grid-template-rows: 
    repeat(3, var(--cell-size)) var(--block-gap)
    repeat(3, var(--cell-size)) var(--block-gap)
    repeat(3, var(--cell-size));
  gap: var(--cell-gap);
  background: transparent;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  /* Improve touch responsiveness */
  -webkit-tap-highlight-color: transparent;
}

/* ====== CELLS ====== */
.cell {
  background: var(--cell-bg);
  border: 1px solid transparent;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1.4rem;
  color: var(--text-user);
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-tap-highlight-color: transparent;
  width: var(--cell-size);
  height: var(--cell-size);
}

/* Skip cells in gap columns/rows */
.cell:nth-child(9n+4),
.cell:nth-child(9n+5),
.cell:nth-child(9n+6) {
  grid-column: span 1 / span 1;
}

.cell:nth-child(9n+7),
.cell:nth-child(9n+8),
.cell:nth-child(9n+9),
.cell:nth-child(9n+10) {
  grid-column: span 1 / span 1;
}

/* Position cells correctly in grid */
.cell:nth-child(9n+1) { grid-column: 1; }
.cell:nth-child(9n+2) { grid-column: 2; }
.cell:nth-child(9n+3) { grid-column: 3; }
.cell:nth-child(9n+4) { grid-column: 5; }
.cell:nth-child(9n+5) { grid-column: 6; }
.cell:nth-child(9n+6) { grid-column: 7; }
.cell:nth-child(9n+7) { grid-column: 9; }
.cell:nth-child(9n+8) { grid-column: 10; }
.cell:nth-child(9n+9) { grid-column: 11; }

/* Position rows correctly */
.cell:nth-child(n+1):nth-child(-n+9) { grid-row: 1; }
.cell:nth-child(n+10):nth-child(-n+18) { grid-row: 2; }
.cell:nth-child(n+19):nth-child(-n+27) { grid-row: 3; }
.cell:nth-child(n+28):nth-child(-n+36) { grid-row: 5; }
.cell:nth-child(n+37):nth-child(-n+45) { grid-row: 6; }
.cell:nth-child(n+46):nth-child(-n+54) { grid-row: 7; }
.cell:nth-child(n+55):nth-child(-n+63) { grid-row: 9; }
.cell:nth-child(n+64):nth-child(-n+72) { grid-row: 10; }
.cell:nth-child(n+73):nth-child(-n+81) { grid-row: 11; }

@media (max-width: 600px) {
  .cell {
    font-size: 1.1rem;
  }
}

.cell.fixed {
  background: var(--cell-fixed);
  color: var(--text-fixed);
  font-weight: 700;
}

/* Only apply hover on devices that support hover */
@media (hover: hover) {
  .cell:hover {
    background: var(--cell-hover);
    z-index: 1;
  }
}

.cell.selected {
  background: var(--cell-selected);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  z-index: 2;
}

.cell.highlight-row,
.cell.highlight-col,
.cell.highlight-block {
  background: var(--cell-highlight);
}

.cell.highlight-same {
  background: var(--cell-same);
}

.cell.highlight-affected {
  background: var(--cell-affected);
}

.cell.marked {
  background: var(--cell-marked) !important;
  color: #1a1a1a !important;
}

.cell.marked2 {
  background: var(--cell-marked2) !important;
  color: #1a1a1a !important;
}

/* Keep highlight color for cells with same number when highlight is active */
.cell.marked.highlight-same,
.cell.marked2.highlight-same {
  color: var(--text-user) !important;
}

/* Keep conflict color - highest priority */
.cell.marked.conflict,
.cell.marked2.conflict {
  background: var(--cell-conflict) !important;
  color: var(--text-conflict) !important;
}

/* Fixed cells in marked state should keep their bold black */
.cell.fixed.marked,
.cell.fixed.marked2 {
  color: var(--text-fixed) !important;
  font-weight: 700;
}

/* Keep normal color for selected marked cells */
.cell.marked.selected,
.cell.marked2.selected {
  color: var(--text-user) !important;
}

.cell.conflict {
  background: var(--cell-conflict);
  color: var(--text-conflict);
}

/* ====== BI-VALUE HIGHLIGHTING ====== */
.cell.bi-value {
  box-shadow: inset 0 0 0 1.5px var(--bi-value-color);
  z-index: 1;
}

/* ====== PENCIL MARKS ====== */
.pencil-marks {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0;
  pointer-events: none;
}

.pencil-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-pencil);
  line-height: 1;
  border-radius: 3px;
  margin: 1px;
  transition: all 0.15s ease;
}

/* Pencil marks in marked cells - more contrast */
.cell.marked .pencil-mark,
.cell.marked2 .pencil-mark {
  color: #666;
  font-weight: 700;
}

.pencil-mark.highlight {
  background: var(--cell-same);
  color: var(--accent);
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(108, 99, 255, 0.2);
}

/* Pencil marks in marked cells */
.cell.marked .pencil-mark.highlight {
  background: #ffe0cc;
  color: #ff7a3d;
  box-shadow: 0 0 0 1px rgba(255, 149, 99, 0.3);
}

.cell.marked2 .pencil-mark.highlight {
  background: #a3d1a3;
  color: #2a6b2a;
  box-shadow: 0 0 0 1px rgba(42, 107, 42, 0.3);
}

@media (max-width: 600px) {
  .pencil-mark {
    font-size: 0.5rem;
  }
}

/* ====== NUMBER PAD ====== */
#numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 8px;
  max-width: 500px;
  width: 100%;
}

@media (max-width: 768px) {
  #numpad {
    gap: 6px;
    max-width: 400px;
  }
}

@media (max-width: 600px) {
  #numpad {
    /* Keep 9 columns on mobile, just reduce size and gap */
    gap: 4px;
    max-width: 100%;
    padding: 0 5px;
  }
}

.num-btn {
  aspect-ratio: 1;
  border: none;
  background: #fff;
  border-radius: 8px;
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: var(--shadow-sm);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 600px) {
  .num-btn {
    font-size: 1rem;
    border-radius: 6px;
  }
}

@media (hover: hover) {
  .num-btn:hover {
    background: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
  
  .num-btn.active:hover {
    background: var(--accent-dark);
  }
}

.num-btn:active {
  transform: translateY(0);
}

.num-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(108,99,255,0.3);
}

.num-btn.disabled {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

/* ====== DANGER BUTTON ====== */
.btn-danger {
  background: var(--danger-color) !important;
  box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3) !important;
}

@media (hover: hover) {
  .btn-danger:hover {
    background: var(--danger-hover) !important;
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.4) !important;
  }
}

/* ====== CODE INPUT ====== */
.codeInputWrap {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.codeInputWrap label {
  display: flex;
  align-items: center;
  gap: 8px;
}

#puzzleNumber {
  color: #999;
  font-size: 0.9em;
  font-weight: normal;
}

.codeInput {
  width: 100%;
  padding: 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.9rem;
}

.codeInput:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108,99,255,0.1);
}

.codeButtons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.codeButtons button {
  flex: 1;
}

#copyCodeBtn.copied,
#loadCodeBtn.copied {
  background: var(--accent);
  color: #fff;
}

/* ====== HELP MODAL ====== */
.helpModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  background: rgba(0, 0, 0, 0.45);
}

.helpBox {
  max-width: 480px;
  background: #fff;
  padding: 30px 28px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
  margin: 20px;
}

.helpBox h2 {
  margin-bottom: 20px;
  font-size: 1.4rem;
  color: var(--text-primary);
}

.helpBox h3 {
  margin-top: 24px;
  margin-bottom: 12px;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.helpBox p {
  margin-bottom: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #666;
}

.helpBox ul {
  margin: 0 0 16px 0;
  padding-left: 24px;
}

.helpBox li {
  margin-bottom: 8px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: #666;
}

.helpBox code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.9em;
}

.helpBox button {
  margin-top: 20px;
  width: 100%;
}

/* ====== FOOTER ADJUSTMENT ====== */
.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0;
  padding: 10px;
  background: var(--bg);
  font-size: .85rem;
  text-align: center;
  z-index: 10;
}

/* ====== SETTINGS SECTIONS ====== */
.settings-section {
  margin-bottom: 32px;
  /*border-bottom: 1px solid var(--border-light);*/
  padding-bottom: 16px;
}

.settings-header {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.6;
}

.settings-section .setting {
  margin-bottom: 16px;
}

.settings-section:first-child {
  margin-top: 30px;
}

.settings-section .setting:last-child {
  margin-bottom: 0;
}

/* ====== MULTIPLAYER SECTION ====== */
.multiplayer-controls {
  display: flex;
  flex-direction: column;
  gap: 8px; /* Reduced from default */
}

.multiplayer-controls .section-label {
  margin-bottom: 4px; /* Small gap between label and buttons */
  font-weight: 600;
}

.multiplayer-buttons {
  display: flex;
  gap: 8px;
}

/* ====== ANIMATIONS ====== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.cell.error {
  animation: shake 0.3s ease;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.cell.placed {
  animation: pulse 0.2s ease;
}