/* =========================================
   1. RESET & GLOBAL VARIABLES
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* LIGHT MODE: Sunny Gradient */
  background: linear-gradient(120deg, #e0c3fc 0%, #8ec5fc 100%);
  min-height: 100vh;
  color: #2d3436;
  line-height: 1.6;
  overflow-x: hidden;
  perspective: 1000px;
  transition: filter 1s ease, background 1s ease;
}

/* GLOOMY MODE (Active when lost) */
body.gloomy {
  filter: grayscale(1) brightness(0.6);
  background: #2d3436;
}

.hidden {
  display: none !important;
}

.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* =========================================
   2. HEADER & UI
   ========================================= */
.header {
  background: rgba(255, 255, 255, 0.65);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  padding: 1rem 0;
  z-index: 100;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.05);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 800;
  color: #2d3436;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo i {
  color: #6c5ce7;
}

.username {
  font-weight: 700;
  color: #6c5ce7;
}

/* BUTTONS */
.btn {
  padding: 0.8rem 1.8rem;
  border: none;
  border-radius: 50px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  text-transform: uppercase;
  font-size: 0.85rem;
  letter-spacing: 1px;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 10px 20px rgba(118, 75, 162, 0.3);
}

.btn-primary:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 15px 30px rgba(118, 75, 162, 0.5);
}

/* Pulsing Button for "Try Again" */
.btn.pulse-btn {
  animation: pulseHeartbeat 1.5s infinite;
  background: linear-gradient(135deg, #0984e3 0%, #00cec9 100%);
}

@keyframes pulseHeartbeat {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(9, 132, 227, 0.7);
  }

  70% {
    transform: scale(1.05);
    box-shadow: 0 0 0 15px rgba(9, 132, 227, 0);
  }

  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(9, 132, 227, 0);
  }
}

.btn-secondary {
  background: #fff;
  color: #2d3436;
  border: 1px solid #dfe6e9;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover {
  background: #f8f9fa;
  transform: translateY(-2px);
}

/* =========================================
   3. GAME AREA
   ========================================= */
.main-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.game-screen {
  width: 100%;
  max-width: 1200px;
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 3rem;
  align-items: start;
}

/* LEFT PANEL */
.room-section {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  border-radius: 24px;
  padding: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.05);
}

.section-title {
  color: #2d3436;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}

.section-subtitle {
  color: #636e72;
  margin-bottom: 1.5rem;
}

.input-group input {
  width: 100%;
  padding: 1rem;
  border-radius: 12px;
  border: 2px solid #dfe6e9;
  background: #fff;
  color: #2d3436;
  transition: 0.3s;
}

.input-group input:focus {
  border-color: #6c5ce7;
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
  outline: none;
}

.room-summary {
  margin-top: 2rem;
  border-top: 1px solid #dfe6e9;
  padding-top: 1rem;
  color: #2d3436;
}

.hint-text {
  color: #b2bec3;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

/* RIGHT PANEL (Board) */
.game-area {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(25px);
  border-radius: 24px;
  padding: 2.5rem;
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 30px 60px rgba(108, 92, 231, 0.15);
  position: relative;
  overflow: hidden;
  transform-style: preserve-3d;
}

.game-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid rgba(0, 0, 0, 0.05);
  padding-bottom: 1rem;
  margin-bottom: 2rem;
}

.current-player {
  font-size: 1.2rem;
  font-weight: 700;
  color: #2d3436;
}

/* =========================================
   4. THE BOARD & CELLS (RESIZED)
   ========================================= */
.game-board-container {
  display: flex;
  flex-direction: column;
}

.tic-tac-toe-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 20px;
  max-width: 500px;
  width: 100%;
  margin: 0 auto;
  aspect-ratio: 1;
  position: relative;
  transform: translateZ(0);
}

.cell {
  background: linear-gradient(145deg, #ffffff, #e6e6e6);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5rem;
  line-height: 1;
  font-weight: 900;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff;
  transition: all 0.2s ease;
  overflow: hidden;
}

.cell:hover {
  transform: translateY(-3px);
  box-shadow: 12px 12px 20px #d1d9e6, -12px -12px 20px #ffffff;
}

.cell.occupied {
  cursor: default;
}

.cell.occupied:hover {
  transform: none;
}

.cell.x {
  color: #ff4757;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2), -1px -1px 2px rgba(255, 255, 255, 0.8);
}

.cell.o {
  color: #2ed573;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2), -1px -1px 2px rgba(255, 255, 255, 0.8);
}

.game-status {
  text-align: center;
  margin-top: 1.5rem;
  font-weight: 600;
  color: #636e72;
}

/* =========================================
   5. OVERLAY (Winner/Loser Screen)
   ========================================= */
.game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
  animation: zoomIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes zoomIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.game-over-content h2.win-title {
  font-size: 4.5rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  color: #0984e3;
  text-shadow: 0 1px 0 #74b9ff, 0 2px 0 #0984e3, 0 3px 0 #0984e3, 0 10px 20px rgba(9, 132, 227, 0.4);
  transform: rotateX(10deg);
}

.game-over-content h2.lose-title {
  font-size: 4.5rem;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
  color: #636e72;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  animation: drip 2s infinite ease-in-out;
}

@keyframes drip {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(5px);
  }
}

.game-over-content p {
  font-size: 1.5rem;
  color: #2d3436;
  font-weight: 600;
  margin-bottom: 2rem;
}

/* =========================================
   6. CELEBRATION EFFECTS
   ========================================= */
.knife-slash {
  position: absolute;
  height: 12px;
  background: #ff4757;
  border-radius: 50px;
  box-shadow: 0 0 10px #ff4757, 0 0 20px #ff6b81, 0 0 40px #ffa502;
  z-index: 200;
  pointer-events: none;
  animation: laserExpand 0.25s ease-out forwards;
}

@keyframes laserExpand {
  0% {
    width: 0;
    opacity: 0.5;
  }

  100% {
    width: 100%;
    opacity: 1;
  }
}

.balloon {
  position: fixed;
  bottom: -200px;
  width: 70px;
  height: 85px;
  border-radius: 50% 50% 50% 50% / 45% 45% 55% 55%;
  z-index: 3000;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.95) 0%, var(--b-color) 40%, #2d3436 100%);
  box-shadow: 5px 10px 20px rgba(0, 0, 0, 0.2);
  animation: floatRealistic linear forwards;
}

.balloon::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 1px;
  height: 120px;
  background: rgba(0, 0, 0, 0.4);
  transform-origin: top center;
  animation: swayString 0.5s ease-in-out infinite alternate;
}

@keyframes floatRealistic {
  0% {
    transform: translateY(0) rotate(0deg) scale(0.8);
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  80% {
    opacity: 1;
  }

  100% {
    transform: translateY(-120vh) rotate(15deg) scale(1);
    opacity: 0;
  }
}

@keyframes swayString {
  from {
    transform: translateX(-50%) rotate(-5deg);
  }

  to {
    transform: translateX(-50%) rotate(5deg);
  }
}

.confetti {
  position: fixed;
  width: 12px;
  height: 12px;
  background: var(--c-color);
  top: -20px;
  z-index: 4000;
  box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.2);
  animation: fallConfetti linear forwards;
}

@keyframes fallConfetti {
  0% {
    transform: translateY(0) rotateX(0) rotateY(0);
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  100% {
    transform: translateY(105vh) rotateX(720deg) rotateY(360deg);
    margin-left: 20px;
    opacity: 0;
  }
}

.firework-particle {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  z-index: 9999;
  background-color: currentColor;
  box-shadow: 0 0 8px 2px currentColor;
  animation: physicsFall 1.5s cubic-bezier(0.1, 1, 0.5, 1) forwards;
}

@keyframes physicsFall {
  0% {
    transform: translate(0, 0) scale(1.5);
    opacity: 1;
  }

  100% {
    transform: translate(var(--tx), var(--ty)) scale(0);
    opacity: 0;
  }
}

/* =========================================
   7. SADNESS EFFECTS
   ========================================= */

.rain-drop {
  position: fixed;
  width: 2px;
  height: 15px;
  background: rgba(174, 194, 238, 0.8);
  top: -20px;
  z-index: 2900;
  animation: rainFall 0.8s linear infinite;
}

@keyframes rainFall {
  0% {
    transform: translateY(0);
  }

  100% {
    transform: translateY(100vh);
  }
}

.sad-emoji {
  position: fixed;
  font-size: 3rem;
  top: -50px;
  z-index: 3100;
  opacity: 0.8;
  animation: floatDownSad 3s linear forwards;
  filter: grayscale(0.5);
}

@keyframes floatDownSad {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  100% {
    transform: translateY(100vh) rotate(-20deg);
    opacity: 0;
  }
}

.thunder-flash {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #fff;
  z-index: 9999;
  opacity: 0;
  animation: flashAnim 0.2s ease-out;
  pointer-events: none;
}

@keyframes flashAnim {
  0% {
    opacity: 0.8;
  }

  100% {
    opacity: 0;
  }
}

.shake-hard {
  animation: shake 0.5s cubic-bezier(.36, .07, .19, .97) both;
}

@keyframes shake {

  10%,
  90% {
    transform: translate3d(-4px, 0, 0) rotate(1deg);
  }

  20%,
  80% {
    transform: translate3d(6px, 0, 0) rotate(-1deg);
  }

  30%,
  50%,
  70% {
    transform: translate3d(-8px, 0, 0) rotate(1deg);
  }

  40%,
  60% {
    transform: translate3d(8px, 0, 0) rotate(-1deg);
  }
}

.notifications {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 10000;
}

.notification {
  background: #2d3436;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  border-left: 4px solid #667eea;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
  }

  to {
    transform: translateX(0);
  }
}

@media (max-width: 900px) {
  .game-screen {
    grid-template-columns: 1fr;
  }

  .room-section {
    margin-bottom: 2rem;
  }
}

/* =========================================
   8. NEW SPECIAL EFFECTS (GLITCH)
   ========================================= */
.glitch-active {
  animation: glitch-anim 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both infinite;
  position: relative;
}

.glitch-active::before,
.glitch-active::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: inherit;
  opacity: 0.5;
}

.glitch-active::before {
  animation: glitch-anim-1 0.5s infinite linear alternate-reverse;
  clip-path: inset(20% 0 80% 0);
  transform: translate(-4px, 0);
  background-color: rgba(255, 0, 0, 0.2);
}

.glitch-active::after {
  animation: glitch-anim-2 0.5s infinite linear alternate-reverse;
  clip-path: inset(60% 0 10% 0);
  transform: translate(4px, 0);
  background-color: rgba(0, 0, 255, 0.2);
}

@keyframes glitch-anim {
  0% {
    transform: translate(0);
  }

  20% {
    transform: translate(-2px, 2px);
  }

  40% {
    transform: translate(-2px, -2px);
  }

  60% {
    transform: translate(2px, 2px);
  }

  80% {
    transform: translate(2px, -2px);
  }

  100% {
    transform: translate(0);
  }
}

@keyframes glitch-anim-1 {
  0% {
    clip-path: inset(20% 0 80% 0);
  }

  100% {
    clip-path: inset(50% 0 30% 0);
  }
}

@keyframes glitch-anim-2 {
  0% {
    clip-path: inset(10% 0 60% 0);
  }

  100% {
    clip-path: inset(20% 0 50% 0);
  }
}

/* =========================================
   9. MODAL
   ========================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
}

.modal-content {
  background: #fff;
  padding: 2.5rem;
  border-radius: 24px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
  animation: zoomIn 0.3s ease-out;
}

.modal-content h2 {
  color: #2d3436;
  margin-bottom: 0.5rem;
}

.modal-content p {
  color: #636e72;
  margin-bottom: 1.5rem;
}

/* ================================================================
   📱 MOBILE RESPONSIVE UPGRADE — UNIVERSAL FIX (ADD AT BOTTOM)
   Makes the whole UI scale beautifully on phones & tablets
================================================================ */

/* Small tablets */
@media (max-width: 768px) {
  .header-content {
    padding: 0 1rem;
  }

  .logo {
    font-size: 1.2rem;
  }

  .username {
    font-size: 1rem;
  }

  .main-content {
    padding: 1.5rem;
  }

  .game-screen {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .room-section,
  .game-area {
    padding: 1.5rem !important;
    border-radius: 16px;
  }

  /* Board scaling */
  .tic-tac-toe-board {
    max-width: 350px;
    gap: 12px;
  }

  .cell {
    font-size: 3.6rem;
    border-radius: 16px;
  }

  .game-info {
    flex-direction: column;
    gap: 10px;
  }

  .game-controls {
    display: flex;
    gap: 10px;
  }

  .btn {
    padding: 0.7rem 1.2rem;
    font-size: 0.75rem;
  }
}

/* Mobile phones */
@media (max-width: 480px) {
  .header-content {
    flex-direction: column;
    gap: 10px;
  }

  .room-section {
    padding: 1.2rem !important;
  }

  .section-title {
    font-size: 1.6rem;
  }

  .section-subtitle {
    font-size: 0.9rem;
  }

  /* Input group on mobile */
  .input-group {
    flex-direction: column;
    gap: 10px;
  }

  .input-group input {
    width: 100%;
    padding: 0.9rem;
    font-size: 1rem;
  }

  /* Buttons become full-width on mobile */
  .btn,
  .btn-sm {
    width: 100%;
    justify-content: center;
    padding: 0.9rem;
  }

  /* Waiting room text scale */
  .waiting-content h3 {
    font-size: 1.4rem;
  }

  /* Board must scale! */
  .tic-tac-toe-board {
    max-width: 90vw;
    gap: 10px;
  }

  .cell {
    font-size: 2.8rem;
    border-radius: 14px;
  }

  /* Game Over screen improvements */
  .game-over-content h2 {
    font-size: 2.6rem !important;
  }

  .game-over-content p {
    font-size: 1.1rem;
  }

  .game-over-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
}

/* Ultra-small phones (iPhone SE) */
@media (max-width: 360px) {
  .cell {
    font-size: 2.3rem;
  }

  .section-title {
    font-size: 1.4rem;
  }

  .btn {
    font-size: 0.7rem;
  }
}