/* Цветовая палитра из ТЗ */
:root {
  --bg-main: #FDF6F0;
  --accent: #D4A5A5;
  --accent-hover: #C99494;
  --text-primary: #9B7E6B;
  --text-secondary: #B8A89A;
  --win-bg: #B8D4C8;
  --x-color: #E8B4B8;
  --o-color: #A8C5D9;
  --white: #FFFFFF;
  --border: #E5DDD5;
  --shadow: rgba(155, 126, 107, 0.15);
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Экраны */
.screen {
  display: none;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

/* Заголовок */
.title {
  font-family: 'Cormorant', serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 30px;
  text-align: center;
}

/* Игровое поле */
.game-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  background: var(--white);
  padding: 20px;
  border-radius: 24px;
  box-shadow: 0 10px 30px var(--shadow);
}

.cell {
  width: 80px;
  height: 80px;
  background: var(--bg-main);
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 42px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
}

.cell:hover:not(.taken) {
  background: var(--white);
  border-color: var(--border);
  transform: scale(1.02);
}

.cell:active:not(.taken) {
  transform: scale(0.98);
}

.cell.taken {
  cursor: not-allowed;
}

.cell.x {
  color: var(--x-color);
}

.cell.o {
  color: var(--o-color);
}

.cell.winner {
  animation: winPulse 0.6s ease infinite alternate;
  background: linear-gradient(135deg, var(--win-bg) 0%, #C8E4D8 100%);
}

@keyframes winPulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* Анимация появления символа */
.cell span {
  animation: symbolAppear 0.3s ease;
}

@keyframes symbolAppear {
  from {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  to {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

/* Статус */
.status {
  margin-top: 25px;
  font-size: 18px;
  color: var(--text-secondary);
  text-align: center;
}

/* Экран результата */
.result-content {
  text-align: center;
  padding: 20px;
}

.win-icon, .lose-icon, .draw-icon {
  font-size: 60px;
  margin-bottom: 15px;
  animation: bounce 0.6s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-15px); }
}

.result-title {
  font-family: 'Cormorant', serif;
  font-size: 36px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.result-text {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 25px;
  line-height: 1.5;
}

/* Промокод */
.promo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--white);
  padding: 15px 25px;
  border-radius: 16px;
  box-shadow: 0 5px 20px var(--shadow);
  margin-bottom: 10px;
}

.promo-code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 3px;
}

.copy-btn {
  background: var(--bg-main);
  border: none;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.copy-btn:hover {
  background: var(--accent);
  color: var(--white);
}

.copy-btn:active {
  transform: scale(0.95);
}

.copy-status {
  font-size: 14px;
  color: var(--win-bg);
  height: 20px;
  margin-bottom: 15px;
}

/* Кнопки */
.btn {
  font-family: 'Nunito', sans-serif;
  font-size: 16px;
  font-weight: 600;
  padding: 16px 40px;
  border: none;
  border-radius: 30px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 200px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  color: var(--white);
  box-shadow: 0 5px 20px rgba(212, 165, 165, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(212, 165, 165, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--white);
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-secondary:hover {
  background: var(--accent);
  color: var(--white);
}

/* Экран победы - особый фон */
#win-screen {
  position: relative;
  background: linear-gradient(135deg, #E8F5F0 0%, #FDF6F0 50%, #FCE8EA 100%);
  min-height: 100vh;
  margin: -20px;
  padding: 20px;
  border-radius: 0;
}

#win-screen .result-content {
  position: relative;
  z-index: 1;
}

/* Конфетти */
.confetti {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -20px;
  animation: confettiFall 3s ease-out forwards;
}

@keyframes confettiFall {
  0% {
    transform: translateY(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) rotate(720deg);
    opacity: 0;
  }
}

/* Адаптивность */
@media (max-width: 380px) {
  .cell {
    width: 70px;
    height: 70px;
    font-size: 36px;
  }

  .game-board {
    padding: 15px;
    gap: 8px;
  }

  .title {
    font-size: 28px;
  }

  .promo-code {
    font-size: 24px;
  }
}

@media (min-height: 700px) {
  .container {
    justify-content: center;
  }
}

/* Поддержка тёмной темы Telegram */
@media (prefers-color-scheme: dark) {
  body.tg-dark {
    --bg-main: #1C1C1E;
    --white: #2C2C2E;
    --text-primary: #E5E5E7;
    --text-secondary: #8E8E93;
    --border: #3A3A3C;
    --shadow: rgba(0, 0, 0, 0.3);
  }
}
