:root {
  --primary: #2c3e50;
  --secondary: #4CAF50;
  --highlight: #FFD700;
  --background: #f9f9f9;
  --border: #ddd;
  --saved-bg: #e8f5e9;
  --court-bg: #f0f8ff;
  --game-bg: #f5f5f5;
  --filled-bg: #e8f5e9;
  --tie-bg: #ffebee;
  --mobile-padding: 10px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: var(--mobile-padding);
  background: var(--background);
  color: var(--primary);
  font-size: 16px;
  line-height: 1.4;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
}

h1 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  text-align: center;
}

h2 {
  font-size: 1.3rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
}

h4 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
}

/* Блок настройки */
#setup {
  margin-bottom: 20px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.players-input {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.players-input input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 16px;
}

.btn-randomize, .btn-new-game, .btn-finish-round {
  padding: 14px 20px;
  margin-right: 10px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  transition: all 0.3s;
  min-height: 50px;
}

.btn-randomize:hover, .btn-new-game:hover, .btn-finish-round:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.btn-randomize {
  background: var(--primary);
}

.btn-randomize:hover {
  background: #1a252f;
}

.btn-new-game {
  background: #e74c3c;
}

.btn-new-game:hover {
  background: #c0392b;
}

.btn-finish-round {
  background: var(--secondary);
  margin-top: 15px;
  width: 100%;
}

.btn-finish-round:hover {
  background: #3d8b40;
}

/* Раунды */
.round {
  margin-bottom: 20px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.round h2 {
  margin-top: 0;
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
  padding-bottom: 10px;
}

/* Корты */
.court {
  margin-bottom: 15px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--court-bg);
}

.court h3 {
  margin-top: 0;
  color: var(--secondary);
}

.court-players {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 12px;
  padding: 8px;
  background: white;
  border-radius: 6px;
}

.court-players div {
  padding: 8px;
  background: #f9f9f9;
  border-radius: 4px;
  text-align: center;
  font-size: 14px;
}

/* Игры */
.court-games {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.game {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--game-bg);
  transition: all 0.3s;
}

.game.filled {
  background: var(--filled-bg);
  border-color: var(--secondary);
  box-shadow: 0 2px 4px rgba(76, 175, 80, 0.2);
}

.teams {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.team {
  padding: 6px;
  background: white;
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  line-height: 1.3;
}

.vs {
  text-align: center;
  font-weight: bold;
  color: var(--primary);
  font-size: 11px;
  margin: 2px 0;
}

.score-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.score-input input {
  width: 45px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 16px;
}

.score-input button {
  padding: 8px 12px;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  min-width: 40px;
}

.score-input button:hover {
  background: #3d8b40;
}

/* Результаты по кортам */
.court-results {
  margin-top: 12px;
  padding: 10px;
  background: white;
  border-radius: 6px;
  border-left: 4px solid var(--secondary);
}

.court-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
  transition: background-color 0.3s;
}

.court-result-item.tie {
  background-color: var(--tie-bg);
  border-left: 4px solid #f44336;
}

.court-result-item:last-child {
  border-bottom: none;
}

.place {
  font-weight: bold;
  color: var(--primary);
  min-width: 70px;
  font-size: 13px;
}

.player-name {
  flex-grow: 1;
  font-size: 14px;
}

.player-stats {
  color: #666;
  font-size: 12px;
}

.tie-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tie-button {
  padding: 4px 8px;
  background: #f44336;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: bold;
}

.tie-button:hover {
  background: #d32f2f;
}

.tie-button:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Финальные результаты */
.final-results {
  background: linear-gradient(135deg, #fff8e1, #ffecb3);
}

/* Таблица лидеров */
#leaderboard, #current-results {
  margin-top: 20px;
  padding: 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
}

.player-score {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 6px 0;
  padding: 8px;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}

.rank {
  font-weight: bold;
  color: var(--primary);
  min-width: 25px;
}

.hidden {
  display: none;
}

.players-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.players-list div {
  padding: 10px;
  background: #f0f0f0;
  border-radius: 6px;
  text-align: center;
  font-size: 14px;
}

/* Мобильная адаптация */
@media (max-width: 768px) {
  body {
    padding: 8px;
    font-size: 14px;
  }
  
  .players-input,
  .players-list {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .court-games {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .court-players {
    grid-template-columns: 1fr;
  }
  
  .court-result-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .player-score {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }
  
  .teams {
    flex-direction: column;
  }
  
  .score-input {
    justify-content: space-between;
  }
  
  .score-input input {
    width: 60px;
    padding: 10px;
    font-size: 18px;
  }
  
  .score-input button {
    padding: 10px 15px;
    font-size: 16px;
    min-width: 50px;
  }
  
  .btn-randomize, .btn-new-game, .btn-finish-round {
    width: 100%;
    margin-bottom: 10px;
    margin-right: 0;
  }
  
  .container {
    padding: 0;
  }
  
  h1 {
    font-size: 1.3rem;
  }
  
  h2 {
    font-size: 1.2rem;
  }
  
  h3 {
    font-size: 1.1rem;
  }
  
  .court {
    padding: 10px;
  }
  
  .round {
    padding: 12px;
  }
  
  .tie-buttons {
    width: 100%;
    justify-content: flex-start;
  }
  
  .tie-button {
    padding: 6px 10px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .players-input,
  .players-list {
    grid-template-columns: 1fr;
  }
  
  body {
    padding: 5px;
  }
  
  #setup, .round, .court, #leaderboard, #current-results {
    padding: 10px;
  }
  
  .players-input input {
    padding: 14px;
  }
  
  .court-players div {
    padding: 10px;
  }
  
  .game {
    padding: 12px;
  }
  
  .team {
    font-size: 13px;
    padding: 8px;
  }
  
  .place {
    min-width: 60px;
  }
}

/* Улучшения для очень маленьких экранов */
@media (max-width: 360px) {
  body {
    font-size: 13px;
  }
  
  .score-input input {
    width: 50px;
    padding: 8px;
  }
  
  .score-input button {
    padding: 8px 12px;
  }
  
  .players-input input {
    padding: 12px;
  }
}

/* Улучшения для планшетов */
@media (min-width: 769px) and (max-width: 1024px) {
  .court-games {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .players-input {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Анимации для улучшения UX */
.game {
  transition: all 0.3s ease;
}

.btn-randomize, .btn-new-game, .btn-finish-round {
  transition: all 0.3s ease;
}

/* Улучшение визуальной иерархии */
.court:nth-child(even) {
  background: #f8fdff;
}

.round:nth-child(even) {
  background: #fdfdfd;
}

/* Выделение активных элементов */
input:focus, button:focus {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}