/* General reset */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #121212;
  color: #eee;
  display: flex;
  justify-content: center;
  overflow-x: hidden; /* prevent horizontal scroll */
}

.app {
  max-width: 1200px;
  width: 100%;
  overflow-x: hidden;
}

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #1f1f1f;
  padding: 1rem;
  border-bottom: 2px solid #333;
  flex-wrap: wrap; /* allow wrap on small screens */
  gap: 0.5rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.control label {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 0.2rem;
}

select, .btn {
  background: #2a2a2a;
  color: #fff;
  border: 1px solid #444;
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn.primary {
  background: #007bff;
  border: none;
}

.btn.ghost {
  background: transparent;
  border: 1px solid #555;
}

/* Main layout */
.main {
  display: flex;
  padding: 1rem;
  gap: 1rem;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
}

.card {
  background: #1e1e1e;
  padding: 1rem;
  margin-bottom: 1rem;
  border-radius: 10px;
}

/* Board */
.board-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.board {
  display: grid;
  background: #000;
  gap: 2px;
  width: 90vw;       /* responsive width */
  max-width: 500px;  /* cap for large screens */
  aspect-ratio: 1;   /* keep square */
}

.tile {
  background-size: cover;
  background-position: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.tile:hover {
  transform: scale(1.05);
}

.tile.empty {
  background: #111;
  cursor: default;
  pointer-events: none;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: #777;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #1e1e1e;
  padding: 2rem;
  border-radius: 10px;
  text-align: center;
  max-width: 90%;
}

.modal-actions {
  margin-top: 1rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Invalid move feedback */
.tile.shake {
  animation: shake 0.18s linear;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
  100% { transform: translateX(0); }
}

/* Responsive */
@media (max-width: 768px) {
  .main {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    order: 2;
  }
  .board-wrap {
    order: 1;
  }
}
