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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    margin: 0;
}

.container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 20px;
    max-width: 1400px;
    width: 100%;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 15px;
    font-size: 1.4rem;
    flex-shrink: 0;
}

h2 {
    color: #333;
    margin-bottom: 15px;
    font-size: 1.3rem;
}

h3 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

h4 {
    color: #666;
    margin-bottom: 10px;
    font-size: 1rem;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 500;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    resize: vertical;
    transition: border-color 0.3s;
    -webkit-appearance: none;
}

textarea:focus {
    outline: none;
    border-color: #667eea;
}

.total-count {
    display: block;
    margin-top: 8px;
    color: #666;
    font-size: 14px;
}

.button-group {
    display: flex;
    gap: 15px;
    margin-top: 25px;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex: 1;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.btn-secondary:hover {
    background: #e8e8e8;
}

.btn-small {
    padding: 8px 20px;
    font-size: 14px;
}

/* 比賽區域 */
.tournament-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tournament-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 10px;
    flex-shrink: 0;
}


/* 對戰區域布局 */
.tournament-brackets {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 15px;
    flex: 1;
    overflow: hidden;
}

.bracket-column {
    background: #f8f9ff;
    border-radius: 12px;
    padding: 15px;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bracket-column h3 {
    text-align: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.winners-column {
    border: 2px solid #667eea;
}

.winners-column h3 {
    color: #667eea;
}

.losers-column {
    border: 2px solid #ff6b6b;
}

.losers-column h3 {
    color: #ff6b6b;
}

.finals-column {
    border: 2px solid #ffd700;
    background: #fffef5;
    max-width: 300px;
    align-self: center;
}

.finals-column h3 {
    color: #ffb700;
}

.matches-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}

.matches-container::-webkit-scrollbar {
    width: 6px;
}

.matches-container::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 3px;
}

.matches-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.matches-container::-webkit-scrollbar-thumb:hover {
    background: rgba(0,0,0,0.3);
}

.round {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

.round h4 {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 8px;
    text-align: center;
}

.match-item {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    transition: all 0.3s;
}

.match-item.completed {
    border-color: #667eea;
}

.match-item.bye-match {
    background: #f0f0f0;
    border-color: #d0d0d0;
}

.match-players {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.player-btn {
    padding: 8px 16px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.player-btn:hover:not(.winner) {
    border-color: #667eea;
    background: #f8f9ff;
}

.player-btn.winner {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.vs {
    color: #667eea;
    font-weight: 700;
    font-size: 16px;
}

.bye-text {
    color: #666;
    font-style: italic;
}



.final-results {
    background: #f8f9ff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.rank-item {
    padding: 15px;
    margin-bottom: 10px;
    background: white;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 500;
}

.rank-1 {
    background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
    color: white;
}

.rank-2 {
    background: linear-gradient(135deg, #C0C0C0 0%, #B8B8B8 100%);
    color: white;
}

.rank-3 {
    background: linear-gradient(135deg, #CD7F32 0%, #B87333 100%);
    color: white;
}

.hidden {
    display: none;
}

/* 平板優化 */
@media (max-width: 1024px) {
    .tournament-brackets {
        grid-template-columns: 1fr;
        gap: 10px;
        overflow-y: auto;
    }
    
    .bracket-column {
        min-height: 300px;
        overflow-y: visible;
    }
    
    .finals-column {
        max-width: none;
        order: -1;
        min-height: 200px;
    }
    
    .matches-container {
        overflow-y: visible;
    }
}

/* 設置區域 */
.setup-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.setup-section.hidden {
    display: none;
}

/* 結果區域 */
.results-section {
    margin-top: 20px;
    text-align: center;
}

/* 手機優化 */
@media (max-width: 480px) {
    body {
        padding: 0;
        align-items: flex-start;
    }
    
    .container {
        padding: 20px 15px;
        border-radius: 0;
        max-height: 100vh;
        height: 100vh;
        box-shadow: none;
    }
    
    h1 {
        font-size: 1.3rem;
        margin-bottom: 15px;
    }
    
    h2 {
        font-size: 1.1rem;
    }
    
    h3 {
        font-size: 1rem;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    label {
        font-size: 14px;
        margin-bottom: 5px;
    }
    
    textarea {
        padding: 10px;
        font-size: 16px;
        min-height: 150px;
        max-height: 250px;
    }
    
    .button-group {
        flex-direction: row;
        gap: 10px;
        margin-top: 15px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 14px;
        flex: 1;
    }
    
    .tournament-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .header-controls {
        flex-direction: column;
        width: 100%;
    }
    
    .header-controls .btn {
        width: 100%;
    }
    
    .tournament-brackets {
        gap: 10px;
    }
    
    .bracket-column {
        padding: 15px;
    }
    
    .round {
        padding: 15px;
    }
    
    .match-item {
        padding: 12px;
        margin-bottom: 10px;
    }
    
    .match-players {
        gap: 10px;
    }
    
    .player-btn {
        padding: 8px 15px;
        font-size: 14px;
    }
    
    .vs {
        font-size: 16px;
    }
    
    .btn-small {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    .rank-item {
        padding: 12px;
        font-size: 16px;
    }
}

/* 平板優化 */
@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 30px;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .bracket-tabs {
        gap: 8px;
    }
    
    .match-players {
        gap: 12px;
    }
}

/* 觸控設備優化 */
@media (hover: none) {
    .btn:active {
        transform: scale(0.98);
    }
    
    .btn-primary:hover {
        transform: none;
        box-shadow: none;
    }
    
    .btn-secondary:hover {
        background: #f5f5f5;
    }
    
    .player-btn:active {
        transform: scale(0.98);
    }
}

/* 滾動條樣式 */
.container::-webkit-scrollbar {
    width: 8px;
}

.container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.container::-webkit-scrollbar-thumb:hover {
    background: #555;
}