body {
  font-family: Arial, sans-serif;
  background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
  margin: 0;
  color: #0f172a;
}

.container {
  display: flex;
  flex-wrap: wrap;
  padding: 20px;
  gap: 20px;
  align-items: flex-start;
  max-width: 1160px;
  margin: 0 auto;
}

.board-area {
  flex: 1 1 620px;
}

.topbar {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 8px 4px;
}

.topbar-label {
  font-weight: bold;
  color: #64748b;
}

.difficulty-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.theme-toggle {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: #0f172a;
  color: white;
  font-weight: bold;
}

.difficulty-btn {
  width: auto;
  margin-top: 0;
  padding: 10px 14px;
  border-radius: 999px;
  background: transparent;
  color: #64748b;
  border: 1px solid transparent;
  font-weight: bold;
}

.difficulty-btn.active-level {
  background: #dbeafe;
  color: #2563eb;
  border-color: #bfdbfe;
}

.board-shell {
  position: relative;
  display: inline-block;
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 60px);
  grid-template-rows: repeat(9, 60px);
  transition: transform 0.3s;
  background: white;
  border: 2px solid #547196;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  position: relative;
  z-index: 1;
}

#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.cell {
  border: 1px solid #c5d2e3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  cursor: pointer;
  font-size: 24px;
  transition: background-color 0.18s, box-shadow 0.18s;
  user-select: none;
  color: #334e73;
}

.cell.fixed {
  background: #eef5fd;
  color: #405c81;
}

.cell.selected {
  background: #b8daf9;
}

.cell.related {
  background: #eef4fb;
}

.cell.same-value {
  background: #d8eafb;
  font-weight: bold;
}

.cell.flash-correct {
  background: #a7f3d0;
}

.cell.flash-error {
  background: #fecdd3;
  color: #be123c;
}

.content {
  transform-origin: center;
}

.notes {
  font-size: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  color: #334155;
}

.cell:nth-child(3n) {
  border-right: 2px solid #547196;
}

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

.panel {
  width: 300px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #dbe3ef;
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.06);
}

.hud {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  background: #f8fbff;
  border: 1px solid #dbe8f6;
  border-radius: 14px;
  padding: 12px;
}

.stat-card strong {
  display: block;
  font-size: 12px;
  color: #64748b;
  margin-bottom: 6px;
}

.stat-card span {
  font-size: 28px;
  font-weight: bold;
  color: #335b96;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.key {
  background: #edf3fa;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  cursor: pointer;
  border-radius: 12px;
  transition: background-color 0.18s, transform 0.18s;
  color: #2d5ca8;
  border: 1px solid #d8e5f4;
}

.key:hover {
  background: #dbeafe;
  transform: translateY(-1px);
}

button {
  width: 100%;
  padding: 10px;
  margin-top: 10px;
  background: #4f46e5;
  color: white;
  border: none;
  cursor: pointer;
  border-radius: 10px;
  transition: background-color 0.18s, opacity 0.18s, transform 0.18s;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button.active {
  background: #0f766e;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status {
  margin-bottom: 18px;
  line-height: 1.6;
}

.status strong {
  display: inline-block;
  min-width: 70px;
}

#feedback {
  min-height: 44px;
  margin-top: 12px;
  font-weight: bold;
  background: #f8fbff;
  border: 1px solid #dbe8f6;
  border-radius: 12px;
  padding: 10px 12px;
}

#feedback.correct {
  color: #166534;
}

#feedback.error {
  color: #b91c1c;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 18px;
}

.toolbar button {
  margin-top: 0;
}

.spark {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  left: 50%;
  top: 50%;
  opacity: 0.95;
  transform: translate(-50%, -50%);
  animation: burst 800ms ease-out forwards;
}

.spark.correct {
  background: radial-gradient(circle, #34d399 0%, #10b981 60%, rgba(16, 185, 129, 0) 100%);
}

.spark.error {
  background: radial-gradient(circle, #fb7185 0%, #e11d48 60%, rgba(225, 29, 72, 0) 100%);
}

@keyframes burst {
  0% {
    opacity: 0.95;
    transform: translate(-50%, -50%) translate(0, 0) scale(0.6);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -50%) translate(var(--dx), var(--dy)) scale(1.8);
  }
}

@media (max-width: 720px) {
  .container {
    padding: 16px;
    gap: 20px;
  }

  #board {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    grid-template-rows: repeat(9, minmax(0, 1fr));
    width: min(540px, calc(100vw - 32px));
    height: min(540px, calc(100vw - 32px));
  }

  .panel {
    width: min(540px, 100%);
  }

  .difficulty-buttons {
    gap: 6px;
  }

  .difficulty-btn {
    padding: 8px 12px;
  }

  .theme-toggle {
    padding: 8px 12px;
  }

  .key {
    height: 78px;
    font-size: 30px;
  }
}
