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

/* Prevent zoom on double-click */
html,
body {
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

body {
  font-family: "Open Sans", sans-serif;
  font-optical-sizing: auto;
  background: linear-gradient(135deg, #0f0f23 0%, #1a1a3e 50%, #0f0f23 100%);
  min-height: 100vh;
  color: #e2e8f0;
  letter-spacing: 0.03em;
  overflow-x: hidden;
}

/* Animated background */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.1) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(59, 130, 246, 0.1) 0%, transparent 40%);
  pointer-events: none;
  z-index: 0;
}

.container {
  position: relative;
  z-index: 1;
  margin-inline: auto;
  padding: 20px;
}

.game-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  max-width: 500px;
  width: 100%;
  text-align: center;
  margin-inline: auto;
}

.screen {
  display: none;
  animation: fadeIn 0.4s ease-out;
}

.screen.active {
  display: block;
}

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

/* Typography */
h1 {
  font-size: 2rem;
  margin-bottom: 24px;
  background: linear-gradient(135deg, #fff 0%, #a5b4fc 50%, #818cf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-family: "Playwrite AU QLD", cursive;
  font-weight: 700;
  letter-spacing: 0.02em;
}

h2 {
  font-size: 1.5rem;
  margin-bottom: 15px;
  color: #f1f5f9;
  font-weight: 600;
}

/* Game Description Card */
.game-description {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 28px;

  ul {
    list-style-type: none;

    li {
      margin-bottom: 12px;
      font-size: 1rem;
      color: rgba(255, 255, 255, 0.75);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;

      &::before {
        content: "→";
        color: #818cf8;
        font-weight: bold;
      }

      &:first-child::before {
        content: "";
      }

      .highlight {
        background: linear-gradient(135deg, #f87171 0%, #fb923c 100%);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        font-weight: 700;
        font-size: 1.3rem;
        text-transform: uppercase;
        letter-spacing: 0.1em;
      }
    }
  }
}

/* Difficulty Selector */
.difficulty-selector {
  margin-bottom: 32px;
}

.difficulty-selector label {
  display: block;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 14px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

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

.difficulty-btn {
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 10px 24px;
  font-size: 0.85rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.difficulty-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.difficulty-btn.active {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-color: transparent;
  color: white;
  box-shadow:
    0 4px 20px rgba(99, 102, 241, 0.4),
    0 0 40px rgba(99, 102, 241, 0.2);
  transform: translateY(-2px);
}

/* Main Button */
.btn {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  border: none;
  padding: 14px 40px;
  font-size: 1rem;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow:
    0 4px 20px rgba(99, 102, 241, 0.4),
    0 0 40px rgba(99, 102, 241, 0.15);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.btn:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow:
    0 8px 30px rgba(99, 102, 241, 0.5),
    0 0 60px rgba(99, 102, 241, 0.25);
}

.btn:hover::before {
  left: 100%;
}

.btn:active {
  transform: translateY(-1px) scale(1);
}

/* Game Header */
.game-header {
  display: none;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.timer,
.round {
  font-size: 1rem;
  font-weight: 600;
  color: #f1f5f9;
}

.timer {
  color: #f87171;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Timer Bar */
.timer-bar {
  width: 100%;
  max-width: 280px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  overflow: hidden;
  margin: 0 auto 24px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.timer-progress {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #4ade80);
  border-radius: 10px;
  transition: width 0.1s linear, background 0.3s ease;
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.5);
}

/* Game Board */
.game-board {
  position: relative;
  width: 320px;
  height: 320px;
  margin: 0 auto 40px;
  overflow: visible;
}

.grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
  background: transparent;
  padding: 0;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(120%) scale(0.9);
  opacity: 0;
}

.grid.active {
  transform: translateX(0) scale(1);
  opacity: 1;
}

.grid.sliding-out {
  transform: translateX(-120%) scale(0.9);
  opacity: 0;
}

.grid-number {
  position: absolute;
  bottom: -55px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.3);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

/* Cells */
.cell {
  background: rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(5px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  color: #f1f5f9;
}

.cell:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.cell.x {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(248, 113, 113, 0.1) 100%);
  border-color: rgba(248, 113, 113, 0.4);
  color: #f87171;
  box-shadow:
    0 0 30px rgba(248, 113, 113, 0.2),
    inset 0 0 20px rgba(248, 113, 113, 0.1);
  animation: placeX 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell.o {
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.2) 0%, rgba(147, 197, 253, 0.1) 100%);
  border-color: rgba(96, 165, 250, 0.4);
  color: #60a5fa;
  box-shadow:
    0 0 30px rgba(96, 165, 250, 0.2),
    inset 0 0 20px rgba(96, 165, 250, 0.1);
  animation: placeO 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell.winning {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.3) 0%, rgba(52, 211, 153, 0.2) 100%);
  border-color: rgba(16, 185, 129, 0.6);
  color: #10b981;
  box-shadow:
    0 0 40px rgba(16, 185, 129, 0.4),
    inset 0 0 30px rgba(16, 185, 129, 0.2);
  animation: winPulse 0.8s ease-in-out infinite;
}

@keyframes placeX {
  0% {
    transform: scale(0.5) rotate(-10deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.1) rotate(5deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

@keyframes placeO {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  50% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes winPulse {
  0%, 100% {
    transform: scale(1);
    box-shadow:
      0 0 40px rgba(16, 185, 129, 0.4),
      inset 0 0 30px rgba(16, 185, 129, 0.2);
  }
  50% {
    transform: scale(1.05);
    box-shadow:
      0 0 60px rgba(16, 185, 129, 0.6),
      inset 0 0 40px rgba(16, 185, 129, 0.3);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* End Screen */
#end-message {
  font-size: 1.2rem;
  margin-bottom: 24px;
  padding: 16px 24px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

#end-message.win {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(52, 211, 153, 0.1) 100%);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
}

#end-message.lose {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.15) 0%, rgba(239, 68, 68, 0.1) 100%);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: #f87171;
}

.game-summary-info {
  margin-bottom: 20px;
}

.difficulty-display {
  display: inline-block;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.7);
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.difficulty-display span:first-child {
  color: rgba(255, 255, 255, 0.5);
  margin-right: 6px;
}

.difficulty-display span:last-child {
  color: #a5b4fc;
  font-weight: 600;
}

/* Grid Summary */
.grid-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  margin: 24px 0;
  padding: 20px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 4px;
  width: 90px;
  height: 90px;
  background: transparent;
  position: relative;
}

.summary-grid::before {
  content: attr(data-grid-number);
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
}

.summary-cell {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: #f1f5f9;
}

.summary-cell.x {
  background: rgba(248, 113, 113, 0.15);
  border-color: rgba(248, 113, 113, 0.3);
  color: #f87171;
}

.summary-cell.o {
  background: rgba(96, 165, 250, 0.15);
  border-color: rgba(96, 165, 250, 0.3);
  color: #60a5fa;
}

.summary-cell.o.winning {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.4);
  color: #10b981;
  position: relative;
}

.summary-cell.o.winning::after {
  content: "";
  position: absolute;
  width: 60%;
  height: 60%;
  border: 2px solid #f87171;
  border-radius: 50%;
  animation: losePulse 1s ease-in-out infinite;
}

@keyframes losePulse {
  0%, 100% {
    opacity: 0.5;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* Responsive design */
@media (max-width: 768px) {
  .container {
    padding: 15px;
  }

  .game-container {
    padding: 15px;
    max-width: 100%;
  }

  h1 {
    font-size: 1.6rem;
  }

  .cell {
    font-size: 3rem;
    border-radius: 12px;
  }

  .grid {
    gap: 6px;
  }
}

@media (max-width: 480px) {
  
  .cell {
    font-size: 3rem;
    border-radius: 10px;
  }

  .grid {
    gap: 5px;
  }

  .btn {
    padding: 12px 32px;
    font-size: 0.9rem;
  }

  .difficulty-btn {
    padding: 8px 16px;
    font-size: 0.75rem;
  }

  .game-description {
    padding: 18px;

    ul li {
      font-size: 0.9rem;
    }
  }
}

@media (max-width: 380px) {
  
  .cell {
    font-size: 3rem;
    border-radius: 8px;
  }

  .grid {
    gap: 4px;
  }

  h1 {
    font-size: 1.4rem;
  }

  .summary-grid {
    width: 70px;
    height: 70px;
  }

  .summary-cell {
    font-size: 0.7rem;
    border-radius: 4px;
  }
}
