@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Montserrat:wght@600;700;800&display=swap');

:root {
  --primary: #3a86ff;
  --primary-alt: #00b4d8;
  --gold: #ffbe0b;
  --success: #06d6a0;
  --warning: #ffd166;
  --error: #ef476f;

  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f4f8ff;
  --text: #0f172a;
  --text-subtle: #475569;
  --line: #d2deef;
  --grid-line: #1f3659;
  --card-shadow: 0 18px 42px rgba(31, 54, 89, 0.15);
  --card-glow: 0 0 0 0 rgba(58, 134, 255, 0);
  --backdrop: rgba(8, 21, 41, 0.42);
  --bg-gradient-end: #dff1ff;
  --theme-hover-bg: rgba(58, 134, 255, 0.12);
  --toggle-track-border: #aac4e8;
  --toggle-track-start: #d7e8ff;
  --toggle-track-end: #c8f4ff;
  --cell-border: #d7e4f6;
  --cell-hover: #edf4ff;
  --cell-given: #e6f0ff;
  --cell-selected: #d3e6ff;
  --cell-peer: #e3f4fb;
  --cell-peer-line: rgba(0, 180, 216, 0.34);
  --cell-match: #fff0cb;
  --cell-conflict: #ffd6e1;
  --action-active: #dce9ff;
  --dialog-primary-border: #2d7af7;
  --win-summary-bg: #e9f2ff;
  --footer-link: #3567b5;
  --win-pulse-ring: rgba(58, 134, 255, 0.16);
}

html[data-theme='dark'] {
  --bg: #020617;
  --surface: #1e293b;
  --surface-soft: #24344d;
  --text: #f8fafc;
  --text-subtle: #94a3b8;
  --line: #334864;
  --grid-line: #dbeafe;
  --card-shadow: 0 24px 50px rgba(2, 6, 23, 0.58);
  --card-glow: 0 0 0 1px rgba(58, 134, 255, 0.26), 0 0 36px rgba(58, 134, 255, 0.16);
  --backdrop: rgba(2, 6, 23, 0.64);
  --bg-gradient-end: #0a1830;
  --theme-hover-bg: rgba(58, 134, 255, 0.22);
  --toggle-track-border: #4a6487;
  --toggle-track-start: #25344c;
  --toggle-track-end: #213f5b;
  --cell-border: #39506d;
  --cell-hover: #273852;
  --cell-given: #3e5f8e;
  --cell-selected: #2f4f82;
  --cell-peer: #1f324d;
  --cell-peer-line: rgba(126, 211, 236, 0.46);
  --cell-match: #5f4d22;
  --cell-conflict: #5e2d3d;
  --action-active: #2c4264;
  --dialog-primary-border: #4f94ff;
  --win-summary-bg: #2a3d5d;
  --footer-link: #78a8ff;
  --win-pulse-ring: rgba(58, 134, 255, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  color: var(--text);
  line-height: 1.5;
  background:
    radial-gradient(circle at 0% 0%, rgba(58, 134, 255, 0.2) 0%, rgba(58, 134, 255, 0) 42%),
    radial-gradient(circle at 88% 12%, rgba(0, 180, 216, 0.2) 0%, rgba(0, 180, 216, 0) 40%),
    linear-gradient(162deg, var(--bg) 0%, var(--bg-gradient-end) 100%);
  transition: background-color 220ms ease, color 220ms ease;
}

#app {
  min-height: 100vh;
  padding: 16px;
}

html[data-platform='ios'][data-native='true'] #app {
  min-height: 100dvh;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
}

.app-shell {
  width: min(100%, 440px);
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

html[data-platform='ios'][data-native='true'] .app-shell {
  width: min(100%, 460px);
  gap: 10px;
}

.top-bar,
.grid-panel,
.controls {
  animation: fade-up 200ms ease both;
}

.grid-panel {
  animation-delay: 40ms;
}

.controls {
  animation-delay: 80ms;
}

.top-bar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--card-shadow), var(--card-glow);
  padding: 11px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.brand-lockup {
  display: grid;
  gap: 1px;
  grid-column: 1 / -1;
}

.brand {
  font-family: 'Montserrat', sans-serif;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.brand-tagline {
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.76rem;
}

.stat-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  padding: 8px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}

.stat-chip span {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.stat-chip strong {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: capitalize;
  margin-left: auto;
  white-space: nowrap;
}

.stat-chip--difficulty {
  min-width: 0;
}

.stat-chip--theme {
  padding: 0;
  border: 0;
  background: transparent;
  justify-self: end;
}

.theme-toggle {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 150ms ease, background-color 150ms ease;
}

.theme-toggle:hover {
  transform: scale(1.05);
  background: var(--theme-hover-bg);
}

.theme-toggle__icon {
  position: absolute;
  transition: opacity 150ms ease, transform 150ms ease;
}

.theme-toggle__icon--sun {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 2px rgba(58, 134, 255, 0.15);
}

.theme-toggle__icon--moon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: -3px 0 0 1px var(--gold);
}

.theme-toggle__label {
  font-size: 0.84rem;
}

.theme-toggle[data-mode='light'] .theme-toggle__icon--sun {
  opacity: 1;
  transform: scale(1);
}

.theme-toggle[data-mode='light'] .theme-toggle__icon--moon {
  opacity: 0;
  transform: scale(0.65);
}

.theme-toggle[data-mode='dark'] .theme-toggle__icon--sun {
  opacity: 0;
  transform: scale(0.65);
}

.theme-toggle[data-mode='dark'] .theme-toggle__icon--moon {
  opacity: 1;
  transform: scale(1);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  white-space: nowrap;
}

.grid-panel {
  background: var(--surface);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--card-shadow), var(--card-glow);
  padding: 10px;
}

.sudoku-grid {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--grid-line);
  border-radius: 10px;
  overflow: hidden;
}

.cell {
  position: relative;
  border: 1px solid var(--cell-border);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: clamp(1rem, 4.3vw, 1.45rem);
  cursor: pointer;
  transition: background-color 140ms ease, transform 120ms ease;
}

.cell:hover {
  background: var(--cell-hover);
}

.cell:active {
  transform: scale(0.97);
}

.cell .cell-value {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.cell .cell-notes {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 3px;
  font-size: clamp(0.42rem, 2vw, 0.56rem);
  color: var(--text-subtle);
}

.cell .cell-notes span {
  display: grid;
  place-items: center;
  opacity: 0;
}

.cell.is-given {
  background: var(--cell-given);
  font-weight: 700;
}

.cell.is-selected {
  background: var(--cell-selected);
  box-shadow: inset 0 0 0 2px var(--primary);
}

.cell.is-peer {
  background: var(--cell-peer);
  box-shadow: inset 0 0 0 1px var(--cell-peer-line);
}

.cell.is-match {
  background: var(--cell-match);
}

.cell.is-conflict {
  color: var(--error);
  background: var(--cell-conflict);
  animation: conflict-shake 280ms ease;
}

.cell.is-just-entered .cell-value {
  animation: digit-pop 180ms ease-out;
}

.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 2px solid var(--grid-line);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--grid-line);
}

.controls {
  background: var(--surface);
  border-radius: 16px;
  border: 1px solid var(--line);
  box-shadow: var(--card-shadow), var(--card-glow);
  padding: 10px;
  display: grid;
  gap: 10px;
}

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

.action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.control-button,
.dialog-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

.control-button {
  padding: 10px 4px;
}

.control-button:hover:not(:disabled),
.dialog-button:hover {
  transform: scale(1.02);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.16);
}

.control-button:active:not(:disabled),
.dialog-button:active {
  transform: scale(0.98);
}

.control-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.number-button {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.98rem;
  padding: 12px 0;
}

.action-button.is-active {
  background: var(--action-active);
  border-color: var(--primary);
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: var(--backdrop);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 20;
}

.dialog-panel {
  width: min(100%, 360px);
  background: var(--surface);
  border-radius: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--card-shadow), var(--card-glow);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.dialog-title {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: 1.25rem;
}

.dialog-description {
  margin: 0;
  color: var(--text-subtle);
}

.dialog-actions {
  display: grid;
  gap: 8px;
}

.dialog-button {
  padding: 10px;
}

.dialog-button.is-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-alt));
  border-color: var(--dialog-primary-border);
  color: #ffffff;
}

.dialog-button.is-secondary {
  background: var(--surface-soft);
  color: var(--text);
}

.win-summary {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: grid;
  gap: 8px;
  background: var(--win-summary-bg);
}

.win-summary > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.win-summary strong {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-subtle);
}

.win-summary span {
  font-family: 'Montserrat', sans-serif;
  font-size: 0.9rem;
}

.brand-footer {
  display: flex;
  justify-content: center;
  padding: 2px 0 10px;
}

html[data-platform='ios'][data-native='true'] .brand-footer {
  display: none;
}

.brand-footer__link {
  color: var(--footer-link);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: color 140ms ease, border-color 140ms ease;
}

.brand-footer__link:hover {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.app-shell.is-win-pulse .grid-panel {
  animation: win-pulse 820ms ease;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes digit-pop {
  0% {
    transform: scale(0.72);
    opacity: 0.2;
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes conflict-shake {
  0% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-2px);
  }

  50% {
    transform: translateX(2px);
  }

  75% {
    transform: translateX(-1px);
  }

  100% {
    transform: translateX(0);
  }
}

@keyframes win-pulse {
  0% {
    transform: scale(1);
    box-shadow: var(--card-shadow), var(--card-glow);
  }

  35% {
    transform: scale(1.01);
    box-shadow: 0 0 0 8px var(--win-pulse-ring), var(--card-shadow), var(--card-glow);
  }

  100% {
    transform: scale(1);
    box-shadow: var(--card-shadow), var(--card-glow);
  }
}

@media (min-width: 640px) {
  #app {
    padding-top: 22px;
  }

  .top-bar {
    grid-template-columns: minmax(0, 1fr) minmax(170px, auto) auto;
    align-items: center;
  }

  .brand-lockup {
    grid-column: 1 / 2;
  }

  .stat-chip--difficulty {
    grid-column: 2 / 3;
  }

  .stat-chip--theme {
    grid-column: 3 / 4;
  }

  .brand {
    font-size: 1.52rem;
  }
}
