/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    line-height: 1.6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
    background-color: #f5f5f5;
    color: #333;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}

/* Container */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0 16px;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007aff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 0 24px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

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

.nav-btn {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.2);
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

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

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* Filter Section */
.filter-section {
    background: white;
    padding: 16px;
    margin: 16px 16px 16px;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #f0f0f0;
}

.date-info {
    color: #666;
    font-size: 0.9rem;
}

.race-count {
    color: #007aff;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Race List */
.race-list {
    padding: 16px;
}

.race-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.race-card:active {
    transform: translateY(1px);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.1);
}

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

.race-grade {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.grade-a1 {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
}

.grade-a {
    background: linear-gradient(135deg, #4ecdc4, #44bd87);
}

.grade-b {
    background: linear-gradient(135deg, #45b7d1, #96ceb4);
}

.grade-other {
    background: linear-gradient(135deg, #778ca3, #a0b4d0);
}

.race-date {
    color: #007aff;
    font-weight: 600;
    font-size: 0.9rem;
}

.race-date.finished {
    color: #999;
    background: #f0f0f0;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.85rem;
}

.race-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 12px;
    line-height: 1.4;
}

.race-info {
    margin-bottom: 12px;
}

.race-time, .race-location {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
}

.race-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.race-item-tag {
    background: #f8f9fa;
    color: #495057;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    border: 1px solid #e9ecef;
}

/* No Data Message */
.no-data {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.no-data-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.no-data h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
    color: #666;
}

/* Error Message */
.error-message {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.error-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.retry-btn {
    background: #007aff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 16px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 0;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close {
    position: absolute;
    right: 16px;
    top: 16px;
    font-size: 24px;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    z-index: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
}

.close:hover {
    color: #000;
}

/* Race Detail */
.race-detail-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 20px 20px;
    border-radius: 16px 16px 0 0;
    position: relative;
}

.race-detail-header h2 {
    font-size: 1.3rem;
    margin-bottom: 12px;
    padding-right: 40px;
    line-height: 1.4;
}

.race-detail-info {
    padding: 24px 20px;
}

.info-item {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
}

.info-item strong {
    color: #333;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.info-item span {
    color: #666;
    font-size: 1rem;
}

.countdown {
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    padding: 16px;
    border-radius: 12px;
    text-align: center;
}

.countdown-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: #d63031 !important;
}

.race-items-detail {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

/* Registration Section */
.registration-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin: 20px 20px 0;
    border: 1px solid #f0f0f0;
}

.registration-header h3 {
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.registration-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    text-align: center;
}

.registration-status.open {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: white;
}

.registration-status.upcoming {
    background: linear-gradient(135deg, #fdcb6e, #e17055);
    color: white;
}

.registration-status.closed {
    background: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.registration-status.unavailable {
    background: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
}

.status-icon {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.status-text {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 4px;
}

.status-detail {
    font-size: 0.9rem;
    opacity: 0.9;
}

.registration-details {
    margin-bottom: 12px;
}

.registration-time,
.registration-method,
.contact-info {
    margin-bottom: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #007aff;
}

.registration-time strong,
.registration-method strong,
.contact-info strong {
    color: #333;
    display: block;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.registration-time span,
.registration-method span,
.contact-info span {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.4;
}

.race-actions {
    padding: 0 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-secondary {
    width: 100%;
    background: #f8f9fa;
    color: #666;
    border: 1px solid #dee2e6;
    padding: 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-secondary:active {
    background: #e9ecef;
}

.btn-outline {
    width: 100%;
    background: white;
    color: #007aff;
    border: 2px solid #007aff;
    padding: 14px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-outline:active {
    background: #f0f8ff;
}

.registration-btn {
    background: linear-gradient(135deg, #00b894, #00cec9) !important;
}

/* Search Section */
.search-section {
    margin: 20px 0;
    padding: 0 16px;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 12px 16px;
    padding-right: 40px;
    border: 2px solid #e0e0e0;
    border-radius: 25px;
    font-size: 16px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    outline: none;
}

.search-input:focus {
    border-color: #007aff;
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.2);
}

.search-input::placeholder {
    color: #999;
    font-size: 14px;
}

.clear-search {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.clear-search:hover {
    background: #f0f0f0;
    color: #666;
}

.clear-search:active {
    transform: scale(0.95);
}

/* Registration Status Badges */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-badge.open {
    background: rgba(52, 199, 89, 0.15);
    color: #34c759;
}

.status-badge.closed {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
}

.status-badge.finished {
    background: rgba(142, 142, 147, 0.15);
    color: #8e8e93;
}

.status-badge.info {
    background: rgba(0, 122, 255, 0.15);
    color: #007aff;
}

/* Footer */
.footer {
    background: white;
    padding: 24px 0;
    text-align: center;
    border-top: 1px solid #f0f0f0;
    margin-top: 32px;
}

.footer p {
    color: #999;
    font-size: 0.8rem;
    margin-bottom: 16px;
}

.share-section {
    margin-top: 12px;
}

.share-btn {
    background: linear-gradient(135deg, #00b894, #00cec9);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

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

.qr-code-image {
    width: 200px;
    height: 200px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 2px solid #f0f0f0;
    transition: transform 0.3s ease;
}

.qr-code-image:hover {
    transform: scale(1.05);
}

/* Mobile responsive for QR code */
@media (max-width: 480px) {
    .qr-code-image {
        width: 150px;
        height: 150px;
    }
}

/* Quick Navigation */
.quick-nav {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 16px;
}

.nav-link {
    color: #74b9ff;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.3s ease;
    font-size: 0.9rem;
    font-weight: 600;
}

.nav-link.active {
    background: #74b9ff;
    color: white;
}

.nav-link:hover {
    background: #0984e3;
    color: white;
}

/* Toast */
.toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s;
}

.toast.show {
    opacity: 1;
}

/* Main Content */
.main-content {
    min-height: 60vh;
    padding-bottom: 20px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 0 12px;
    }
    
    .header h1 {
        font-size: 1.3rem;
    }
    
    .race-card {
        padding: 16px;
        margin-bottom: 12px;
    }
    
    .race-name {
        font-size: 1rem;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
    
    .filter-section {
        margin: 12px 12px 0;
        padding: 12px;
    }
    
    .race-list {
        padding: 12px;
    }
}

/* iPhone X and above safe area */
@media (max-width: 480px) and (-webkit-min-device-pixel-ratio: 2) {
    .header {
        padding-top: max(20px, env(safe-area-inset-top));
    }
    
    .footer {
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
}

/* WeChat specific optimizations */
@media (max-width: 414px) {
    body {
        font-size: 16px; /* Prevent zoom on input focus */
    }
    
    .race-card {
        border-radius: 12px;
    }
    
    .modal-content {
        border-radius: 12px;
    }
}

/* Dark mode support (if device supports it) */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #e0e0e0;
    }
    
    .race-card {
        background: #2d2d2d;
        border-color: #404040;
    }
    
    .filter-section {
        background: #2d2d2d;
        border-color: #404040;
    }
    
    .modal-content {
        background: #2d2d2d;
    }
    
    .race-name {
        color: #e0e0e0;
    }
    
    .footer {
        background: #2d2d2d;
        border-color: #404040;
    }
}

/* Month Calendar Filter */
.month-calendar {
    margin: 0 0 20px 0;
    padding: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
}

.month-calendar h4 {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 16px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Year Selection */
.year-selection {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e9ecef;
}

.year-item {
    padding: 10px 8px;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f0f8ff;
    color: #1976d2;
    border: 2px solid #e3f2fd;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.year-item:hover {
    background: #e3f2fd;
    border-color: #bbdefb;
    transform: translateY(-1px);
}

.year-item.active {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    color: white;
    border-color: #1976d2;
    box-shadow: 0 3px 12px rgba(25, 118, 210, 0.3);
}

.year-item:first-child {
    background: #fff3e0;
    color: #f57c00;
    border-color: #ffcc02;
}

.year-item:first-child.active {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
    border-color: #ff9800;
}

.calendar-months {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.month-item {
    padding: 10px 8px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9fa;
    color: #666;
    border: 1px solid #e9ecef;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.month-item:hover {
    background: #e3f2fd;
    color: #1976d2;
    border-color: #bbdefb;
    transform: translateY(-1px);
}

.month-item.active {
    background: linear-gradient(135deg, #007aff, #0056d2);
    color: white;
    border-color: #007aff;
    box-shadow: 0 3px 12px rgba(0, 122, 255, 0.3);
}

.month-item:first-child {
    grid-column: 1 / -1;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    font-weight: 600;
    font-size: 15px;
}

.month-item:first-child.active {
    background: linear-gradient(135deg, #34c759, #28a745);
    border-color: #34c759;
}

/* Mobile optimizations */
@media (max-width: 480px) {
    .month-calendar {
        margin: 0 -4px 16px -4px;
        padding: 12px;
        border-radius: 8px;
    }
    
    .year-selection {
        gap: 6px;
        margin-bottom: 12px;
        padding-bottom: 12px;
    }
    
    .year-item {
        padding: 8px 6px;
        font-size: 13px;
        min-height: 40px;
    }
    
    .calendar-months {
        gap: 8px;
    }
    
    .month-item {
        padding: 8px 6px;
        font-size: 13px;
        min-height: 40px;
    }
    
    .month-item:first-child {
        font-size: 14px;
    }
}

/* No races message */
.no-races {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.no-races p:first-child {
    font-size: 18px;
    margin-bottom: 8px;
}

.no-races p:last-child {
    font-size: 14px;
    color: #666;
}