* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Arial", sans-serif;
  background-color: #f0f0f0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
  background-color: #333;
  color: white;
}

.container {
  max-width: 1200px;
  width: 100%;
  padding: 20px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  transition: background-color 0.3s, box-shadow 0.3s;
}

body.dark-mode .container {
  background-color: #444;
  box-shadow: 0 4px 10px rgba(255, 255, 255, 0.2);
}

header {
  text-align: center;
  margin-bottom: 30px;
}

header h1 {
  font-size: 2.5em;
  color: #333;
}

body.dark-mode header h1 {
  color: white;
}

.online-controls {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.online-controls .row {
  display: flex;
  gap: 8px;
}
.online-controls input {
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.online-controls input:disabled { opacity: 0.7; background: #f5f5f5; }
.online-controls #connection-status {
  font-size: 0.9em;
  opacity: 0.8;
}
.online-controls .room-info {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.peer-hover {
  outline: 3px dashed #ff4081;
  outline-offset: -3px;
}

.rooms-panel { margin-top: 12px; }
.rooms-panel h3 { margin-bottom: 6px; }
.rooms-table { width: 100%; border-collapse: collapse; font-size: 0.95em; }
.rooms-table th, .rooms-table td { border: 1px solid #ddd; padding: 6px 8px; text-align: left; }
.rooms-table tbody tr:hover { background: rgba(0,0,0,0.03); }
.rooms-table .badge { padding: 2px 6px; border-radius: 10px; font-size: 0.85em; }
.rooms-table .badge.full { background: #ffcdd2; color: #b71c1c; }
.rooms-table .badge.open { background: #c8e6c9; color: #1b5e20; }

.scoreboard p {
  font-size: 1.2em;
  margin: 5px 0;
}

body.dark-mode .scoreboard p {
  color: white;
}

button {
  padding: 10px 20px;
  margin-top: 10px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

body.dark-mode button {
  background-color: #444;
  color: white;
}

body.dark-mode button:hover {
  background-color: #666;
}

.game {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
.game.hidden { display: none; }

.empty-state {
  margin: 16px auto;
  padding: 16px 20px;
  border-radius: 8px;
  background: #eef5ff;
  color: #123;
  text-align: center;
  max-width: 600px;
}

.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}
.toast {
  padding: 10px 14px;
  background: #333;
  color: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  opacity: 0;
  transform: translateY(-8px);
  animation: toast-in 220ms ease-out forwards;
}
.toast.info { background: #2962ff; }
.toast.success { background: #2e7d32; }
.toast.warn { background: #f57f17; }
.toast.error { background: #c62828; }

@keyframes toast-in {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(4px, 1.2vw, 10px);
  width: min(92vw, 680px);
  aspect-ratio: 1 / 1;
  height: auto;
  margin: 10px auto;
  background-color: #fff;
  border: 2px solid #ccc;
  border-radius: 8px;
  transition: background-color 0.3s, border-color 0.3s;
}

body.dark-mode .board {
  background-color: #555;
  border-color: #444;
}

.cell {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2em;
  cursor: pointer;
  background-color: #f9f9f9;
  border: 2px solid #ddd;
  transition: background-color 0.3s;
}

body.dark-mode .cell {
  background-color: #333;
  border-color: #444;
}

body.dark-mode .cell:hover {
  background-color: #444;
}

body:not(.dark-mode) .cell:hover {
  background-color: #e3e3e3;
}

.small-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(2px, 0.8vw, 6px);
  width: 100%;
  height: 100%;
}

.small-board .cell {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(1rem, 2.8vw, 1.5rem);
  cursor: pointer;
  background-color: #f9f9f9;
  border: 1px solid #ddd;
  transition: background-color 0.3s;
}

body.dark-mode .small-board .cell {
  background-color: #444;
  border-color: #555;
}

body.dark-mode .small-board .cell:hover {
  background-color: #555;
}
body:not(.dark-mode) .small-board .cell:hover {
  background-color: #c2c2c2;
}

/* Responsive display for a won big cell */
.big-winner {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Use clamp to keep sizes reasonable: min 2.5rem, scales with viewport, max 8rem */
  font-size: clamp(2.5rem, 8vw, 7rem);
  line-height: 1;
}

.game-info {
  width: 45%;
  padding: 20px;
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}

body.dark-mode .game-info {
  background-color: #444;
  box-shadow: 0 4px 10px rgba(255, 255, 255, 0.2);
}

/* Rooms table becomes horizontally scrollable on small screens */
.rooms-panel { width: 100%; overflow-x: auto; }
.rooms-table { min-width: 560px; }

@media (max-width: 900px) {
  header h1 { font-size: 2rem; }
  .scoreboard p { font-size: 1em; }
  .online-controls .row { flex-wrap: wrap; }
}

@media (max-width: 768px) {
  .game {
    flex-direction: column;
    align-items: center;
  }
  .online-controls input { width: min(85vw, 360px); }
  .online-controls .row { justify-content: center; }
  button { padding: 10px 14px; }
}

@media (max-width: 480px) {
  header h1 { font-size: 1.6rem; }
  .board { width: 94vw; }
  .online-controls input { width: 100%; }
  .online-controls .row { gap: 6px; }
  .rooms-table { font-size: 0.9em; }
}
