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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #0c1f3d 0%, #1e3c72 100%);
    min-height: 100vh;
    color: #fff;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}

.subtitle {
    font-size: 1.2em;
    opacity: 0.9;
}

main {
    display: grid;
    gap: 30px;
}

section {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 25px;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
}

h2 {
    margin-bottom: 20px;
    color: #ffd700;
    font-size: 1.5em;
}

.input-section textarea {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    font-size: 14px;
    resize: vertical;
    margin-bottom: 15px;
}

.input-instructions {
    margin-bottom: 15px;
}

.input-instructions small {
    opacity: 0.8;
    font-style: italic;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

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

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.3);
}

.api-key-section {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.api-key-section input {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
}

.api-key-section small a {
    color: #ffd700;
    text-decoration: none;
}

.api-key-section small a:hover {
    text-decoration: underline;
}

.region-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
}

.region-section select {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    cursor: pointer;
}

.region-section .btn-secondary {
    flex: 0;
}

.player-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.player-card {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    padding: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    aspect-ratio: 1 / 1.2;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 0;
    overflow: hidden;
}

.player-card.loading {
    opacity: 0.6;
}

.player-name {
    font-size: 0.9em;
    font-weight: bold;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    line-height: 1.1;
}

.player-rank {
    font-size: 0.75em;
    margin-bottom: 4px;
    color: #ffd700;
    line-height: 1.1;
    text-align: center;
}

.player-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
    font-size: 0.75em;
    margin-bottom: 3px;
    opacity: 0.9;
    line-height: 1.1;
}

.player-score {
    background: rgba(0, 0, 0, 0.2);
    padding: 3px;
    border-radius: 3px;
    margin-bottom: 2px;
    font-size: 0.8em;
}

.score-value {
    font-size: 1.1em;
    font-weight: bold;
    color: #ffd700;
}

.rank-equivalent {
    margin-left: 10px;
    color: #ffd700;
    font-size: 0.9em;
    font-style: italic;
    opacity: 0.9;
}

.adjustment-container {
    margin-top: 3px;
}

.adjustment-label {
    font-size: 0.75em;
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    line-height: 1.1;
}

.adjustment-slider {
    width: 100%;
    -webkit-appearance: none;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.3);
    outline: none;
}

.adjustment-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffd700;
    cursor: pointer;
}

.adjustment-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffd700;
    cursor: pointer;
    border: none;
}

.teams-container {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

.team {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 20px;
}

.team-blue {
    border: 2px solid #0099ff;
}

.team-red {
    border: 2px solid #ff4444;
}

.team h3 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 1.3em;
}

.team-blue h3 {
    color: #0099ff;
}

.team-red h3 {
    color: #ff4444;
}

.team-score {
    text-align: center;
    font-size: 1.2em;
    margin-bottom: 15px;
    font-weight: bold;
}

.team-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2em;
    font-weight: bold;
    color: #ffd700;
}

.team-members {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.team-member {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 5px;
    text-align: center;
    cursor: move;
}

.team-member.dragging {
    opacity: 0.5;
}

.member-name {
    font-weight: 600;
    display: block;
}

.team-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
}

.warning {
    background: rgba(255, 193, 7, 0.2);
    border: 1px solid #ffc107;
    color: #ffc107;
    padding: 15px;
    border-radius: 5px;
    text-align: center;
    margin-top: 20px;
}

.history-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 10px;
}

.history-date {
    font-size: 0.85em;
    opacity: 0.7;
    margin-bottom: 10px;
}

.history-teams {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

footer {
    text-align: center;
    margin-top: 50px;
    padding: 20px;
    opacity: 0.7;
    font-size: 0.9em;
}

.loading-spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 3px solid #ffd700;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.error {
    color: #ff4444;
    font-size: 0.9em;
    margin-top: 5px;
}

.success {
    color: #44ff44;
    font-size: 0.9em;
    margin-top: 5px;
}


/* リージョン選択 */
.region-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.region-section label {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9em;
    flex-shrink: 0;
}

.region-section select {
    width: 150px;
    max-width: 150px;
    min-width: 150px;
    flex: 0 0 150px;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    color: #fff;
    font-size: 0.85em;
}

.region-section select option {
    background: #2a5298;
    color: #fff;
}

.region-section .btn-secondary {
    white-space: nowrap;
    min-width: fit-content;
    flex: 0 0 auto;
    padding: 8px 16px;
    font-size: 0.85em;
}

/* ロール選択 */
.role-container {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.role-container label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85em;
}

.role-selector {
    padding: 5px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 5px;
    color: #fff;
    font-size: 0.9em;
}

.role-selector option {
    background: #2a5298;
    color: #fff;
}

/* セクション制御 */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.section-header h2 {
    margin: 0;
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.3s ease, background 0.3s ease;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.toggle-btn.rotated {
    transform: rotate(180deg);
}

.section-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.section-content.hidden {
    max-height: 0;
    opacity: 0;
}

/* 手動ランク選択 */
.manual-rank-container {
    margin: 4px 0;
    padding: 4px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.manual-rank-container label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.7em;
    margin-right: 4px;
    display: block;
}

.manual-rank-selector {
    padding: 3px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    color: #fff;
    font-size: 0.7em;
    width: 100%;
    margin-top: 2px;
}

.manual-rank-selector option {
    background: #2a5298;
    color: #fff;
}

.estimated-rank {
    margin-top: 5px;
    font-size: 12px;
    color: #ffd700;
    font-style: italic;
}

/* ===== 連続試合用の追加スタイル ===== */

.performance-section {
    background: linear-gradient(135deg, rgba(30, 60, 114, 0.8), rgba(42, 82, 152, 0.8));
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.match-result-section {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 10px;
    margin: 15px 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.winner-selection {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin: 20px 0;
}

.winner-btn {
    padding: 15px 30px;
    font-size: 16px;
    font-weight: bold;
    border-radius: 10px;
    border: 2px solid;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.winner-btn.blue {
    border-color: #4fc3f7;
    color: #4fc3f7;
}

.winner-btn.red {
    border-color: #f44336;
    color: #f44336;
}

.winner-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.performance-adjustments {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
}

.performance-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
}

.performance-player:last-child {
    border-bottom: none;
}

.performance-change {
    font-weight: bold;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    min-width: 40px;
    text-align: center;
}

.performance-change.positive {
    background: rgba(76, 175, 80, 0.3);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.5);
}

.performance-change.negative {
    background: rgba(244, 67, 54, 0.3);
    color: #f44336;
    border: 1px solid rgba(244, 67, 54, 0.5);
}

.match-history {
    max-height: 250px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border-radius: 8px;
    margin: 15px 0;
}

.match-record {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
}

.match-record:last-child {
    border-bottom: none;
}

.reset-performance-btn {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    margin: 15px 0;
    transition: all 0.3s ease;
}

.reset-performance-btn:hover {
    background: linear-gradient(135deg, #f57c00, #ef6c00);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 124, 0, 0.3);
}

.nav-links {
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.nav-links a {
    color: #4fc3f7;
    text-decoration: none;
    margin: 0 15px;
    padding: 8px 16px;
    border-radius: 6px;
    transition: all 0.3s ease;
    display: inline-block;
}

.nav-links a:hover {
    background: rgba(79, 195, 247, 0.1);
    color: #81d4fa;
}

.nav-links strong {
    color: #ffd700;
    margin: 0 15px;
    padding: 8px 16px;
    background: rgba(255, 215, 0, 0.1);
    border-radius: 6px;
    border: 1px solid rgba(255, 215, 0, 0.3);
}

/* プレイヤーカード内のパフォーマンス表示 */
.performance-container {
    margin: 6px 0;
    padding: 5px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    border-left: 3px solid transparent;
}

.performance-container .adjustment-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.performance-adjustment {
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    min-width: 30px;
    text-align: center;
}

.performance-adjustment.positive {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
    border: 1px solid rgba(76, 175, 80, 0.4);
}

.performance-adjustment.negative {
    background: rgba(244, 67, 54, 0.2);
    color: #f44336;
    border: 1px solid rgba(244, 67, 54, 0.4);
}

.performance-adjustment:empty {
    background: rgba(128, 128, 128, 0.2);
    color: #999;
    border: 1px solid rgba(128, 128, 128, 0.4);
}

/* ===== セクショントグル機能スタイル ===== */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
    padding: 0 0 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.section-header:hover {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 10px 15px 10px 15px;
    margin: -10px -15px 5px -15px;
}

.section-header h2 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.4em;
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    transition: all 0.3s ease;
    min-width: 35px;
    text-align: center;
}

.toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

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

.section-content {
    margin-top: 15px;
    transition: all 0.3s ease;
    overflow: hidden;
}

.section-content.collapsed {
    display: none !important;
}

/* セクション表示状態のデフォルト設定 */
#teamSection {
    display: block !important; /* チーム分けは常に表示 */
}

#teamSection-content {
    display: block !important; /* チーム分け内容も常に表示 */
}

#inputSection {
    display: block !important; /* 入力セクションは常に表示 */
}

/* 折りたたまれた状態の視覚的フィードバック */
.section-header .toggle-btn {
    transition: transform 0.3s ease;
}

.section-header.collapsed .toggle-btn {
    transform: rotate(180deg);
}

/* セクション間のスペーシング調整 */
section {
    margin-bottom: 25px;
}

section:last-child {
    margin-bottom: 0;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .section-header h2 {
        font-size: 1.2em;
    }
    
    .toggle-btn {
        align-self: flex-end;
        padding: 6px 10px;
        font-size: 12px;
    }
}