/* ============================================
   SUDOKU PWA - CSS (sudoku.com style)
   ============================================ */

:root {
  --blue: #325aaf;
  --blue-light: #5a7bc0;
  --blue-hover: #7091d5;
  --blue-dark: #4363a7;
  --green: #009f27;
  --red: #e53935;
  --bg: #f0f4ff;
  --board-bg: #fff;
  --cell-default: #fff;
  --cell-given: #f0f4ff;
  --text-dark: #344861;
  --text-mid: #6e7c8c;
  --text-light: #94a3b7;
  --border-light: #c3cbd5;
  --border-dark: #344861;
  --selected: #dce9fc;
  --highlight: #e8f0fd;
  --same-num: #c9d9f6;
  --error-bg: #fde8e8;
  --error-text: #c62828;
  --shadow: 0 2px 12px rgba(50,90,175,.15);
  --radius: 8px;
  --header-h: 52px;
  --tab-h: 40px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  height: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  height: 100%;
  font-family: 'Hauss', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-dark);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* ===== HEADER ===== */
.header {
  background: #fff;
  height: var(--header-h);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
  flex-shrink: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  gap: 10px;
}
.header-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-mid);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
.header-btn:hover { background: var(--bg); }
.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
  flex: 1;
}
.header-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
}

/* ===== DIFFICULTY TABS ===== */
.difficulty-tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.difficulty-tabs::-webkit-scrollbar { display: none; }
.diff-tab {
  flex: 1;
  min-width: 64px;
  height: var(--tab-h);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mid);
  cursor: pointer;
  transition: color .2s, border-color .2s;
  white-space: nowrap;
  padding: 0 8px;
}
.diff-tab.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}
.diff-tab:hover { color: var(--blue-light); }

/* ===== MAIN GAME AREA ===== */
.game-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px 8px;
  overflow: hidden;
  gap: 10px;
}
.board-wrap {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== BOARD ===== */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 2px solid var(--border-dark);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--board-bg);
  touch-action: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-default);
  border-right: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .1s;
  font-size: clamp(14px, 3.5vw, 22px);
  font-weight: 600;
  color: var(--text-dark);
  -webkit-tap-highlight-color: transparent;
}
/* Remove right/bottom on last col/row */
.cell:nth-child(9n) { border-right: none; }
.cell:nth-child(n+73) { border-bottom: none; }

/* Thick borders for 3x3 blocks */
.cell[data-col="3"], .cell[data-col="6"] { border-left: 2px solid var(--border-dark); }
.cell[data-row="3"], .cell[data-row="6"] { border-top: 2px solid var(--border-dark); }

/* States */
.cell.given { background: var(--cell-given); color: var(--text-dark); }
.cell.selected { background: var(--selected); }
.cell.highlight { background: var(--highlight); }
.cell.same-num { background: var(--same-num); }
.cell.error { background: var(--error-bg); color: var(--error-text); }
.cell.error.selected { background: #fcc; }
.cell.pulse { animation: cellPulse .35s ease-out; }
.cell.error-shake { animation: errorShake .3s ease-out; }

.cell-value {
  position: relative;
  z-index: 1;
  line-height: 1;
}
.cell-value.user-num { color: var(--blue); }

/* Notes grid inside cell */
.cell-notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 1px;
}
.note-num {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(7px, 1.4vw, 10px);
  font-weight: 500;
  color: var(--text-mid);
  line-height: 1;
}

/* ===== CONTROLS AREA ===== */
.controls-area {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.game-controls {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.ctrl-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--blue);
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background .15s, transform .1s;
  font-size: 11px;
  font-weight: 600;
}
.ctrl-btn:active { transform: scale(.93); background: var(--highlight); }
.ctrl-btn.active-notes { background: var(--same-num); }
.ctrl-btn em { font-style: normal; font-size: 10px; background: var(--blue); color: #fff; border-radius: 10px; padding: 0 5px; min-width: 18px; text-align: center; }
.ctrl-btn svg { flex-shrink: 0; }

/* ===== NUMPAD ===== */
.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 4px;
}
.num-btn {
  aspect-ratio: 1;
  background: #fff;
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  font-size: clamp(16px, 4vw, 26px);
  font-weight: 700;
  color: var(--blue);
  cursor: pointer;
  transition: background .15s, transform .1s, border-color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(50,90,175,.1);
}
.num-btn:hover { background: var(--highlight); border-color: var(--blue-light); }
.num-btn:active { transform: scale(.9); background: var(--same-num); }
.num-btn.completed { color: var(--border-light); border-color: var(--border-light); pointer-events: none; }

/* ===== POPUP ===== */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s cubic-bezier(.23,1.56,.57,1.24);
  padding: 16px;
}
.popup-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.popup-box {
  background: #fff;
  border-radius: 12px;
  padding: 32px 24px 24px;
  width: 100%;
  max-width: 300px;
  text-align: center;
  transform: scale(.6);
  transition: transform .35s cubic-bezier(.23,1.56,.57,1.24);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.popup-overlay.show .popup-box { transform: scale(1); }

.win-trophy {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 10px;
  animation: trophyBounce .6s ease-out .1s both;
}
.gameover-icon { font-size: 56px; line-height: 1; margin-bottom: 10px; }

.popup-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 4px;
}
.popup-sub {
  font-size: 14px;
  color: var(--text-mid);
  margin-bottom: 16px;
}

.win-stats {
  display: flex;
  justify-content: space-around;
  background: var(--bg);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 20px;
}
.win-stat { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.win-stat-label { font-size: 11px; font-weight: 500; color: var(--text-mid); text-transform: uppercase; letter-spacing: .5px; }
.win-stat-value { font-size: 20px; font-weight: 700; color: var(--text-dark); }

.popup-btn {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  margin-top: 8px;
}
.popup-btn:active { transform: scale(.97); }
.popup-btn.primary { background: var(--blue); color: #fff; }
.popup-btn.primary:hover { background: var(--blue-hover); }
.popup-btn.secondary { background: var(--green); color: #fff; }
.popup-btn.secondary:hover { background: #009124; }
.popup-btn.ghost { background: transparent; color: var(--blue); border: 1.5px solid var(--blue-light); }
.popup-btn.ghost:hover { background: var(--highlight); }

/* ===== MENU DRAWER ===== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.menu-overlay.show { opacity: 1; pointer-events: auto; }

.menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: #fff;
  z-index: 51;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  box-shadow: 4px 0 16px rgba(0,0,0,.12);
}
.menu-drawer.open { transform: translateX(0); }

.menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.menu-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-mid);
  padding: 4px 8px;
  border-radius: 6px;
}
.menu-close:hover { background: var(--bg); }

.menu-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.menu-section { margin-bottom: 24px; }
.menu-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 10px;
}
.menu-diff-btns {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.menu-diff-btn {
  background: var(--bg);
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  height: 40px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  text-align: left;
  padding: 0 14px;
  transition: background .15s, border-color .15s;
}
.menu-diff-btn:hover { background: var(--highlight); border-color: var(--blue-light); }
.menu-diff-btn.active { border-color: var(--blue); color: var(--blue); background: var(--highlight); }

.menu-action-btn {
  width: 100%;
  background: none;
  border: 1.5px solid var(--border-light);
  border-radius: 8px;
  height: 40px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}
.menu-action-btn:hover { background: var(--bg); }

.menu-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dark);
  gap: 8px;
}
.menu-toggle input { display: none; }
.toggle-track {
  width: 44px;
  height: 24px;
  background: var(--border-light);
  border-radius: 12px;
  position: relative;
  flex-shrink: 0;
  transition: background .2s;
}
.menu-toggle input:checked ~ .toggle-track { background: var(--blue); }
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.menu-toggle input:checked ~ .toggle-track .toggle-thumb { transform: translateX(20px); }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.stats-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}
.stats-card-label { font-size: 10px; color: var(--text-light); text-transform: uppercase; letter-spacing: .5px; }
.stats-card-value { font-size: 20px; font-weight: 700; color: var(--blue); }

/* ===== INSTALL BANNER ===== */
.install-banner {
  position: fixed;
  bottom: -80px;
  left: 0;
  right: 0;
  z-index: 30;
  padding: 8px 12px;
  transition: bottom .4s cubic-bezier(.4,0,.2,1);
}
.install-banner.show { bottom: 0; }
.install-banner-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--blue);
  color: #fff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 4px 16px rgba(50,90,175,.4);
}
.install-icon { flex-shrink: 0; }
.install-text { flex: 1; display: flex; flex-direction: column; }
.install-text strong { font-size: 13px; }
.install-text span { font-size: 11px; opacity: .8; }
.install-btn {
  background: #fff;
  color: var(--blue);
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.install-dismiss {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--text-dark);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== ANIMATIONS ===== */
@keyframes cellPulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.15); }
  100% { transform: scale(1); }
}
@keyframes errorShake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes trophyBounce {
  0% { transform: scale(.3) rotate(-10deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== RESPONSIVE SIZING ===== */
@media (max-height: 700px) {
  .game-main { padding: 6px 8px 4px; gap: 6px; }
}
@media (min-width: 480px) {
  .numpad { gap: 6px; }
  .game-main { padding: 16px 16px 12px; }
}
