/* ─── Sudoku page layout ─── */
.sudoku-shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 60px;
}

.sudoku-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 18px;
  backdrop-filter: blur(18px);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.sudoku-header h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  text-decoration: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: transparent;
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
  color: #fff;
  transform: translateY(-1px);
}

.btn.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: transparent;
  color: #fff;
}

.hidden { display: none !important; }

/* ─── Map screen ─── */
#screen-map {
  animation: fadeIn 0.3s ease;
}

.map-intro {
  text-align: center;
  margin-bottom: 32px;
}

.map-intro h2 {
  font-size: 1.8rem;
  margin: 0 0 8px;
}

.map-intro p {
  color: var(--text-muted);
  margin: 0;
}

.map-container {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  backdrop-filter: blur(14px);
}

.chapter-heading {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 0 16px;
  margin-top: 8px;
}

.chapter-easy { color: #34d399; }
.chapter-medium { color: #fbbf24; }
.chapter-hard { color: #f87171; }

#map-levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 12px;
}

/* Chapter headings span full width */
.chapter-heading {
  grid-column: 1 / -1;
}

/* ─── Level nodes ─── */
.level-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 80px;
  position: relative;
  overflow: hidden;
}

.level-node:hover:not(.locked) {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.level-node.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-node.available {
  border-color: var(--primary);
  animation: pulse-border 2s ease-in-out infinite;
}

.level-node.completed.chapter-easy   { border-color: #34d399; background: rgba(52,211,153,0.08); }
.level-node.completed.chapter-medium { border-color: #fbbf24; background: rgba(251,191,36,0.08); }
.level-node.completed.chapter-hard   { border-color: #f87171; background: rgba(248,113,113,0.08); }

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110,168,254,0.4); }
  50%       { box-shadow: 0 0 0 6px rgba(110,168,254,0); }
}

.level-num {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.level-stars {
  font-size: 0.75rem;
  letter-spacing: 1px;
}
.chapter-easy   .level-stars { color: #34d399; }
.chapter-medium .level-stars { color: #fbbf24; }
.chapter-hard   .level-stars { color: #f87171; }

.level-time {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.level-play {
  font-size: 1rem;
  color: var(--primary);
}

.lock-icon {
  font-size: 0.9rem;
}

/* ─── Game screen ─── */
#screen-game {
  animation: fadeIn 0.3s ease;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 24px;
  align-items: start;
}

@media (max-width: 700px) {
  .game-layout {
    grid-template-columns: 1fr;
  }
}

.game-board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.game-info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  padding: 10px 16px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.game-title-group {
  display: flex;
  flex-direction: column;
}

.game-level-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.game-chapter-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.game-timer {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  letter-spacing: 0.02em;
}

/* ─── Sudoku board ─── */
.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 2px;
  width: min(480px, calc(100vw - 48px));
  aspect-ratio: 1;
  background: var(--bg-soft);
  border: 3px solid var(--primary);
  border-radius: 12px;
  padding: 3px;
  backdrop-filter: blur(10px);
  position: relative;
}

/* 3×3 box borders */
.cell.box-left { border-left: 2px solid rgba(110,168,254,0.5); }
.cell.box-top  { border-top:  2px solid rgba(110,168,254,0.5); }

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s ease;
  position: relative;
  background: var(--bg-elevated);
  min-width: 0;
  min-height: 0;
  user-select: none;
  -webkit-user-select: none;
}

.cell:hover { background: rgba(110,168,254,0.14); }

.cell.given {
  background: rgba(110,168,254,0.06);
}

/* ── Dark mode highlight (default) ── */
.cell.selected {
  background: rgba(110,168,254,0.42) !important;
  border-color: var(--primary) !important;
}

.cell.highlight {
  background: rgba(110,168,254,0.20);
}

.cell.same-num {
  background: rgba(110,168,254,0.32);
}

/* ── Light mode overrides ── */
body.light .cell.selected {
  background: rgba(37,99,235,0.22) !important;
  border-color: var(--primary) !important;
}

body.light .cell.highlight {
  background: rgba(37,99,235,0.10);
}

body.light .cell.same-num {
  background: rgba(37,99,235,0.20);
}

.cell.error {
  background: rgba(248,113,113,0.22) !important;
}

body.light .cell.error {
  background: rgba(220,38,38,0.14) !important;
}

/* Error flash: orange when a wrong number is entered and check is consumed */
.cell.validate-error {
  background: rgba(251,146,60,0.45) !important;
  border-color: #f97316 !important;
  animation: error-pulse 0.35s ease;
}

body.light .cell.validate-error {
  background: rgba(234,88,12,0.20) !important;
  border-color: #ea580c !important;
}

@keyframes error-pulse {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ── Error-check hearts ── */
.error-checks {
  display: flex;
  gap: 4px;
  align-items: center;
}

.ec-icon {
  font-size: 1.3rem;
  line-height: 1;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.ec-filled {
  color: #f87171;
  filter: drop-shadow(0 0 4px rgba(248,113,113,0.6));
}

.ec-empty {
  color: var(--border);
  opacity: 0.5;
}

body.light .ec-filled {
  color: #dc2626;
  filter: drop-shadow(0 0 3px rgba(220,38,38,0.4));
}

/* Pop animation when a heart is lost */
.ec-icon.pop {
  animation: heart-pop 0.4s ease;
}

@keyframes heart-pop {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.4); }
  60%  { transform: scale(0.85); }
  100% { transform: scale(1); }
}

.cell-value {
  font-size: clamp(14px, 3.5vw, 24px);
  font-weight: 600;
  line-height: 1;
}

.cell.given .cell-value { color: var(--text); }
.cell:not(.given) .cell-value { color: var(--primary); }
.cell.error .cell-value { color: #f87171; }

/* Notes grid inside cell */
.note-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
}

.note-num {
  font-size: clamp(6px, 1.2vw, 10px);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ─── Number pad ─── */
.num-pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.num-btn {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(16px, 4vw, 26px);
  font-weight: 700;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.num-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: scale(1.05);
}

.num-btn.clear-btn {
  font-size: clamp(12px, 2.5vw, 16px);
  color: var(--text-muted);
}

/* ─── Side panel ─── */
.game-side-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.side-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  backdrop-filter: blur(10px);
}

.side-card h3 {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.side-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.side-actions .btn {
  width: 100%;
  justify-content: center;
}

/* Pause overlay */
.pause-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7,17,31,0.85);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-muted);
  z-index: 10;
  backdrop-filter: blur(4px);
}

/* ─── Result screen ─── */
#screen-result {
  animation: fadeIn 0.4s ease;
}

.result-card {
  max-width: 480px;
  margin: 60px auto;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px;
  text-align: center;
  backdrop-filter: blur(18px);
}

.result-trophy {
  font-size: 4rem;
  margin-bottom: 12px;
}

.result-card h2 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.result-level-tag {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.result-time-big {
  font-size: 3.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
  letter-spacing: -0.02em;
  margin: 8px 0;
}

.result-stars-big {
  font-size: 2rem;
  letter-spacing: 4px;
  color: #fbbf24;
  margin: 8px 0;
}

.result-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 16px 0 28px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-actions .btn {
  justify-content: center;
  padding: 12px;
  font-size: 1rem;
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Mobile adjustments ─── */
@media (max-width: 700px) {
  .sudoku-header h1 { font-size: 1.1rem; }
  .game-side-panel { order: -1; }
  .side-actions { flex-direction: row; flex-wrap: wrap; }
  .side-actions .btn { width: auto; flex: 1; }
  .result-time-big { font-size: 2.5rem; }
  .result-card { margin: 20px auto; padding: 28px 20px; }
}

/* ─── Back-link ─── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: color 0.15s;
}
.back-link:hover { color: var(--primary); }

/* ─── Progress banner ─── */
.progress-banner {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  backdrop-filter: blur(10px);
}

.progress-bar-wrap {
  flex: 1;
  min-width: 160px;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #34d399 0%, #6ea8fe 50%, #f87171 100%);
  border-radius: 99px;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}
