/* === Reset & Base === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f1923;
  --bg-secondary: #1a2a3a;
  --bg-cell: #1e3448;
  --bg-cell-selected: #2a5a8a;
  --bg-cell-highlight: #1a3a5a;
  --bg-cell-same-num: #2a4a6a;
  --bg-cell-given: #243b53;
  --bg-cell-error: rgba(231, 76, 60, 0.3);
  --text: #e0e6ed;
  --text-dim: #7a8a9a;
  --text-given: #e0e6ed;
  --text-user: #5dade2;
  --text-notes: #7ab8e0;
  --text-error: #e74c3c;
  --border: #2a3a4a;
  --border-box: #4a6a8a;
  --accent: #3498db;
  --accent-hover: #2980b9;
  --success: #2ecc71;
  --btn-bg: #1a2a3a;
  --btn-active: #2a4a6a;
  --numpad-bg: #1e3448;
  --numpad-active: #3498db;
  --overlay-bg: rgba(15, 25, 35, 0.92);
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
}

/* === Layout === */
#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 8px 12px;
  overflow: hidden;
}

/* === Top Bar === */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 0;
  flex-shrink: 0;
}

.top-bar .left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar .right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-icon:active {
  background: var(--btn-active);
}

.game-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}

/* === Info Bar === */
.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 0;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.info-bar .difficulty-badge {
  background: var(--bg-secondary);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.timer {
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  color: var(--text);
}

/* === Sudoku Grid === */
.rule-hint {
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.4);
  margin-bottom: 6px;
}

.grid-container {
  width: 100%;
  aspect-ratio: 1;
  max-height: calc(100vh - 280px);
  max-width: calc(100vh - 280px);
  flex-shrink: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sudoku-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  border: 2.5px solid var(--border-box);
  border-radius: 8px;
  overflow: hidden;
  background: var(--border);
  gap: 1px;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-cell);
  font-size: min(6vw, 28px);
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}

/* 3x3 box borders */
.cell[data-col="2"], .cell[data-col="5"] {
  border-right: 2px solid var(--border-box);
}
.cell[data-row="2"], .cell[data-row="5"] {
  border-bottom: 2px solid var(--border-box);
}

.cell.given {
  color: var(--text-given);
  background: var(--bg-cell-given);
}

.cell.user-input {
  color: var(--text-user);
}

.cell.selected {
  background: var(--bg-cell-selected) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.cell.highlighted {
  background: var(--bg-cell-highlight);
}

.cell.same-number {
  background: var(--bg-cell-same-num);
}

.cell.error {
  color: var(--text-error) !important;
  background: var(--bg-cell-error) !important;
}

.cell.hint-flash {
  animation: hintPulse 0.6s ease;
}

@keyframes hintPulse {
  0%, 100% { background: var(--bg-cell); }
  50% { background: var(--success); }
}

/* Notes in cell */
.cell .notes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
}

.cell .notes-grid span {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: min(2.2vw, 10px);
  color: var(--text-notes);
  font-weight: 400;
  line-height: 1;
}

/* === Action Bar === */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 0 4px;
  flex-shrink: 0;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  border: none;
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  min-width: 52px;
  transition: background 0.15s;
}

.action-btn .icon {
  font-size: 20px;
  line-height: 1;
}

.action-btn:active {
  background: var(--btn-active);
}

.action-btn.active {
  background: var(--accent);
  color: #fff;
}

/* === Number Pad === */
.numpad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  padding: 4px 0 8px;
  flex-shrink: 0;
}

.numpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 48px;
  border: none;
  border-radius: 10px;
  background: var(--numpad-bg);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.1s, transform 0.1s;
}

.numpad-btn:active {
  background: var(--numpad-active);
  transform: scale(0.95);
}

.numpad-btn.erase-btn {
  font-size: 16px;
  color: var(--text-dim);
}

.numpad-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* === Difficulty Modal === */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 28px 24px;
  width: 85%;
  max-width: 320px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal h2 {
  font-size: 20px;
  margin-bottom: 20px;
  color: var(--text);
}

.modal .diff-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal .diff-btn {
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--bg-cell);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.modal .diff-btn:active {
  background: var(--accent);
}

/* === Win Modal === */
.win-modal .stats {
  margin: 16px 0 20px;
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.8;
}

.win-modal .play-again-btn {
  padding: 14px 28px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.win-modal .play-again-btn:active {
  background: var(--accent-hover);
}

/* === Responsive === */
@media (max-height: 600px) {
  .numpad-btn { height: 40px; font-size: 18px; }
  .action-btn { padding: 4px 8px; font-size: 10px; min-width: 44px; }
  .action-btn .icon { font-size: 16px; }
}

@media (min-width: 500px) {
  .cell { font-size: 28px; }
  .cell .notes-grid span { font-size: 10px; }
}
