:root {
  --x-red: #eb2f57;
  --x-red-alt: #ec677f;
  --o-purple: #5e4a96;
  --o-purple-alt: #8687bc;
  --bg-white: #fff;
  --text-main: #0a0904;
  --accent-green: #33d6a6;
  --gray-light: #f1f1f1;
}

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

body {
  background-color: var(--bg-white);
  color: var(--text-main);
  font-family: "Outfit", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#landing {
  max-width: 900px;
  width: 100%;
  padding: 60px 20px;
  text-align: center;
}

#landing h1 {
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-weight: 900;
  margin-bottom: 20px;
  line-height: 1.1;
}

.won-x {
  color: var(--x-red);
}
.won-o {
  color: var(--o-purple);
}

#landing > p {
  font-size: 1.2rem;
  max-width: 650px;
  margin: 0 auto 50px;
  /* color: #666; */
}

.rules-container {
  display: flex;
  flex-direction: column;
  gap: 30px;
  margin-bottom: 60px;
}

.rule {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 40px;
  background: var(--gray-light);
  padding: 40px;
  text-align: left;
  align-items: center;
  border: 3px solid black;
}

.rule:nth-child(even) {
  direction: rtl;
}
.rule:nth-child(even) .description {
  direction: ltr;
}

.description {
  font-size: 1.15rem;
  line-height: 1.6;
}

.description em {
  margin-top: 15px;
  font-style: normal;
  font-weight: 700;
  color: var(--o-purple);
}

.img-container img {
  width: 100%;
  display: block;
  height: 25%;
  border: 4px solid var(--text-main);
  background: white;
}

.next-controls {
  margin-top: 40px;
}

.next-controls h4 {
  font-size: 1.4rem;
  margin-bottom: 20px;
}

.next-controls button {
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 800;
  padding: 18px 36px;
  margin: 10px;
  border: none;
  border-radius: 100px;
  cursor: pointer;
  transition:
    transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275),
    box-shadow 0.2s;
  color: white;
}

.next-controls button:nth-of-type(1) {
  background-color: var(--x-red-alt);
}

.next-controls button:nth-of-type(2) {
  background-color: var(--o-purple);
}

.next-controls button:hover {
  transform: scale(1.05) translateY(-2px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
}

#ultimate-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2.5vw, 25px);
  padding: clamp(10px, 2.4vw, 25px);
  background-color: var(--text-main);
  border-radius: 18px;
}

.small-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(2px, 0.5vw, 4px);
  background-color: var(--text-main);
  transition: all 0.3s ease;
}

.small-board.active-board {
  outline: 5px solid var(--accent-green);
  outline-offset: 2px;
  border-radius: 2px;
  z-index: 2;
  transform: scale(1.03);
}

.cell {
  width: clamp(36px, 10vw, 55px);
  height: clamp(36px, 10vw, 55px);
  background-color: var(--bg-white);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: clamp(1rem, 3vw 1.8rem);
  cursor: pointer;
  transition: background 0.2s;
}

.cell:hover:not(.taken) {
  background-color: var(--gray-light);
}

.small-board::after {
  content: attr(data-winner);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(2rem, 8vw, 5rem);
  font-weight: 900;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
}

.small-board.won-x::after {
  opacity: 1;
  content: "X";
  color: var(--x-red);
}
.small-board.won-o::after {
  opacity: 1;
  content: "O";
  color: var(--o-purple);
}
.small-board.won-draw::after {
  opacity: 1;
  content: "/";
  color: #aaa;
}

.game-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 600px;
  margin-bottom: 20px;
  padding: 0 10px;
}

#btn-back {
  font-family: inherit;
  font-weight: 800;
  background-color: var(--gray-light);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
#btn-back:hover {
  transform: scale(1.02);
  background-color: var(--o-purple-alt);
}

#turn-indicator {
  font-size: 1.5rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#turn-indicator.thinking::after {
  content: "...";
  animation: blink 0.6s step-start infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

#turn-indicator.thinking {
  opacity: 0.6;
  transition: opacity 0.2s;
}

#current-player {
  margin-left: 5px;
}

#btn-restart {
  font-family: inherit;
  font-weight: 800;
  background-color: var(--gray-light);
  color: var(--text-main);
  padding: 8px 16px;
  border-radius: 12px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

#btn-restart:hover {
  transform: scale(1.02);
  background-color: var(--x-red-alt);
  color: white;
}

.hidden {
  display: none !important;
}

#gameEndModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 40px;
  border-radius: 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  z-index: 100;
  text-align: center;
  min-width: 300px;
}

#gameEndModal h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin-bottom: 10px;
}

.modal-subtitle {
  font-size: 1rem;
  color: #666;
  margin-bottom: 28px;
  min-height: 1.4rem;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

#modal-menu-btn {
  background: var(--gray-light);
  color: var(--text-main);
  padding: 12px 30px;
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

#modal-menu-btn:hover {
  background-color: var(--o-purple-alt);
  color: white;
}

#modal-restart-btn {
  background-color: var(--accent-green);
  color: white;
  padding: 12px 30px;
  border: none;
  padding: 12px 30px;
  border: none;
  border-radius: 100px;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

#modal-restart-btn:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 16px rgba(51, 214, 166, 0.35);
}

#gameEndModal button {
  background: var(--accent-green);
  color: white;
  padding: 12px 30px;
  border: none;
  border-radius: 100px;
  font-weight: 800;
  cursor: pointer;
}

#toast {
  position: fixed;
  bottom: 60px;
  left: 60%;
  transform: translateX(-50%);
  background: var(--o-purple-alt);
  color: white;
  padding: 12px 24px;
  border-radius: 5px;
  font-weight: 700;
  font-size: 0.95rem;
  z-index: 200;
  opacity: 1;
  transition: opacity 0.4s ease;
  pointer-events: none;
  white-space: nowrap;
}

#toast.hidden {
  display: none !important;
}

#toast.fade-out {
  opacity: 0;
}

#lobby {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}

.lobby-box {
  background: white;
  padding: 40px;
  border-radius: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 300px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.lobby-box h2 {
  font-size: 1.8rem;
  font-weight: 900;
}

.connection-status {
  font-weight: 700;
  color: var(--o-purple);
  min-height: 1.4em;
}

#lobby-join-form {
  display: flex;
  gap: 8px;
}

#room-code-input {
  font-family: inherit;
  font-size: 1.4rem;
  font-weight: 800;
  width: 120px;
  padding: 10px;
  border: 3px solid var(--text-main);
  border-radius: 12px;
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
}

#room-code-input:focus {
  outline: none;
  border-color: var(--o-purple);
}

#btn-join-code {
  font-family: inherit;
  font-weight: 800;
  background: var(--o-purple);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 10px 20px;
  cursor: pointer;
  flex: 1;
  transition: all 0.2s;
}

#btn-join-code:hover {
  background: var(--o-purple-alt);
}

#btn-back-lobby {
  font-family: inherit;
  font-weight: 700;
  background: var(--gray-light);
  border: none;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
}

#btn-back-lobby:hover {
  background: var(--x-red-alt);
  color: white;
}
