:root {
    --primary-gradient: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
    --secondary-gradient: linear-gradient(135deg, #10B981 0%, #059669 100%);
    --success-gradient: linear-gradient(135deg, #10B981 0%, #059669 100%);
    --danger-gradient: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    --info-gradient: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
    --warning-gradient: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    --bg-gradient: linear-gradient(135deg, #FFFFFF 0%, #F9FAFB 100%);
    --card-bg: rgba(255, 255, 255, 0.98);
    --text-primary: #111827;
    --text-secondary: #4B5563;
    --text-muted: #6B7280;
    --border-color: #E5E7EB;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

body {
    font-family: 'Microsoft YaHei', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 80%, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(30, 64, 175, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 40% 40%, rgba(20, 184, 166, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

.header {
    background: transparent;
    color: black;
    padding: 40px 20px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.header-content {
    position: relative;
    z-index: 1;
    animation: fadeInDown 0.8s ease-out;
}

.header h1 {
    font-size: 2.2em;
    font-weight: 700;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}

.header p {
    font-size: 1.1em;
    opacity: 0.8;
    font-weight: 300;
}

.controls {
    background: var(--card-bg);
    padding: 20px 30px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.controls-left {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.controls-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.current-time {
    font-size: 1.3em;
    font-weight: 600;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
    gap: 10px;
}

.current-time::before {
    content: '';
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
}

.mode-selector {
    display: flex;
    gap: 12px;
    align-items: center;
}

.mode-btn {
    background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
}

.mode-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.mode-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.mode-btn:hover::before {
    left: 100%;
}

.mode-btn:active {
    transform: translateY(0);
}

.mode-btn.active {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
}

.simulation-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.simulation-controls.hidden {
    display: none;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-group label {
    font-size: 0.85em;
    color: var(--text-muted);
}

.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9em;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #0EA5E9;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

.btn {
    background: linear-gradient(135deg, #0EA5E9 0%, #0284C7 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.95em;
    font-weight: 500;
    font-family: inherit;
    transition: all 0.5s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
    border-right: 8px solid currentColor;
    margin-left: 8px;
    transition: all 0.5s ease;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.8s ease;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.1), 0 6px 10px -3px rgba(0, 0, 0, 0.05);
    background: linear-gradient(135deg, #0284C7 0%, #0EA5E9 100%);
}

.btn:hover::before {
    left: 100%;
}

.btn:hover::after {
    transform: translateX(3px);
}

.btn:active {
    transform: translateY(0);
    transition: all 0.2s ease;
}

.btn-success {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    color: white;
    transition: all 0.5s ease;
}

.btn-success:hover {
    background: linear-gradient(135deg, #059669 0%, #10B981 100%);
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.1), 0 6px 10px -3px rgba(0, 0, 0, 0.05);
}

.btn-warning {
    background: linear-gradient(135deg, #F59E0B 0%, #D97706 100%);
    color: white;
    transition: all 0.5s ease;
}

.btn-warning:hover {
    background: linear-gradient(135deg, #D97706 0%, #F59E0B 100%);
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.1), 0 6px 10px -3px rgba(0, 0, 0, 0.05);
}

.btn-secondary {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    color: white;
    transition: all 0.5s ease;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #475569 0%, #64748b 100%);
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -5px rgba(0, 0, 0, 0.1), 0 6px 10px -3px rgba(0, 0, 0, 0.05);
}

.btn-exit {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent !important;
    color: black !important;
    border: none !important;
    box-shadow: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}

.btn-exit svg {
    stroke: black;
    fill: none;
    width: 20px;
    height: 20px;
}

.line-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 30px 20px;
    overflow-x: auto;
}

.line-diagram {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 30px 30px 60px;
    min-height: 450px;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.8);
    animation: fadeInUp 0.6s ease-out;
    width: auto;
    min-width: 100%;
    white-space: nowrap;
}

/* Anchor station UI to the same screen coordinate as the SVG station dots. */
.station {
    --station-line-gap: 46px;
    --station-name-gap: 16px;
    width: auto;
    min-width: 80px;
    min-height: 0;
    padding: 0;
    display: block;
    overflow: visible;
    position: absolute;
    transform: translateX(-50%);
    text-align: center;
    z-index: 50; /* 设置为中间层级 */
    transition: all var(--transition-normal);
}

.station:hover {
    transform: translateX(-50%) scale(1.1);
}

.station-dot {
    position: absolute;
    top: 0;
    left: 50%;
    margin: 0;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: #0EA5E9;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
    display: block;
    z-index: 1; /* 设置为最低层级 */
}

.station:hover .station-dot {
    transform: translate(-50%, -50%) scale(1.3);
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
    z-index: 1;
}

.station-up .station-dot,
.station-down .station-dot {
    position: absolute;
    left: 50%;
    margin: 0;
    transform: translate(-50%, -50%);
    width: 12px;
    height: 12px;
    background: #0EA5E9;
    border-radius: 50%;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
    display: block;
    z-index: 1; /* 设置为最低层级 */
}

.station-up .station-dot {
    top: calc(-1 * var(--station-line-gap));
}

.station-down .station-dot {
    top: var(--station-line-gap);
}

.station-name {
    position: absolute;
    left: 50%;
    margin: 0;
    transform: translateX(-50%);
    white-space: nowrap;
    font-size: 0.85em;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    transition: all var(--transition-fast);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    line-height: 1.5;
    text-align: center;
    max-width: 120px;
    overflow: visible;
}

.station-up .station-name {
    bottom: calc(var(--station-line-gap) + var(--station-name-gap));
    transform: translateX(-50%);
}

.station-down .station-name {
    top: calc(var(--station-line-gap) + var(--station-name-gap));
    transform: translateX(-50%);
    position: absolute;
    left: 50%;
}

.station-name:hover {
    color: #0EA5E9;
    background: rgba(14, 165, 233, 0.1);
}

.train {
    position: absolute;
    width: 36px;
    height: 36px;
    cursor: pointer;
    transition: all var(--transition-normal);
    z-index: 200; /* 设置为最高层级 */
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    overflow: hidden;
    transform: none;
}

.train img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.train:hover {
    transform: scale(1.5);
    z-index: 200;
    box-shadow: var(--shadow-xl);
}

.train-up {
    border: 3px solid #10b981;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.train-down {
    border: 3px solid #ef4444;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.train-stopped {
    border: 3px solid #3b82f6 !important;
    animation: pulse-train 2s ease-in-out infinite;
}

@keyframes pulse-train {
    0%, 100% { transform: scale(1); box-shadow: var(--shadow-lg); }
    50% { transform: scale(1.15); box-shadow: 0 0 20px rgba(59, 130, 246, 0.5); }
}

.train-stopped:hover {
    animation: none;
    transform: scale(1.5);
}

.train-tooltip {
    position: absolute;
    background: rgba(30, 41, 59, 0.95);
    color: white;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85em;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast);
    z-index: 100;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease-out;
}

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

.modal-content {
    background-color: var(--card-bg);
    margin: 5% auto;
    padding: 0;
    border-radius: var(--radius-xl);
    width: 85%;
    max-width: 850px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    animation: slideInUp 0.4s ease-out;
    border: 1px solid rgba(255, 255, 255, 0.8);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px 30px;
    background: var(--primary-gradient);
    color: white;
}

.modal-title {
    font-size: 1.5em;
    font-weight: 600;
}

.close {
    color: white;
    font-size: 1.8em;
    font-weight: 300;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
    background: rgba(255, 255, 255, 0.1);
}

.close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal-body {
    padding: 30px;
    max-height: 60vh;
    overflow-y: auto;
}

.schedule-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 15px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.schedule-table th {
    background: linear-gradient(135deg, #334155 0%, #1e293b 100%);
    color: white;
    padding: 14px 12px;
    text-align: left;
    font-weight: 500;
    font-size: 0.9em;
    letter-spacing: 0.02em;
}

.schedule-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.schedule-table tr:last-child td {
    border-bottom: none;
}

.schedule-table tbody tr {
    transition: all var(--transition-fast);
}

.schedule-table tbody tr:hover {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.clickable {
    color: #0EA5E9;
    cursor: pointer;
    text-decoration: none;
    font-weight: 500;
    transition: all var(--transition-fast);
    position: relative;
}

.clickable::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-gradient);
    transition: width var(--transition-normal);
}

.clickable:hover {
    color: #0284C7;
}

.clickable:hover::after {
    width: 100%;
}

.loading {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
    font-size: 1.2em;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.loading::before {
    content: '';
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: #0EA5E9;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.legend {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 25px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    color: var(--text-primary);
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    box-shadow: var(--shadow-sm);
}

.legend-up {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.legend-down {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.legend-stopped {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    animation: pulse-legend 2s ease-in-out infinite;
}

@keyframes pulse-legend {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@media (max-width: 768px) {
    .header {
        padding: 30px 15px;
    }

    .header h1 {
        font-size: 1.6em;
    }

    .controls {
        flex-direction: column;
        gap: 15px;
        padding: 15px;
    }

    .controls-left, .controls-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .mode-selector {
        width: 100%;
        justify-content: center;
    }

    .simulation-controls {
        flex-wrap: wrap;
        justify-content: center;
    }

    .btn {
        padding: 10px 18px;
        font-size: 0.9em;
    }

    .line-diagram {
        padding: 20px;
        min-height: 280px;
    }

    .modal-content {
        width: 95%;
        margin: 10% auto;
    }

    .modal-header {
        padding: 20px;
    }

    .modal-body {
        padding: 20px;
    }

    .legend {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }

    .schedule-table {
        font-size: 0.85em;
    }

    .schedule-table th, .schedule-table td {
        padding: 10px 8px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}