/* ========================================================
   Sudoku Solver — Heatmap Edition  |  style.css
   ======================================================== */

/* --- Reset & Root --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #16162a;
  --bg-card: #1c1c36;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b4;
  --accent: #7b5cff;
  --accent-glow: rgba(123, 92, 255, 0.35);
  --border-grid: #3a3a5c;
  --border-subgrid: #5c5c88;
  --danger: #ff4d6a;
  --warning: #ffb84d;
  --success: #2dd4a8;
  --radius: 12px;
  --radius-sm: 6px;
  --transition: 0.25s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Cell sizing — desktop default */
  --cell-size: 54px;
  --cell-gap: 2px;
  --subgrid-gap: 5px;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem 4rem;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(123, 92, 255, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(45, 212, 168, 0.06) 0%, transparent 60%);
}

/* --- App Container --- */
.app-container {
  max-width: 600px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
}

/* --- Header --- */
.app-header {
  text-align: center;
}

.logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.logo-icon {
  font-size: 1.6rem;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
  animation: pulse-glow 3s ease-in-out infinite;
}

.accent {
  color: var(--accent);
}

.tagline {
  margin-top: 0.4rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-weight: 300;
}

@keyframes pulse-glow {

  0%,
  100% {
    filter: drop-shadow(0 0 6px var(--accent-glow));
  }

  50% {
    filter: drop-shadow(0 0 16px var(--accent-glow));
  }
}

/* --- Palette Section (collapsible) --- */
.palette-section {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0;
  border: 1px solid var(--border-grid);
  overflow: hidden;
}

.palette-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.85rem 1.2rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  font-family: var(--font);
}

.palette-toggle .section-title {
  margin-bottom: 0;
}

.toggle-arrow {
  font-size: 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 0 6px var(--accent-glow));
  transition: transform 0.3s ease, filter 0.3s ease;
  line-height: 1;
}

.palette-toggle:hover .toggle-arrow {
  filter: drop-shadow(0 0 12px var(--accent-glow));
}

.palette-toggle[aria-expanded="false"] .toggle-arrow {
  transform: rotate(-90deg);
}

.palette-body {
  padding: 0 1.2rem 1rem;
  transition: max-height 0.3s ease, opacity 0.25s ease, padding 0.3s ease;
  max-height: 300px;
  opacity: 1;
}

.palette-body.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0 1.2rem;
  overflow: hidden;
}

.section-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: 0.85rem;
}

.palette-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.palette-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 2px solid transparent;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.palette-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.palette-btn.active {
  border-color: var(--accent);
  background: rgba(123, 92, 255, 0.15);
  box-shadow: 0 0 12px var(--accent-glow);
}

.palette-swatch {
  display: inline-flex;
  gap: 2px;
}

.palette-swatch span {
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

/* --- Heatmap Legend --- */
.heatmap-legend {
  display: flex;
  gap: 2px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.legend-item {
  flex: 1;
  text-align: center;
}

.legend-color {
  height: 18px;
  width: 100%;
}

.legend-label {
  font-size: 0.6rem;
  color: var(--text-secondary);
  font-weight: 500;
  padding-top: 4px;
}

/* --- Sudoku Board --- */
.board-wrapper {
  perspective: 800px;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, var(--cell-size));
  grid-template-rows: repeat(9, var(--cell-size));
  gap: var(--cell-gap);
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-grid);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  position: relative;
}

.sudoku-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  text-align: center;
  font-family: var(--font);
  font-size: 1.35rem;
  font-weight: 600;
  border: 1px solid var(--border-grid);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform 0.15s ease;
  caret-color: var(--accent);
  cursor: pointer;
}

.sudoku-cell::placeholder {
  color: rgba(152, 152, 180, 0.3);
  font-weight: 300;
}

.sudoku-cell:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), inset 0 0 8px rgba(123, 92, 255, 0.08);
  transform: scale(1.05);
  z-index: 2;
  position: relative;
}

.sudoku-cell.user-input {
  font-weight: 700;
}

.sudoku-cell.solved {
  font-weight: 400;
  animation: cell-fill 0.35s ease forwards;
}

.sudoku-cell.error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 8px rgba(255, 77, 106, 0.3) !important;
  animation: shake 0.35s ease;
}

/* Subgrid thick borders */
.sudoku-cell.border-right-thick {
  border-right: 2.5px solid var(--border-subgrid);
}

.sudoku-cell.border-bottom-thick {
  border-bottom: 2.5px solid var(--border-subgrid);
}

/* --- Given cells (from generator) --- */
.sudoku-cell.given {
  font-weight: 800;
  letter-spacing: 0.5px;
}

@keyframes cell-fill {
  0% {
    transform: scale(0.7);
    opacity: 0.3;
  }

  60% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes shake {

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

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

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

  60% {
    transform: translateX(-3px);
  }

  80% {
    transform: translateX(3px);
  }
}

/* --- Unified Controls Bar --- */
.controls-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.controls-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.difficulty-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
}

.difficulty-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-grid);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.7rem 1.6rem;
  border-radius: 999px;
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.2px;
}

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

.btn-primary {
  background: linear-gradient(135deg, #7b5cff, #5c3fd4);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-grid);
}

.btn-secondary:hover {
  border-color: var(--accent);
  background: rgba(123, 92, 255, 0.08);
  transform: translateY(-2px);
}

.btn-generate {
  background: linear-gradient(135deg, #2dd4a8, #1a9e7a);
  color: #fff;
  box-shadow: 0 4px 20px rgba(45, 212, 168, 0.3);
}

.btn-generate:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(45, 212, 168, 0.4);
}

.btn-generate:active {
  transform: translateY(0);
}

.btn-verify {
  background: linear-gradient(135deg, #ffb84d, #e09600);
  color: #111;
  box-shadow: 0 4px 20px rgba(255, 184, 77, 0.25);
}

.btn-verify:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(255, 184, 77, 0.35);
}

.btn-verify:active {
  transform: translateY(0);
}

/* --- Difficulty Buttons --- */
.difficulty-options {
  display: flex;
  gap: 0.4rem;
}

.difficulty-btn {
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-grid);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.difficulty-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.difficulty-btn.active {
  border-color: var(--accent);
  background: rgba(123, 92, 255, 0.15);
  color: var(--text-primary);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn-warning {
  background: linear-gradient(135deg, var(--danger), #d4303f);
  color: #fff;
  padding: 0.7rem 1.6rem;
  border-radius: 999px;
  border: none;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-warning:hover {
  transform: translateY(-2px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-grid);
  padding: 0.7rem 1.6rem;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-ghost:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  transform: translateY(-2px);
}

/* --- Info Bar (stats + status) --- */
.info-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: 100%;
}

/* --- Stats Bar --- */
.stats-bar {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  align-items: center;
  padding: 0;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease, max-height 0.3s ease;
  max-height: 0;
  overflow: hidden;
}

.stats-bar.visible {
  opacity: 1;
  transform: translateY(0);
  max-height: 60px;
  padding: 0.5rem 1.2rem;
  border: 1px solid var(--border-grid);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- Status Bar --- */
.status-bar {
  min-height: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.status-bar.success {
  color: var(--success);
}

.status-bar.error {
  color: var(--danger);
}

.status-bar.warning {
  color: var(--warning);
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(5, 5, 15, 0.8);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fade-in 0.2s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-grid);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.6);
  animation: modal-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-icon {
  font-size: 2.8rem;
  margin-bottom: 0.75rem;
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.modal-message {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==========================================================
   RESPONSIVE — MOBILE FIRST FIT-ON-SCREEN
   ========================================================== */

/* Medium screens (tablets / small laptops) */
@media (max-width: 560px) {
  :root {
    --cell-size: 38px;
  }

  body {
    padding: 1rem 0.5rem 1rem;
  }

  .app-container {
    gap: 0.75rem;
  }

  .logo {
    font-size: 1.5rem;
  }

  .tagline {
    font-size: 0.75rem;
    margin-top: 0.2rem;
  }

  .sudoku-cell {
    font-size: 1rem;
  }

  .sudoku-board {
    padding: 6px;
  }

  .btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.78rem;
  }

  .btn-icon {
    font-size: 0.85rem;
  }

  .difficulty-select {
    padding: 0.5rem 1.6rem 0.5rem 0.7rem;
    font-size: 0.78rem;
  }

  .controls-row {
    gap: 0.4rem;
  }

  .stats-bar {
    gap: 1rem;
  }

  .stat-label {
    font-size: 0.68rem;
  }

  .stat-value {
    font-size: 0.78rem;
  }

  .status-bar {
    font-size: 0.78rem;
    min-height: 1.2rem;
  }

  .palette-section {
    border-radius: 8px;
  }

  .palette-toggle {
    padding: 0.6rem 1rem;
  }

  .palette-body {
    padding: 0 0.8rem 0.6rem;
  }

  .palette-options {
    gap: 0.4rem;
    margin-bottom: 0.6rem;
  }

  .palette-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.7rem;
  }

  .palette-swatch span {
    width: 8px;
    height: 8px;
  }

  .legend-color {
    height: 12px;
  }

  .legend-label {
    font-size: 0.5rem;
  }
}

/* Small phones — aggressive compaction */
@media (max-width: 400px) {
  :root {
    --cell-size: 34px;
    --cell-gap: 1px;
  }

  body {
    padding: 0.5rem 0.25rem 0.5rem;
  }

  .app-container {
    gap: 0.5rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .logo-icon {
    font-size: 1.1rem;
  }

  .tagline {
    display: none;
  }

  .sudoku-board {
    padding: 4px;
    border-radius: 8px;
  }

  .sudoku-cell {
    font-size: 0.9rem;
    border-radius: 3px;
  }

  .sudoku-cell:focus {
    transform: none;
    box-shadow: 0 0 0 2px var(--accent-glow);
  }

  .btn {
    padding: 0.4rem 0.65rem;
    font-size: 0.7rem;
    gap: 0.2rem;
    border-radius: 8px;
  }

  .btn-icon {
    font-size: 0.75rem;
  }

  .difficulty-select {
    padding: 0.4rem 1.4rem 0.4rem 0.5rem;
    font-size: 0.7rem;
    border-radius: 8px;
    background-position: right 0.5rem center;
  }

  .controls-row {
    gap: 0.3rem;
  }

  .palette-body.collapsed {
    padding: 0 0.5rem;
  }

  .info-bar {
    gap: 0.15rem;
  }

  .stats-bar.visible {
    padding: 0.35rem 0.8rem;
  }

  .status-bar {
    font-size: 0.7rem;
  }
}

/* Very small / short screens (iPhone SE, older Androids) */
@media (max-height: 700px) and (max-width: 500px) {
  :root {
    --cell-size: 32px;
    --cell-gap: 1px;
  }

  body {
    padding: 0.3rem 0.25rem;
  }

  .app-container {
    gap: 0.4rem;
  }

  .logo {
    font-size: 1.1rem;
  }

  .tagline {
    display: none;
  }

  .sudoku-board {
    padding: 3px;
  }

  .sudoku-cell {
    font-size: 0.85rem;
  }

  .palette-toggle {
    padding: 0.5rem 0.8rem;
  }

  .section-title {
    font-size: 0.7rem;
    letter-spacing: 1px;
  }

  .btn {
    padding: 0.35rem 0.55rem;
    font-size: 0.65rem;
  }

  .difficulty-select {
    padding: 0.35rem 1.2rem 0.35rem 0.45rem;
    font-size: 0.65rem;
  }
}