body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    max-width: none;
    min-width: 320px;
    margin: 0;
    padding: 0;
    background: #f5f5f5;
    min-height: 100vh;
    color: #333;
}

.container {
    background: #ffffff;
    border-radius: 0;
    padding: 10px;
    box-shadow: none;
    border: none;
    width: 100%;
    max-width: none;
    margin: 0;
}

h1 {
    color: #1B5E20;
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.8em;
    font-weight: 300;
}

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

label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    color: #333;
}

input[type="date"], input[type="text"], input[type="number"], select {
    width: auto;
    max-width: 200px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
    background: #fff;
}

#presetSelect {
    max-width: 300px;
}

#raceMonth, #raceWeek, #dayOfWeek, #racePlace, #raceCourse, #raceGrade, #raceNumber {
    max-width: 150px;
}

#startDate, #endDate {
    max-width: 150px;
}

#raceName {
    max-width: 100%;
    width: 100%;
}

/* 追加: 重み用プルダウンの幅を調整 */
.weight-form select {
    max-width: 100px; /* 重み用セレクトボックスは狭めに */
}

input[type="date"]:focus, input[type="text"]:focus, input[type="number"]:focus, select:focus {
    border-color: #666;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 102, 102, 0.2);
}

.date-range {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.date-range .form-group {
    flex: 1;
    min-width: 100px;
}

.form-row {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 120px;
}

button {
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    background-color: #1B5E20;
    color: white;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
    width: 100%;
}

button:hover {
    background-color: #2E7D32;
}

@media (hover: none) and (pointer: coarse) {
    button:hover {
        background-color: #1B5E20;
    }
}

#resultArea {
    margin-top: 15px;
    background: #fafafa;
    border-radius: 4px;
    padding: 10px;
    border: 1px solid #e0e0e0;
    overflow-x: auto;
    width: 100%;
    box-sizing: border-box;
}

#resultArea table {
    width: 100%;
    min-width: 800px;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #ddd;
    font-size: 14px;
    table-layout: auto;
}

#resultArea th, #resultArea td {
    padding: 6px 8px;
    text-align: left;
    border: 1px solid #ddd;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#resultArea th {
    background-color: #f0f0f0;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    position: relative;
}

#resultArea th:hover {
    background-color: #e0e0e0;
}

#resultArea th::after {
    content: '';
    margin-left: 5px;
    display: inline-block;
    vertical-align: middle;
}

#resultArea th.asc::after {
    content: '↑';
}

#resultArea th.desc::after {
    content: '↓';
}

#resultArea tr:nth-child(even) {
    background-color: #f9f9f9;
}

#resultArea tr:hover {
    background-color: #f0f0f0;
}

/* 拡大したローディングスピナー（背景をより透過） */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.7); /* 透明度を0.9から0.7に変更 */
    z-index: 1000;
    gap: 20px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 6px solid #f3f3f3;
    border-top: 6px solid #1B5E20;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-message {
    font-size: 18px;
    font-weight: 500;
    color: #333;
}

.error, .info {
    padding: 15px;
    text-align: center;
    border-radius: 4px;
    border: 1px solid;
}

.error {
    background: #f8f8f8;
    color: #333;
    border-color: #ccc;
}

.info {
    background: #f8f8f8;
    color: #666;
    border-color: #ddd;
}

.id-link {
    color: #0066cc;
    text-decoration: underline;
    cursor: pointer;
    font-weight: bold;
}

.horse-results {
    margin-top: 15px;
    padding: 10px;
    background: #f0f8ff;
    border: 1px solid #b3d9ff;
    border-radius: 4px;
}

.horse-results h3 {
    margin-top: 0;
    color: #0066cc;
    border-bottom: 2px solid #0066cc;
    padding-bottom: 8px;
}

.back-link {
    display: inline-block;
    margin-bottom: 10px;
    padding: 8px 16px;
    background: #1B5E20;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.back-link:hover {
    background-color: #2E7D32;
}

.horse-table {
    margin-top: 10px;
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.horse-table th, .horse-table td {
    padding: 6px 8px;
    border: 1px solid #ddd;
}

.horse-table th {
    background-color: #d0e5ff;
    cursor: pointer;
}

.horse-table th:hover {
    background-color: #c0d5ff;
}

.horse-table th.asc::after {
    content: '↑';
    margin-left: 5px;
}

.horse-table th.desc::after {
    content: '↓';
    margin-left: 5px;
}

.horse-table tr:nth-child(even) {
    background-color: #f0f8ff;
}

.section-title {
    background: #e6e6e6;
    padding: 8px 12px;
    border-radius: 4px;
    margin: 10px 0 8px 0;
    font-weight: 600;
    color: #333;
    font-size: 1.1em;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.detail-item {
    padding: 6px;
    background: #f8f8f8;
    border-radius: 4px;
    border: 1px solid #e0e0e0;
}

.detail-label {
    font-weight: 600;
    color: #666;
    font-size: 0.9em;
}

.detail-value {
    font-size: 1em;
    margin-top: 4px;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px 0;
    gap: 5px;
    flex-wrap: wrap;
}

.pagination-button {
    padding: 6px 12px;
    border: 1px solid #ddd;
    background: white;
    color: #333;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 14px;
}

.pagination-button:hover:not(:disabled) {
    background: #2E7D32;
    color: white;
}

.pagination-button:disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

.pagination-button.active {
    background: #1B5E20;
    color: white;
    border-color: #1B5E20;
}

.pagination-info {
    margin: 0 10px;
    font-weight: 600;
    color: #666;
    font-size: 14px;
}

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 8px 0;
}

.page-size-selector select {
    width: auto;
    padding: 5px 8px;
}

.stats-button {
    margin-top: 10px;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    background-color: #1B5E20;
    color: white;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s;
    width: 100%;
}

.stats-button:hover {
    background-color: #2E7D32;
}

.stats-section {
    margin-top: 15px;
    background: #fafafa;
    border-radius: 4px;
    padding: 10px;
    border: 1px solid #e0e0e0;
    width: 100%;
    margin-left: 0;
    box-sizing: border-box;
}

.stats-table {
    width: 100%;
    max-width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    font-size: 14px;
    table-layout: auto;
}

.stats-table th, .stats-table td {
    padding: 8px 6px;
    text-align: center;
    border: 1px solid #ddd;
    white-space: nowrap;
}

.stats-table th {
    background-color: #f0f0f0;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
}

.stats-table th:hover {
    background-color: #e0e0e0;
}

.stats-table th.asc::after {
    content: '↑';
    margin-left: 5px;
}

.stats-table th.desc::after {
    content: '↓';
    margin-left: 5px;
}

.stats-table td {
    font-size: 13px;
}

.frame-1 { background-color: #FFFFFF; color: #000000; font-weight: bold; }
.frame-2 { background-color: #000000; color: #FFFFFF; font-weight: bold; }
.frame-3 { background-color: #FF0000; color: #000000; font-weight: bold; }
.frame-4 { background-color: #0000FF; color: #FFFFFF; font-weight: bold; }
.frame-5 { background-color: #FFFF00; color: #000000; font-weight: bold; }
.frame-6 { background-color: #008000; color: #FFFFFF; font-weight: bold; }
.frame-7 { background-color: #FFA500; color: #000000; font-weight: bold; }
.frame-8 { background-color: #FFC1CC; color: #000000; font-weight: bold; }

.weight-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.weight-form .form-group {
    flex: 1;
    min-width: 100px;
}

@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .container {
        padding: 5px;
        border-radius: 0;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 10px;
    }
    
    .form-row {
        gap: 3px;
    }
    
    .form-row .form-group {
        min-width: 100%;
        flex: none;
    }
    
    .date-range .form-group {
        min-width: 100%;
        flex: none;
    }
    
    #resultArea {
        padding: 5px;
        margin-top: 10px;
    }
    
    #resultArea table, .horse-table, .stats-table {
        font-size: 12px;
        overflow-x: auto;
        display: block;
        white-space: nowrap;
    }
    
    #resultArea th, #resultArea td,
    .horse-table th, .horse-table td {
        padding: 4px 6px;
        min-width: 80px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .stats-section {
        width: 100%;
        margin-left: 0;
        padding: 5px;
    }
    
    .stats-table th, .stats-table td {
        padding: 6px 4px;
        font-size: 11px;
        min-width: 40px;
        white-space: normal;
        word-break: break-word;
    }
    
    .pagination {
        flex-direction: column;
        gap: 5px;
    }
    
    .pagination-button {
        width: 100%;
        padding: 10px;
    }
    
    .detail-grid {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .back-link {
        width: 100%;
        text-align: center;
    }
    
    button {
        padding: 12px;
        font-size: 16px;
    }
    
    .weight-form {
        gap: 5px;
    }

    input[type="date"], input[type="text"], input[type="number"], select {
        width: 100%;
        max-width: none;
    }
}

@media (max-width: 480px) {
    body {
        min-width: auto;
    }
    
    .container {
        box-shadow: none;
        border: none;
        padding: 3px;
    }
    
    h1 {
        font-size: 1.3em;
    }
    
    #resultArea {
        padding: 3px;
    }
    
    #resultArea table, .horse-table, .stats-table {
        overflow-x: auto;
        display: block;
    }
    
    .stats-section {
        width: 100%;
        margin-left: 0;
        padding: 3px;
    }
    
    .stats-table th, .stats-table td {
        min-width: 35px;
        padding: 4px 2px;
        font-size: 10px;
    }
    
    input[type="date"], input[type="text"], input[type="number"], select {
        padding: 6px;
        font-size: 14px;
    }
}