.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 1px;
  --sudoku-board-size: 31rem;
  width: min(100%, var(--sudoku-board-size));
  aspect-ratio: 1 / 1;
  box-sizing: border-box;
  background: #d1d5db;
  border: 2px solid #374151;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgb(15 23 42 / 0.10);
}

@media (min-width: 1024px) {
  .sudoku-grid {
    --sudoku-board-size: 40.375rem;
  }
}

.sudoku-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  font-size: 1.25rem;
  font-weight: 700;
  border: 0;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s, color 0.1s;
}

.sudoku-cell:hover {
  filter: brightness(0.98);
}

/* thick right border after cols 3 and 6 */
.sudoku-cell:nth-of-type(9n+3),
.sudoku-cell:nth-of-type(9n+6) {
  border-right: 2px solid #374151;
}

/* last col - grid border handles the right edge */
.sudoku-cell:nth-of-type(9n) {
  border-right: none;
}

/* thick bottom border after rows 3 and 6 */
.sudoku-cell:nth-of-type(n+19):nth-of-type(-n+27),
.sudoku-cell:nth-of-type(n+46):nth-of-type(-n+54) {
  border-bottom: 2px solid #374151;
}

/* last row - grid border handles the bottom edge */
.sudoku-cell:nth-of-type(n+73) {
  border-bottom: none;
}

/* dark mode borders */
.dark .sudoku-grid {
  background: #334155;
  border-color: #64748b;
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.22);
}
.dark .sudoku-cell:nth-of-type(9n+3),
.dark .sudoku-cell:nth-of-type(9n+6) {
  border-right-color: #64748b;
}
.dark .sudoku-cell:nth-of-type(n+19):nth-of-type(-n+27),
.dark .sudoku-cell:nth-of-type(n+46):nth-of-type(-n+54) {
  border-bottom-color: #64748b;
}

button {
  touch-action: manipulation;
}

@keyframes finish-fill {
  0%   { filter: brightness(1.5); }
  100% { filter: brightness(1); }
}

.sudoku-cell.finish-flash {
  animation: finish-fill 0.55s ease-out;
}

.cell-candidates {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}

.cell-candidate {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.5rem;
  font-weight: 600;
  line-height: 1;
  color: #94a3b8;
}

.dark .cell-candidate {
  color: #64748b;
}

/* === Control panel redesign === */

.algo-ring {
  border: 1.5px solid rgba(124, 58, 237, 0.4) !important;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.08), inset 0 1px 0 rgba(167, 139, 250, 0.07);
}

.algo-select {
  display: block;
  width: 100%;
  background: #f5f3ff;
  color: #4c1d95;
  border: 2px solid #7c3aed;
  border-radius: 0.5rem;
  padding: 0.688rem 2.5rem 0.688rem 0.875rem;
  font-size: 0.9rem;
  font-weight: 800;
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.2);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237c3aed' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
}

.dark .algo-select {
  background-color: #2d1a5e;
  color: #e2e8f0;
  box-shadow: 0 0 14px rgba(124, 58, 237, 0.3);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a78bfa' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

.dark .algo-select option {
  background: #1e1b4b;
  color: #e2e8f0;
}

.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.algo-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  background: #ede9fe;
  color: #7c3aed;
  border: 1px solid rgba(124, 58, 237, 0.33);
}

.dark .algo-badge {
  background: #2d1a5e;
  color: #a78bfa;
}

.stat-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  height: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.stat-value {
  font-size: 0.875rem;
  font-weight: 800;
  font-family: monospace;
}

.stat-place {
  background: #dbeafe;
  border: 1px solid rgba(37, 99, 235, 0.27);
  border-radius: 7px;
  padding: 0.4rem 0.25rem;
  text-align: center;
}

.stat-place .stat-label { color: #2563eb; }
.stat-place .stat-value { color: #1d4ed8; }

.dark .stat-place { background: #1e3a5f; }
.dark .stat-place .stat-label { color: #60a5fa; }
.dark .stat-place .stat-value { color: #93c5fd; }

.stat-back {
  background: #fee2e2;
  border: 1px solid rgba(239, 68, 68, 0.27);
  border-radius: 7px;
  padding: 0.4rem 0.25rem;
  text-align: center;
}

.stat-back .stat-label { color: #dc2626; }
.stat-back .stat-value { color: #991b1b; }

.dark .stat-back { background: #3b1a1a; }
.dark .stat-back .stat-label { color: #f87171; }
.dark .stat-back .stat-value { color: #fca5a5; }

.stat-time {
  background: #fef3c7;
  border: 1px solid rgba(217, 119, 6, 0.27);
  border-radius: 7px;
  padding: 0.4rem 0.25rem;
  text-align: center;
}
.stat-time .stat-label { color: #d97706; }
.stat-time .stat-value { color: #92400e; }
.dark .stat-time { background: #3b2500; }
.dark .stat-time .stat-label { color: #fbbf24; }
.dark .stat-time .stat-value { color: #fde68a; }

@media (max-width: 639px) {
  body.min-h-screen {
    padding: 0.5rem !important;
  }

  body header {
    margin-bottom: 0.5rem !important;
  }

  body header h1 {
    font-size: 1.375rem !important;
    line-height: 1.1 !important;
  }

  body header p {
    font-size: 0.6875rem !important;
    line-height: 1.1 !important;
  }

  body main {
    gap: 0.5rem !important;
  }

  body .sudoku-grid {
    /* Fill the full content width on phones. svh-based sizing shrank the
       board well below the screen width once Safari's chrome reduced svh. */
    --sudoku-board-size: calc(100vw - 1rem);
    width: min(100%, var(--sudoku-board-size)) !important;
  }

  body .sudoku-cell {
    font-size: clamp(0.75rem, 4vw, 1.125rem) !important;
  }

  body .cell-candidate {
    font-size: clamp(0.4rem, 1.6vw, 0.55rem) !important;
  }

  body aside {
    gap: 0.5rem !important;
  }

  body aside section {
    padding: 0.375rem !important;
  }

  body .difficulty-panel {
    display: grid !important;
    grid-template-columns: 4.75rem minmax(0, 1fr);
    align-items: center;
    gap: 0.375rem !important;
  }

  body .difficulty-panel > .text-xs:first-child {
    margin: 0 !important;
  }

  body .difficulty-panel > .grid {
    gap: 0.35rem !important;
  }

  body aside section > .text-xs:first-child,
  body .algo-ring > .text-xs:first-child {
    margin-bottom: 0.25rem !important;
  }

  body aside button {
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
    min-height: 1.875rem !important;
    font-size: 0.75rem !important;
  }

  body .algo-ring {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.35rem !important;
  }

  body .algo-ring > .text-xs:first-child,
  body .algo-ring > .algo-select,
  body .algo-ring > button,
  body .algo-ring > .grid,
  body .algo-ring > hr {
    margin: 0 !important;
  }

  body .algo-ring > .text-xs:first-child {
    align-self: center;
  }

  body .algo-ring > .text-xs:nth-of-type(2),
  body .algo-ring > button,
  body .algo-ring > .grid,
  body .algo-ring > hr {
    grid-column: 1 / -1;
  }

  body .algo-ring > hr {
    display: none !important;
  }

  body .algo-select {
    min-height: 1.875rem !important;
    padding: 0.35rem 2rem 0.35rem 0.625rem !important;
    font-size: 0.75rem !important;
    background-position: right 0.625rem center !important;
  }

  body .stat-time {
    margin-top: 0 !important;
  }

  body .stat-place,
  body .stat-back,
  body .stat-time {
    padding: 0.3rem 0.25rem !important;
  }

  body .stat-label {
    font-size: 0.5rem !important;
    letter-spacing: 0.05em !important;
    margin-bottom: 1px !important;
    height: 1.5rem !important;
  }

  body .stat-value {
    font-size: 0.8125rem !important;
  }

  body .status-panel p {
    font-size: 0.6875rem !important;
    line-height: 1.1 !important;
  }
}

/* === Fish technique highlights (X-Wing / Swordfish) === */

.fish-base {
  border: 2px solid #f59e0b !important;
  background-color: #fffbeb !important;
}

.dark .fish-base {
  border-color: #d97706 !important;
  background-color: #1c1200 !important;
}

.fish-cover {
  background-color: rgba(251, 191, 36, 0.15) !important;
}

.dark .fish-cover {
  background-color: rgba(217, 119, 6, 0.12) !important;
}
