@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700&display=swap');

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans KR', sans-serif;
    background-color: #f8f9fa;
    color: #333;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
    overflow-x: hidden;
}

.container {
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    background-color: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

h1 { text-align: center; color: #007bff; margin-bottom: 10px; }
p { text-align: center; color: #6c757d; margin-bottom: 30px; line-height: 1.6; }

.controls {
    display: grid;
    /* --- 수정된 부분 --- */
    grid-template-areas:
        "view-mode search"
        "selection selection"
        "sorting sorting"      /* 정렬 버튼을 위한 'sorting' 영역 추가 */
        "functions functions";  /* 이미지 저장 버튼은 'functions' 영역 사용 */
    grid-template-columns: auto 1fr;
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 8px;
    align-items: center;
}

.view-mode-container {
    grid-area: view-mode;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.selection-container {
    grid-area: selection;
}
#comparisonSelection, #singleSelection {
    display: flex;
    gap: 15px;
    width: 100%;
}
.selection-item {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.selection-item label {
    font-weight: bold;
    white-space: nowrap;
}
#yearSelector, #monthWeekSelector, #dataSelector {
    padding: 10px;
    border: 1px solid #ced4da;
    background-color: #ffffff;
    color: #495057;
    border-radius: 5px;
    font-size: 14px;
    width: 100%;
}

.search-container { grid-area: search; }
#searchInput { width: 100%; box-sizing: border-box; padding: 10px; border: 1px solid #ced4da; background-color: #ffffff; color: #495057; border-radius: 5px; font-size: 14px; }
#searchInput::placeholder { color: #6c757d; }

.function-buttons {
    grid-area: functions;
}
#saveAsImageBtn {
    border: none; padding: 10px 20px; border-radius: 5px; font-size: 15px; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease;
    background-color: #28a745; color: white;
    width: 100%;
    box-sizing: border-box;
}

.table-container { overflow-x: auto; }
#resultsTable { width: 100%; border-collapse: collapse; margin-top: 20px; }
#resultsTable th, #resultsTable td { padding: 12px 15px; text-align: center; border-bottom: 1px solid #dee2e6; vertical-align: middle; }
#resultsTable th { background-color: #007bff; color: #ffffff; font-weight: bold; }
#resultsTable tbody tr:nth-child(even):not(.rank-up):not(.rank-down) { background-color: #f8f9fa; }

tr.rank-up { background: linear-gradient(to right, rgb(240, 161, 161), transparent); }
tr.rank-down { background: linear-gradient(to right, rgb(160, 205, 241), transparent); }

tr.rank-up .rank-change { color: red; }
tr.rank-down .rank-change { color: rgb(0, 140, 255); }
tr.rank-same .rank-change { color: #6c757d; }
tr.rank-new .rank-change { color: #629b41; font-weight: bold; }

.no-results { color: #6c757d; font-weight: bold; padding: 30px 0; text-align: center; font-size: 1.1em; }

.table-container.single-view .rank-change { display: none; }

.tgall-icon {
    background-color: #ffc107;
    color: #212529;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    margin-left: 8px;
    display: inline-block;
}

/* 유대결전 페이지용 추가 스타일 */
.sort-controls {
    grid-area: sorting; /* --- 수정된 부분 --- */
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.sort-controls span { font-weight: bold; color: #6c757d; }
.sort-btn { border: 1px solid #ced4da; background-color: transparent; color: #495057; padding: 8px 12px; border-radius: 5px; font-size: 14px; font-weight: bold; cursor: pointer; transition: background-color 0.3s ease; }
.sort-btn.active { background-color: #007bff; color: #ffffff; border-color: #007bff; }

.history-link {
    color: inherit; /* 부모 요소의 색상을 상속받음 */
    text-decoration: none; /* 밑줄 제거 */
}

.history-link:hover {
    text-decoration: underline; /* 마우스를 올리면 밑줄 표시 */
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .container {
        padding: 15px;
    }
    h1 {
        font-size: 1.8em;
    }
    .controls {
        grid-template-areas:
            "view-mode"
            "search"
            "selection"
            "sorting"   /* --- 수정된 부분 --- */
            "functions";
        grid-template-columns: 1fr;
    }
    #comparisonSelection, #singleSelection {
        flex-direction: column;
        align-items: stretch;
    }
    #resultsTable th, #resultsTable td {
        padding: 8px 10px;
        font-size: 0.9em;
    }
}