/* Universal box-sizing for consistent layout */
* {
  box-sizing: border-box;
}

body {
  font-family: Verdana, Geneva, sans-serif;
}

.start-button,
.restart,
.save {
  border-radius: 0.4rem;
  padding: 0.3rem 1rem;
  font-size: 1.2rem;
  font-weight: bold;
  width: 100%;
  background-color: #007bff;
  color: white;
}

.start-button[disabled],
.restart[disabled],
.save[disabled] {
  background-color: #ededed;
  color: grey;
}

.start-button {
  background-color: rgb(152, 217, 178);
  color: black;
}

.start-game {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2em;
  gap: 1.5em;
  background-color: white;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  max-width: 400px;
  margin: 50px auto;
}

.start-button {
  width: 100%;
  padding: 0.8em;
  font-size: 1.2em;
  cursor: pointer;
}

.divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  text-align: center;
  gap: 1em;
  width: 100%;
  color: #777;
}

.divider::before,
.divider::after {
  content: '';
  border-top: 1px solid #ccc;
}

.join-game {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 0.5em;
}

.join-game label {
  font-weight: bold;
  color: #333;
}

.input-group {
  display: flex;
  gap: 0.5em;
}

.input-group input {
  flex-grow: 1;
  padding: 0.5em;
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 4px;
  text-transform: uppercase;
}

.input-group button {
  padding: 0.5em 1em;
  font-size: 1em;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

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

main {
  display: flex;
  justify-content: center;
  align-items: start;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1em;
}

h1 {
  font-size: 48px;
  margin: 5px;
}

.progress-circle {
  width: 60px;
  height: 60px;
  position: relative;
  margin: 20px auto;
  display: flex;
  justify-content: center;
  align-items: center;
}

.progress-circle .number {
  position: absolute;
  font-size: 24px;
  font-weight: bold;
}

.progress-circle .number.small-font {
  font-size: 18px;
}

.progress-circle svg {
  width: 60px;
  height: 60px;
  transform: rotate(-90deg);
}

.progress-circle circle {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}

.progress-circle .bg {
  stroke: #f0f0f0;
}

.progress-circle .progress {
  stroke: #007bff;
  stroke-dasharray: 157;
  /* Approximately 2 * PI * 25 (radius) */
  stroke-dashoffset: 47.1;
  /* 157 * 0.3 to show 70% progress */
}

.progress-circle.hide {
  display: none;
}

.game-board {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1em;
  background-color: bisque;
  border: 1px solid black;
  border-radius: 5px;
  gap: 1em;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-radius: 5px;
}

.grid-cell {
  background-color: white;
  border: 1px solid black;
  height: 100px;
  width: 100px;
  text-align: center;
  cursor: pointer;
}

.grid-cell[disabled] {
  cursor: not-allowed;
}

.grid-cell[disabled].x:not(.winner),
.grid-cell[disabled].o:not(.winner) {
  background-color: #ededed;
}

.grid-cell.vote-mark {
  position: relative;
}

.grid-cell.vote-mark::before {
  opacity: var(--vote-opacity, 0.2);
  stroke: blue;
}

.vote-count {
  position: absolute;
  bottom: 2px;
  right: 5px;
  font-size: 0.8rem;
  color: blue;
  font-weight: bold;
  pointer-events: none; /* Ensure clicks pass through to the button */
}

.x::before {
  content: url('/x.svg');
  width: 75px;
  height: 75px;
  stroke: black;
}

.o::before {
  content: url('/o.svg');
  width: 75px;
  height: 75px;
  stroke: black;
}

.player {
  border-radius: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.player.o::before,
.player.x::before {
  font-size: 35px;
  opacity: 0.4;
}

.player.turn {
  background-color: rgb(255, 242, 224);
}

.player.winner,
.grid-cell.winner {
  background-color: rgb(152, 217, 178);
}

.player.winner::before {
  opacity: 1;
}

.player.turn::before {
  opacity: 1;
}

.turn-status {
  width: 100%;
  gap: 0.5em; /* Smaller gap for vertical arrangement */
  display: flex;
  flex-direction: row; /* Arrange items vertically */
  justify-content: space-between; /* Center horizontally in the column */
  align-items: center; /* Center horizontally in the column */
  text-align: center; /* Center text within turn-message */
}

.turn-message {
  flex-grow: 0; /* No longer needs to grow */
  max-width: none; /* Remove max-width restriction */
}

.progress-circle {
  margin: 0; /* Remove auto margins when centrally aligned by flexbox */
}

.player {
  /* Ensure players are still horizontally aligned if needed, or adjust based on overall layout */
  flex-direction: row; /* Keep player elements in a row */
  align-items: center;
  justify-content: center;
  gap: 0.5em;
}

.turn-progress {
  display: flex;
  max-width: 7em;
  align-items: center;
  flex-direction: column;
}

#connection-info {
  display: flex;
  justify-content: flex-end;
  gap: 0.5em;
  align-items: center;
}

#message {
  flex-grow: 1;
}

#chat {
  border: 1px solid black;
  padding: 1em;
}

form {
  display: flex;
  gap: 0.5em;
}

.sync {
  padding: 1em;
  max-width: 360px;
  text-align: center;
}

.settings {
  flex-direction: column;
  padding: 1em;
  border: 1px solid black;
  border-radius: 0.3em;
  background-color: white;
  max-width: 302px;
}

.settings h2 {
  margin-top: 0.5em;
  margin-bottom: 0.2em;
}

.settings form {
  flex-direction: column;
  gap: 0.5em;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}

.settings fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.settings fieldset legend {
  margin-bottom: 0.3em;
}

.settings .radio-group {
  display: flex;
  gap: 0.5em;
  flex-direction: row;
  margin-top: 0.4em;
}

.settings .radio-group label {
  align-items: center;
  flex-direction: row;
  border: 1px solid black;
  padding: 0.5em;
  border-radius: 0.3em;
  cursor: pointer;
  flex: 1;
  justify-content: center;
}

.settings .radio-group.small label {
  padding-right: 1em;
}

.mode-specific {
  display: none;
}

.settings input[type='number'] {
  font-size: 1em;
  padding: 0.3em;
  text-align: center;
}

.links-panel {
  margin: 1em auto;
  padding: 1em;
  background-color: #f9f9f9;
  border: 1px solid #ccc;
  border-radius: 5px;
  flex-direction: column;
  gap: 0.5em;
  font-size: 0.9em;
  width: fit-content;
  max-width: 100%;
}

.links-panel strong {
  margin-right: 0.5em;
}

.links-panel div {
  display: flex;
  align-items: center;
  min-width: 0;
}

.links-panel div a {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-grow: 1;
}

.copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2em;
  margin-left: 0.5em;
  padding: 0;
  position: relative;
}

.copy-btn:hover {
  opacity: 0.7;
}

.copy-popover {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 0.3em 0.6em;
  border-radius: 4px;
  font-size: 0.7em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  animation: fadeInOut 2s ease-in-out;
  margin-bottom: 5px;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translate(-50%, 5px);
  }
  10% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  90% {
    opacity: 1;
    transform: translate(-50%, 0);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -5px);
  }
}

.sync.hide {
  opacity: 0;
  transition: opacity 1s cubic-bezier(0.64, 0, 0.78, 0);
}

.settings label.games-per-round {
  display: none;
}
