:root {
  --background-color: #ffffff;
  --text-color: #000000;
  --credits-link-color: #ffffff;
  --header-color: #000000;
  --card-background: #ffffff;
  --card-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  --button-background: #0388fc;
  --button-text: white;
  --button-hover-background: #146dba;
  --board-background: #ffffff;
  --cell-background: #d4e0e9;
  --cell-hover-background: #a9c6d6;
  --winning-glow: #f1c40f;
  --player1-color: #f55a5a;
  --player2-color: #f1c40f;
  --blue-start: #007bff;
  --blue-end: #00c6ff;
  --hover-blue-start: #0056b3;
  --hover-blue-end: #00a0d4;
  --dialog-bg: #FFFFFF;
  --dialog-text: #1F1F1F;
  --dialog-secondary-text: #616161;
  --select-bg: #F0F0F0;
  --button-text: #4285F4;
  --button-hover-bg: rgba(66, 133, 244, 0.08);
  --font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --cell-size: clamp(48px, 7.5vw, 80px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #1a1a1a;
    --text-color: #ffffff;
    --header-color: #ffffff;
    --credits-link-color: #ffffff;
    --card-background: #2c2c2c;
    --card-shadow: 0 0px 18px rgba(0, 0, 0, 0.2);
    --button-background: #0388fc;
    --button-text: white;
    --button-hover-background: #146dba;
    --board-background: #1f1f1f;
    --cell-background: #3c3c3c;
    --cell-hover-background: #4a4a4a;
    --winning-glow: #f1c40f;
    --player1-color: #f55a5a;
    --player2-color: #f1c40f;
    --dialog-bg: #202020;
    --dialog-text: #E0E0E0;
    --dialog-secondary-text: #B0B0B0;
    --button-text: #8AB4F8;
    --button-hover-bg: rgba(138, 180, 248, 0.1);
    --cell-size: clamp(48px, 7.5vw, 80px);
  }
}

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

body {
  font-family: var(--font-family);
  background: var(--background-color);
  color: var(--text-color);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
  overflow-x: hidden;
  overflow-y: auto;
  transition: background 0.4s ease, color 0.4s ease;
  -webkit-tap-highlight-color: transparent;
}

#start-screen, #game-container {
  opacity: 1;
  transition: opacity 0.6s ease;
}

#start-screen {
  position: fixed;
  inset: 0;
  background: var(--background-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  z-index: 9999;
  transition: background 0.4s ease;
}

#start-screen h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 700;
  margin-bottom: 40px;
  color: var(--header-color);
  text-shadow: none;
}

.start-screen-button {
  padding: 15px 50px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  color: #ffffff;
  margin: 10px 0;
  box-shadow: var(--card-shadow);
  transition: transform 0.4s ease, background-position 0.4s ease,
    box-shadow 0.4s ease;
  width: 80%;
  max-width: 300px;
  background: linear-gradient(
    45deg,
    var(--blue-start),
    var(--blue-end),
    var(--blue-start),
    var(--blue-end)
  );
  background-size: 300% 300%;
  background-position: 50% 0;
}

.start-screen-button.hover,
.start-screen-button:hover {
  transform: scale(1.05);
  background-position: 0 100%;
  box-shadow: 0 0 20px rgba(0, 123, 255, 0.8), 0 0 30px rgba(0, 198, 255, 0.6);
}

.start-screen-button:active {
  transform: scale(1.03);
}

.start-screen-button-disabled {
  padding: 15px 50px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  background: #777;
  color: var(--button-text);
  margin: 10px 0;
  box-shadow: var(--card-shadow);
  transition: transform 0.2s ease, background-color 0.3s ease;
  width: 80%;
  max-width: 300px;
  opacity: 0.3;
}

.credits-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 500;
  color: var(--text-color);
  text-align: center;
}

.credits-link {
  font-weight: bold;
  text-decoration: underline;
  color: var(--text-color);
  transition: color 0.4s ease;
}

.gamebutton-container {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 10%;
  margin-top: 20px;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.game-container {
  display: flex;
  text-align: center;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: none;
  position: relative;
}

h1 {
  margin-bottom: 20px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--header-color);
  text-shadow: none;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(6, 1fr);
  grid-gap: clamp(8px, 1.5vw, 12px);
  background: var(--board-background);
  padding: clamp(10px, 2vw, 15px);
  border-radius: 15px;
  box-shadow: var(--card-shadow);
  user-select: none;
  cursor: pointer;
  transform-origin: center;
  opacity: 1;
  transition: transform 0.5s ease, background 0.4s ease, opacity 0.4s ease-in-out;
  aspect-ratio: 7 / 6;
  max-width: 90vw;
}

.board.shake {
  animation: boardShake 0.7s ease-in-out;
}

.board.faded {
  opacity: 0.5;
  transition: opacity 0.5s ease-in-out;
}

.board.fade-in {
  opacity: 0;
  animation: fadeInBoard 0.5s forwards;
}

@keyframes boardShake {
  0%, 100% {
    transform: translateX(0) rotate(0deg);
  }
  20%, 60% {
    transform: translateX(-15px) rotate(-5deg);
  }
  40%, 80% {
    transform: translateX(15px) rotate(5deg);
  }
}

@keyframes fadeInBoard {
  from { opacity: 0; }
  to { opacity: 1; }
}

.cell {
  background: var(--cell-background);
  border-radius: 50%;
  aspect-ratio: 1 / 1;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.1);
  transition: background 0.2s ease, opacity 0.2s ease;
}

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

.cell[data-player="1"]::before,
.cell[data-player="2"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.2);
  opacity: 1;
  pointer-events: none;
  transition: none;
}

.cell[data-player="1"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, var(--player1-color) 60%, #e63939);
  box-shadow:
    inset 0 0 10px rgba(0, 0, 0, 0.4),
    0 4px 6px rgba(0, 0, 0, 0.2);
  opacity: 1;
  pointer-events: none;
  transition: none;
}

.cell[data-player="2"]::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, var(--player2-color) 60%, #ffb300);
  box-shadow:
    inset 0 0 10px rgba(0, 0, 0, 0.4),
    0 4px 6px rgba(0, 0, 0, 0.2);
  opacity: 1;
  pointer-events: none;
  transition: none;
}

.cell.winning {
  box-shadow: 0 0 15px 5px var(--winning-glow);
  animation: pulseWin 1s infinite alternate ease-in-out;
}

@keyframes pulseWin {
  0% {
    transform: scale(1);
    box-shadow: 0 0 15px 5px var(--winning-glow);
  }
  100% {
    transform: scale(1.05);
    box-shadow: 0 0 25px 10px var(--winning-glow);
  }
}

.info {
  margin: 20px 0 10px;
  font-weight: 600;
  font-size: 1.4rem;
  min-height: 1.5em;
  opacity: 1;
  transition: opacity 0.2s ease;
  color: var(--text-color);
}

.restart-btn {
  display: inline-block;
  padding: 12px 35px;
  font-size: clamp(1.2rem, 3vw, 1.6rem);
  font-weight: 600;
  border: none;
  border-radius: 50px;
  cursor: pointer;
  color: #ffffff;
  margin: 10px 0;
  box-shadow: var(--card-shadow);
  transition: transform 0.4s ease, background-position 0.4s ease,
    box-shadow 0.4s ease, opacity 0.4s ease;
  background: linear-gradient(
    45deg,
    var(--blue-start),
    var(--blue-end),
    var(--blue-start),
    var(--blue-end)
  );
  background-size: 300% 300%;
  background-position: 50% 0;
  pointer-events: none;
  opacity: 0;
}

.restart-btn.visible,
.restart-btn.offline {
  opacity: 1;
  pointer-events: auto;
}

.restart-btn:hover,
.restart-btn.hover {
  transform: scale(1.05);
  background-position: 0 100%;
  box-shadow: 0 0 20px rgba(0, 123, 255, 0.8), 0 0 30px rgba(0, 198, 255, 0.6);
}

.restart-btn:active {
  transform: scale(1.05);
}

.restart-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.fade-in {
  opacity: 1 !important;
}

.fade-out {
  opacity: 0 !important;
}

.falling-disc {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  pointer-events: none;
  box-shadow: inset 0 4px 8px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  will-change: transform;
  animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  animation-fill-mode: forwards;
  animation-duration: 400ms;
}

.falling-disc.red {
  background: radial-gradient(circle at 35% 35%, var(--player1-color) 60%, #e63939);
  box-shadow:
    inset 0 0 10px rgba(0, 0, 0, 0.4),
    0 4px 6px rgba(0, 0, 0, 0.2);
}

.falling-disc.yellow {
  background: radial-gradient(circle at 35% 35%, var(--player2-color) 60%, #ffb300);
  box-shadow:
    inset 0 0 10px rgba(0, 0, 0, 0.4),
    0 4px 6px rgba(0, 0, 0, 0.2);
}

@keyframes dropDisc {
  0% {
    transform: translate(Y(calc(-100% - var(--cell-size))));
  }
  100% {
    transform: translate(0);
  }
}

#confetti-canvas {
  position: fixed;
  pointer-events: none;
  top: 0; left: 0; width: 100vw; height: 100vh;
  z-index: 10001;
  display: none;
}

.mode-select {
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.mode-btn {
  flex: 1;
  padding: 12px 0;
  background: var(--button-background);
  border: none;
  border-radius: 30px;
  color: var(--button-text);
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--card-shadow);
  transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
  user-select: none;
  max-width: 150px;
}

.mode-btn.active,
.mode-btn:hover {
  background: var(--button-hover-background);
  box-shadow: var(--card-shadow);
  transform: scale(1.02);
  color: #fff;
}

#multiplayer-screen {
  position: fixed;
  inset: 0;
  background: var(--background-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  z-index: 9999;
  transition: opacity 0.4s ease;
}

#multiplayer-screen h1 {
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 700;
  margin-bottom: 40px;
  color: var(--header-color);
  text-shadow: none;
}

#multiplayer-options,
#join-input-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.join-game-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 80%;
  max-width: 300px;
  margin-bottom: 20px;
}

.text-input {
  width: 100%;
  padding: 12px 20px;
  margin-bottom: 10px;
  font-size: 1rem;
  border: 2px solid var(--cell-background);
  border-radius: 50px;
  background: var(--card-background);
  color: var(--text-color);
  box-shadow: var(--card-shadow);
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.text-input::placeholder {
  color: #a9a9a9;
}

.text-input:focus {
  outline: none;
  border-color: var(--button-background);
  box-shadow: 0 0 0 3px rgba(3, 136, 252, 0.2);
}

.status-message {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 500;
  color: var(--text-color);
  min-height: 1.5rem;
  margin-bottom: 20px;
}

.room-code-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
  padding: 15px;
  background: var(--card-background);
  border-radius: 15px;
  box-shadow: var(--card-shadow);
  width: 80%;
  max-width: 300px;
}

.room-code-section p {
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0;
}

#room-code {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: 2px;
  background: var(--board-background);
  color: var(--header-color);
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  user-select: all;
}

.back-button {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  margin-top: 30px;
  padding: 10px;
  transition: opacity 0.2s ease;
}

.back-button:hover,
.back-button.hover {
  opacity: 0.3;
}

.leave-game {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 1000;
  padding: 8px 12px;
  background-color: transparent;
  color: var(--text-color);
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: opacity 0.2s, color 0.2s;
}

.leave-game.hover,
.leave-game:hover {
  opacity: 0.5;
}

.hidden {
  display: none !important;
}

.dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms cubic-bezier(0.4, 0, 0.2, 1), transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 999;
  border: none;
  padding: 0;
  margin: 0;
  max-height: 90vh;
  overflow: auto;
  width: 90vw;
  max-width: 500px;
  border-radius: 20px;
  background-color: var(--dialog-bg);
  color: var(--dialog-text);
  font-family: 'Roboto', sans-serif;
  display: flex;
  flex-direction: column;
}

.dialog.open {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
  pointer-events: auto;
}

.dialog.closing {
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.92);
  pointer-events: none;
}

.modal-header {
  display: flex;
  flex-direction: column;
  align-items: left;
  padding: 24px 24px 8px;
}

.modal-header h2 {
  margin-bottom: 10px;
  font-weight: 500;
  font-size: 1.5rem;
  color: inherit;
}

.modal-body {
  padding: 0 24px 0px;
  text-align: center;
}

.modal-body p {
  margin-top: 0;
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: var(--dialog-secondary-text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 15px 15px;
  margin-top: 0px;
  gap: 0px;
}

.button {
  color: var(--button-text);
  background: none;
  border: none;
  font-family: 'Roboto', sans-serif;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 10px 12px;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease-out;
  border-radius: 50px;
  outline: none;
  text-transform: none;
  letter-spacing: 0.01em;
}

.button:active {
  transform: scale(0.98);
}

.dialog .primary-button:hover {
  background-color: var(--button-hover-bg);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.05);
  opacity: 0;
  transition: opacity 250ms ease;
}

dialog[open]::backdrop {
  opacity: 1;
}

@media (min-width: 600px) and (max-width: 899px) {
  :root {
    --cell-size: clamp(50px, 8vw, 90px);
    --button-font-size: clamp(1.2rem, 2.5vw, 1.6rem);
    --info-font-size: clamp(1rem, 2.5vw, 1.2rem);
    --board-gap: clamp(10px, 1.5vw, 14px);
  }
  .start-screen-button,
  .start-screen-button-disabled,
  .restart-btn {
    width: 70%;
    max-width: 280px;
  }
}

@media (min-width: 900px) and (max-width: 1199px) {
  :root {
    --cell-size: clamp(55px, 6vw, 95px);
    --button-font-size: clamp(1.3rem, 2.2vw, 1.7rem);
    --info-font-size: clamp(1.1rem, 2.2vw, 1.3rem);
    --board-gap: clamp(12px, 1.5vw, 16px);
  }
  .start-screen-button,
  .start-screen-button-disabled,
  .restart-btn {
    width: 65%;
    max-width: 300px;
  }
}

@media (min-width: 1200px) and (max-width: 1599px) {
  :root {
    --cell-size: clamp(60px, 5vw, 100px);
    --button-font-size: clamp(1.4rem, 2vw, 1.8rem);
    --info-font-size: clamp(1.2rem, 2vw, 1.4rem);
    --board-gap: clamp(14px, 1.2vw, 18px);
  }
  .start-screen-button,
  .start-screen-button-disabled,
  .restart-btn {
    width: 60%;
    max-width: 320px;
  }
}

@media (min-width: 1600px) and (max-width: 1999px) {
  :root {
    --cell-size: clamp(65px, 4.5vw, 110px);
    --button-font-size: clamp(1.5rem, 1.8vw, 2rem);
    --info-font-size: clamp(1.3rem, 1.8vw, 1.5rem);
    --board-gap: clamp(16px, 1.2vw, 20px);
  }
  .start-screen-button,
  .start-screen-button-disabled,
  .restart-btn {
    width: 55%;
    max-width: 350px;
  }
}

@media (min-width: 2000px) {
  :root {
    --cell-size: clamp(75px, 4vw, 130px);
    --button-font-size: clamp(1.6rem, 1.5vw, 2.2rem);
    --info-font-size: clamp(1.4rem, 1.5vw, 1.6rem);
    --board-gap: clamp(18px, 1vw, 24px);
  }
  .start-screen-button,
  .start-screen-button-disabled,
  .restart-btn {
    width: 50%;
    max-width: 400px;
  }
}

@media (min-width: 1600px) {
  .board {
    max-width: 1200px;
    grid-gap: var(--board-gap);
  }
  .info {
    font-size: var(--info-font-size);
  }
  .cell {
    width: var(--cell-size);
    height: var(--cell-size);
  }
}