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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7fa;
  color: #333;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

h1 {
  font-size: 1.5rem;
  color: #4a90d9;
  text-align: center;
  margin-bottom: 20px;
  padding: 12px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

h2 {
  font-size: 1.1rem;
  color: #555;
  margin-bottom: 12px;
}

section {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

input[type="text"] {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

input[type="text"]:focus {
  border-color: #4a90d9;
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  white-space: nowrap;
}

button:active {
  opacity: 0.8;
}

#add-btn {
  background: #4a90d9;
  color: #fff;
}

button.primary {
  background: #4a90d9;
  color: #fff;
  font-size: 1rem;
  padding: 12px 20px;
}

button.secondary {
  background: #eee;
  color: #555;
}

button.danger {
  background: #e74c3c;
  color: #fff;
  font-size: 0.85rem;
  padding: 8px 14px;
}

#team-list {
  list-style: none;
  margin-bottom: 12px;
  max-height: 240px;
  overflow-y: auto;
}

#team-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.95rem;
}

#team-list li:last-child {
  border-bottom: none;
}

.team-num {
  color: #999;
  font-size: 0.8rem;
  margin-right: 8px;
  min-width: 20px;
}

.team-name {
  flex: 1;
}

.bye-badge {
  font-size: 0.75rem;
  color: #999;
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

.remove-btn {
  background: none;
  border: none;
  color: #ccc;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.remove-btn:hover {
  color: #e74c3c;
  background: #ffeaea;
}

.action-row {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  margin-bottom: 0;
}

.hidden {
  display: none;
}

/* トーナメントブラケット */
#tournament-wrapper {
  overflow-x: auto;
  padding-bottom: 8px;
}

#tournament-bracket {
  display: flex;
  gap: 0;
  align-items: center;
  min-width: max-content;
}

.round {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 0;
}

.round-label {
  text-align: center;
  font-size: 0.75rem;
  color: #999;
  padding: 4px 8px;
  margin-bottom: 6px;
}

.matches-col {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  flex: 1;
}

.match-wrapper {
  display: flex;
  align-items: center;
}

.match {
  display: flex;
  flex-direction: column;
  width: 140px;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
  margin: 4px 0;
  background: #fff;
}

.team-slot {
  padding: 8px 10px;
  font-size: 0.88rem;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  user-select: none;
}

.team-slot:last-child {
  border-bottom: none;
}

.team-slot:hover:not(.bye):not(.empty):not(.winner):not(.loser) {
  background: #eaf3ff;
}

.team-slot.winner {
  background: #d4edda;
  color: #155724;
  font-weight: bold;
}

.team-slot.loser {
  background: #f8f8f8;
  color: #bbb;
  text-decoration: line-through;
}

.team-slot.bye {
  color: #bbb;
  font-style: italic;
  cursor: default;
}

.team-slot.empty {
  color: #ddd;
  cursor: default;
}

.team-slot.tbd {
  color: #bbb;
  cursor: default;
}

/* コネクター線 */
.connector {
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 20px;
  position: relative;
}

.connector-top,
.connector-bottom {
  flex: 1;
  border-right: 2px solid #ddd;
}

.connector-mid {
  width: 20px;
  border-top: 2px solid #ddd;
}

/* 優勝者 */
#champion-area {
  text-align: center;
  padding: 16px;
  margin-top: 12px;
  background: linear-gradient(135deg, #fff9e6, #fffbe8);
  border: 2px solid #f0c040;
  border-radius: 8px;
}

#champion-area .trophy {
  font-size: 2rem;
}

#champion-area .champion-label {
  font-size: 0.85rem;
  color: #999;
}

#champion-area .champion-name {
  font-size: 1.4rem;
  font-weight: bold;
  color: #c8a000;
  margin-top: 4px;
}

.team-count-info {
  font-size: 0.8rem;
  color: #999;
  margin-bottom: 8px;
}

@media (max-width: 500px) {
  .match {
    width: 120px;
  }
  .team-slot {
    font-size: 0.8rem;
    padding: 7px 8px;
    max-width: 120px;
  }
  button.primary {
    font-size: 0.9rem;
    padding: 10px 14px;
  }
}
