:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-elevated: #273549;
  --border: #334155;
  --border-strong: #94a3b8;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0284c7;
  --given-text: #f8fafc;
  --user-text: #7dd3fc;
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, 0.16);
  --highlight-peer: rgba(148, 163, 184, 0.12);
  --highlight-same: rgba(56, 189, 248, 0.22);
  --highlight-selected: rgba(56, 189, 248, 0.36);
  --success: #4ade80;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-elevated: #e2e8f0;
  --border: #cbd5e1;
  --border-strong: #475569;
  --text: #0f172a;
  --text-muted: #475569;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --given-text: #0f172a;
  --user-text: #0284c7;
  --error: #dc2626;
  --error-bg: rgba(220, 38, 38, 0.12);
  --highlight-peer: rgba(15, 23, 42, 0.05);
  --highlight-same: rgba(2, 132, 199, 0.2);
  --highlight-selected: rgba(2, 132, 199, 0.3);
  --success: #16a34a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 20px 14px 40px;
}

.app-shell {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

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

.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.dot {
  margin: 0 4px;
}

.new-hour-banner {
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.difficulty-tabs {
  display: inline-flex;
  background: var(--surface);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  gap: 4px;
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab-btn.active {
  background: var(--accent-strong);
  color: #ffffff;
}

.status-pills {
  display: flex;
  gap: 8px;
}

.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
}

.pill-label {
  color: var(--text-muted);
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sudoku-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--surface);
  border: 2.5px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  user-select: none;
}

.cell {
  position: relative;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--user-text);
  font-size: clamp(1.1rem, 4.5vw, 1.65rem);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s;
}

.cell.box-right {
  border-right: 2px solid var(--border-strong);
}

.cell.box-bottom {
  border-bottom: 2px solid var(--border-strong);
}

.cell.col-last {
  border-right: none;
}

.cell.row-last {
  border-bottom: none;
}

.cell.given {
  color: var(--given-text);
  font-weight: 700;
}

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

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

.cell.selected {
  background: var(--highlight-selected);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

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

.notes-grid {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 2px;
}

.note-digit {
  font-size: clamp(0.5rem, 1.8vw, 0.72rem);
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.num-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 700;
  padding: 12px 0;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.num-btn:hover {
  background: var(--surface-elevated);
  border-color: var(--accent);
}

.num-btn.active {
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #ffffff;
}

.num-btn.completed {
  opacity: 0.45;
}

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--accent-strong);
  color: #ffffff;
}

.btn-primary:hover {
  background: #0369a1;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-elevated);
}

.btn-secondary[aria-pressed="true"] {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--accent);
  color: var(--accent);
}

.keyboard-hint {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-card-wide {
  max-width: 540px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.result-meta {
  margin: 0 0 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.share-preview {
  margin: 0 0 14px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.copy-feedback {
  margin: 8px 0 0;
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--success);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
}

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

.section-title {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.history-info strong {
  display: block;
  font-size: 0.92rem;
}

.history-info span {
  font-size: 0.8rem;
  color: var(--text-muted);
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

