:root {
  color-scheme: light;
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-muted: #F5F7FB;
  --text: #1F2D3D;
  --text-muted: #6E7A8A;
  --accent: #4A6CF7;
  --accent-soft: #DCEBFF;
  --accent-strong: #355DE8;
  --line: #E3E8F0;
  --line-strong: #C7D0DB;
  --grid: #23364d;
  --success: #2AB673;
  --danger: #FF5A5F;
  --warning: #FFC107;
  --shadow: 0 20px 45px rgba(31, 45, 61, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button, select { font: inherit; }
button {
  border: none;
  border-radius: 14px;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
button:focus-visible, select:focus-visible, .cell:focus-visible {
  outline: 3px solid rgba(74, 108, 247, 0.25);
  outline-offset: 2px;
}

.app-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 1.25rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.brand-block h1 { margin: 0.25rem 0 0; font-size: clamp(1.6rem, 3vw, 2.1rem); }
.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: center;
}

.difficulty-select {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 0.95rem;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.difficulty-select select {
  background: transparent;
  color: var(--text);
  border: none;
}

.action-btn {
  padding: 0.8rem 1rem;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.action-btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}
.action-btn.pill { padding: 0.72rem 0.95rem; }
.text-btn { background: transparent; color: var(--accent); padding: 0; box-shadow: none; }

.status-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin: 0 auto 1rem;
  max-width: 980px;
}
.stat-card, .panel-card, .overlay-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.stat-card { padding: 1rem 1.05rem; display: flex; flex-direction: column; gap: 0.28rem; }
.label { color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.16em; }

.game-layout {
  display: flex;
  justify-content: center;
  align-items: start;
  padding: 0.2rem 0 1.2rem;
}
.board-section {
  width: min(100%, 860px);
}
.board-shell {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 32px;
  box-shadow: var(--shadow);
}
.board-wrapper {
  display: flex;
  justify-content: center;
  padding: 0.35rem;
}
.board-wrapper.paused { filter: blur(6px); }
.sudoku-board {
  width: min(100%, 700px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 3px solid var(--grid);
  border-radius: 18px;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(35, 54, 77, 0.06);
}
.cell {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: clamp(1rem, 2.2vw, 1.4rem);
  font-weight: 700;
  padding: 0.2rem;
  transition: transform 180ms ease, background 180ms ease, box-shadow 180ms ease;
  animation: cellIn 240ms ease both;
}
.cell:nth-child(3n) { border-right: 3px solid var(--grid); }
.cell:nth-child(27n), .cell:nth-child(54n) { border-bottom: 3px solid var(--grid); }
.cell:hover { transform: scale(0.98); }
.cell.locked { background: #F5F7FB; color: var(--text); }
.cell.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); transform: scale(1.02); }
.cell.highlight-row, .cell.highlight-col, .cell.highlight-box { background: #F8FBFF; }
.cell.same-value { background: #FFF4CC; }
.cell.revealed { animation: reveal 260ms ease; }
.cell.invalid { animation: shake 320ms ease; color: var(--danger); }
.cell.notes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.08rem; padding: 0.16rem; font-size: 0.54rem; }
.cell-note { color: var(--text-muted); display: flex; align-items: center; justify-content: center; }

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.game-meta {
  display: flex;
  justify-content: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.95rem;
}
.meta-pill strong { color: var(--text); }
.num-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.7rem; }
.num-pad button { aspect-ratio: 1; background: var(--surface-muted); color: var(--text); font-size: 1.1rem; font-weight: 700; box-shadow: var(--shadow); }
.num-pad button.clear-btn { background: rgba(255, 90, 95, 0.12); color: var(--danger); }
.pad-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.7rem; }
.mobile-keypad { display: none; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.6rem; }
.mobile-keypad button { min-height: 48px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(31, 45, 61, 0.58);
  backdrop-filter: blur(9px);
}
.overlay-card {
  width: min(100%, 540px);
  padding: 1.35rem;
  text-align: left;
  animation: overlayIn 220ms ease;
}
.pause-card, .result-card { text-align: center; }
.tutorial-header { display: flex; justify-content: space-between; align-items: center; gap: 0.7rem; margin-bottom: 1rem; }
.progress-dots { display: flex; gap: 0.35rem; }
.progress-dot { width: 8px; height: 8px; border-radius: 999px; background: rgba(31, 45, 61, 0.16); }
.progress-dot.active { background: var(--accent); transform: scale(1.2); }
.tutorial-demo { margin-top: 1rem; padding: 0.95rem; border-radius: 16px; background: var(--surface-muted); border: 1px solid var(--line); color: var(--text-muted); line-height: 1.7; }
.overlay-actions { display: flex; flex-wrap: wrap; gap: 0.7rem; margin-top: 1rem; justify-content: center; }
.tutorial-actions { justify-content: flex-start; }
.pause-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; margin-top: 0.85rem; }
.pause-stats div { padding: 0.8rem; border-radius: 16px; background: var(--surface-muted); }
.pause-stats span { display: block; color: var(--text-muted); margin-bottom: 0.3rem; }
.result-details { display: grid; gap: 0.38rem; margin: 0.9rem 0 1rem; color: var(--text-muted); }

.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 80; display: flex; flex-direction: column; gap: 0.7rem; pointer-events: none; }
.toast { min-width: 240px; max-width: min(360px, 90vw); padding: 0.85rem 1rem; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); border-left: 4px solid var(--accent); animation: toastIn 220ms ease; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast-title { font-weight: 700; margin-bottom: 0.2rem; }
.toast-message { color: var(--text-muted); font-size: 0.95rem; }

.confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; }
.confetti-piece { position: absolute; width: 10px; height: 18px; border-radius: 4px; animation: confetti-fall 1.1s cubic-bezier(.2,.8,.2,1) forwards; }
.hidden { display: none; }

@keyframes cellIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes reveal { 0% { transform: scale(0.82); opacity: 0.4; } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake { 0%,100% { transform: translateX(0);} 25% { transform: translateX(-4px);} 50% { transform: translateX(4px);} 75% { transform: translateX(-4px);} }
@keyframes overlayIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes confetti-fall { 0% { transform: translateY(-30px) rotate(0deg); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(120vh) rotate(720deg); opacity: 0; } }

@media (max-width: 760px) {
  .app-shell { padding: 0.8rem; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
  .status-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .board-shell { padding: 0.8rem; border-radius: 24px; }
  .sudoku-board { width: min(100%, 560px); }
  .mobile-keypad { display: grid; }
  .num-pad { display: none; }
  .pad-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 470px) {
  .status-bar { grid-template-columns: 1fr; }
  .pad-actions, .overlay-actions { grid-template-columns: 1fr; }
}
